/* This program is a Sun version of the FITS format converter to take NICMOS2 images extracted from ramp runs. The files are assumed to contain floating point nos. All files in a directory will be converted and will have .fits appended to indicate which are the FITS format images. usage: fitsarch directory created: 08/11/89 mjr { drawing from T. Greene's b2f and Irene's FITS } modified: 11/03/97 mjr revised for FSPEC modified: 11/03/97 mjr revised for newer 256x256 format */ #include #include #include #include #define TRUE 1 #define FALSE 0 #define MAXSTR 180 #define FOREVER TRUE #define NBYTES 2880 /* Fits block size */ #define NICMOS3 TRUE /* Definitions to load for 256x256 version */ #if NICMOS3 #define NUM_PIX 65536 /* 256x256 w/ no overscans */ #define B_SIZE 131072 #define R_WFRAME TRUE #define MAXCOLS 256 #define MAXROWS 256 #define NBLOCKS 46 /* No. of 2880-byte blocks for biggest image */ #endif short int libuf[MAXCOLS*MAXROWS]; short int sibuf[MAXCOLS*MAXROWS]; char buf[NBYTES],buf2[NBYTES]; char ext[] = ".fits"; char ext2[] = ".dat"; char *name[3000]; char dummy[] = {"000000000"}; void main(argc,argv) int argc; char *argv[]; { int t_ok,t_stat,handle,n_samp,n_line,err_no,n,obs_no; int nframes,hdr_len,num_read,i,l,j,wframe,deg,min; long int nbyte; float dmax,dmin,itime,am,fsec; char cur_path[MAXSTR],*p,*hdstr,time[30],date[30],temp[80]; char c, title[80], data[MAXSTR], filename[MAXSTR], filter[13]; char swap_bytes = TRUE, t_append = TRUE, answer[5]; char l_int = TRUE, *fname[3000],outname[105],gain[MAXSTR],sign[2]; char revs[MAXSTR], lst[30], tele_ra[30],tele_dec[30]; char telescope[4],tele[10]; FILE *fpin,*fopen(),*fptest,*fplog; char *malloc(); void float_swap(); void strip(),append(),fixname(); if ( argc != 3 ) { fprintf(stderr,"Error in fspecfit. Usage: fspecfit filelist telescope.\n"); exit(0); } sscanf(argv[2],"%s",telescope); sscanf(argv[2],"%s",tele); append(tele); /* Pad data buffers with zeros to end of NBLOCKS*2880 */ for (i=0; i0 ) fname[nframes]=fname[nframes-1]+l+1; /* Inc name ptr */ l = strlen(filename); strcpy(fname[nframes],filename); nframes++; } fclose(fpin); nframes--; for (j=0; j dmax ) dmax = (float)sibuf[i]; if ( (float)sibuf[i] < dmin ) dmin = (float)sibuf[i]; } if ( swap_bytes ) { swab(sibuf, libuf, MAXCOLS*MAXROWS*2); } for (i=0; i<2880; buf[i++] = ' '); hdstr = "SIMPLE = T"; p = buf; strncpy(p, hdstr, 30) ; hdstr = "BITPIX = 16"; p = buf+80; strncpy(p, hdstr, 30) ; hdstr = "NAXIS = 2"; p = buf+160; strncpy(p, hdstr, 30) ; hdstr = "NAXIS1 = 256"; p = buf+240; strncpy(p, hdstr, 30) ; hdstr = "NAXIS2 = 256"; p = buf+320; strncpy(p, hdstr, 30) ; hdstr = "BSCALE = 1.0E00"; p = buf+400; strncpy(p, hdstr, 30) ; hdstr = "BZERO = 0.0E00"; p = buf+480; strncpy(p, hdstr, 30) ; hdstr = "BUNIT = 'ADU/PIX ' "; p = buf+560; strncpy(p, hdstr, 30) ; hdstr = "BLANK = -32767"; p = buf+640; strncpy(p, hdstr, 30) ; hdstr = "COMMENT = ' "; p = buf+720 ; strncpy(p, hdstr, 30); p = buf + 731; sprintf(data,"Coadds = %d'",wframe); l = strlen(data); strncpy(p, data, l); hdstr = "DATAMAX = "; p = buf+800; strncpy(p, hdstr, 50) ; sprintf(&(data[0]), "%9.1f", (float)dmax); p = buf+821; strncpy(p, data, 9) ; hdstr = "DATAMIN = "; p = buf+880; strncpy(p, hdstr, 50) ; sprintf(&(data[0]), "%9.1f", (float)dmin); p = buf+901; strncpy(p, data, 9) ; hdstr = "DATE-OBS= ' "; p = buf + 960; strncpy(p, hdstr, 30) ; p = buf + 971; i = strlen(date); strncpy(p, date, i); hdstr = "OBJECT = ' "; p = buf+1040; strncpy(p, hdstr, 30) ; p = buf + 1051; l = strlen(title); if ( l > 70 ) l = 70; strncpy(p, title, l); hdstr = "INSTRUME= '256x256 ' "; p = buf+1120; strncpy(p, hdstr, 50) ; hdstr = "FILTER = ' ' "; p = buf+1200; strncpy(p, hdstr, 30) ; p = buf + 1211; i = strlen(filter); strncpy(p, filter, i); hdstr = "ITIME = "; p = buf+1280; strncpy(p, hdstr, 30) ; sprintf(&(data[0]),"%9.1f", itime); p = buf + 1301; strncpy(p, data, 9); hdstr = "IRAFNAME= ' "; p = buf+1360; strncpy(p, hdstr, 50) ; p = buf+1371; i = strlen(filename); strncpy(p, filename, i) ; hdstr = "TIME-OBS= ' "; p = buf + 1440; strncpy(p, hdstr, 30); p = buf + 1451; l = strlen(time); strncpy(p, time, l); hdstr = "TELE RA = ' "; p = buf + 1520; strncpy(p, hdstr, 30); p = buf + 1531; l = strlen(tele_ra); strncpy(p, tele_ra, l); hdstr = "TELE DEC= ' "; p = buf + 1600; strncpy(p, hdstr, 30); p = buf + 1611; l = strlen(tele_dec); strncpy(p, tele_dec, l); hdstr = "LST = ' "; p = buf + 1680; strncpy(p, hdstr, 30); p = buf + 1691; l = strlen(lst); strncpy(p, lst, l); hdstr = "AIRMASS = "; p = buf+1760; strncpy(p, hdstr, 30) ; sprintf(&(data[0]),"%9.2f", am); p = buf + 1771; strncpy(p, data, 9); hdstr = "TELESCOP= ' "; p = buf + 1840; strncpy(p, hdstr, 30); p = buf + 1851; l = strlen(tele); strncpy(p,tele , l); hdstr = "END "; p = buf+1920; strncpy(p, hdstr, 40) ; hdr_len = 2880; fwrite(buf,sizeof(char),NBYTES,fptest); /* Now work on transferring data to disk. */ n_samp = NBLOCKS; for (i=0; i 0); /* delete it */ if ( sign < 0 ) s[i++] = '-'; s[i] = '\0'; reverse(s); } void reverse(s) /* reverse string s in place. K&R p.59 */ char s[]; { int c, i, j; for (i = 0, j =strlen(s) - 1; i < j; i++, j--) { c = s[i]; s[i] = s[j]; s[j] = c; } } void float_swap(array) float *array; { int j; char temp[4]; union { /* This hack is used for byte-swapping. */ char t_num[4]; float num; } nums; for (j=0; j