The VisAO Camera
visaoimutils.cpp
Go to the documentation of this file.
1 /************************************************************
2  * visaoimutils.cpp
3  *
4  * Author: Jared R. Males (jrmales@email.arizona.edu)
5  *
6  * Definitions for various image utility functions.
7  *
8  * Developed as part of the Magellan Adaptive Optics system.
9  ************************************************************/
10 
11 /** \file visaoimutils.cpp
12  * \author Jared R. Males
13  * \brief Definitions for various image utility functions.
14  *
15  */
16 
17 #include "visaoimutils.h"
18 
19 
20 #ifndef ERROR_REPORT
21 #define ERROR_REPORT(er,f,l) if(global_error_report) (*global_error_report)(er,f,l);
22 #endif
23 
24 void init_visao_imheader(visao_imheader * imhead)
25 {
26  imhead->fsb = 0;
27  imhead->csb = 0;
28  imhead->ssb = 0;
29  imhead->fw2sb = 0;
30  imhead->fw3sb = 0;
31  imhead->wsb = 0;
32  imhead->aosb = 0;
33  imhead->gsb = 0;
34  imhead->vssb = 0;
35  imhead->rsb = 0;
36  imhead->stsb = 0;
37 }
38 
39 int get_visao_filename(char * buffer, struct timeval *tv)
40 {
41  struct tm uttime;
42  time_t t0;
43 
44  t0 = tv->tv_sec;
45 
46  if(gmtime_r(&t0, &uttime) == 0)
47  {
48  ERROR_REPORT("Error getting UT time (gmtime_r returned 0).", __FILE__, __LINE__);
49  return -1;
50  }
51 
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);
53 
54  return 0;
55 }
56 
57 int get_visao_filename(char * buffer, struct timespec *ts)
58 {
59  struct tm uttime;
60  struct timeval tv;
61 
62  time_t t0;
63 
64  tv.tv_sec = ts->tv_sec;
65  tv.tv_usec= (long) (ts->tv_nsec/1e3 + .5);
66 
67  t0 = tv.tv_sec;
68 
69  if(gmtime_r(&t0, &uttime) == 0)
70  {
71  ERROR_REPORT("Error getting UT time (gmtime_r returned 0).", __FILE__, __LINE__);
72  return -1;
73  }
74 
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);
76 
77  return 0;
78 }
79 
80 int write_visao_fits_aosys_header(fitsfile * outfptr, visao_imheader * head)
81 {
82  //std::cout << "In Write head\n";
83  int status = 0;
84  if(head->aosb)
85  {
86  //std::cout << "Writing head\n";
87  //std::cout << "->" << head->aosb->catobj << "<-\n";
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);
107 
108 
109  //Weather data from TCS
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);
124 
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);
127 
128 
129  fits_update_key(outfptr, TSTRING, "AOLOOPST", (void *)"NOT PROCESSED","Loop Status - added in post processing", &status);
130 
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);
153  }
154 
155  return status;
156 }
157 
158 int write_visao_fits_visao_header(fitsfile * outfptr, visao_imheader * head)
159 {
160  struct tm *timestamp_tm;
161  char tmp[30], datestr[80];
162  int status = 0;
163  if(head->csb)
164  {
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);
174 
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);
178  //yyyy-mm-ddTHH:MM:SS[.sss]
179  fits_update_key(outfptr, TSTRING, "FGDMATS", (void *)datestr, "F.G. DMA Timestamp", &status);
180 
181 
182  switch(head->csb->gain)
183  {
184  case 0:
185  fits_update_key(outfptr, TSTRING, "V47GAIN", (void *)"HIGH","CCD47 gain", &status);
186  break;
187  case 1:
188  fits_update_key(outfptr, TSTRING, "V47GAIN", (void *)"MED HIGH","CCD47 gain", &status);
189  break;
190  case 2:
191  fits_update_key(outfptr, TSTRING, "V47GAIN", (void *)"MED LOW","CCD47 gain", &status);
192  break;
193  case 3:
194  fits_update_key(outfptr, TSTRING, "V47GAIN", (void *)"LOW","CCD47 gain", &status);
195  break;
196  default:
197  fits_update_key(outfptr, TSTRING, "V47GAIN", (void *)"UNK","CCD47 gain", &status);
198  break;
199  }
200  fits_update_key(outfptr, TDOUBLE, "V47JTEMP", (void *)&(head->csb->joe_temp),"CCD47 little joe case temp (C)", &status);
201  if(head->vssb) //We want exhaust temp to show up in the right spot.
202  {
203  fits_update_key(outfptr, TDOUBLE, "V47JXTMP", (void *)&(head->vssb->Joe47Temp),"CCD47 little joe exhaust temp (C)", &status);
204  }
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);
209  switch(head->csb->imtype)
210  {
211  case 0:
212  fits_update_key(outfptr, TSTRING, "VIMTYPE", (void *)"SCIENCE","Image Type", &status);
213  break;
214  case 1:
215  fits_update_key(outfptr, TSTRING, "VIMTYPE", (void *)"ACQUISITION","Image Type", &status);
216  break;
217  case 2:
218  fits_update_key(outfptr, TSTRING, "VIMTYPE", (void *)"DARK","Image Type", &status);
219  break;
220  case 3:
221  fits_update_key(outfptr, TSTRING, "VIMTYPE", (void *)"SKY","Image Type", &status);
222  break;
223  case 4:
224  fits_update_key(outfptr, TSTRING, "VIMTYPE", (void *)"FLAT","Image Type", &status);
225  break;
226  default:
227  fits_update_key(outfptr, TSTRING, "VIMTYPE", (void *)"UNK","Image Type", &status);
228  break;
229  }
230 
231  }
232  if(head->fsb)
233  {
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);
237  else
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);
241  else
242  fits_update_key(outfptr, TSTRING, "VFOCPWR", (void *)"OFF","Status of VisAO Focus stage controller", &status);
243  }
244  if(head->fw2sb)
245  {
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);
248  }
249  if(head->fw3sb)
250  {
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);
253  }
254  if(head->wsb)
255  {
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);
259  }
260 
261  if(head->ssb)
262  {
263  int sps = head->ssb->power_state;
264  char ssat[5], hsat[10];
265 
266  if(head->ssb->sync_enabled == 0) strcpy(hsat, "IGNORED");
267  else hsat[0] = '\0';
268 
269  if( sps == 0) strcpy(ssat, "OFF");
270  else strcpy(ssat, "UNK");
271  if (sps == -1) strcpy(ssat, "UNK");
272  else
273  {
274  if(head->ssb->in_auto) strcpy(ssat, "AUTO");
275  else
276  {
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)
281  {
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");
285  }
286 
287  }
288  }
289  //We'll update for more than OFF or UNK
290  fits_update_key(outfptr, TSTRING, "VSHUTTER", (void *)ssat,"Status of VisAO Shutter", &status);
291 
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);
294  }
295  if(head->gsb)
296  {
297  if(head->gsb->power)
298  fits_update_key(outfptr, TSTRING, "VGIMPWR", (void *)"ON","Status of VisAO Gimbal controller", &status);
299  else
300  fits_update_key(outfptr, TSTRING, "VGIMPWR", (void *)"OFF","Status of VisAO Gimbal controller", &status);
301 
302 
303  fits_update_key(outfptr, TDOUBLE, "VGIMXPOS", (void *)&(head->gsb->xpos),"X Position of VisAO Gimbal", &status);
304 
305  fits_update_key(outfptr, TDOUBLE, "VGIMYPOS", (void *)&(head->gsb->ypos),"Y Position of VisAO Gimbal", &status);
306  }
307 
308  /* if(head->rsb)
309  {
310  double tmp = head->rsb->avgwfe_1_sec;
311  fits_update_key(outfptr, TDOUBLE, "WFEAVG", (void *)(&tmp), "1 sec average WFE, nm rms phase", &status);
312  tmp = head->rsb->stdwfe_1_sec;
313  fits_update_key(outfptr, TDOUBLE, "WFESTD", (void *)(&tmp), "1 sec std dev of WFE, nm rms phase", &status);
314  tmp = head->rsb->inst_wfe;
315  //fits_update_key(outfptr, TDOUBLE, "WFEINST", (void *)(&tmp), "Instantaneous WFE, nm rms phase", &status);
316 }*/
317 
318  return status;
319 }
320 
321 template <> int visao_fits_create_img<short>( fitsfile *fptr, int naxis, long *naxes, int *status)
322 {
323  return fits_create_img( fptr, SHORT_IMG, naxis, naxes, status);
324 }
325 
326 template <> int visao_fits_create_img<unsigned char>( fitsfile *fptr, int naxis, long *naxes, int *status)
327 {
328  return fits_create_img( fptr, BYTE_IMG, naxis, naxes, status);
329 }
330 
331 template <> int visao_fits_write_subset<short>(fitsfile *fptr, long *fpixel, long *lpixel, short *array, int *status)
332 {
333  return fits_write_subset(fptr,TSHORT , fpixel, lpixel, array, status);
334 }
335 
336 template <> int visao_fits_write_subset<unsigned char>(fitsfile *fptr, long *fpixel, long *lpixel, unsigned char *array, int *status)
337 {
338  return fits_write_subset(fptr,TBYTE, fpixel, lpixel, array, status);
339 }
340 
341 int write_visao_raw(const char * name_base, sharedimS *sim, visao_imheader * head __attribute__((unused)))
342 {
343  FILE *fout;
344  std::string fname;
345  char fext[21];
346  fname = name_base;
347  get_visao_filename(fext, &sim->frame_time);
348 
349  fname += fext;
350  fname += ".raw";
351 
352  fout = fopen(fname.c_str(), "w+");
353  if(fout ==0 )
354  {
355  std::cerr << "Error opening file " << fname << "\n";
356  return -1;
357  }
358  fwrite(sim->imdata, sizeof(short), sim->nx*sim->ny, fout);
359 
360  fclose(fout);
361  return 0;
362 }
363 
364 int get_fits_im(unsigned char *im, long hduno, long *fpix, long *lpix, fitsfile **fptr, const char *fname)
365 {
366  int fstatus = 0;
367  long inc[2] = {1,1};
368  //std::cout << fname << "\n" << hduno << "\n";
369  if(*fptr == 0 && fname > 0)
370  {
371  fits_open_file(fptr, fname, READONLY, &fstatus);
372  if (fstatus)
373  {
374  fprintf(stderr, "Error in get_fits_data.\n");
375  fits_report_error(stderr, fstatus); /* print any error message */
376  return -1;
377  }
378  }
379  fits_movabs_hdu(*fptr, hduno, NULL, &fstatus);
380  if (fstatus)
381  {
382  fprintf(stderr, "Error in get_fits_data.\n");
383  fits_report_error(stderr, fstatus); /* print any error message */
384  return -1;
385  }
386 
387 
388  fits_read_subset(*fptr, TBYTE, fpix, lpix, inc, 0, im, 0, &fstatus);
389  if (fstatus && fstatus != 107)
390  {
391  fprintf(stderr, "Error in get_fits_data.\n");
392  fits_report_error(stderr, fstatus); /* print any error message */
393  return -1;
394  }
395 
396  return fstatus;
397 }
398 
399 int get_fits_im(float *im, long hduno, long *fpix, long *lpix, fitsfile **fptr, const char *fname)
400 {
401  int fstatus = 0;
402  long inc[2] = {1,1};
403  //std::cout << fname << "\n" << hduno << "\n";
404  if(*fptr == 0 && fname > 0)
405  {
406  fits_open_file(fptr, fname, READONLY, &fstatus);
407  if (fstatus)
408  {
409  fprintf(stderr, "Error in get_fits_data.\n");
410  fits_report_error(stderr, fstatus); // print any error message
411  return -1;
412  }
413  }
414 
415 
416 
417  fits_movabs_hdu(*fptr, hduno, NULL, &fstatus);
418  if (fstatus)
419  {
420  fprintf(stderr, "Error in get_fits_data.\n");
421  fits_report_error(stderr, fstatus); // print any error message
422  return -1;
423  }
424 
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;
428 
429  fits_read_subset(*fptr, TFLOAT, fpix, lpix, inc, 0, im, 0, &fstatus);
430  if (fstatus && fstatus != 107)
431  {
432  fprintf(stderr, "Error in get_fits_data.\n");
433  fits_report_error(stderr, fstatus); // print any error message
434  return -1;
435  }
436 
437  return fstatus;
438 }
439 
440 int get_fits_im(double *im, long hduno, long *fpix, long *lpix, fitsfile **fptr, const char *fname)
441 {
442  int fstatus = 0;
443  long inc[2] = {1,1};
444  //std::cout << fname << "\n" << hduno << "\n";
445  if(*fptr == 0 && fname > 0)
446  {
447  fits_open_file(fptr, fname, READONLY, &fstatus);
448  if (fstatus)
449  {
450  fprintf(stderr, "Error in get_fits_data.\n");
451  fits_report_error(stderr, fstatus); // print any error message
452  return -1;
453  }
454  }
455 
456 
457  fits_movabs_hdu(*fptr, hduno, NULL, &fstatus);
458  if (fstatus)
459  {
460  fprintf(stderr, "Error in get_fits_data.\n");
461  fits_report_error(stderr, fstatus); // print any error message
462  return -1;
463  }
464 
465 
466  fits_read_subset(*fptr, TDOUBLE, fpix, lpix, inc, 0, im, 0, &fstatus);
467  if (fstatus && fstatus != 107)
468  {
469  fprintf(stderr, "Error in get_fits_data.\n");
470  fits_report_error(stderr, fstatus); // print any error message
471  return -1;
472  }
473 
474  return fstatus;
475 }
476 
int imtype
0=science, 1=acquisition, 2=dark, 3=sky, 4=flat
Definition: statusboard.h:130
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.