MUSE Pipeline Reference Manual  1.0.2
muse_pfits.c
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set sw=2 sts=2 et cin: */
3 /*
4  * This file is part of the MUSE Instrument Pipeline
5  * Copyright (C) 2005-2014 European Southern Observatory
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 
26 /*----------------------------------------------------------------------------*
27  * Includes *
28  *----------------------------------------------------------------------------*/
29 #include <cpl.h>
30 #include <math.h>
31 #include <string.h>
32 
33 #include "muse_pfits.h"
34 #include "muse_instrument.h"
35 
36 /*----------------------------------------------------------------------------*/
40 /*----------------------------------------------------------------------------*/
41 
44 /*----------------------------------------------------------------------------*/
52 /*----------------------------------------------------------------------------*/
53 const char *
54 muse_pfits_get_arcfile(const cpl_propertylist *aHeaders)
55 {
56  const char *value = cpl_propertylist_get_string(aHeaders, "ARCFILE");
57  cpl_ensure(value, cpl_error_get_code(), NULL);
58  return value;
59 }
60 
61 /*----------------------------------------------------------------------------*/
69 /*----------------------------------------------------------------------------*/
70 const char *
71 muse_pfits_get_pipefile(const cpl_propertylist *aHeaders)
72 {
73  const char *value = cpl_propertylist_get_string(aHeaders, "PIPEFILE");
74  cpl_ensure(value, cpl_error_get_code(), NULL);
75  return value;
76 }
77 
78 /*----------------------------------------------------------------------------*/
86 /*----------------------------------------------------------------------------*/
87 const char *
88 muse_pfits_get_dpr_type(const cpl_propertylist *aHeaders)
89 {
90  cpl_errorstate prestate = cpl_errorstate_get();
91  const char *value = cpl_propertylist_get_string(aHeaders, "ESO DPR TYPE");
92  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
93  return value;
94 } /* muse_pfits_get_dpr_type() */
95 
96 /*----------------------------------------------------------------------------*/
104 /*----------------------------------------------------------------------------*/
105 const char *
106 muse_pfits_get_dpr_catg(const cpl_propertylist *aHeaders)
107 {
108  cpl_errorstate prestate = cpl_errorstate_get();
109  const char *value = cpl_propertylist_get_string(aHeaders, "ESO DPR CATG");
110  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
111  return value;
112 } /* muse_pfits_get_dpr_catg() */
113 
114 /*----------------------------------------------------------------------------*/
122 /*----------------------------------------------------------------------------*/
123 const char *
124 muse_pfits_get_pro_type(const cpl_propertylist *aHeaders)
125 {
126  cpl_errorstate prestate = cpl_errorstate_get();
127  const char *value = cpl_propertylist_get_string(aHeaders, "ESO PRO TYPE");
128  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
129  return value;
130 } /* muse_pfits_get_pro_type() */
131 
132 /*----------------------------------------------------------------------------*/
140 /*----------------------------------------------------------------------------*/
141 const char *
142 muse_pfits_get_pro_catg(const cpl_propertylist *aHeaders)
143 {
144  cpl_errorstate prestate = cpl_errorstate_get();
145  const char *value = cpl_propertylist_get_string(aHeaders, "ESO PRO CATG");
146  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
147  return value;
148 } /* muse_pfits_get_pro_catg() */
149 
150 /*----------------------------------------------------------------------------*/
162 /*----------------------------------------------------------------------------*/
163 cpl_boolean
164 muse_pfits_has_ifu(const cpl_propertylist *aHeaders, unsigned char aIFU)
165 {
166  cpl_errorstate prestate = cpl_errorstate_get();
167  const char *extname = muse_pfits_get_extname(aHeaders);
168  if (!cpl_errorstate_is_equal(prestate) || /* no EXTNAME */
169  strncmp(extname, "CHAN", 4) || /* doesn't start with CHAN */
170  strlen(extname) < 6) { /* too short */
171  cpl_errorstate_set(prestate); /* ignore the error */
172  return CPL_FALSE;
173  }
174  unsigned char chan = atoi(extname + 4);
175  return chan == aIFU;
176 } /* muse_pfits_has_ifu() */
177 
178 /*----------------------------------------------------------------------------*/
186 /*----------------------------------------------------------------------------*/
187 const char *
188 muse_pfits_get_extname(const cpl_propertylist *aHeaders)
189 {
190  cpl_errorstate prestate = cpl_errorstate_get();
191  const char *value = cpl_propertylist_get_string(aHeaders, "EXTNAME");
192  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
193  return value;
194 } /* muse_pfits_get_extname() */
195 
196 /*----------------------------------------------------------------------------*/
205 /*----------------------------------------------------------------------------*/
206 cpl_size
207 muse_pfits_get_naxis(const cpl_propertylist *aHeaders, unsigned int aAxis)
208 {
209  cpl_errorstate prestate = cpl_errorstate_get();
210  if (aAxis == 0) {
211  cpl_size value = cpl_propertylist_get_long_long(aHeaders, "NAXIS");
212  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
213  return value;
214  }
215  char keyword[KEYWORD_LENGTH];
216  snprintf(keyword, KEYWORD_LENGTH, "NAXIS%u", aAxis);
217  cpl_size value = cpl_propertylist_get_long_long(aHeaders, keyword);
218  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
219  return value;
220 }
221 
222 /*----------------------------------------------------------------------------*/
230 /*----------------------------------------------------------------------------*/
231 double
232 muse_pfits_get_ra(const cpl_propertylist *aHeaders)
233 {
234  cpl_errorstate prestate = cpl_errorstate_get();
235  const double value = cpl_propertylist_get_double(aHeaders, "RA");
236  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
237  return value;
238 }
239 
240 /*----------------------------------------------------------------------------*/
248 /*----------------------------------------------------------------------------*/
249 double
250 muse_pfits_get_dec(const cpl_propertylist *aHeaders)
251 {
252  cpl_errorstate prestate = cpl_errorstate_get();
253  const double value = cpl_propertylist_get_double(aHeaders, "DEC");
254  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
255  return value;
256 }
257 
258 /*----------------------------------------------------------------------------*/
269 /*----------------------------------------------------------------------------*/
270 double
271 muse_pfits_get_equinox(const cpl_propertylist *aHeaders)
272 {
273  cpl_errorstate prestate = cpl_errorstate_get();
274  double value = cpl_propertylist_get_double(aHeaders, "EQUINOX");
275  if (!cpl_errorstate_is_equal(prestate)) {
276  cpl_errorstate_set(prestate);
277  value = cpl_propertylist_get_long_long(aHeaders, "EQUINOX");
278  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
279  } /* if error when reading as double */
280  return value;
281 }
282 
283 /*----------------------------------------------------------------------------*/
291 /*----------------------------------------------------------------------------*/
292 double
293 muse_pfits_get_lst(const cpl_propertylist *aHeaders)
294 {
295  cpl_errorstate prestate = cpl_errorstate_get();
296  const double value = cpl_propertylist_get_double(aHeaders, "LST");
297  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
298  return value;
299 }
300 
301 /*----------------------------------------------------------------------------*/
309 /*----------------------------------------------------------------------------*/
310 double
311 muse_pfits_get_mjdobs(const cpl_propertylist *aHeaders)
312 {
313  cpl_errorstate prestate = cpl_errorstate_get();
314  const double value = cpl_propertylist_get_double(aHeaders, "MJD-OBS");
315  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
316  return value;
317 }
318 
319 /*----------------------------------------------------------------------------*/
327 /*----------------------------------------------------------------------------*/
328 const char *
329 muse_pfits_get_dateobs(const cpl_propertylist *aHeaders)
330 {
331  cpl_errorstate prestate = cpl_errorstate_get();
332  const char *value = cpl_propertylist_get_string(aHeaders, "DATE-OBS");
333  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
334  return value;
335 }
336 
337 /*----------------------------------------------------------------------------*/
345 /*----------------------------------------------------------------------------*/
346 double
347 muse_pfits_get_exptime(const cpl_propertylist *aHeaders)
348 {
349  cpl_errorstate prestate = cpl_errorstate_get();
350  const double value = cpl_propertylist_get_double(aHeaders, "EXPTIME");
351  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
352  return value;
353 }
354 
355 /*----------------------------------------------------------------------------*/
363 /*----------------------------------------------------------------------------*/
364 int
365 muse_pfits_get_read_id(const cpl_propertylist *aHeaders)
366 {
367  cpl_errorstate prestate = cpl_errorstate_get();
368  const int value = cpl_propertylist_get_int(aHeaders, "ESO DET READ CURID");
369  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
370  return value;
371 }
372 
373 /*----------------------------------------------------------------------------*/
381 /*----------------------------------------------------------------------------*/
382 const char *
383 muse_pfits_get_read_name(const cpl_propertylist *aHeaders)
384 {
385  cpl_errorstate prestate = cpl_errorstate_get();
386  const char *value = cpl_propertylist_get_string(aHeaders, "ESO DET READ CURNAME");
387  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
388  return value;
389 }
390 
391 /*----------------------------------------------------------------------------*/
399 /*----------------------------------------------------------------------------*/
400 int
401 muse_pfits_get_binx(const cpl_propertylist *aHeaders)
402 {
403  cpl_errorstate prestate = cpl_errorstate_get();
404  const int value = cpl_propertylist_get_int(aHeaders, "ESO DET BINX");
405  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 1);
406  return value;
407 }
408 
409 /*----------------------------------------------------------------------------*/
417 /*----------------------------------------------------------------------------*/
418 int
419 muse_pfits_get_biny(const cpl_propertylist *aHeaders)
420 {
421  cpl_errorstate prestate = cpl_errorstate_get();
422  const int value = cpl_propertylist_get_int(aHeaders, "ESO DET BINY");
423  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 1);
424  return value;
425 }
426 
427 /*----------------------------------------------------------------------------*/
435 /*----------------------------------------------------------------------------*/
436 const char *
437 muse_pfits_get_chip_name(const cpl_propertylist *aHeaders)
438 {
439  cpl_errorstate prestate = cpl_errorstate_get();
440  const char *value = cpl_propertylist_get_string(aHeaders, "ESO DET CHIP NAME");
441  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
442  return value;
443 }
444 
445 /*----------------------------------------------------------------------------*/
453 /*----------------------------------------------------------------------------*/
454 const char *
455 muse_pfits_get_chip_id(const cpl_propertylist *aHeaders)
456 {
457  cpl_errorstate prestate = cpl_errorstate_get();
458  const char *value = cpl_propertylist_get_string(aHeaders, "ESO DET CHIP ID");
459  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
460  return value;
461 }
462 
463 /*----------------------------------------------------------------------------*/
471 /*----------------------------------------------------------------------------*/
472 const char *
473 muse_pfits_get_chip_date(const cpl_propertylist *aHeaders)
474 {
475  cpl_errorstate prestate = cpl_errorstate_get();
476  const char *value = cpl_propertylist_get_string(aHeaders, "ESO DET CHIP DATE");
477  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
478  return value;
479 }
480 
481 /*----------------------------------------------------------------------------*/
490 /*----------------------------------------------------------------------------*/
491 cpl_boolean
492 muse_pfits_get_chip_live(const cpl_propertylist *aHeaders)
493 {
494  cpl_errorstate prestate = cpl_errorstate_get();
495  const cpl_boolean value = cpl_propertylist_get_bool(aHeaders,
496  "ESO DET CHIP LIVE") == 0
497  ? CPL_FALSE : CPL_TRUE;
498  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), CPL_FALSE);
499  return value;
500 }
501 
502 /*----------------------------------------------------------------------------*/
511 /*----------------------------------------------------------------------------*/
512 double
513 muse_pfits_get_ron(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
514 {
515  char keyword[KEYWORD_LENGTH];
516  snprintf(keyword, KEYWORD_LENGTH, "ESO DET OUT%d RON", aQuadrant);
517  if (!cpl_propertylist_has(aHeaders, keyword)) {
518  cpl_msg_warning(__func__, "Could not get %s, using RON=1.0",
519  keyword);
520  return 1.0;
521  }
522  return cpl_propertylist_get_double(aHeaders, keyword);
523 }
524 
525 /*----------------------------------------------------------------------------*/
537 /*----------------------------------------------------------------------------*/
538 double
539 muse_pfits_get_gain(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
540 {
541  char keyword[KEYWORD_LENGTH];
542  snprintf(keyword, KEYWORD_LENGTH, "ESO DET OUT%d GAIN", aQuadrant);
543  return cpl_propertylist_get_double(aHeaders, keyword);
544 } /* muse_pfits_get_gain() */
545 
546 /*----------------------------------------------------------------------------*/
555 /*----------------------------------------------------------------------------*/
556 int
557 muse_pfits_get_out_output_x(const cpl_propertylist *aHeaders,
558  unsigned char aQuadrant)
559 {
560  cpl_errorstate prestate = cpl_errorstate_get();
561  char keyword[KEYWORD_LENGTH];
562  snprintf(keyword, KEYWORD_LENGTH, "ESO DET OUT%d X", aQuadrant);
563  const int value = cpl_propertylist_get_int(aHeaders, keyword);
564  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), -1);
565  return value;
566 }
567 
568 /*----------------------------------------------------------------------------*/
577 /*----------------------------------------------------------------------------*/
578 int
579 muse_pfits_get_out_output_y(const cpl_propertylist *aHeaders,
580  unsigned char aQuadrant)
581 {
582  cpl_errorstate prestate = cpl_errorstate_get();
583  char keyword[KEYWORD_LENGTH];
584  snprintf(keyword, KEYWORD_LENGTH, "ESO DET OUT%d Y", aQuadrant);
585  const int value = cpl_propertylist_get_int(aHeaders, keyword);
586  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), -1);
587  return value;
588 }
589 
590 /*----------------------------------------------------------------------------*/
599 /*----------------------------------------------------------------------------*/
600 int
601 muse_pfits_get_out_nx(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
602 {
603  cpl_errorstate prestate = cpl_errorstate_get();
604  char keyword[KEYWORD_LENGTH];
605  snprintf(keyword, KEYWORD_LENGTH, "ESO DET OUT%d NX", aQuadrant);
606  const int value = cpl_propertylist_get_int(aHeaders, keyword);
607  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), -1);
608  return value;
609 }
610 
611 /*----------------------------------------------------------------------------*/
620 /*----------------------------------------------------------------------------*/
621 int
622 muse_pfits_get_out_ny(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
623 {
624  cpl_errorstate prestate = cpl_errorstate_get();
625  char keyword[KEYWORD_LENGTH];
626  snprintf(keyword, KEYWORD_LENGTH, "ESO DET OUT%d NY", aQuadrant);
627  const int value = cpl_propertylist_get_int(aHeaders, keyword);
628  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), -1);
629  return value;
630 }
631 
632 /*----------------------------------------------------------------------------*/
641 /*----------------------------------------------------------------------------*/
642 int
643 muse_pfits_get_out_prescan_x(const cpl_propertylist *aHeaders,
644  unsigned char aQuadrant)
645 {
646  cpl_errorstate prestate = cpl_errorstate_get();
647  char keyword[KEYWORD_LENGTH];
648  snprintf(keyword, KEYWORD_LENGTH, "ESO DET OUT%d PRSCX", aQuadrant);
649  const int value = cpl_propertylist_get_int(aHeaders, keyword);
650  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), -1);
651  return value;
652 }
653 
654 /*----------------------------------------------------------------------------*/
663 /*----------------------------------------------------------------------------*/
664 int
665 muse_pfits_get_out_prescan_y(const cpl_propertylist *aHeaders,
666  unsigned char aQuadrant)
667 {
668  cpl_errorstate prestate = cpl_errorstate_get();
669  char keyword[KEYWORD_LENGTH];
670  snprintf(keyword, KEYWORD_LENGTH, "ESO DET OUT%d PRSCY", aQuadrant);
671  const int value = cpl_propertylist_get_int(aHeaders, keyword);
672  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), -1);
673  return value;
674 }
675 
676 /*----------------------------------------------------------------------------*/
685 /*----------------------------------------------------------------------------*/
686 int
687 muse_pfits_get_out_overscan_x(const cpl_propertylist *aHeaders,
688  unsigned char aQuadrant)
689 {
690  cpl_errorstate prestate = cpl_errorstate_get();
691  char keyword[KEYWORD_LENGTH];
692  snprintf(keyword, KEYWORD_LENGTH, "ESO DET OUT%d OVSCX", aQuadrant);
693  const int value = cpl_propertylist_get_int(aHeaders, keyword);
694  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), -1);
695  return value;
696 }
697 
698 /*----------------------------------------------------------------------------*/
707 /*----------------------------------------------------------------------------*/
708 int
709 muse_pfits_get_out_overscan_y(const cpl_propertylist *aHeaders,
710  unsigned char aQuadrant)
711 {
712  cpl_errorstate prestate = cpl_errorstate_get();
713  char keyword[KEYWORD_LENGTH];
714  snprintf(keyword, KEYWORD_LENGTH, "ESO DET OUT%d OVSCY", aQuadrant);
715  const int value = cpl_propertylist_get_int(aHeaders, keyword);
716  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), -1);
717  return value;
718 }
719 
720 /*----------------------------------------------------------------------------*/
733 /*----------------------------------------------------------------------------*/
734 double
735 muse_pfits_get_geolat(const cpl_propertylist *aHeaders)
736 {
737  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL GEOLAT");
738  if (fabs(value) < DBL_EPSILON) {
739  return -24.625278;
740  }
741  return value;
742 }
743 
744 /*----------------------------------------------------------------------------*/
757 /*----------------------------------------------------------------------------*/
758 double
759 muse_pfits_get_geolon(const cpl_propertylist *aHeaders)
760 {
761  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL GEOLON");
762  if (fabs(value) < DBL_EPSILON) {
763  return 70.402222;
764  }
765  return value;
766 }
767 
768 /*----------------------------------------------------------------------------*/
779 /*----------------------------------------------------------------------------*/
780 double
781 muse_pfits_get_geoelev(const cpl_propertylist *aHeaders)
782 {
783  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL GEOELEV");
784  if (fabs(value) < DBL_EPSILON) {
785  return 2648.;
786  }
787  return value;
788 }
789 
790 /*----------------------------------------------------------------------------*/
802 /*----------------------------------------------------------------------------*/
803 double
804 muse_pfits_get_focu_scale(const cpl_propertylist *aHeaders)
805 {
806  double value = 1.705;
807  if (aHeaders && cpl_propertylist_has(aHeaders, "ESO TEL FOCU SCALE")) {
808  value = cpl_propertylist_get_double(aHeaders, "ESO TEL FOCU SCALE");
809  }
810  return value;
811 }
812 
813 /*----------------------------------------------------------------------------*/
821 /*----------------------------------------------------------------------------*/
822 double
823 muse_pfits_get_airmass_start(const cpl_propertylist *aHeaders)
824 {
825  cpl_errorstate prestate = cpl_errorstate_get();
826  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL AIRM START");
827  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
828  return value;
829 }
830 
831 /*----------------------------------------------------------------------------*/
839 /*----------------------------------------------------------------------------*/
840 double
841 muse_pfits_get_airmass_end(const cpl_propertylist *aHeaders)
842 {
843  cpl_errorstate prestate = cpl_errorstate_get();
844  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL AIRM END");
845  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
846  return value;
847 }
848 
849 /*----------------------------------------------------------------------------*/
857 /*----------------------------------------------------------------------------*/
858 double
859 muse_pfits_get_temp(const cpl_propertylist *aHeaders)
860 {
861  cpl_errorstate prestate = cpl_errorstate_get();
862  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL AMBI TEMP");
863  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
864  return value;
865 }
866 
867 /*----------------------------------------------------------------------------*/
875 /*----------------------------------------------------------------------------*/
876 double
877 muse_pfits_get_rhum(const cpl_propertylist *aHeaders)
878 {
879  cpl_errorstate prestate = cpl_errorstate_get();
880  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL AMBI RHUM");
881  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
882  return value;
883 }
884 
885 /*----------------------------------------------------------------------------*/
893 /*----------------------------------------------------------------------------*/
894 double
895 muse_pfits_get_pres_start(const cpl_propertylist *aHeaders)
896 {
897  cpl_errorstate prestate = cpl_errorstate_get();
898  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL AMBI PRES START");
899  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
900  return value;
901 }
902 
903 /*----------------------------------------------------------------------------*/
911 /*----------------------------------------------------------------------------*/
912 double
913 muse_pfits_get_pres_end(const cpl_propertylist *aHeaders)
914 {
915  cpl_errorstate prestate = cpl_errorstate_get();
916  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL AMBI PRES END");
917  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
918  return value;
919 }
920 
921 /*----------------------------------------------------------------------------*/
929 /*----------------------------------------------------------------------------*/
930 double
931 muse_pfits_get_fwhm_start(const cpl_propertylist *aHeaders)
932 {
933  cpl_errorstate prestate = cpl_errorstate_get();
934  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL AMBI FWHM START");
935  cpl_ensure(cpl_errorstate_is_equal(prestate) && value > 0.,
936  cpl_error_get_code(), 0.0);
937  return value;
938 }
939 
940 /*----------------------------------------------------------------------------*/
948 /*----------------------------------------------------------------------------*/
949 double
950 muse_pfits_get_fwhm_end(const cpl_propertylist *aHeaders)
951 {
952  cpl_errorstate prestate = cpl_errorstate_get();
953  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL AMBI FWHM END");
954  cpl_ensure(cpl_errorstate_is_equal(prestate) && value > 0.,
955  cpl_error_get_code(), 0.0);
956  return value;
957 }
958 
959 /*----------------------------------------------------------------------------*/
967 /*----------------------------------------------------------------------------*/
968 double
969 muse_pfits_get_altang(const cpl_propertylist *aHeaders)
970 {
971  cpl_errorstate prestate = cpl_errorstate_get();
972  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL ALT");
973  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
974  return value;
975 }
976 
977 /*----------------------------------------------------------------------------*/
985 /*----------------------------------------------------------------------------*/
986 double
987 muse_pfits_get_parang_start(const cpl_propertylist *aHeaders)
988 {
989  cpl_errorstate prestate = cpl_errorstate_get();
990  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL PARANG START");
991  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
992  return value;
993 }
994 
995 /*----------------------------------------------------------------------------*/
1003 /*----------------------------------------------------------------------------*/
1004 double
1005 muse_pfits_get_parang_end(const cpl_propertylist *aHeaders)
1006 {
1007  cpl_errorstate prestate = cpl_errorstate_get();
1008  const double value = cpl_propertylist_get_double(aHeaders, "ESO TEL PARANG END");
1009  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1010  return value;
1011 }
1012 
1013 /*----------------------------------------------------------------------------*/
1021 /*----------------------------------------------------------------------------*/
1022 const char *
1023 muse_pfits_get_drot_mode(const cpl_propertylist *aHeaders)
1024 {
1025  cpl_errorstate prestate = cpl_errorstate_get();
1026  const char *value = cpl_propertylist_get_string(aHeaders, "ESO INS DROT MODE");
1027  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
1028  return value;
1029 }
1030 
1031 /*----------------------------------------------------------------------------*/
1039 /*----------------------------------------------------------------------------*/
1040 double
1041 muse_pfits_get_drot_posang(const cpl_propertylist *aHeaders)
1042 {
1043  cpl_errorstate prestate = cpl_errorstate_get();
1044  const double value = cpl_propertylist_get_double(aHeaders, "ESO INS DROT POSANG");
1045  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1046  return value;
1047 }
1048 
1049 /*----------------------------------------------------------------------------*/
1057 /*----------------------------------------------------------------------------*/
1058 double
1059 muse_pfits_get_drot_start(const cpl_propertylist *aHeaders)
1060 {
1061  cpl_errorstate prestate = cpl_errorstate_get();
1062  const double value = cpl_propertylist_get_double(aHeaders, "ESO INS DROT START");
1063  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1064  return value;
1065 }
1066 
1067 /*----------------------------------------------------------------------------*/
1075 /*----------------------------------------------------------------------------*/
1076 double
1077 muse_pfits_get_drot_end(const cpl_propertylist *aHeaders)
1078 {
1079  cpl_errorstate prestate = cpl_errorstate_get();
1080  const double value = cpl_propertylist_get_double(aHeaders, "ESO INS DROT END");
1081  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1082  return value;
1083 }
1084 
1085 /*----------------------------------------------------------------------------*/
1095 /*----------------------------------------------------------------------------*/
1096 muse_ins_mode
1097 muse_pfits_get_mode(const cpl_propertylist *aHeaders)
1098 {
1099  const char *value = muse_pfits_get_insmode(aHeaders);
1100  cpl_ensure(value, cpl_error_get_code(), MUSE_MODE_WFM_NONAO_N);
1101  if (!strncmp(value, "NFM", 3)) {
1102  return MUSE_MODE_NFM_AO_N;
1103  }
1104  if (!strncmp(value, "WFM-AO", 6)) {
1105  return MUSE_MODE_WFM_AO_N;
1106  }
1107  if (!strncmp(value, "WFM-NOAO-N", 10) || !strncmp(value, "WFM-NONAO-N", 11)) {
1108  return MUSE_MODE_WFM_NONAO_N;
1109  }
1110  return MUSE_MODE_WFM_NONAO_X;
1111 }
1112 
1113 /*----------------------------------------------------------------------------*/
1123 /*----------------------------------------------------------------------------*/
1124 const char *
1125 muse_pfits_get_insmode(const cpl_propertylist *aHeaders)
1126 {
1127  cpl_errorstate prestate = cpl_errorstate_get();
1128  const char *value = cpl_propertylist_get_string(aHeaders, "ESO INS MODE");
1129  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
1130  return value;
1131 }
1132 
1133 /*----------------------------------------------------------------------------*/
1149 /*----------------------------------------------------------------------------*/
1150 double
1151 muse_pfits_get_pam_intensity(const cpl_propertylist *aHeaders, int aDiode)
1152 {
1153  cpl_errorstate prestate = cpl_errorstate_get();
1154  char keyword[KEYWORD_LENGTH];
1155  snprintf(keyword, KEYWORD_LENGTH, "ESO INS AMPL%d CURR", aDiode);
1156  double value = cpl_propertylist_get_double(aHeaders, keyword);
1157  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1158  const char *comment = cpl_propertylist_get_comment(aHeaders, keyword);
1159  cpl_boolean ismilliampere = comment && strstr(comment, "[mA]")
1160  ? CPL_TRUE : CPL_FALSE;
1161  if (!ismilliampere) {
1162  cpl_error_set_message(__func__, CPL_ERROR_INCOMPATIBLE_INPUT,
1163  "Could not ensure that %s is in mA!", keyword);
1164  } else {
1165  value /= 1000.; /* convert from mA to A */
1166  }
1167  return value;
1168 }
1169 
1170 /*----------------------------------------------------------------------------*/
1179 /*----------------------------------------------------------------------------*/
1180 double
1181 muse_pfits_get_pam_stdev(const cpl_propertylist *aHeaders, int aDiode)
1182 {
1183  cpl_errorstate prestate = cpl_errorstate_get();
1184  char keyword[KEYWORD_LENGTH];
1185  snprintf(keyword, KEYWORD_LENGTH, "ESO INS AMPL%d STDEV", aDiode);
1186  const double value = cpl_propertylist_get_double(aHeaders, keyword);
1187  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1188  return value;
1189 }
1190 
1191 /*----------------------------------------------------------------------------*/
1199 /*----------------------------------------------------------------------------*/
1200 const char *
1201 muse_pfits_get_pam2_filter(const cpl_propertylist *aHeaders)
1202 {
1203  cpl_errorstate prestate = cpl_errorstate_get();
1204  const char *value = cpl_propertylist_get_string(aHeaders,
1205  "ESO INS AMPL2 FILTER");
1206  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
1207  return value;
1208 }
1209 
1210 /*----------------------------------------------------------------------------*/
1223 /*----------------------------------------------------------------------------*/
1224 int
1225 muse_pfits_get_lampnum(const cpl_propertylist *aHeaders)
1226 {
1227  cpl_errorstate prestate = cpl_errorstate_get();
1228  const int value = cpl_propertylist_get_int(aHeaders, "ESO INS LAMPNUM");
1229  if (!cpl_errorstate_is_equal(prestate)) {
1230  /* header keyword not present (old data of some sort?!) */
1231  cpl_errorstate_set(prestate); /* be backward-compatible */
1232  return 6; /* return the default */
1233  }
1234  return value;
1235 }
1236 
1237 /*----------------------------------------------------------------------------*/
1246 /*----------------------------------------------------------------------------*/
1247 const char *
1248 muse_pfits_get_lamp_name(const cpl_propertylist *aHeaders, int aLamp)
1249 {
1250  cpl_errorstate prestate = cpl_errorstate_get();
1251  char keyword[KEYWORD_LENGTH];
1252  snprintf(keyword, KEYWORD_LENGTH, "ESO INS LAMP%d NAME", aLamp);
1253  const char *value = cpl_propertylist_get_string(aHeaders, keyword);
1254  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
1255  return value;
1256 }
1257 
1258 /*----------------------------------------------------------------------------*/
1267 /*----------------------------------------------------------------------------*/
1268 int
1269 muse_pfits_get_lamp_status(const cpl_propertylist *aHeaders, int aLamp)
1270 {
1271  cpl_errorstate prestate = cpl_errorstate_get();
1272  char keyword[KEYWORD_LENGTH];
1273  snprintf(keyword, KEYWORD_LENGTH, "ESO INS LAMP%d ST", aLamp);
1274  const int value = cpl_propertylist_get_bool(aHeaders, keyword);
1275  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
1276  return value;
1277 }
1278 
1279 /*----------------------------------------------------------------------------*/
1288 /*----------------------------------------------------------------------------*/
1289 const char *
1290 muse_pfits_get_shut_name(const cpl_propertylist *aHeaders, int aShutter)
1291 {
1292  cpl_errorstate prestate = cpl_errorstate_get();
1293  char keyword[KEYWORD_LENGTH];
1294  snprintf(keyword, KEYWORD_LENGTH, "ESO INS SHUT%d NAME", aShutter);
1295  const char *value = cpl_propertylist_get_string(aHeaders, keyword);
1296  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), NULL);
1297  return value;
1298 }
1299 
1300 /*----------------------------------------------------------------------------*/
1309 /*----------------------------------------------------------------------------*/
1310 int
1311 muse_pfits_get_shut_status(const cpl_propertylist *aHeaders, int aShutter)
1312 {
1313  cpl_errorstate prestate = cpl_errorstate_get();
1314  char keyword[KEYWORD_LENGTH];
1315  snprintf(keyword, KEYWORD_LENGTH, "ESO INS SHUT%d ST", aShutter);
1316  const int value = cpl_propertylist_get_bool(aHeaders, keyword);
1317  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
1318  return value;
1319 }
1320 
1321 /*----------------------------------------------------------------------------*/
1332 /*----------------------------------------------------------------------------*/
1333 int
1334 muse_pfits_get_posenc(const cpl_propertylist *aHeaders, unsigned short aEncoder)
1335 {
1336  cpl_errorstate prestate = cpl_errorstate_get();
1337  char keyword[KEYWORD_LENGTH];
1338  snprintf(keyword, KEYWORD_LENGTH, "ESO INS POS%d ENC", aEncoder);
1339  const int value = cpl_propertylist_get_int(aHeaders, keyword);
1340  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0);
1341  return value;
1342 }
1343 
1344 /*----------------------------------------------------------------------------*/
1361 /*----------------------------------------------------------------------------*/
1362 double
1363 muse_pfits_get_pospos(const cpl_propertylist *aHeaders, unsigned short aEncoder)
1364 {
1365  cpl_errorstate prestate = cpl_errorstate_get();
1366  char keyword[KEYWORD_LENGTH];
1367  snprintf(keyword, KEYWORD_LENGTH, "ESO INS POS%d POS", aEncoder);
1368  const double value = cpl_propertylist_get_double(aHeaders, keyword);
1369  cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
1370  return value;
1371 }
1372 
const char * muse_pfits_get_dpr_type(const cpl_propertylist *aHeaders)
find out the DPR type
Definition: muse_pfits.c:88
cpl_boolean muse_pfits_has_ifu(const cpl_propertylist *aHeaders, unsigned char aIFU)
Find out the whether this header related to a certain IFU.
Definition: muse_pfits.c:164
int muse_pfits_get_out_overscan_y(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
find out the vertical size of the overscan region of one quadrant
Definition: muse_pfits.c:709
int muse_pfits_get_out_output_y(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
find out the vertical location of the output port of one quadrant
Definition: muse_pfits.c:579
cpl_boolean muse_pfits_get_chip_live(const cpl_propertylist *aHeaders)
find out if the CCD was active (live)
Definition: muse_pfits.c:492
const char * muse_pfits_get_extname(const cpl_propertylist *aHeaders)
find out the extension name
Definition: muse_pfits.c:188
const char * muse_pfits_get_insmode(const cpl_propertylist *aHeaders)
find out the observation mode
Definition: muse_pfits.c:1125
int muse_pfits_get_read_id(const cpl_propertylist *aHeaders)
find out the readout mode id
Definition: muse_pfits.c:365
const char * muse_pfits_get_dpr_catg(const cpl_propertylist *aHeaders)
find out the DPR category
Definition: muse_pfits.c:106
double muse_pfits_get_rhum(const cpl_propertylist *aHeaders)
find out the relavtive humidity (in %)
Definition: muse_pfits.c:877
double muse_pfits_get_ra(const cpl_propertylist *aHeaders)
find out the right ascension
Definition: muse_pfits.c:232
cpl_size muse_pfits_get_naxis(const cpl_propertylist *aHeaders, unsigned int aAxis)
find out the size of a given axis
Definition: muse_pfits.c:207
double muse_pfits_get_gain(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
find the detector gain (in units of count/adu)
Definition: muse_pfits.c:539
int muse_pfits_get_shut_status(const cpl_propertylist *aHeaders, int aShutter)
query the status of one shutter
Definition: muse_pfits.c:1311
int muse_pfits_get_out_overscan_x(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
find out the horizontal size of the overscan region of one quadrant
Definition: muse_pfits.c:687
double muse_pfits_get_altang(const cpl_propertylist *aHeaders)
find out the altitude angle at start of the exposure (in degrees)
Definition: muse_pfits.c:969
int muse_pfits_get_out_output_x(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
find out the horizontal location of the output port of one quadrant
Definition: muse_pfits.c:557
double muse_pfits_get_pres_start(const cpl_propertylist *aHeaders)
find out the ambient pressure at start of exposure (in mbar)
Definition: muse_pfits.c:895
double muse_pfits_get_airmass_start(const cpl_propertylist *aHeaders)
find out the airmass at start of exposure
Definition: muse_pfits.c:823
const char * muse_pfits_get_dateobs(const cpl_propertylist *aHeaders)
find out the date of observations
Definition: muse_pfits.c:329
double muse_pfits_get_focu_scale(const cpl_propertylist *aHeaders)
find out the scale in the VLT focal plane
Definition: muse_pfits.c:804
const char * muse_pfits_get_shut_name(const cpl_propertylist *aHeaders, int aShutter)
query the name of one shutter
Definition: muse_pfits.c:1290
int muse_pfits_get_lampnum(const cpl_propertylist *aHeaders)
query the number of lamps installed
Definition: muse_pfits.c:1225
double muse_pfits_get_drot_posang(const cpl_propertylist *aHeaders)
find out the MUSE derotator position angle (in degrees)
Definition: muse_pfits.c:1041
const char * muse_pfits_get_chip_date(const cpl_propertylist *aHeaders)
find out the chip installation date
Definition: muse_pfits.c:473
double muse_pfits_get_equinox(const cpl_propertylist *aHeaders)
find out the equinox
Definition: muse_pfits.c:271
const char * muse_pfits_get_pam2_filter(const cpl_propertylist *aHeaders)
query the filter set up in front of photo diode (pico amplifier) 2
Definition: muse_pfits.c:1201
double muse_pfits_get_fwhm_end(const cpl_propertylist *aHeaders)
find out the ambient seeing at end of exposure (in arcsec)
Definition: muse_pfits.c:950
int muse_pfits_get_biny(const cpl_propertylist *aHeaders)
find out the binning factor in y direction
Definition: muse_pfits.c:419
double muse_pfits_get_geolat(const cpl_propertylist *aHeaders)
find out the telescope's latitude
Definition: muse_pfits.c:735
const char * muse_pfits_get_lamp_name(const cpl_propertylist *aHeaders, int aLamp)
query the name of one lamp
Definition: muse_pfits.c:1248
double muse_pfits_get_pam_intensity(const cpl_propertylist *aHeaders, int aDiode)
query the intensity measured by one photo diode (pico amplifier)
Definition: muse_pfits.c:1151
const char * muse_pfits_get_pipefile(const cpl_propertylist *aHeaders)
find out the pipefile
Definition: muse_pfits.c:71
const char * muse_pfits_get_drot_mode(const cpl_propertylist *aHeaders)
find out the MUSE derotator mode
Definition: muse_pfits.c:1023
int muse_pfits_get_out_prescan_y(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
find out the vertical size of the prescan region of one quadrant
Definition: muse_pfits.c:665
int muse_pfits_get_out_nx(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
find out the horizontal size of the data region of one quadrant
Definition: muse_pfits.c:601
const char * muse_pfits_get_arcfile(const cpl_propertylist *aHeaders)
find out the arcfile
Definition: muse_pfits.c:54
double muse_pfits_get_ron(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
find the detector read-out noise
Definition: muse_pfits.c:513
const char * muse_pfits_get_read_name(const cpl_propertylist *aHeaders)
find out the readout mode name
Definition: muse_pfits.c:383
double muse_pfits_get_pam_stdev(const cpl_propertylist *aHeaders, int aDiode)
query the intensity std. dev. of one photo diode (pico amplifier)
Definition: muse_pfits.c:1181
double muse_pfits_get_drot_end(const cpl_propertylist *aHeaders)
find out the MUSE derotator rotation at exposure end (in degrees)
Definition: muse_pfits.c:1077
double muse_pfits_get_fwhm_start(const cpl_propertylist *aHeaders)
find out the ambient seeing at start of exposure (in arcsec)
Definition: muse_pfits.c:931
double muse_pfits_get_drot_start(const cpl_propertylist *aHeaders)
find out the MUSE derotator rotation at exposure start (in degrees)
Definition: muse_pfits.c:1059
double muse_pfits_get_dec(const cpl_propertylist *aHeaders)
find out the declination
Definition: muse_pfits.c:250
int muse_pfits_get_posenc(const cpl_propertylist *aHeaders, unsigned short aEncoder)
query the absolute encoder position of one encoder
Definition: muse_pfits.c:1334
const char * muse_pfits_get_chip_id(const cpl_propertylist *aHeaders)
find out the chip id
Definition: muse_pfits.c:455
int muse_pfits_get_binx(const cpl_propertylist *aHeaders)
find out the binning factor in x direction
Definition: muse_pfits.c:401
double muse_pfits_get_parang_start(const cpl_propertylist *aHeaders)
find out the parallactic angle at start of exposure (in degrees)
Definition: muse_pfits.c:987
double muse_pfits_get_pres_end(const cpl_propertylist *aHeaders)
find out the ambient pressure at end of exposure (in mbar)
Definition: muse_pfits.c:913
double muse_pfits_get_airmass_end(const cpl_propertylist *aHeaders)
find out the airmass at end of exposure
Definition: muse_pfits.c:841
int muse_pfits_get_lamp_status(const cpl_propertylist *aHeaders, int aLamp)
query the status of one lamp
Definition: muse_pfits.c:1269
double muse_pfits_get_mjdobs(const cpl_propertylist *aHeaders)
find out the Julian Date of the observation
Definition: muse_pfits.c:311
double muse_pfits_get_pospos(const cpl_propertylist *aHeaders, unsigned short aEncoder)
query the position in user units of one encoder
Definition: muse_pfits.c:1363
const char * muse_pfits_get_pro_type(const cpl_propertylist *aHeaders)
find out the PRO type
Definition: muse_pfits.c:124
double muse_pfits_get_exptime(const cpl_propertylist *aHeaders)
find out the exposure time
Definition: muse_pfits.c:347
const char * muse_pfits_get_pro_catg(const cpl_propertylist *aHeaders)
find out the PRO category
Definition: muse_pfits.c:142
double muse_pfits_get_temp(const cpl_propertylist *aHeaders)
find out the ambient temperature (in degrees Celsius)
Definition: muse_pfits.c:859
double muse_pfits_get_geoelev(const cpl_propertylist *aHeaders)
find out the telescope's elevation
Definition: muse_pfits.c:781
int muse_pfits_get_out_prescan_x(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
find out the horizontal size of the prescan region of one quadrant
Definition: muse_pfits.c:643
double muse_pfits_get_lst(const cpl_propertylist *aHeaders)
find out the local siderial time
Definition: muse_pfits.c:293
int muse_pfits_get_out_ny(const cpl_propertylist *aHeaders, unsigned char aQuadrant)
find out the vertical size of the data region of one quadrant
Definition: muse_pfits.c:622
const char * muse_pfits_get_chip_name(const cpl_propertylist *aHeaders)
find out the chip name
Definition: muse_pfits.c:437
double muse_pfits_get_geolon(const cpl_propertylist *aHeaders)
find out the telescope's longitude
Definition: muse_pfits.c:759
muse_ins_mode muse_pfits_get_mode(const cpl_propertylist *aHeaders)
find out the observation mode
Definition: muse_pfits.c:1097
double muse_pfits_get_parang_end(const cpl_propertylist *aHeaders)
find out the parallactic angle at end of exposure (in degrees)
Definition: muse_pfits.c:1005