21 #define ERROR_REPORT(er,f,l) if(global_error_report) (*global_error_report)(er,f,l);
46 if(gmtime_r(&t0, &uttime) == 0)
48 ERROR_REPORT(
"Error getting UT time (gmtime_r returned 0).", __FILE__, __LINE__);
52 sprintf(buffer,
"%04i%02i%02i%02i%02i%02i%06li",uttime.tm_year+1900, uttime.tm_mon+1, uttime.tm_mday, uttime.tm_hour, uttime.tm_min, uttime.tm_sec, tv->tv_usec);
64 tv.tv_sec = ts->tv_sec;
65 tv.tv_usec= (
long) (ts->tv_nsec/1e3 + .5);
69 if(gmtime_r(&t0, &uttime) == 0)
71 ERROR_REPORT(
"Error getting UT time (gmtime_r returned 0).", __FILE__, __LINE__);
75 sprintf(buffer,
"%04i%02i%02i%02i%02i%02i%06li",uttime.tm_year+1900, uttime.tm_mon+1, uttime.tm_mday, uttime.tm_hour, uttime.tm_min, uttime.tm_sec, tv.tv_usec);
80 int write_visao_fits_aosys_header(fitsfile * outfptr,
visao_imheader * head)
88 fits_update_key(outfptr, TSTRING,
"OBSINST",(
void*)(head->aosb->obsinst),
"Observer Institution", &status);
89 fits_update_key(outfptr, TSTRING,
"OBSNAME",(
void*)(head->aosb->obsname),
"Observer Name", &status);
90 fits_update_key(outfptr, TSTRING,
"OBJECT",(
void*)(head->aosb->catobj),
"Object Name", &status);
91 fits_update_key(outfptr, TINT,
"UT",(
void*)(&head->aosb->ut),
"UT from TCS (sec since midnight)", &status);
92 fits_update_key(outfptr, TINT,
"ST",(
void*)(&head->aosb->st),
"ST from TCS (sec since midnight)", &status);
93 fits_update_key(outfptr, TDOUBLE,
"EPOCH",(
void*)&head->aosb->epoch,
"Epoch of target coordinates", &status);
94 fits_update_key(outfptr, TDOUBLE,
"RA",(
void*)&head->aosb->ra,
"Telescope pointing RA (degrees)", &status);
95 fits_update_key(outfptr, TDOUBLE,
"DEC",(
void*)&head->aosb->dec,
"Telescope pointing DEC (degrees)", &status);
96 fits_update_key(outfptr, TDOUBLE,
"CATRA",(
void*)&head->aosb->catra,
"Catalog input RA (degrees)", &status);
97 fits_update_key(outfptr, TDOUBLE,
"CATDEC",(
void*)&head->aosb->catdec,
"Catalog input DEC (degrees)", &status);
98 fits_update_key(outfptr, TDOUBLE,
"AZIMUTH",(
void*)&head->aosb->az,
"Telescope azimuth (degrees)", &status);
99 fits_update_key(outfptr, TDOUBLE,
"ELEVATIO",(
void*)&head->aosb->el,
"Telescope elevation (degrees)", &status);
100 fits_update_key(outfptr, TDOUBLE,
"PARANG",(
void*)&head->aosb->pa,
"Par. ang. at end of obs. (degrees)", &status);
101 fits_update_key(outfptr, TDOUBLE,
"AM",(
void*)&head->aosb->am,
"Airmass at end of observation", &status);
102 fits_update_key(outfptr, TDOUBLE,
"HA",(
void*)&head->aosb->ha,
"Hour angle at end of observation", &status);
103 fits_update_key(outfptr, TDOUBLE,
"ZD",(
void*)&head->aosb->zd,
"Zenith distance at end of observation", &status);
104 fits_update_key(outfptr, TDOUBLE,
"ROTANG",(
void*)&head->aosb->rotang,
"Rotator angle at end of observation (degrees)", &status);
105 fits_update_key(outfptr, TDOUBLE,
"ROTOFF",(
void*)&head->aosb->rotoffset,
"Rotator offset at end of observation (degrees)", &status);
106 fits_update_key(outfptr, TSTRING,
"ROTMODE",(
void*)head->aosb->catrm,
"Rotator mode, from catalog input", &status);
110 fits_update_key(outfptr, TDOUBLE,
"WXTEMP",(
void*)&head->aosb->wxtemp,
"Outside temperature (C)", &status);
111 fits_update_key(outfptr, TDOUBLE,
"WXPRES",(
void*)&head->aosb->wxpres,
"Outside pressure (millibars)", &status);
112 fits_update_key(outfptr, TDOUBLE,
"WXHUMID",(
void*)&head->aosb->wxhumid,
"Outside humidity (%)", &status);
113 fits_update_key(outfptr, TDOUBLE,
"WXWIND",(
void*)&head->aosb->wxwind,
"Outside wind intensity (mph)", &status);
114 fits_update_key(outfptr, TDOUBLE,
"WXWDIR",(
void*)&head->aosb->wxwdir,
"Outside wind direction (degrees)", &status);
115 fits_update_key(outfptr, TDOUBLE,
"WXDEWPNT",(
void*)&head->aosb->wxdewpoint,
"Dew Point (C)", &status);
116 fits_update_key(outfptr, TDOUBLE,
"WXPWVEST",(
void*)&head->aosb->wxpwvest,
"Rough estimate of PWV (mm)", &status);
117 fits_update_key(outfptr, TDOUBLE,
"TTRUSS",(
void*)&head->aosb->ttruss,
"Telescope truss temperature (C)", &status);
118 fits_update_key(outfptr, TDOUBLE,
"TCELL",(
void*)&head->aosb->tcell,
"Primary mirror cell temperature (C)", &status);
119 fits_update_key(outfptr, TDOUBLE,
"TAMBIENT",(
void*)&head->aosb->tambient,
"Dome air temperature (C)", &status);
120 fits_update_key(outfptr, TDOUBLE,
"DIMMFWHM",(
void*)&head->aosb->dimmfwhm,
"DIMM seeing FWHM at zenith (arcsec)", &status);
121 fits_update_key(outfptr, TINT,
"DIMMTIME",(
void*)&head->aosb->dimmtime,
"DIMM seeing timestamp (sec since midnight)", &status);
122 fits_update_key(outfptr, TDOUBLE,
"MAG1FWHM",(
void*)&head->aosb->mag1fwhm,
"Baade (Mag1) seeing FWHM at zenith (arcsec)", &status);
123 fits_update_key(outfptr, TINT,
"MAG1TIME",(
void*)&head->aosb->mag1time,
"Baade (Mag1) seeing timestamp (sec since midnight)", &status);
125 if(head->aosb->loop_on == 0) fits_update_key(outfptr, TSTRING,
"AOLOOPST", (
void *)
"OPEN",
"Loop Status", &status);
126 else fits_update_key(outfptr, TSTRING,
"AOLOOPST", (
void *)
"CLOSED",
"Loop status", &status);
129 fits_update_key(outfptr, TSTRING,
"AOLOOPST", (
void *)
"NOT PROCESSED",
"Loop Status - added in post processing", &status);
131 fits_update_key(outfptr, TSTRING,
"AOREC", (
void*)head->aosb->reconstructor,
"reconstructor", &status);
132 fits_update_key(outfptr, TINT,
"AOMODES", (
void*)&head->aosb->correctedmodes,
"Number of corrected modes", &status);
133 fits_update_key(outfptr, TDOUBLE,
"AOSPEED", (
void*)&head->aosb->ccd39_freq,
"AO loop speed (Hz), from CCD39", &status);
134 fits_update_key(outfptr, TINT,
"AOBIN", (
void*)&head->aosb->ccd39_bin,
"AO WFS binning, from CCD39", &status);
135 fits_update_key(outfptr, TINT,
"AOCOUNTS", (
void*)&head->aosb->wfs_counts,
"AO WFS counts per subap", &status);
136 fits_update_key(outfptr, TDOUBLE,
"AOGAINTT", (
void*)&head->aosb->loop_gain_tt,
"AO loop T/T gain", &status);
137 fits_update_key(outfptr, TDOUBLE,
"AOGAINH1", (
void*)&head->aosb->loop_gain_ho1,
"AO loop high order gain group 1", &status);
138 fits_update_key(outfptr, TDOUBLE,
"AOGAINH2", (
void*)&head->aosb->loop_gain_ho2,
"AO loop high order gain group 2", &status);
139 fits_update_key(outfptr, TDOUBLE,
"AOMODSP1", (
void*)&head->aosb->tt_freq[0],
"AO modulation speed (Hz), axis 1", &status);
140 fits_update_key(outfptr, TDOUBLE,
"AOMODSP2", (
void*)&head->aosb->tt_freq[1],
"AO modulation speed (Hz), axis 2", &status);
141 fits_update_key(outfptr, TDOUBLE,
"AOMODAM1", (
void*)&head->aosb->tt_amp[0],
"AO modulation amplitude (millirad), axis 1", &status);
142 fits_update_key(outfptr, TDOUBLE,
"AOMODAM2", (
void*)&head->aosb->tt_amp[1],
"AO modulation amplitude (millirad), axis 2", &status);
143 fits_update_key(outfptr, TDOUBLE,
"AOMODOF1", (
void*)&head->aosb->tt_offset[0],
"AO piezo offset (millirad), axis 1", &status);
144 fits_update_key(outfptr, TDOUBLE,
"AOMODOF2", (
void*)&head->aosb->tt_offset[1],
"AO piezo offset (millirad), axis 2", &status);
145 fits_update_key(outfptr, TDOUBLE,
"VFW1POS", (
void *)&(head->aosb->filter1_pos),
"Position of MagAO Filter Wheel #1", &status);
146 fits_update_key(outfptr, TSTRING,
"VFW1POSN", (
void *)(head->aosb->filter1_name),
"Filter name in MagAO Filter Wheel #1", &status);
147 fits_update_key(outfptr, TDOUBLE,
"BAYSIDX", (
void *)&(head->aosb->baysidex),
"Position of MagAO Bayside X stage", &status);
148 fits_update_key(outfptr, TINT,
"BAYSIDXE", (
void *)&(head->aosb->baysidex_enabled),
"Enable status of MagAO Bayside X stage", &status);
149 fits_update_key(outfptr, TDOUBLE,
"BAYSIDY", (
void *)&(head->aosb->baysidey),
"Position of MagAO Bayside Y stage", &status);
150 fits_update_key(outfptr, TINT,
"BAYSIDYE", (
void *)&(head->aosb->baysidey_enabled),
"Enable status of MagAO Bayside Y stage", &status);
151 fits_update_key(outfptr, TDOUBLE,
"BAYSIDZ", (
void *)&(head->aosb->baysidez),
"Position of MagAO Bayside Z stage", &status);
152 fits_update_key(outfptr, TINT,
"BAYSIDZE", (
void *)&(head->aosb->baysidez_enabled),
"Enable status of MagAO Bayside Z stage", &status);
158 int write_visao_fits_visao_header(fitsfile * outfptr,
visao_imheader * head)
160 struct tm *timestamp_tm;
161 char tmp[30], datestr[80];
165 fits_update_key(outfptr, TINT,
"V47WINDX", (
void *)&(head->csb->windowx),
"CCD47 x window", &status);
166 fits_update_key(outfptr, TINT,
"V47WINDY", (
void *)&(head->csb->windowy),
"CCD47 y window", &status);
167 fits_update_key(outfptr, TINT,
"V47BINX", (
void *)&(head->csb->xbin),
"CCD47 x binning", &status);
168 fits_update_key(outfptr, TINT,
"V47BINY", (
void *)&(head->csb->xbin),
"CCD47 y binning", &status);
169 fits_update_key(outfptr, TINT,
"V47PIXRT", (
void *)&(head->csb->speed),
"CCD47 speed (kHz)", &status);
170 fits_update_key(outfptr, TINT,
"V47REPS", (
void *)&(head->csb->repetitions),
"CCD47 accumulator repetitions", &status);
171 fits_update_key(outfptr, TDOUBLE,
"V47FRMRT", (
void *)&(head->csb->framerate),
"CCD47 frame rate (fps)", &status);
172 double et = 1./head->csb->framerate;
173 fits_update_key(outfptr, TDOUBLE,
"EXPTIME", (
void *)&(et),
"CCD47 exposure time (sec)", &status);
175 timestamp_tm = gmtime(&head->timestamp_dma.tv_sec);
176 strftime(tmp, 30,
"%Y-%m-%dT%H:%M:%S", timestamp_tm);
177 sprintf(datestr,
"%s.%06u", tmp, (
unsigned) head->timestamp_dma.tv_usec);
179 fits_update_key(outfptr, TSTRING,
"FGDMATS", (
void *)datestr,
"F.G. DMA Timestamp", &status);
182 switch(head->csb->gain)
185 fits_update_key(outfptr, TSTRING,
"V47GAIN", (
void *)
"HIGH",
"CCD47 gain", &status);
188 fits_update_key(outfptr, TSTRING,
"V47GAIN", (
void *)
"MED HIGH",
"CCD47 gain", &status);
191 fits_update_key(outfptr, TSTRING,
"V47GAIN", (
void *)
"MED LOW",
"CCD47 gain", &status);
194 fits_update_key(outfptr, TSTRING,
"V47GAIN", (
void *)
"LOW",
"CCD47 gain", &status);
197 fits_update_key(outfptr, TSTRING,
"V47GAIN", (
void *)
"UNK",
"CCD47 gain", &status);
200 fits_update_key(outfptr, TDOUBLE,
"V47JTEMP", (
void *)&(head->csb->joe_temp),
"CCD47 little joe case temp (C)", &status);
203 fits_update_key(outfptr, TDOUBLE,
"V47JXTMP", (
void *)&(head->vssb->Joe47Temp),
"CCD47 little joe exhaust temp (C)", &status);
205 fits_update_key(outfptr, TDOUBLE,
"V47TEMP1", (
void *)&(head->csb->head_temp1),
"CCD47 head temp (C) #1", &status);
206 fits_update_key(outfptr, TDOUBLE,
"V47TEMP2", (
void *)&(head->csb->head_temp2),
"CCD47 head temp (C) #2", &status);
207 fits_update_key(outfptr, TINT,
"V47BLCK1", (
void *)&(head->csb->black0),
"CCD47 channel #1 black level", &status);
208 fits_update_key(outfptr, TINT,
"V47BLCK2", (
void *)&(head->csb->black1),
"CCD47 channel #2 black level", &status);
212 fits_update_key(outfptr, TSTRING,
"VIMTYPE", (
void *)
"SCIENCE",
"Image Type", &status);
215 fits_update_key(outfptr, TSTRING,
"VIMTYPE", (
void *)
"ACQUISITION",
"Image Type", &status);
218 fits_update_key(outfptr, TSTRING,
"VIMTYPE", (
void *)
"DARK",
"Image Type", &status);
221 fits_update_key(outfptr, TSTRING,
"VIMTYPE", (
void *)
"SKY",
"Image Type", &status);
224 fits_update_key(outfptr, TSTRING,
"VIMTYPE", (
void *)
"FLAT",
"Image Type", &status);
227 fits_update_key(outfptr, TSTRING,
"VIMTYPE", (
void *)
"UNK",
"Image Type", &status);
234 fits_update_key(outfptr, TDOUBLE,
"VFOCPOS", (
void *)&(head->fsb->cur_pos),
"Position of VisAO Focus stage (microns)", &status);
235 if(head->fsb->is_moving)
236 fits_update_key(outfptr, TSTRING,
"VFOCSTAT", (
void *)
"MOVING",
"Status of VisAO Focus stage", &status);
238 fits_update_key(outfptr, TSTRING,
"VFOCSTAT", (
void *)
"STOPPED",
"Status of VisAO Focus stage", &status);
239 if(head->fsb->power_state)
240 fits_update_key(outfptr, TSTRING,
"VFOCPWR", (
void *)
"ON",
"Status of VisAO Focus stage controller", &status);
242 fits_update_key(outfptr, TSTRING,
"VFOCPWR", (
void *)
"OFF",
"Status of VisAO Focus stage controller", &status);
246 fits_update_key(outfptr, TDOUBLE,
"VFW2POS", (
void *)&(head->fw2sb->pos),
"Position of VisAO Filter Wheel #2", &status);
247 fits_update_key(outfptr, TSTRING,
"VFW2POSN", (
void *)(head->fw2sb->filter_name),
"Filter name in VisAO Filter Wheel #2", &status);
251 fits_update_key(outfptr, TDOUBLE,
"VFW3POS", (
void *)&(head->fw3sb->pos),
"Position of VisAO Filter Wheel #3", &status);
252 fits_update_key(outfptr, TSTRING,
"VFW3POSN", (
void *)(head->fw3sb->filter_name),
"Filter name in VisAO Filter Wheel #3", &status);
256 if(head->wsb->cur_pos == 1) fits_update_key(outfptr, TSTRING,
"VWOLLSTN", (
void *)
"IN",
"Status of VisAO Wollaston", &status);
257 if(head->wsb->cur_pos == 0) fits_update_key(outfptr, TSTRING,
"VWOLLSTN", (
void *)
"INTERMEDIATE",
"Status of VisAO Wollaston", &status);
258 if(head->wsb->cur_pos == -1) fits_update_key(outfptr, TSTRING,
"VWOLLSTN", (
void *)
"OUT",
"Status of VisAO Wollaston", &status);
263 int sps = head->ssb->power_state;
264 char ssat[5], hsat[10];
266 if(head->ssb->sync_enabled == 0) strcpy(hsat,
"IGNORED");
269 if( sps == 0) strcpy(ssat,
"OFF");
270 else strcpy(ssat,
"UNK");
271 if (sps == -1) strcpy(ssat,
"UNK");
274 if(head->ssb->in_auto) strcpy(ssat,
"AUTO");
277 if(head->ssb->sw_state == 1) strcpy(ssat,
"OPEN");
278 else if(head->ssb->sw_state == -1) strcpy(ssat,
"SHUT");
279 else strcpy(ssat,
"INT");
280 if(head->ssb->sync_enabled == 1)
282 if(head->ssb->hw_state == 1) strcpy(hsat,
"OPEN");
283 else if(head->ssb->hw_state == -1) strcpy(hsat,
"SHUT");
284 else strcpy(hsat,
"INT");
290 fits_update_key(outfptr, TSTRING,
"VSHUTTER", (
void *)ssat,
"Status of VisAO Shutter", &status);
292 if(hsat[0]) fits_update_key(outfptr, TSTRING,
"VSHUTSYN", (
void *)hsat,
"Status of VisAO Shutter Sync Signal", &status);
293 else fits_update_key(outfptr, TSTRING,
"VSHUTSYN", (
void *)
"UNK",
"Status of VisAO Shutter Sync Signal", &status);
298 fits_update_key(outfptr, TSTRING,
"VGIMPWR", (
void *)
"ON",
"Status of VisAO Gimbal controller", &status);
300 fits_update_key(outfptr, TSTRING,
"VGIMPWR", (
void *)
"OFF",
"Status of VisAO Gimbal controller", &status);
303 fits_update_key(outfptr, TDOUBLE,
"VGIMXPOS", (
void *)&(head->gsb->xpos),
"X Position of VisAO Gimbal", &status);
305 fits_update_key(outfptr, TDOUBLE,
"VGIMYPOS", (
void *)&(head->gsb->ypos),
"Y Position of VisAO Gimbal", &status);
321 template <>
int visao_fits_create_img<short>( fitsfile *fptr,
int naxis,
long *naxes,
int *status)
323 return fits_create_img( fptr, SHORT_IMG, naxis, naxes, status);
326 template <>
int visao_fits_create_img<unsigned char>( fitsfile *fptr,
int naxis,
long *naxes,
int *status)
328 return fits_create_img( fptr, BYTE_IMG, naxis, naxes, status);
331 template <>
int visao_fits_write_subset<short>(fitsfile *fptr,
long *fpixel,
long *lpixel,
short *array,
int *status)
333 return fits_write_subset(fptr,TSHORT , fpixel, lpixel, array, status);
336 template <>
int visao_fits_write_subset<unsigned char>(fitsfile *fptr,
long *fpixel,
long *lpixel,
unsigned char *array,
int *status)
338 return fits_write_subset(fptr,TBYTE, fpixel, lpixel, array, status);
352 fout = fopen(fname.c_str(),
"w+");
355 std::cerr <<
"Error opening file " << fname <<
"\n";
358 fwrite(sim->imdata,
sizeof(
short), sim->nx*sim->ny, fout);
364 int get_fits_im(
unsigned char *im,
long hduno,
long *fpix,
long *lpix, fitsfile **fptr,
const char *fname)
369 if(*fptr == 0 && fname > 0)
371 fits_open_file(fptr, fname, READONLY, &fstatus);
374 fprintf(stderr,
"Error in get_fits_data.\n");
375 fits_report_error(stderr, fstatus);
379 fits_movabs_hdu(*fptr, hduno, NULL, &fstatus);
382 fprintf(stderr,
"Error in get_fits_data.\n");
383 fits_report_error(stderr, fstatus);
388 fits_read_subset(*fptr, TBYTE, fpix, lpix, inc, 0, im, 0, &fstatus);
389 if (fstatus && fstatus != 107)
391 fprintf(stderr,
"Error in get_fits_data.\n");
392 fits_report_error(stderr, fstatus);
399 int get_fits_im(
float *im,
long hduno,
long *fpix,
long *lpix, fitsfile **fptr,
const char *fname)
404 if(*fptr == 0 && fname > 0)
406 fits_open_file(fptr, fname, READONLY, &fstatus);
409 fprintf(stderr,
"Error in get_fits_data.\n");
410 fits_report_error(stderr, fstatus);
417 fits_movabs_hdu(*fptr, hduno, NULL, &fstatus);
420 fprintf(stderr,
"Error in get_fits_data.\n");
421 fits_report_error(stderr, fstatus);
425 std::cout << fpix[0] <<
" " << fpix[1] << std::endl;
426 std::cout << lpix[0] <<
" " << lpix[1] << std::endl;
427 std::cout << inc[0] <<
" " << inc[1] << std::endl;
429 fits_read_subset(*fptr, TFLOAT, fpix, lpix, inc, 0, im, 0, &fstatus);
430 if (fstatus && fstatus != 107)
432 fprintf(stderr,
"Error in get_fits_data.\n");
433 fits_report_error(stderr, fstatus);
440 int get_fits_im(
double *im,
long hduno,
long *fpix,
long *lpix, fitsfile **fptr,
const char *fname)
445 if(*fptr == 0 && fname > 0)
447 fits_open_file(fptr, fname, READONLY, &fstatus);
450 fprintf(stderr,
"Error in get_fits_data.\n");
451 fits_report_error(stderr, fstatus);
457 fits_movabs_hdu(*fptr, hduno, NULL, &fstatus);
460 fprintf(stderr,
"Error in get_fits_data.\n");
461 fits_report_error(stderr, fstatus);
466 fits_read_subset(*fptr, TDOUBLE, fpix, lpix, inc, 0, im, 0, &fstatus);
467 if (fstatus && fstatus != 107)
469 fprintf(stderr,
"Error in get_fits_data.\n");
470 fits_report_error(stderr, fstatus);
int imtype
0=science, 1=acquisition, 2=dark, 3=sky, 4=flat
int get_visao_filename(char *buffer, struct timeval *tv)
Writes the standard visao unique filename for a timeval to the buffer.
Declarations for various image utility functions.