UVES Pipeline Reference Manual  5.4.0
uves_pfits.c
1 /*
2  * This file is part of the UVES Pipeline
3  * Copyright (C) 2002, 2003, 2004, 2005 Europpean Southern Observatory
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18  */
19 
20 /*
21  * $Author: amodigli $
22  * $Date: 2013-04-16 15:46:38 $
23  * $Revision: 1.110 $
24  * $Name: not supported by cvs2svn $
25  * $Log: not supported by cvs2svn $
26  * Revision 1.109 2010/09/24 09:32:06 amodigli
27  * put back QFITS dependency to fix problem spot by NRI on FIBER mode (with MIDAS calibs) data
28  *
29  * Revision 1.107 2010/06/01 13:30:20 amodigli
30  * defined UVES_TUNIT, uves_pfits_set_tunit_no(), uves_pfits_set_bunit_no()
31  *
32  * Revision 1.106 2009/07/13 06:37:46 amodigli
33  * added uves_ccd_is_new()
34  *
35  * Revision 1.105 2009/05/15 11:17:33 amodigli
36  * replace irplib_vsprintf by cpl_vsprintf
37  *
38  * Revision 1.104 2008/09/29 06:58:49 amodigli
39  * add #include <string.h>
40  *
41  * Revision 1.103 2007/10/08 14:10:31 amodigli
42  * assumes 5 for DATANCOM if not found in FITS header
43  *
44  * Revision 1.102 2007/08/30 07:56:54 amodigli
45  * fixed some doxygen warnings
46  *
47  * Revision 1.101 2007/08/21 13:08:26 jmlarsen
48  * Removed irplib_access module, largely deprecated by CPL-4
49  *
50  * Revision 1.100 2007/06/28 09:18:21 jmlarsen
51  * Added functions to write DPR keywords
52  *
53  * Revision 1.99 2007/06/06 08:17:33 amodigli
54  * replace tab with 4 spaces
55  *
56  * Revision 1.98 2007/06/01 14:09:57 jmlarsen
57  * Exported uves_pfits_get_pixelscale
58  *
59  * Revision 1.97 2007/05/23 13:03:19 jmlarsen
60  * Added missing include directive
61  *
62  * Revision 1.96 2007/05/16 14:38:03 amodigli
63  * added uves_flames_pfits_get_ident & uves_flames_pfits_get_object
64  *
65  * Revision 1.95 2007/05/14 09:36:50 amodigli
66  * added checks on return types
67  *
68  * Revision 1.94 2007/05/04 08:53:49 amodigli
69  * added uves_flames_pfits_get_nflats
70  *
71  * Revision 1.93 2007/05/03 15:21:33 jmlarsen
72  * Added function to read wavecal offset
73  *
74  * Revision 1.92 2007/04/26 13:19:40 jmlarsen
75  * Added uves_pfits_set_ocs_simcal()
76  *
77  * Revision 1.91 2007/04/25 08:37:19 amodigli
78  * added uves_pfits_get_origfile
79  *
80  * Revision 1.90 2007/04/24 12:50:29 jmlarsen
81  * Replaced cpl_propertylist -> uves_propertylist which is much faster
82  *
83  * Revision 1.89 2007/04/24 09:41:09 jmlarsen
84  * Renamed irplib_vsnprintf_create -> irplib_vsprintf
85  *
86  * Revision 1.88 2007/03/05 10:18:16 jmlarsen
87  * Write 2d extraion slit length
88  *
89  * Revision 1.87 2007/01/31 13:11:27 jmlarsen
90  * Added SIMCAL accessor functions
91  *
92  * Revision 1.86 2007/01/29 12:10:19 jmlarsen
93  * Exported set_history_val() for usage by FLAMES
94  *
95  * Revision 1.85 2007/01/26 12:33:57 amodigli
96  * added function for common QC
97  *
98  * Revision 1.84 2007/01/17 13:27:10 jmlarsen
99  * Added BITPIX accessor function
100  *
101  * Revision 1.83 2007/01/10 14:16:15 jmlarsen
102  * Fixed wrong format string
103  *
104  * Revision 1.82 2007/01/10 12:39:09 jmlarsen
105  * Unified two get_plate_id functions
106  *
107  * Revision 1.81 2006/12/27 13:55:29 amodigli
108  * added flames_pfits_get_plate_id and some FLAMES_ defines for FIBER mode
109  *
110  * Revision 1.80 2006/12/07 08:25:07 jmlarsen
111  * Added uves_pfits_get_readspeed
112  *
113  * Revision 1.79 2006/12/01 12:27:25 jmlarsen
114  * Factored out FLAMES plate-id code
115  *
116  * Revision 1.78 2006/11/24 09:36:25 jmlarsen
117  * Workaround for slow uves_propertylist_get_size
118  *
119  * Revision 1.77 2006/11/15 15:02:14 jmlarsen
120  * Implemented const safe workarounds for CPL functions
121  *
122  * Revision 1.75 2006/11/15 14:04:08 jmlarsen
123  * Removed non-const version of parameterlist_get_first/last/next which is
124  * already in CPL, added const-safe wrapper, unwrapper and deallocator functions
125  *
126  * Revision 1.74 2006/11/13 14:23:55 jmlarsen
127  * Removed workarounds for CPL const bugs
128  *
129  * Revision 1.73 2006/11/06 15:19:41 jmlarsen
130  * Removed unused include directives
131  *
132  * Revision 1.72 2006/10/25 07:21:35 jmlarsen
133  * Documentation bug fix
134  *
135  * Revision 1.71 2006/10/24 14:05:47 jmlarsen
136  * Added OBSPLATE
137  *
138  * Revision 1.70 2006/10/05 06:50:23 jmlarsen
139  * Renamed function format_is_new -> uves_format_is_new
140  *
141  * Revision 1.69 2006/10/04 10:55:33 jmlarsen
142  * Added telescope lat-/longitude accessor functions
143  *
144  * Revision 1.68 2006/09/27 13:14:15 jmlarsen
145  * Added accessor functions for RA/DEC
146  *
147  * Revision 1.67 2006/09/20 10:57:36 jmlarsen
148  * Propagate DATAMEAN/DATAMED/DATARMS if present
149  *
150  * Revision 1.66 2006/09/19 07:19:30 jmlarsen
151  * Changed function set_history_int -> set_history_val to support writing values of any type
152  *
153  * Revision 1.65 2006/08/24 11:37:12 jmlarsen
154  * Write recipe start/stop time to header
155  *
156  * Revision 1.64 2006/08/21 12:51:02 jmlarsen
157  * Renamed shadowing variable
158  *
159  * Revision 1.63 2006/08/21 07:45:51 jmlarsen
160  * Update HISTORY FABSORD keyword if it already exists, rather than adding a new keyword
161  *
162  * Revision 1.62 2006/08/21 07:06:16 jmlarsen
163  * Fixed documantation bug
164  *
165  * Revision 1.61 2006/08/18 13:32:37 jmlarsen
166  * Fixed memory leak
167  *
168  * Revision 1.60 2006/08/18 10:14:04 jmlarsen
169  * Use legal FITS keywords for TRACEID/WINDOW/FABSORD/LABSORD
170  *
171  * Revision 1.59 2006/08/17 14:40:06 jmlarsen
172  * Added missing documentation
173  *
174  * Revision 1.58 2006/08/17 14:11:25 jmlarsen
175  * Use assure_mem macro to check for memory allocation failure
176  *
177  * Revision 1.57 2006/08/17 13:56:53 jmlarsen
178  * Reduced max line length
179  *
180  * Revision 1.56 2006/08/09 14:23:19 jmlarsen
181  * Removed unused function argument
182  *
183  * Revision 1.55 2006/07/31 06:29:26 amodigli
184  * added QC on stability test
185  *
186  * Revision 1.54 2006/07/14 12:24:49 jmlarsen
187  * Added conad, target name
188  *
189  * Revision 1.53 2006/06/13 11:58:55 jmlarsen
190  * Bugfix: Use proper chipname keyword for REDL chip
191  *
192  * Revision 1.52 2006/06/02 06:42:12 jmlarsen
193  * Added missing cleanup label
194  *
195  * Revision 1.51 2006/06/01 14:43:17 jmlarsen
196  * Added missing documentation
197  *
198  * Revision 1.50 2006/06/01 14:22:48 amodigli
199  * moved format_is_new to c module and made it static
200  *
201  * Revision 1.49 2006/05/31 09:26:40 amodigli
202  * fixed some problem dumping QC log
203  *
204  * Revision 1.48 2006/05/19 13:07:20 amodigli
205  * added uves_pfits_get_slit3_x1encoder
206  *
207  * Revision 1.47 2006/05/09 15:43:13 amodigli
208  * added useful key/functions
209  *
210  * Revision 1.46 2006/04/26 12:25:20 amodigli
211  * fixed a problem with ARCFILE keyword
212  *
213  * Revision 1.45 2006/04/25 14:58:48 amodigli
214  * added paf creation functionalities
215  *
216  * Revision 1.44 2006/04/20 10:48:58 amodigli
217  * added uves_pfits_get_tpl_start
218  *
219  * Revision 1.43 2006/03/24 13:59:41 jmlarsen
220  * Added check that central wavelength is always positive
221  *
222  * Revision 1.42 2006/03/03 13:54:11 jmlarsen
223  * Changed syntax of check macro
224  *
225  * Revision 1.41 2005/12/20 16:10:32 jmlarsen
226  * Added some documentation
227  *
228  * Revision 1.40 2005/12/19 16:17:56 jmlarsen
229  * Replaced bool -> int
230  *
231  */
232 
233 #ifdef HAVE_CONFIG_H
234 #include <config.h>
235 #endif
236 
237 /*----------------------------------------------------------------------------*/
243 /*----------------------------------------------------------------------------*/
246 /*-----------------------------------------------------------------------------
247  Defines
248  -----------------------------------------------------------------------------*/
249 
250 /*-----------------------------------------------------------------------------
251  Includes
252  -----------------------------------------------------------------------------*/
253 #include <stdio.h>
254 #include <uves_pfits.h>
255 
256 #include <uves_utils.h>
257 #include <uves_utils_wrappers.h>
258 #include <uves_dump.h>
259 #include <uves_error.h>
260 
261 #include <irplib_utils.h>
262 
263 #include <cpl.h>
264 
265 #include <stdio.h>
266 #include <stdbool.h>
267 #include <errno.h>
268 #include <string.h>
269 /*-----------------------------------------------------------------------------
270  Forward declarations
271  -----------------------------------------------------------------------------*/
272 
273 /*-----------------------------------------------------------------------------
274  Function codes
275  -----------------------------------------------------------------------------*/
276 
277 /*----------------------------------------------------------------------------*/
283 /*----------------------------------------------------------------------------*/
285 {
286  int result=0;
287  check(result=uves_propertylist_get_int(plist,UVES_ENCODER_REF1),
288  "Error getting %s", UVES_ENCODER_REF1);
289 
290  cleanup:
291  return result;
292 
293 }
294 
295 /*----------------------------------------------------------------------------*/
301 /*----------------------------------------------------------------------------*/
303 {
304  int result=0;
305  check(result=uves_propertylist_get_int(plist,UVES_ENCODER_REF2),
306  "Error getting %s",UVES_ENCODER_REF2);
307 
308 
309  cleanup:
310  return result;
311 
312 }
313 
314 /*----------------------------------------------------------------------------*/
320 /*----------------------------------------------------------------------------*/
322 {
323  int result=0;
324  check(uves_get_property_value(plist, "MAXFIBRES",
325  CPL_TYPE_INT, &result),
326  "Error reading MAXFIBRES");
327 
328  cleanup:
329  return result;
330 
331 }
332 
333 /*----------------------------------------------------------------------------*/
339 /*----------------------------------------------------------------------------*/
341 {
342  char result=0;
343  check(result=uves_propertylist_get_char(plist,"CHIPCHOICE"),
344  "Error getting CHIPCHOICE");
345 
346  cleanup:
347  return result;
348 
349 }
350 /*----------------------------------------------------------------------------*/
356 /*----------------------------------------------------------------------------*/
357 const char * uves_pfits_get_badpxframe(const uves_propertylist * plist)
358 {
359 
360  const char* result=NULL;
361 
362  check(uves_get_property_value(plist, "BADPXFRAME",
363  CPL_TYPE_STRING, &result),
364  "Error reading BADPXFRAME");
365 
366  cleanup:
367  return result;
368 
369 }
370 
371 
372 /*----------------------------------------------------------------------------*/
378 /*----------------------------------------------------------------------------*/
380 {
381  double result=0;
382 
383  check(uves_get_property_value(plist, "ESO INS SENS26 MEAN",
384  CPL_TYPE_DOUBLE, &result),
385  "Error reading ESO INS SENS26 MEAN");
386 
387  cleanup:
388  return result;
389 
390 }
391 
392 
393 /*---------------------------------------------------------------------------*/
399 /*---------------------------------------------------------------------------*/
400 const char * uves_pfits_get_arcfile(const uves_propertylist * plist)
401 {
402 
403  const char* result=NULL;
404 
405 
406  check(uves_get_property_value(plist, "ARCFILE",
407  CPL_TYPE_STRING, &result),
408  "Error reading ARCFILE");
409 
410  cleanup:
411  return result;
412 
413 }
414 
415 /*---------------------------------------------------------------------------*/
421 /*---------------------------------------------------------------------------*/
423 {
424 
425  const char* result=NULL;
426 
427  check(result=uves_propertylist_get_string(plist,"IDENT"),
428  "Error getting IDENT");
429 
430  cleanup:
431  return result;
432 
433 }
434 
435 /*---------------------------------------------------------------------------*/
441 /*---------------------------------------------------------------------------*/
443 {
444 
445  const char* result=NULL;
446 
447  check(result=uves_propertylist_get_string(plist,UVES_OBJECT),
448  "Error getting OBJECT");
449 
450  cleanup:
451  return result;
452 
453 }
454 
455 /*---------------------------------------------------------------------------*/
461 /*---------------------------------------------------------------------------*/
462 const char * uves_pfits_get_origfile(const uves_propertylist * plist)
463 {
464 
465  const char* result=NULL;
466 
467  check(uves_get_property_value(plist, "ORIGFILE",
468  CPL_TYPE_STRING, &result),
469  "Error reading ORIGFILE");
470 
471  cleanup:
472  return result;
473 
474 }
475 
476 /*----------------------------------------------------------------------------*/
482 /*----------------------------------------------------------------------------*/
483 const char * uves_pfits_get_pipefile(const uves_propertylist * plist)
484 {
485 
486  const char* result=NULL;
487 
488 
489  check(uves_get_property_value(plist, "PIPEFILE",
490  CPL_TYPE_STRING, &result),
491  "Error reading PIPEFILE");
492 
493  cleanup:
494  return result;
495 
496 }
497 
498 
499 
500 
501 /*----------------------------------------------------------------------------*/
507 /*----------------------------------------------------------------------------*/
509 {
510  const char* result=NULL;
511 
512  check(uves_get_property_value(plist, "ESO PRO REC1 RAW1 NAME",
513  CPL_TYPE_STRING, &result),
514  "Error reading ESO PRO REC1 RAW1 NAME");
515 
516 
517  cleanup:
518  return result;
519 }
520 /*----------------------------------------------------------------------------*/
526 /*----------------------------------------------------------------------------*/
527 const char * uves_pfits_get_templateid(const uves_propertylist * plist)
528 {
529  const char* result=NULL;
530 
531  check(uves_get_property_value(plist, "ESO TPL ID",
532  CPL_TYPE_STRING, &result),
533  "Error reading ESO TPL ID");
534 
535 
536  cleanup:
537 
538  return result;
539 }
540 
541 
542 /*----------------------------------------------------------------------------*/
548 /*----------------------------------------------------------------------------*/
549 const char * uves_pfits_get_date_obs(const uves_propertylist * plist)
550 {
551 
552  const char* result=NULL;
553  check(uves_get_property_value(plist, "DATE-OBS",
554  CPL_TYPE_STRING, &result),
555  "Error reading DATE-OBS");
556 
557  cleanup:
558  return result;
559 
560 }
561 /*----------------------------------------------------------------------------*/
567 /*----------------------------------------------------------------------------*/
568 const char * uves_pfits_get_dpr_catg(const uves_propertylist * plist)
569 {
570  const char* result=NULL;
571 
572  check(uves_get_property_value(plist, UVES_DPR_CATG,
573  CPL_TYPE_STRING, &result),
574  "Error reading %s", UVES_DPR_CATG);
575 
576  cleanup:
577  return result;
578 }
579 
580 /*----------------------------------------------------------------------------*/
586 /*----------------------------------------------------------------------------*/
588 {
589  int returnvalue = 0;
590 
591  check( uves_get_property_value(plist, UVES_OCS_SIMCAL, CPL_TYPE_INT, &returnvalue),
592  "Error reading keyword '%s'", UVES_OCS_SIMCAL);
593 
594  cleanup:
595  return returnvalue;
596 }
597 
598 /*----------------------------------------------------------------------------*/
604 /*----------------------------------------------------------------------------*/
606 {
607  check( uves_propertylist_update_int(plist, UVES_OCS_SIMCAL, simcal),
608  "Error writing keyword '%s'", UVES_OCS_SIMCAL);
609 
610  cleanup:
611  return;
612 
613 }
614 
615 /*----------------------------------------------------------------------------*/
621 /*----------------------------------------------------------------------------*/
622 const char * uves_pfits_get_pro_catg(const uves_propertylist * plist)
623 {
624  const char* result=NULL;
625 
626  check(uves_get_property_value(plist, "ESO PRO CATG",
627  CPL_TYPE_STRING, &result),
628  "Error reading ESO PRO CATG");
629 
630  cleanup:
631  return result;
632 }
633 
634 /*----------------------------------------------------------------------------*/
640 /*----------------------------------------------------------------------------*/
641 const char * uves_pfits_get_dpr_tech(const uves_propertylist * plist)
642 {
643  const char* result=NULL;
644 
645  check( uves_get_property_value(plist, UVES_DPR_TECH,
646  CPL_TYPE_STRING, &result),
647  "Error reading %s", UVES_DPR_TECH);
648 
649  cleanup:
650  return result;
651 }
652 
653 /*----------------------------------------------------------------------------*/
659 /*----------------------------------------------------------------------------*/
660 const char * uves_pfits_get_dpr_type(const uves_propertylist * plist)
661 {
662  const char* result=NULL;
663 
664 
665  check( uves_get_property_value(plist, UVES_DPR_TYPE,
666  CPL_TYPE_STRING, &result),
667  "Error reading %s", UVES_DPR_TYPE);
668 
669  cleanup:
670  return result;
671 }
672 
673 /*----------------------------------------------------------------------------*/
680 /*----------------------------------------------------------------------------*/
682 {
683  double mjd_obs = 0.0; /* Observation date */
684 
685  check( mjd_obs = uves_pfits_get_mjdobs(plist),
686  "Could not read observation date");
687 
688  cleanup:
689  /* New format iff modified julian date is after April 1st, 2004 = 53096 mjd */
690  return (mjd_obs > 55018.0);
691 }
692 
693 /*----------------------------------------------------------------------------*/
700 /*----------------------------------------------------------------------------*/
702 {
703  double mjd_obs = 0.0; /* Observation date */
704 
705  check( mjd_obs = uves_pfits_get_mjdobs(plist),
706  "Could not read observation date");
707 
708  cleanup:
709  /* New format iff modified julian date is after April 1st, 2004 = 53096 mjd */
710  return (mjd_obs > 53096.0);
711 }
712 
713 /*----------------------------------------------------------------------------*/
721 /*----------------------------------------------------------------------------*/
722 int uves_pfits_get_prescanx(const uves_propertylist * plist, enum uves_chip chip)
723 {
724  int returnvalue = 0;
725  bool new_format;
726 
727  check( new_format = uves_format_is_new(plist),
728  "Error determining FITS header format");
729 
730  check( uves_get_property_value(plist, UVES_PRESCANX(new_format, chip),
731  CPL_TYPE_INT, &returnvalue),
732  "Error reading keyword %s", UVES_PRESCANX(new_format, chip));
733 
734  cleanup:
735  return returnvalue;
736 }
737 
738 /*----------------------------------------------------------------------------*/
746 /*----------------------------------------------------------------------------*/
747 const char* uves_pfits_get_chipid(const uves_propertylist * plist, enum uves_chip chip)
748 {
749  const char* returnvalue = "";
750 
751  check( uves_get_property_value(plist, UVES_CHIP_ID(chip), CPL_TYPE_STRING, &returnvalue),
752  "Error reading keyword %s", UVES_CHIP_ID(chip));
753 
754  cleanup:
755  return returnvalue;
756 }
757 
758 /*----------------------------------------------------------------------------*/
766 /*----------------------------------------------------------------------------*/
767 const char* uves_pfits_get_chip_name(const uves_propertylist * plist, enum uves_chip chip)
768 {
769  const char* returnvalue = "";
770 
771  check( uves_get_property_value(plist, UVES_CHIP_NAME(chip), CPL_TYPE_STRING, &returnvalue),
772  "Error reading keyword %s", UVES_CHIP_NAME(chip));
773 
774  cleanup:
775  return returnvalue;
776 }
777 
778 /*----------------------------------------------------------------------------*/
786 /*----------------------------------------------------------------------------*/
787 int uves_pfits_get_ovrscanx(const uves_propertylist * plist, enum uves_chip chip)
788 {
789  int returnvalue = 0;
790  bool new_format;
791 
792  check( new_format = uves_format_is_new(plist),
793  "Error determining FITS header format");
794 
795  check( uves_get_property_value(plist, UVES_OVRSCANX(new_format, chip),
796  CPL_TYPE_INT, &returnvalue),
797  "Error reading keyword %s", UVES_OVRSCANX(new_format, chip));
798 
799  cleanup:
800  return returnvalue;
801 }
802 
803 /*----------------------------------------------------------------------------*/
811 /*----------------------------------------------------------------------------*/
812 int uves_pfits_get_prescany(const uves_propertylist * plist, enum uves_chip chip)
813 {
814  int returnvalue = 0;
815  bool new_format;
816 
817 
818  check( new_format = uves_format_is_new(plist),
819  "Error determining FITS header format");
820 
821  check( uves_get_property_value(plist, UVES_PRESCANY(new_format, chip),
822  CPL_TYPE_INT, &returnvalue),
823  "Error reading keyword %s", UVES_PRESCANY(new_format, chip));
824 
825  cleanup:
826  return returnvalue;
827 }
828 
829 /*----------------------------------------------------------------------------*/
837 /*----------------------------------------------------------------------------*/
838 int uves_pfits_get_ovrscany(const uves_propertylist * plist, enum uves_chip chip)
839 {
840  int returnvalue = 0;
841  bool new_format;
842 
843  check( new_format = uves_format_is_new(plist),
844  "Error determining FITS header format");
845 
846  check( uves_get_property_value(plist, UVES_OVRSCANY(new_format, chip),
847  CPL_TYPE_INT, &returnvalue),
848  "Error reading keyword %s", UVES_OVRSCANY(new_format, chip));
849 
850  cleanup:
851  return returnvalue;
852 }
853 
854 /*----------------------------------------------------------------------------*/
867 /*----------------------------------------------------------------------------*/
868 double uves_pfits_get_ron_adu(const uves_propertylist * plist, enum uves_chip chip)
869 {
870  double ron_el = 0; /* Read-out noise in electron units */
871  double default_ron_el = 5.0;/* Number converted from MIDAS */
872  double gain = 0; /* Conversion from electrons to ADUs */
873  bool new_format;
874 
875  check( new_format = uves_format_is_new(plist),
876  "Error determining FITS header format");
877 
878  check( uves_get_property_value(plist, UVES_RON(new_format, chip), CPL_TYPE_DOUBLE, &ron_el),
879  "Error reading keyword '%s'", UVES_RON(new_format, chip));
880 
881  if (ron_el <= 0)
882  {
883  uves_msg_warning("Read-out-noise is "
884  "non-positive (%e electrons). Using default value %e",
885  ron_el, default_ron_el);
886  ron_el = default_ron_el;
887  }
888 
889  check( gain = uves_pfits_get_gain(plist, chip),
890  "Error reading gain");
891 
892  assure( ron_el * gain > 0, CPL_ERROR_ILLEGAL_INPUT,
893  "Non-positive read-out noise: %f ADU", ron_el * gain);
894 
895  cleanup:
896  return ron_el * gain;
897 }
898 /*----------------------------------------------------------------------------*/
906 /*----------------------------------------------------------------------------*/
908 {
909  double result = 0;
910 
911  check( uves_get_property_value(plist, UVES_AIRMASS_START, CPL_TYPE_DOUBLE, &result),
912  "Error reading keyword '%s'", UVES_AIRMASS_START);
913 
914  cleanup:
915  return result;
916 }
917 /*----------------------------------------------------------------------------*/
925 /*----------------------------------------------------------------------------*/
927 {
928  double result = 0;
929 
930  check( uves_get_property_value(plist, UVES_AIRMASS_END, CPL_TYPE_DOUBLE, &result),
931  "Error reading keyword '%s'", UVES_AIRMASS_END);
932 
933  cleanup:
934  return result;
935 }
936 /*----------------------------------------------------------------------------*/
945 /*----------------------------------------------------------------------------*/
946 double uves_pfits_get_conad(const uves_propertylist * plist, enum uves_chip chip)
947 {
948  double result = 0;
949 
950  bool new_format;
951 
952  check( new_format = uves_format_is_new(plist),
953  "Error determining FITS header format");
954 
955  check( uves_get_property_value(plist, UVES_CONAD(new_format, chip),
956  CPL_TYPE_DOUBLE, &result),
957  "Error reading keyword '%s'", UVES_CONAD(new_format, chip));
958 
959  cleanup:
960  return result;
961 }
962 /*----------------------------------------------------------------------------*/
970 /*----------------------------------------------------------------------------*/
971 const char *uves_pfits_get_targ_name(const uves_propertylist * plist)
972 {
973  const char* returnvalue = "";
974 
975  check( uves_get_property_value(plist, UVES_TARG_NAME, CPL_TYPE_STRING, &returnvalue),
976  "Error reading keyword %s", UVES_TARG_NAME);
977 
978  cleanup:
979  return returnvalue;
980 }
981 
982 /*----------------------------------------------------------------------------*/
992 /*----------------------------------------------------------------------------*/
993 double uves_pfits_get_gain(const uves_propertylist * plist, enum uves_chip chip)
994 {
995  double result = 0;
996  double default_gain = 2.1; /* Adopted from MIDAS */
997  bool new_format;
998 
999  check( new_format = uves_format_is_new(plist),
1000  "Error determining FITS header format");
1001 
1002  check( uves_get_property_value(plist, UVES_GAIN(new_format, chip),
1003  CPL_TYPE_DOUBLE, &result),
1004  "Error reading keyword '%s'", UVES_GAIN(new_format, chip));
1005 
1006  if (result <= 0)
1007  {
1008  uves_msg_warning("Gain factor from header is "
1009  "non-positive (%e). Using default value %e",
1010  result, default_gain);
1011  result = default_gain;
1012  }
1013 
1014  cleanup:
1015  return result;
1016 }
1017 /*----------------------------------------------------------------------------*/
1027 /*----------------------------------------------------------------------------*/
1029 {
1030  double result = 0; /* Conversion from electrons to ADUs */
1031 
1032  check( uves_get_property_value(plist, UVES_EXPTIME, CPL_TYPE_DOUBLE, &result),
1033  "Error reading keyword '%s'", UVES_EXPTIME);
1034  assure( result >= 0, CPL_ERROR_ILLEGAL_OUTPUT, "Exposure time is negative: %f", result);
1035 
1036  cleanup:
1037  return result;
1038 }
1039 
1040 /*----------------------------------------------------------------------------*/
1048 /*----------------------------------------------------------------------------*/
1049 cpl_error_code
1051 {
1052  check(( uves_propertylist_update_double(plist, UVES_EXPTIME, exptime),
1053  uves_propertylist_set_comment(plist, UVES_EXPTIME, "Total integration time")),
1054  "Error writing keyword '%s'", UVES_EXPTIME);
1055  cleanup:
1056  return cpl_error_get_code();
1057 }
1058 
1059 
1060 /*----------------------------------------------------------------------------*/
1068 /*----------------------------------------------------------------------------*/
1069 void
1071 {
1072  check( uves_propertylist_update_double(plist, UVES_DEC, dec),
1073  "Error writing keyword '%s'", UVES_DEC);
1074  cleanup:
1075  return;
1076 }
1077 
1078 /*----------------------------------------------------------------------------*/
1086 /*----------------------------------------------------------------------------*/
1087 void
1089 {
1090  check( uves_propertylist_update_double(plist, UVES_RA, ra),
1091  "Error writing keyword '%s'", UVES_RA);
1092  cleanup:
1093  return;
1094 }
1095 
1096 /*----------------------------------------------------------------------------*/
1104 /*----------------------------------------------------------------------------*/
1105 cpl_error_code
1107 {
1108  check(( uves_propertylist_update_int(plist, UVES_ORD_PRED, nord),
1109  uves_propertylist_set_comment(plist, UVES_ORD_PRED, "Predicted no of orders")),
1110  "Error writing keyword '%s'", UVES_ORD_PRED);
1111  cleanup:
1112  return cpl_error_get_code();
1113 }
1114 
1115 /*----------------------------------------------------------------------------*/
1121 /*----------------------------------------------------------------------------*/
1122 const char *
1124 {
1125  const char *result = "";
1126 
1127  check( uves_get_property_value(plist, UVES_DRS_ID, CPL_TYPE_STRING, &result),
1128  "Error reading keyword '%s'", UVES_DRS_ID);
1129 
1130  cleanup:
1131  if (cpl_error_get_code() != CPL_ERROR_NONE)
1132  {
1133  result = NULL;
1134  }
1135 
1136  return result;
1137 }
1138 
1139 
1140 
1141 /*----------------------------------------------------------------------------*/
1147 /*----------------------------------------------------------------------------*/
1148 const char *
1150 {
1151  const char *result = "";
1152 
1153  check( uves_get_property_value(plist, UVES_TPL_START, CPL_TYPE_STRING, &result),
1154  "Error reading keyword '%s'", UVES_TPL_START);
1155 
1156  cleanup:
1157  if (cpl_error_get_code() != CPL_ERROR_NONE)
1158  {
1159  result = NULL;
1160  }
1161 
1162  return result;
1163 }
1164 
1165 
1166 /*----------------------------------------------------------------------------*/
1172 /*----------------------------------------------------------------------------*/
1174 {
1175  double returnvalue = 0;
1176 
1177  check( uves_get_property_value(plist, UVES_UTC, CPL_TYPE_DOUBLE, &returnvalue),
1178  "Error reading keyword '%s'", UVES_UTC);
1179 
1180  cleanup:
1181  return returnvalue;
1182 }
1183 
1184 
1185 /*----------------------------------------------------------------------------*/
1191 /*----------------------------------------------------------------------------*/
1193 {
1194  double returnvalue = 0;
1195 
1196  check( uves_get_property_value(plist, UVES_MJDOBS, CPL_TYPE_DOUBLE, &returnvalue),
1197  "Error reading keyword '%s'", UVES_MJDOBS);
1198 
1199  cleanup:
1200  return returnvalue;
1201 }
1202 
1203 /*----------------------------------------------------------------------------*/
1209 /*----------------------------------------------------------------------------*/
1211 {
1212  double returnvalue = 0;
1213 
1214  check( uves_get_property_value(plist, UVES_GEOLAT, CPL_TYPE_DOUBLE, &returnvalue),
1215  "Error reading keyword '%s'", UVES_GEOLAT);
1216 
1217  cleanup:
1218  return returnvalue;
1219 }
1220 
1221 /*----------------------------------------------------------------------------*/
1227 /*----------------------------------------------------------------------------*/
1229 {
1230  double returnvalue = 0;
1231 
1232  check( uves_get_property_value(plist, UVES_GEOLON, CPL_TYPE_DOUBLE, &returnvalue),
1233  "Error reading keyword '%s'", UVES_GEOLON);
1234 
1235  cleanup:
1236  return returnvalue;
1237 }
1238 
1239 /*----------------------------------------------------------------------------*/
1245 /*----------------------------------------------------------------------------*/
1247 {
1248  double returnvalue = 0;
1249 
1250  check( uves_get_property_value(plist, UVES_RA, CPL_TYPE_DOUBLE, &returnvalue),
1251  "Error reading keyword '%s'", UVES_RA);
1252 
1253  cleanup:
1254  return returnvalue;
1255 }
1256 
1257 /*----------------------------------------------------------------------------*/
1263 /*----------------------------------------------------------------------------*/
1265 {
1266  double returnvalue = 0;
1267 
1268  check( uves_get_property_value(plist, UVES_DEC, CPL_TYPE_DOUBLE, &returnvalue),
1269  "Error reading keyword '%s'", UVES_DEC);
1270 
1271  cleanup:
1272  return returnvalue;
1273 }
1274 
1275 /*----------------------------------------------------------------------------*/
1281 /*----------------------------------------------------------------------------*/
1283 {
1284  int returnvalue = 0;
1285 
1286  check( uves_get_property_value(plist, UVES_BINX, CPL_TYPE_INT, &returnvalue),
1287  "Error reading keyword '%s'", UVES_BINX);
1288 
1289  cleanup:
1290  return returnvalue;
1291 }
1292 
1293 /*----------------------------------------------------------------------------*/
1299 /*----------------------------------------------------------------------------*/
1301 {
1302  int returnvalue = 0;
1303 
1304  check( uves_get_property_value(plist, UVES_BINY, CPL_TYPE_INT, &returnvalue),
1305  "Error reading keyword '%s'", UVES_BINY);
1306 
1307  cleanup:
1308  return returnvalue;
1309 }
1310 
1311 /*----------------------------------------------------------------------------*/
1317 /*----------------------------------------------------------------------------*/
1319 {
1320  int returnvalue = 0;
1321 
1322  /* This keyword changed name at some point. For support of older products, try to
1323  first new then old FITS card */
1324 
1325  assure( plist != NULL, CPL_ERROR_NULL_INPUT, "Null plist");
1326 
1327  if (uves_propertylist_contains(plist, UVES_DATANCOM))
1328  {
1329  check( uves_get_property_value(plist, UVES_DATANCOM, CPL_TYPE_INT, &returnvalue),
1330  "Error reading keyword '%s'", UVES_DATANCOM);
1331  }
1332  else if( uves_propertylist_contains(plist, UVES_DATANCOM_OLD))
1333  {
1334 
1335  check( uves_get_property_value(plist, UVES_DATANCOM_OLD, CPL_TYPE_INT, &returnvalue),
1336  "Error reading keyword '%s'", UVES_DATANCOM_OLD);
1337  } else {
1338 
1339  uves_msg_warning("Neither %s nor %s found! We assume a value of 5! This may affect noise/error propagation",
1340  UVES_DATANCOM,UVES_DATANCOM_OLD);
1341  returnvalue=5;
1342  }
1343 
1344  cleanup:
1345  return returnvalue;
1346 }
1347 
1348 
1349 
1350 /*----------------------------------------------------------------------------*/
1356 /*----------------------------------------------------------------------------*/
1357 const char* uves_pfits_get_ccdid(const uves_propertylist * plist)
1358 {
1359  const char* result="";
1360 
1361  check( uves_get_property_value(plist, UVES_CCDID, CPL_TYPE_STRING, &result),
1362  "Error reading keyword '%s'", UVES_CCDID);
1363 
1364  cleanup:
1365  return result;
1366 }
1367 
1368 /*----------------------------------------------------------------------------*/
1374 /*----------------------------------------------------------------------------*/
1376 {
1377  double returnvalue;
1378 
1379  check( uves_get_property_value(plist, UVES_PRESSURE, CPL_TYPE_DOUBLE, &returnvalue),
1380  "Error reading keyword '%s'", UVES_PRESSURE);
1381 
1382  cleanup:
1383  return returnvalue;
1384 }
1385 /*----------------------------------------------------------------------------*/
1393 /*----------------------------------------------------------------------------*/
1394 const char * uves_chop_eso_prefix(const char* key)
1395 {
1396  const char *result = NULL;
1397  const char *prefix = "ESO ";
1398  unsigned int pref_len = strlen(prefix);
1399 
1400  assure( strlen(key) >= pref_len &&
1401  strncmp(key, prefix, pref_len) == 0,
1402  CPL_ERROR_ILLEGAL_INPUT,
1403  "Keyword %s does not contain 'ESO ' prefix", key);
1404 
1405  result = key + pref_len;
1406 
1407  cleanup:
1408  return result;
1409 }
1410 
1411 /*----------------------------------------------------------------------------*/
1418 /*----------------------------------------------------------------------------*/
1419 double uves_pfits_get_tempcam(const uves_propertylist * plist, enum uves_chip chip)
1420 {
1421  double returnvalue;
1422 
1423  check( uves_get_property_value(plist, UVES_TEMPCAM(chip), CPL_TYPE_DOUBLE, &returnvalue),
1424  "Error reading keyword '%s'", UVES_TEMPCAM(chip));
1425 
1426  cleanup:
1427  return returnvalue;
1428 }
1429 
1430 
1431 /*----------------------------------------------------------------------------*/
1437 /*----------------------------------------------------------------------------*/
1439 {
1440  double returnvalue;
1441 
1442  check( uves_get_property_value(plist, UVES_HUMIDITY, CPL_TYPE_DOUBLE, &returnvalue),
1443  "Error reading keyword '%s'", UVES_HUMIDITY);
1444 
1445  cleanup:
1446  return returnvalue;
1447 }
1448 
1449 /*----------------------------------------------------------------------------*/
1456 /*----------------------------------------------------------------------------*/
1457 double uves_pfits_get_gratwlen(const uves_propertylist * plist, enum uves_chip chip)
1458 {
1459  double returnvalue;
1460 
1461  check( uves_get_property_value(plist, UVES_GRATWLEN(chip), CPL_TYPE_DOUBLE, &returnvalue),
1462  "Error reading keyword '%s'", UVES_GRATWLEN(chip));
1463 
1464  assure(returnvalue > 0, CPL_ERROR_ILLEGAL_INPUT, "Non-positive wavelength: %e", returnvalue);
1465 
1466  cleanup:
1467  return returnvalue;
1468 }
1469 
1470 /*----------------------------------------------------------------------------*/
1476 /*----------------------------------------------------------------------------*/
1477 const char* uves_pfits_get_insmode(const uves_propertylist * plist)
1478 {
1479  const char* returnvalue="";
1480 
1481  check( uves_get_property_value(plist, UVES_INSMODE, CPL_TYPE_STRING, &returnvalue),
1482  "Error reading keyword '%s'", UVES_INSMODE);
1483 
1484  cleanup:
1485  return returnvalue;
1486 }
1487 
1488 /*----------------------------------------------------------------------------*/
1494 /*----------------------------------------------------------------------------*/
1495 const char* uves_pfits_get_inspath(const uves_propertylist * plist)
1496 {
1497  const char* returnvalue="";
1498 
1499  check( uves_get_property_value(plist, UVES_INSPATH, CPL_TYPE_STRING, &returnvalue),
1500  "Error reading keyword '%s'", UVES_INSPATH);
1501 
1502  cleanup:
1503  return returnvalue;
1504 }
1505 /*----------------------------------------------------------------------------*/
1512 /*----------------------------------------------------------------------------*/
1513 const char* uves_pfits_get_gratname(const uves_propertylist * plist, enum uves_chip chip)
1514 {
1515  const char* returnvalue="";
1516 
1517  check( uves_get_property_value(plist, UVES_GRATNAME(chip), CPL_TYPE_STRING, &returnvalue),
1518  "Error reading keyword '%s'", UVES_GRATNAME(chip));
1519 
1520  cleanup:
1521  return returnvalue;
1522 }
1523 
1524 /*----------------------------------------------------------------------------*/
1531 /*----------------------------------------------------------------------------*/
1533 {
1534  const char* returnvalue="";
1535 
1536  check( uves_get_property_value(plist, UVES_READ_SPEED, CPL_TYPE_STRING, &returnvalue),
1537  "Error reading keyword '%s'", UVES_READ_SPEED);
1538 
1539  cleanup:
1540  return returnvalue;
1541 }
1542 
1543 /*----------------------------------------------------------------------------*/
1550 /*----------------------------------------------------------------------------*/
1551 const char* uves_pfits_get_gratid(const uves_propertylist * plist, enum uves_chip chip)
1552 {
1553  const char* returnvalue="";
1554 
1555  check( uves_get_property_value(plist, UVES_GRATID(chip), CPL_TYPE_STRING, &returnvalue),
1556  "Error reading keyword '%s'", UVES_GRATID(chip));
1557 
1558  cleanup:
1559  return returnvalue;
1560 }
1561 
1562 /*----------------------------------------------------------------------------*/
1569 /*----------------------------------------------------------------------------*/
1570 double uves_pfits_get_slitlength(const uves_propertylist * plist, enum uves_chip chip)
1571 {
1572  double returnvalue;
1573 
1574  check( uves_get_property_value(plist, UVES_SLITLENGTH(chip), CPL_TYPE_DOUBLE, &returnvalue),
1575  "Error reading keyword '%s'", UVES_SLITLENGTH(chip));
1576 
1577  cleanup:
1578  return returnvalue;
1579 }
1580 
1581 
1582 /*----------------------------------------------------------------------------*/
1589 /*----------------------------------------------------------------------------*/
1590 double uves_pfits_get_slitwidth(const uves_propertylist * plist, enum uves_chip chip)
1591 {
1592  double returnvalue;
1593 
1594  check( uves_get_property_value(plist, UVES_SLITWIDTH(chip), CPL_TYPE_DOUBLE, &returnvalue),
1595  "Error reading keyword '%s'", UVES_SLITWIDTH(chip));
1596 
1597  cleanup:
1598  return returnvalue;
1599 }
1600 
1601 /*----------------------------------------------------------------------------*/
1607 /*----------------------------------------------------------------------------*/
1609 {
1610  cpl_type type;
1611  int returnvalue;
1612 
1613  assure( plist != NULL, CPL_ERROR_NULL_INPUT, "Null plist");
1614 
1615  /* In the UVES calibration data base this keyword
1616  is sometimes integer (e.g. '33'), sometimes a floating
1617  point value (e.g. '33.'), so support both types */
1618 
1619  assure( uves_propertylist_contains(plist, UVES_ORD_PRED),
1620  CPL_ERROR_DATA_NOT_FOUND,
1621  "Keyword %s does not exist", UVES_ORD_PRED);
1622  check ( type = uves_propertylist_get_type(plist, UVES_ORD_PRED),
1623  "Error reading type of property '%s'", UVES_ORD_PRED);
1624 
1625  if (type == CPL_TYPE_INT)
1626  {
1627  check( uves_get_property_value(
1628  plist, UVES_ORD_PRED, CPL_TYPE_INT, &returnvalue),
1629  "Error reading keyword '%s'", UVES_ORD_PRED);
1630  }
1631  else if (type == CPL_TYPE_DOUBLE)
1632  {
1633  double dvalue;
1634  check( uves_get_property_value(
1635  plist, UVES_ORD_PRED, CPL_TYPE_DOUBLE, &dvalue),
1636  "Error reading keyword '%s'", UVES_ORD_PRED);
1637  returnvalue = uves_round_double(dvalue);
1638  }
1639  else
1640  {
1641  assure( false, CPL_ERROR_TYPE_MISMATCH,
1642  "Keyword '%s' has wrong type '%s'",
1643  UVES_ORD_PRED, uves_tostring_cpl_type(type));
1644  }
1645 
1646  cleanup:
1647  return returnvalue;
1648 }
1649 
1650 /*----------------------------------------------------------------------------*/
1663 /*----------------------------------------------------------------------------*/
1664 void
1665 uves_pfits_set_history_val(uves_propertylist *plist, const char *name, const char *format, ...)
1666 {
1667  char *val_str = NULL;
1668  char *number_str = NULL;
1669  cpl_property *existing = NULL;
1670  va_list arglist;
1671  const long int plist_size = uves_propertylist_get_size(plist);
1672  int i;
1673 
1674  for (i = 0;
1675  existing == NULL && i < plist_size; i++)
1676  {
1677  cpl_property *p = uves_propertylist_get(plist, i);
1678  const char *pname = cpl_property_get_name(p);
1679 
1680  if (strcmp(pname, "HISTORY") == 0)
1681  {
1682  const char *pval;
1683  check( pval = cpl_property_get_string(p),
1684  "Error reading property value");
1685 
1686  /* match the string "<name> " */
1687 
1688  if (strlen(pval) > strlen(name) + strlen(" ") &&
1689  strncmp(pval, name, strlen(name)) == 0 &&
1690  pval[strlen(name)] == ' ')
1691  {
1692  /* Remember this one and stop searching */
1693  existing = p;
1694  }
1695  }
1696  }
1697 
1698  va_start(arglist, format);
1699  number_str = cpl_vsprintf(format, arglist);
1700  va_end(arglist);
1701 
1702  val_str = uves_sprintf("%s %s", name, number_str);
1703 
1704  if (existing != NULL)
1705  {
1706  check( cpl_property_set_string(existing, val_str),
1707  "Error updating HISTORY keyword with value '%s'", val_str);
1708  }
1709  else
1710  {
1711  check( uves_propertylist_append_string(plist, "HISTORY", val_str),
1712  "Error writing HISTORY keyword with value '%s'", val_str);
1713  }
1714 
1715  cleanup:
1716  cpl_free(val_str);
1717  cpl_free(number_str);
1718  return;
1719 }
1720 /*----------------------------------------------------------------------------*/
1737 /*----------------------------------------------------------------------------*/
1738 static double
1739 parse_history(const uves_propertylist *plist, const char *name, cpl_type type)
1740 {
1741  double returnvalue = 0;
1742  const long int plist_size = uves_propertylist_get_size(plist);
1743  int i;
1744  bool found;
1745 
1746  found = false;
1747  for (i = 0; !found && i < plist_size; i++) {
1748  const cpl_property *p = uves_propertylist_get_const(plist, i);
1749  const char *value = cpl_property_get_name(p);
1750 
1751  if (strcmp(value, "HISTORY") == 0) {
1752  check( value = cpl_property_get_string(p),
1753  "Error reading property value");
1754 
1755  /* match the string "<name> " */
1756 
1757  if (strlen(value) > strlen(name) + strlen(" ") &&
1758  strncmp(value, name, strlen(name)) == 0 &&
1759  value[strlen(name)] == ' ') {
1760  errno = 0;
1761  switch(type) {
1762  case CPL_TYPE_INT:
1763  returnvalue = atoi(value + strlen(name) + strlen(" "));
1764  assure(errno == 0, CPL_ERROR_ILLEGAL_INPUT,
1765  "Could not parse string '%s' as integer. "
1766  "atoi() returned %d",
1767  value + strlen(name) + strlen(" "), errno);
1768  break;
1769  case CPL_TYPE_DOUBLE:
1770  returnvalue = strtod(value + strlen(name) + strlen(" "), NULL);
1771  assure(errno == 0, CPL_ERROR_ILLEGAL_INPUT,
1772  "Could not parse string '%s' as double. "
1773  "strtod() returned %d",
1774  value + strlen(name) + strlen(" "), errno);
1775  break;
1776  default:
1777  assure( false, CPL_ERROR_UNSUPPORTED_MODE,
1778  "Type is %s", uves_tostring_cpl_type(type));
1779  break;
1780  }
1781  found = true;
1782  }
1783  }
1784  }
1785 
1786  assure( found, CPL_ERROR_DATA_NOT_FOUND, "Missing record 'HISTORY %s '",
1787  name );
1788 
1789  cleanup:
1790  return returnvalue;
1791 }
1792 
1793 /*----------------------------------------------------------------------------*/
1801 /*----------------------------------------------------------------------------*/
1802 void
1804 {
1805  uves_pfits_set_history_val(plist, UVES_FIRSTABSORDER, "%d", first_abs_order);
1806 
1807  return;
1808 }
1809 
1810 /*----------------------------------------------------------------------------*/
1816 /*----------------------------------------------------------------------------*/
1817 int
1819 {
1820  return uves_round_double(parse_history(plist, UVES_FIRSTABSORDER, CPL_TYPE_INT));
1821 }
1822 
1823 
1824 /*----------------------------------------------------------------------------*/
1832 /*----------------------------------------------------------------------------*/
1833 void
1835 {
1836  uves_pfits_set_history_val(plist, UVES_LASTABSORDER, "%d", last_abs_order);
1837 
1838  return;
1839 }
1840 /*----------------------------------------------------------------------------*/
1846 /*----------------------------------------------------------------------------*/
1847 int
1849 {
1850  return uves_round_double(parse_history(plist, UVES_LASTABSORDER, CPL_TYPE_INT));
1851 }
1852 
1853 /*---------------------------------------------------------------------------*/
1860 /*---------------------------------------------------------------------------*/
1861 cpl_error_code
1863 {
1864  check(( uves_propertylist_update_double(plist, UVES_PRO_DATAAVG, average),
1865  uves_propertylist_set_comment (plist, UVES_PRO_DATAAVG, "Mean of pixel values")),
1866  "Error writing keyword '%s'", UVES_PRO_DATAAVG);
1867  cleanup:
1868  return cpl_error_get_code();
1869 }
1870 
1871 /*---------------------------------------------------------------------------*/
1878 /*---------------------------------------------------------------------------*/
1879 cpl_error_code
1881 {
1882  check(( uves_propertylist_update_double(plist, UVES_PRO_DATARMS, stddev),
1883  uves_propertylist_set_comment (plist, UVES_PRO_DATARMS,
1884  "Standard deviation of pixel values")),
1885  "Error writing keyword '%s'", UVES_PRO_DATARMS);
1886 
1887  cleanup:
1888  return cpl_error_get_code();
1889 }
1890 
1891 /*---------------------------------------------------------------------------*/
1898 /*---------------------------------------------------------------------------*/
1899 cpl_error_code
1901 {
1902  check(( uves_propertylist_update_double(plist, UVES_PRO_DATAMED, median),
1903  uves_propertylist_set_comment (plist, UVES_PRO_DATAMED, "Median of pixel values")),
1904  "Error writing keyword '%s'", UVES_PRO_DATAMED);
1905 
1906  cleanup:
1907  return cpl_error_get_code();
1908 }
1909 /*---------------------------------------------------------------------------*/
1916 /*---------------------------------------------------------------------------*/
1917 cpl_error_code
1919 {
1920  check(( uves_propertylist_update_double(plist, UVES_DATAMIN, min),
1921  uves_propertylist_set_comment (plist, UVES_DATAMIN, "Minimum of pixel values")),
1922  "Error writing keyword '%s'", UVES_DATAMIN);
1923 
1924  cleanup:
1925  return cpl_error_get_code();
1926 }
1927 /*---------------------------------------------------------------------------*/
1934 /*---------------------------------------------------------------------------*/
1935 cpl_error_code
1937 {
1938  check(( uves_propertylist_update_double(plist, UVES_DATAMAX, max),
1939  uves_propertylist_set_comment (plist, UVES_DATAMAX,
1940  "Maximum of pixel values")),
1941  "Error writing keyword '%s'", UVES_DATAMAX);
1942 
1943  cleanup:
1944  return cpl_error_get_code();
1945 }
1946 
1947 /*---------------------------------------------------------------------------*/
1954 /*---------------------------------------------------------------------------*/
1955 void
1957 {
1958  uves_pfits_set_history_val(plist, UVES_TRACEID, "%d", trace_id);
1959  return;
1960 }
1961 
1962 /*---------------------------------------------------------------------------*/
1968 /*---------------------------------------------------------------------------*/
1969 double
1971 {
1972  double offset;
1973  if (uves_propertylist_contains(plist, UVES_TRACE_OFFSET))
1974  /* MIDAS format */
1975  {
1976  check( uves_get_property_value(plist, UVES_TRACE_OFFSET, CPL_TYPE_DOUBLE,
1977  &offset),
1978  "Error reading keyword %s", UVES_TRACE_OFFSET);
1979  }
1980  else
1981  {
1982  offset = parse_history(plist, UVES_TRACE_OFFSET, CPL_TYPE_DOUBLE);
1983  }
1984 
1985  cleanup:
1986  return offset;
1987 }
1988 /*---------------------------------------------------------------------------*/
1995 /*---------------------------------------------------------------------------*/
1996 void
1997 uves_pfits_set_offset(uves_propertylist * plist, double trace_offset)
1998 {
1999  uves_pfits_set_history_val(plist, UVES_TRACE_OFFSET, "%f", trace_offset);
2000  return;
2001 }
2002 
2003 /*---------------------------------------------------------------------------*/
2010 /*---------------------------------------------------------------------------*/
2011 void
2013 {
2014  uves_pfits_set_history_val(plist, UVES_WINDOWNUMBER, "%d", window_number);
2015  return;
2016 }
2017 
2018 
2019 /*---------------------------------------------------------------------------*/
2025 /*---------------------------------------------------------------------------*/
2026 int
2028 {
2029  return uves_round_double(parse_history(plist, UVES_TRACEID, CPL_TYPE_INT));
2030 }
2031 
2032 /*---------------------------------------------------------------------------*/
2038 /*---------------------------------------------------------------------------*/
2039 int
2041 {
2042  return uves_round_double(parse_history(plist, UVES_WINDOWNUMBER, CPL_TYPE_INT));
2043 }
2044 
2045 /*---------------------------------------------------------------------------*/
2051 /*---------------------------------------------------------------------------*/
2052 const char*
2054 {
2055  const char* returnvalue="";
2056 
2057  check( uves_get_property_value(plist, UVES_BUNIT, CPL_TYPE_STRING, &returnvalue),
2058  "Error reading keyword '%s'", UVES_BUNIT);
2059 
2060  cleanup:
2061  return returnvalue;
2062 }
2063 
2064 /*---------------------------------------------------------------------------*/
2070 /*---------------------------------------------------------------------------*/
2071 double
2073 {
2074  double returnvalue = 0;
2075 
2076  check( uves_get_property_value(plist, UVES_BSCALE, CPL_TYPE_DOUBLE, &returnvalue),
2077  "Error reading keyword '%s'", UVES_BSCALE);
2078 
2079  cleanup:
2080  return returnvalue;
2081 }
2082 
2083 
2084 /*---------------------------------------------------------------------------*/
2090 /*---------------------------------------------------------------------------*/
2091 const char*
2093 {
2094  const char* returnvalue="";
2095 
2096  check( uves_get_property_value(plist, UVES_CUNIT1, CPL_TYPE_STRING, &returnvalue),
2097  "Error reading keyword '%s'", UVES_CUNIT1);
2098 
2099  cleanup:
2100  return returnvalue;
2101 }
2102 
2103 /*---------------------------------------------------------------------------*/
2109 /*---------------------------------------------------------------------------*/
2110 const char*
2112 {
2113  const char* returnvalue="";
2114 
2115  check( uves_get_property_value(plist, UVES_CUNIT2, CPL_TYPE_STRING, &returnvalue),
2116  "Error reading keyword '%s'", UVES_CUNIT2);
2117 
2118  cleanup:
2119  return returnvalue;
2120 }
2121 
2122 /*---------------------------------------------------------------------------*/
2128 /*---------------------------------------------------------------------------*/
2129 const char*
2131 {
2132  const char* returnvalue="";
2133 
2134  check( uves_get_property_value(plist, UVES_CTYPE1, CPL_TYPE_STRING, &returnvalue),
2135  "Error reading keyword '%s'", UVES_CTYPE1);
2136 
2137  cleanup:
2138  return returnvalue;
2139 }
2140 
2141 /*---------------------------------------------------------------------------*/
2147 /*---------------------------------------------------------------------------*/
2148 const
2150 {
2151  const char* returnvalue="";
2152 
2153  check( uves_get_property_value(plist, UVES_CTYPE2, CPL_TYPE_STRING, &returnvalue),
2154  "Error reading keyword '%s'", UVES_CTYPE2);
2155 
2156  cleanup:
2157  return returnvalue;
2158 }
2159 
2160 /*---------------------------------------------------------------------------*/
2166 /*---------------------------------------------------------------------------*/
2167 double
2169 {
2170  double returnvalue = 0;
2171  bool new_format;
2172 
2173  check( new_format = uves_format_is_new(plist),
2174  "Error determining FITS header format");
2175 
2176  check( uves_get_property_value(plist, UVES_UIT(new_format), CPL_TYPE_DOUBLE, &returnvalue),
2177  "Error reading keyword %s", UVES_UIT(new_format));
2178 
2179  cleanup:
2180  return returnvalue;
2181 
2182 }
2183 
2184 
2185 /*---------------------------------------------------------------------------*/
2192 /*---------------------------------------------------------------------------*/
2193 int
2194 uves_pfits_get_nx(const uves_propertylist * plist,enum uves_chip chip)
2195 {
2196 
2197  int returnvalue = 0;
2198  bool new_format;
2199 
2200  check( new_format = uves_format_is_new(plist),
2201  "Error determining FITS header format");
2202 
2203  check( uves_get_property_value(plist, UVES_NX(new_format, chip), CPL_TYPE_INT, &returnvalue),
2204  "Error reading keyword %s", UVES_NX(new_format, chip));
2205 
2206  cleanup:
2207  return returnvalue;
2208 
2209 }
2210 
2211 
2212 
2213 
2214 /*---------------------------------------------------------------------------*/
2221 /*---------------------------------------------------------------------------*/
2222 int
2223 uves_pfits_get_ny(const uves_propertylist * plist,enum uves_chip chip)
2224 {
2225 
2226  int returnvalue = 0;
2227  bool new_format;
2228 
2229  check( new_format = uves_format_is_new(plist),
2230  "Error determining FITS header format");
2231 
2232  check( uves_get_property_value(plist, UVES_NY(new_format, chip), CPL_TYPE_INT, &returnvalue),
2233  "Error reading keyword %s", UVES_NY(new_format, chip));
2234 
2235  cleanup:
2236  return returnvalue;
2237 
2238 }
2239 
2240 
2241 
2242 /*---------------------------------------------------------------------------*/
2248 /*---------------------------------------------------------------------------*/
2249 int
2251 {
2252  int returnvalue = 0;
2253 
2254  check( uves_get_property_value(plist, UVES_OUT1NX, CPL_TYPE_INT, &returnvalue),
2255  "Error reading keyword '%s'", UVES_OUT1NX);
2256 
2257  cleanup:
2258  return returnvalue;
2259 }
2260 
2261 /*---------------------------------------------------------------------------*/
2267 /*---------------------------------------------------------------------------*/
2268 int
2270 {
2271  int returnvalue = 0;
2272 
2273  check( uves_get_property_value(plist, UVES_OUT1NY, CPL_TYPE_INT, &returnvalue),
2274  "Error reading keyword '%s'", UVES_OUT1NY);
2275 
2276  cleanup:
2277  return returnvalue;
2278 }
2279 
2280 /*---------------------------------------------------------------------------*/
2286 /*---------------------------------------------------------------------------*/
2287 int
2289 {
2290  int returnvalue = 0;
2291 
2292  check( uves_get_property_value(plist, UVES_OUT4NX, CPL_TYPE_INT, &returnvalue),
2293  "Error reading keyword '%s'", UVES_OUT4NX);
2294 
2295  cleanup:
2296  return returnvalue;
2297 }
2298 
2299 /*---------------------------------------------------------------------------*/
2305 /*---------------------------------------------------------------------------*/
2306 int
2308 {
2309  int returnvalue = 0;
2310 
2311  check( uves_get_property_value(plist, UVES_OUT4NY, CPL_TYPE_INT, &returnvalue),
2312  "Error reading keyword '%s'", UVES_OUT4NY);
2313 
2314  cleanup:
2315  return returnvalue;
2316 }
2317 
2318 
2319 /*---------------------------------------------------------------------------*/
2325 /*---------------------------------------------------------------------------*/
2326 int
2328 {
2329  int returnvalue = 0;
2330 
2331  check( uves_get_property_value(plist, UVES_NAXIS, CPL_TYPE_INT, &returnvalue),
2332  "Error reading keyword '%s'", UVES_NAXIS);
2333 
2334  cleanup:
2335  return returnvalue;
2336 }
2337 
2338 /*---------------------------------------------------------------------------*/
2344 /*---------------------------------------------------------------------------*/
2345 int
2347 {
2348  int returnvalue = 0;
2349 
2350  check( uves_get_property_value(plist, FLAMES_NFLATS, CPL_TYPE_INT, &returnvalue),
2351  "Error reading keyword '%s'", FLAMES_NFLATS);
2352 
2353  cleanup:
2354  return returnvalue;
2355 }
2356 
2357 
2358 /*---------------------------------------------------------------------------*/
2364 /*---------------------------------------------------------------------------*/
2365 int
2367 {
2368  int returnvalue = 0;
2369 
2370  check( uves_get_property_value(plist, UVES_BITPIX, CPL_TYPE_INT, &returnvalue),
2371  "Error reading keyword '%s'", UVES_BITPIX);
2372 
2373  cleanup:
2374  return returnvalue;
2375 }
2376 
2377 /*---------------------------------------------------------------------------*/
2383 /*---------------------------------------------------------------------------*/
2385 {
2386  int returnvalue = 0;
2387 
2388  check( uves_get_property_value(plist, UVES_NAXIS1, CPL_TYPE_INT, &returnvalue),
2389  "Error reading keyword '%s'", UVES_NAXIS1);
2390 
2391  cleanup:
2392  return returnvalue;
2393 }
2394 
2395 
2396 /*---------------------------------------------------------------------------*/
2402 /*---------------------------------------------------------------------------*/
2403 double
2405 {
2406  double returnvalue = 0;
2407 
2408  check( uves_get_property_value(plist, UVES_STARTX, CPL_TYPE_DOUBLE, &returnvalue),
2409  "Error reading keyword '%s'", UVES_STARTX);
2410 
2411  cleanup:
2412  return returnvalue;
2413 }
2414 
2415 
2416 /*---------------------------------------------------------------------------*/
2422 /*---------------------------------------------------------------------------*/
2423 double
2425 {
2426  double returnvalue = 0;
2427 
2428  check( uves_get_property_value(plist, UVES_STARTY, CPL_TYPE_DOUBLE, &returnvalue),
2429  "Error reading keyword '%s'", UVES_STARTY);
2430 
2431  cleanup:
2432  return returnvalue;
2433 }
2434 
2435 /*---------------------------------------------------------------------------*/
2441 /*---------------------------------------------------------------------------*/
2442 int
2444 {
2445  int returnvalue = 0;
2446 
2447  check( uves_get_property_value(plist, UVES_NAXIS2, CPL_TYPE_INT, &returnvalue),
2448  "Error reading keyword '%s'", UVES_NAXIS2);
2449 
2450  cleanup:
2451  return returnvalue;
2452 }
2453 /*---------------------------------------------------------------------------*/
2459 /*---------------------------------------------------------------------------*/
2460 double
2462 {
2463  double returnvalue = 0.0;
2464 
2465  check( uves_get_property_value(plist, UVES_CRVAL1, CPL_TYPE_DOUBLE, &returnvalue),
2466  "Error reading keyword '%s'", UVES_CRVAL1);
2467 
2468  cleanup:
2469  return returnvalue;
2470 }
2471 /*---------------------------------------------------------------------------*/
2477 /*---------------------------------------------------------------------------*/
2478 double
2480 {
2481  double returnvalue = 0.0;
2482 
2483  check( uves_get_property_value(plist, UVES_CRVAL2, CPL_TYPE_DOUBLE, &returnvalue),
2484  "Error reading keyword '%s'", UVES_CRVAL2);
2485 
2486  cleanup:
2487  return returnvalue;
2488 }
2489 /*---------------------------------------------------------------------------*/
2495 /*---------------------------------------------------------------------------*/
2496 double
2498 {
2499  double returnvalue = 0.0;
2500 
2501  check( uves_get_property_value(plist, UVES_CRPIX1, CPL_TYPE_DOUBLE, &returnvalue),
2502  "Error reading keyword '%s'", UVES_CRPIX1);
2503 
2504  cleanup:
2505  return returnvalue;
2506 }
2507 /*---------------------------------------------------------------------------*/
2513 /*---------------------------------------------------------------------------*/
2514 double
2516 {
2517  double returnvalue = 0.0;
2518 
2519  check( uves_get_property_value(plist, UVES_CRPIX2, CPL_TYPE_DOUBLE, &returnvalue),
2520  "Error reading keyword '%s'", UVES_CRPIX2);
2521 
2522  cleanup:
2523  return returnvalue;
2524 }
2525 /*---------------------------------------------------------------------------*/
2531 /*---------------------------------------------------------------------------*/
2532 double
2534 {
2535  double returnvalue = 0.0;
2536 
2537  check( uves_get_property_value(plist, UVES_CDELT1, CPL_TYPE_DOUBLE, &returnvalue),
2538  "Error reading keyword '%s'", UVES_CDELT1);
2539 
2540  cleanup:
2541  return returnvalue;
2542 }
2543 /*---------------------------------------------------------------------------*/
2549 /*---------------------------------------------------------------------------*/
2550 double
2552 {
2553  double returnvalue = 0.0;
2554 
2555  check( uves_get_property_value(plist, UVES_CDELT2, CPL_TYPE_DOUBLE, &returnvalue),
2556  "Error reading keyword '%s'", UVES_CDELT2);
2557 
2558  cleanup:
2559  return returnvalue;
2560 }
2561 
2562 
2563 /*---------------------------------------------------------------------------*/
2570 /*---------------------------------------------------------------------------*/
2571 void
2572 uves_pfits_set_dpr_catg(uves_propertylist * plist, const char *catg)
2573 {
2574  check( uves_propertylist_update_string(plist, UVES_DPR_CATG, catg),
2575  "Error writing %s", UVES_DPR_CATG);
2576  cleanup:
2577  return;
2578 }
2579 
2580 /*---------------------------------------------------------------------------*/
2587 /*---------------------------------------------------------------------------*/
2588 void
2589 uves_pfits_set_dpr_tech(uves_propertylist * plist, const char *tech)
2590 {
2591  check( uves_propertylist_update_string(plist, UVES_DPR_TECH, tech),
2592  "Error writing %s", UVES_DPR_TECH);
2593  cleanup:
2594  return;
2595 }
2596 /*---------------------------------------------------------------------------*/
2603 /*---------------------------------------------------------------------------*/
2604 void
2605 uves_pfits_set_dpr_type(uves_propertylist * plist, const char *type)
2606 {
2607  check( uves_propertylist_update_string(plist, UVES_DPR_TYPE, type),
2608  "Error writing %s", UVES_DPR_TYPE);
2609  cleanup:
2610  return;
2611 }
2612 
2613 /*---------------------------------------------------------------------------*/
2620 /*---------------------------------------------------------------------------*/
2621 cpl_error_code
2622 uves_pfits_set_object(uves_propertylist * plist, const char *object)
2623 {
2624  check( uves_propertylist_update_string(plist, UVES_OBJECT, object),
2625  "Error writing keyword '%s'", UVES_OBJECT);
2626 
2627  cleanup:
2628  return cpl_error_get_code();
2629 }
2630 /*---------------------------------------------------------------------------*/
2637 /*---------------------------------------------------------------------------*/
2638 cpl_error_code
2640 {
2641  check( uves_propertylist_update_string(plist, UVES_QC_BADPIXCORR, corr),
2642  "Error writing keyword '%s'", UVES_QC_BADPIXCORR);
2643 
2644  cleanup:
2645  return cpl_error_get_code();
2646 }
2647 
2648 /*---------------------------------------------------------------------------*/
2655 /*---------------------------------------------------------------------------*/
2656 cpl_error_code
2657 uves_pfits_set_redlevel(uves_propertylist * plist, const char *redlevel)
2658 {
2659  check( uves_propertylist_update_string(plist, UVES_REDLEVEL, redlevel),
2660  "Error writing keyword '%s'", UVES_REDLEVEL);
2661 
2662  cleanup:
2663  return cpl_error_get_code();
2664 }
2665 
2666 /*---------------------------------------------------------------------------*/
2673 /*---------------------------------------------------------------------------*/
2674 cpl_error_code
2675 uves_pfits_set_status(uves_propertylist * plist, const char *status)
2676 {
2677  check( uves_propertylist_update_string(plist, UVES_STATUS, status),
2678  "Error writing keyword '%s'", UVES_STATUS);
2679 
2680  cleanup:
2681  return cpl_error_get_code();
2682 }
2683 
2684 /*---------------------------------------------------------------------------*/
2691 /*---------------------------------------------------------------------------*/
2692 cpl_error_code
2693 uves_pfits_set_starttime(uves_propertylist * plist, const char *start_time)
2694 {
2695  check( uves_propertylist_update_string(plist, UVES_START, start_time),
2696  "Error writing keyword '%s'", UVES_START);
2697 
2698  cleanup:
2699  return cpl_error_get_code();
2700 }
2701 /*---------------------------------------------------------------------------*/
2708 /*---------------------------------------------------------------------------*/
2709 cpl_error_code
2710 uves_pfits_set_stoptime(uves_propertylist * plist, const char *stop_time)
2711 {
2712  check( uves_propertylist_update_string(plist, UVES_STOP, stop_time),
2713  "Error writing keyword '%s'", UVES_STOP);
2714 
2715  cleanup:
2716  return cpl_error_get_code();
2717 }
2718 
2719 /*---------------------------------------------------------------------------*/
2726 /*---------------------------------------------------------------------------*/
2727 cpl_error_code
2728 uves_pfits_set_bunit(uves_propertylist * plist, const char *bunit)
2729 {
2730  check( uves_propertylist_update_string(plist, UVES_BUNIT, bunit),
2731  "Error writing keyword '%s'", UVES_BUNIT);
2732 
2733  cleanup:
2734  return cpl_error_get_code();
2735 }
2736 
2737 /*---------------------------------------------------------------------------*/
2744 /*---------------------------------------------------------------------------*/
2745 cpl_error_code
2746 uves_pfits_set_bscale(uves_propertylist * plist, const double bscale)
2747 {
2748  check( uves_propertylist_update_double(plist, UVES_BSCALE, bscale),
2749  "Error writing keyword '%s'", UVES_BSCALE);
2750 
2751  cleanup:
2752  return cpl_error_get_code();
2753 }
2754 
2755 
2756 /*---------------------------------------------------------------------------*/
2763 /*---------------------------------------------------------------------------*/
2764 cpl_error_code
2765 uves_pfits_set_tunit_no(uves_propertylist * plist, const int col_no, const char *tunit)
2766 {
2767  char key_name[20];
2768  sprintf(key_name,"%s%d",UVES_TUNIT,col_no);
2769  uves_msg("Filling key %s with value %s",key_name,tunit);
2770  check( uves_propertylist_update_string(plist, key_name, tunit),
2771  "Error writing keyword '%s'", key_name);
2772 
2773  cleanup:
2774  return cpl_error_get_code();
2775 }
2776 
2777 /*---------------------------------------------------------------------------*/
2784 /*---------------------------------------------------------------------------*/
2785 cpl_error_code
2786 uves_pfits_set_bunit_no(uves_propertylist * plist, const int axis_no, const char *bunit)
2787 {
2788  check( uves_propertylist_update_string(plist, UVES_BUNIT, bunit),
2789  "Error writing keyword '%s'", UVES_BUNIT);
2790 
2791  cleanup:
2792  return cpl_error_get_code();
2793 }
2794 
2795 /*---------------------------------------------------------------------------*/
2802 /*---------------------------------------------------------------------------*/
2803 cpl_error_code
2804 uves_pfits_set_ctype1(uves_propertylist * plist, const char *ctype1)
2805 {
2806  check( uves_propertylist_update_string(plist, UVES_CTYPE1, ctype1),
2807  "Error writing keyword '%s'", UVES_CTYPE1);
2808 
2809  cleanup:
2810  return cpl_error_get_code();
2811 }
2812 /*---------------------------------------------------------------------------*/
2819 /*---------------------------------------------------------------------------*/
2820 cpl_error_code
2821 uves_pfits_set_ctype2(uves_propertylist * plist, const char *ctype2)
2822 {
2823  check( uves_propertylist_update_string(plist, UVES_CTYPE2, ctype2),
2824  "Error writing keyword '%s'", UVES_CTYPE2);
2825 
2826  cleanup:
2827  return cpl_error_get_code();
2828 }
2829 
2830 
2831 
2832 /*---------------------------------------------------------------------------*/
2839 /*---------------------------------------------------------------------------*/
2840 cpl_error_code
2841 uves_pfits_set_cunit1(uves_propertylist * plist, const char *cunit1)
2842 {
2843  check( uves_propertylist_update_string(plist, UVES_CUNIT1, cunit1),
2844  "Error writing keyword '%s'", UVES_CUNIT1);
2845 
2846  cleanup:
2847  return cpl_error_get_code();
2848 }
2849 
2850 /*---------------------------------------------------------------------------*/
2857 /*---------------------------------------------------------------------------*/
2858 cpl_error_code
2859 uves_pfits_set_cunit2(uves_propertylist * plist, const char *cunit2)
2860 {
2861  check( uves_propertylist_update_string(plist, UVES_CUNIT2, cunit2),
2862  "Error writing keyword '%s'", UVES_CUNIT2);
2863 
2864  cleanup:
2865  return cpl_error_get_code();
2866 }
2867 
2868 /*---------------------------------------------------------------------------*/
2875 /*---------------------------------------------------------------------------*/
2876 cpl_error_code
2878 {
2879  check( uves_propertylist_update_double(plist, UVES_CRVAL1, crval1),
2880  "Error writing keyword '%s'", UVES_CRVAL1);
2881 
2882  cleanup:
2883  return cpl_error_get_code();
2884 }
2885 
2886 /*---------------------------------------------------------------------------*/
2893 /*---------------------------------------------------------------------------*/
2894 cpl_error_code
2896 {
2897  check( uves_propertylist_update_double(plist, UVES_CRVAL2, crval2),
2898  "Error writing keyword '%s'", UVES_CRVAL2);
2899 
2900  cleanup:
2901  return cpl_error_get_code();
2902 }
2903 /*---------------------------------------------------------------------------*/
2910 /*---------------------------------------------------------------------------*/
2911 cpl_error_code
2913 {
2914  check( uves_propertylist_update_double(plist, UVES_CRPIX1, crpix1),
2915  "Error writing keyword '%s'", UVES_CRPIX1);
2916 
2917  cleanup:
2918  return cpl_error_get_code();
2919 }
2920 
2921 /*---------------------------------------------------------------------------*/
2928 /*---------------------------------------------------------------------------*/
2929 cpl_error_code
2931 {
2932  check( uves_propertylist_update_double(plist, UVES_CRPIX2, crpix2),
2933  "Error writing keyword '%s'", UVES_CRPIX2);
2934 
2935  cleanup:
2936  return cpl_error_get_code();
2937 }
2938 /*---------------------------------------------------------------------------*/
2945 /*---------------------------------------------------------------------------*/
2946 cpl_error_code
2948 {
2949  check( uves_propertylist_update_double(plist, UVES_CDELT1, cdelt1),
2950  "Error writing keyword '%s'", UVES_CDELT1);
2951 
2952  cleanup:
2953  return cpl_error_get_code();
2954 }
2955 
2956 /*---------------------------------------------------------------------------*/
2963 /*---------------------------------------------------------------------------*/
2964 void
2966 {
2967  check( uves_propertylist_update_double(plist, FLAMES_CCFPOSMAX, ccfposmax),
2968  "Error writing keyword '%s'", FLAMES_CCFPOSMAX);
2969 
2970  cleanup:
2971  return;
2972 }
2973 
2974 /*---------------------------------------------------------------------------*/
2981 /*---------------------------------------------------------------------------*/
2982 cpl_error_code
2984 {
2985  check( uves_propertylist_update_double(plist, UVES_CDELT2, cdelt2),
2986  "Error writing keyword '%s'", UVES_CDELT2);
2987 
2988  cleanup:
2989  return cpl_error_get_code();
2990 }
2991 
2992 /*---------------------------------------------------------------------------*/
2998 /*---------------------------------------------------------------------------*/
2999 void
3001 {
3002  check( uves_propertylist_update_int(plist, UVES_HS, hs),
3003  "Error writing keyword '%s'", UVES_HS);
3004 
3005  cleanup:
3006  return;
3007 }
3008 
3009 
3010 /*---------------------------------------------------------------------------*/
3018 /*---------------------------------------------------------------------------*/
3019 cpl_error_code
3020 uves_pfits_set_wstart(uves_propertylist * plist, int order, double wstart)
3021 {
3022  char *wstart_string = NULL;
3023 
3024  assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT,
3025  "Illegal order number: %d. Allowed range is 1 to 99", order);
3026 
3027  /* allocate room for two digits and '\0' */
3028  wstart_string = cpl_malloc( strlen(UVES_WSTART) + 2 + 1);
3029  assure_mem( wstart_string );
3030 
3031  snprintf(wstart_string, strlen(UVES_WSTART)+2+1, UVES_WSTART "%d", order);
3032 
3033  check( uves_propertylist_update_double(plist, wstart_string, wstart ),
3034  "Error updating product header");
3035 
3036  cleanup:
3037  cpl_free(wstart_string);
3038  return cpl_error_get_code();
3039 }
3040 
3041 
3042 /*---------------------------------------------------------------------------*/
3049 /*---------------------------------------------------------------------------*/
3050 
3051 double
3052 uves_pfits_get_wstart(const uves_propertylist * plist, int order)
3053 {
3054  double returnvalue;
3055  char *wstart = NULL;
3056 
3057  assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT,
3058  "Illegal order number: %d. Allowed range is 1 to 99", order);
3059 
3060  /* allocate room for two digits and '\0' */
3061  wstart = cpl_malloc( strlen(UVES_WSTART) + 2 + 1);
3062  assure_mem( wstart );
3063 
3064  snprintf(wstart, strlen(UVES_WSTART)+2+1, UVES_WSTART "%d", order);
3065 
3066  check( uves_get_property_value(plist, wstart, CPL_TYPE_DOUBLE, &returnvalue),
3067  "Error reading keyword '%s'", wstart);
3068 
3069  cleanup:
3070  cpl_free(wstart);
3071  return returnvalue;
3072 }
3073 /*---------------------------------------------------------------------------*/
3081 /*---------------------------------------------------------------------------*/
3082 cpl_error_code
3083 uves_pfits_set_wend(uves_propertylist * plist, int order, double wend)
3084 {
3085  char *wend_string = NULL;
3086 
3087  assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT,
3088  "Illegal order number: %d. Allowed range is 1 to 99", order);
3089 
3090  /* allocate room for two digits and '\0' */
3091  wend_string = cpl_malloc( strlen(UVES_WEND) + 2 + 1);
3092  assure_mem( wend_string );
3093 
3094  snprintf(wend_string, strlen(UVES_WEND)+2+1, UVES_WEND "%d", order);
3095 
3096  check( uves_propertylist_update_double(plist, wend_string, wend ),
3097  "Error updating product header");
3098 
3099  cleanup:
3100  cpl_free(wend_string);
3101  return cpl_error_get_code();
3102 }
3103 
3104 
3105 /*---------------------------------------------------------------------------*/
3112 /*---------------------------------------------------------------------------*/
3113 
3114 double
3115 uves_pfits_get_wend(const uves_propertylist * plist, int order)
3116 {
3117  double returnvalue;
3118  char *wend = NULL;
3119 
3120  assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT,
3121  "Illegal order number: %d. Allowed range is 1 to 99", order);
3122 
3123  /* allocate room for two digits and '\0' */
3124  wend = cpl_malloc( strlen(UVES_WEND) + 2 + 1);
3125  assure_mem( wend );
3126 
3127  snprintf(wend, strlen(UVES_WEND)+2+1, UVES_WEND "%d", order);
3128 
3129  check( uves_get_property_value(plist, wend, CPL_TYPE_DOUBLE, &returnvalue),
3130  "Error reading keyword '%s'", wend);
3131 
3132  cleanup:
3133  cpl_free(wend);
3134  return returnvalue;
3135 }
3136 
3137 /*---------------------------------------------------------------------------*/
3143 /*---------------------------------------------------------------------------*/
3144 double
3146 {
3147  double pixelscale = 0;
3148 
3149  check( uves_get_property_value(plist, UVES_PIXELSCALE, CPL_TYPE_DOUBLE, &pixelscale),
3150  "Error reading keyword '%s'", UVES_PIXELSCALE);
3151 
3152  cleanup:
3153  return pixelscale;
3154 }
3155 
3156 /*---------------------------------------------------------------------------*/
3162 /*---------------------------------------------------------------------------*/
3163 const char*
3165 {
3166  const char* returnvalue = "";
3167 
3168  check( uves_get_property_value(plist, UVES_SLIT1NAME, CPL_TYPE_STRING, &returnvalue),
3169  "Error reading keyword '%s'", UVES_SLIT1NAME);
3170 
3171  cleanup:
3172  return returnvalue;
3173 }
3174 
3175 
3176 /*---------------------------------------------------------------------------*/
3186 /*---------------------------------------------------------------------------*/
3187 
3188 double
3190  enum uves_chip chip)
3191 {
3192  double slitlength_pixels = 0; /* Result */
3193 
3194  const char *slicer_name = "";
3195  double slitlength_arcsecs = 0; /* Slit length in arc-seconds */
3196 
3197  check( slicer_name = uves_pfits_get_slit1_name(plist),
3198  "Could not read slicer id");
3199 
3200  if ( strncmp(slicer_name, "FREE", 4) != 0)
3201  {
3202  /* Slicer inserted */
3203  if (strncmp(slicer_name, "SLIC#1", 6) == 0) slitlength_arcsecs = 8.0;
3204  else if (strncmp(slicer_name, "SLIC#2", 6) == 0) slitlength_arcsecs = 8.0;
3205  else if (strncmp(slicer_name, "SLIC#3", 6) == 0) slitlength_arcsecs = 10.0;
3206  else
3207  {
3208  assure( false, CPL_ERROR_ILLEGAL_INPUT, "Unrecognized slicer name: '%s'. "
3209  "Recognized names are 'FREE', 'SLIC#1', 'SLIC#2', 'SLIC#3'.",
3210  slicer_name);
3211  }
3212  }
3213  else
3214  {
3215  /* slicer_name = 'FREE', no slicer */
3216 
3217  check( uves_get_property_value(
3218  plist, UVES_SLITLENGTH(chip), CPL_TYPE_DOUBLE, &slitlength_arcsecs),
3219  "Error reading keyword '%s'", UVES_SLITLENGTH(chip));
3220  }
3221 
3222  /* Convert from arcseconds to pixels */
3223  {
3224  double pixelscale; /* Arcseconds per pixel */
3225  int binx; /* The x-binning of the raw image
3226  is the y-binning of the extracted/rotated image */
3227 
3228  check_nomsg( pixelscale = uves_pfits_get_pixelscale(plist) );
3229 
3230  check( binx = uves_pfits_get_binx(plist),
3231  "Could not get x-binning");
3232 
3233  slitlength_pixels = slitlength_arcsecs / (pixelscale * binx);
3234  }
3235 
3236  cleanup:
3237  return slitlength_pixels;
3238 }
3239 
3240 
3241 /*---------------------------------------------------------------------------*/
3247 /*---------------------------------------------------------------------------*/
3248 int
3250 {
3251  int plate_no;
3252 
3253  if (uves_propertylist_contains(raw_header,
3254  FLAMES_NEWPLATEID))
3255  {
3256  check( uves_get_property_value(raw_header, FLAMES_NEWPLATEID,
3257  CPL_TYPE_INT, &plate_no),
3258  "Error reading keyword '%s'", FLAMES_NEWPLATEID);
3259  }
3260  else if(uves_propertylist_contains(raw_header,
3261  FLAMES_OBS_PLATE_ID))
3262  {
3263  check( uves_get_property_value(raw_header, FLAMES_OBS_PLATE_ID,
3264  CPL_TYPE_INT, &plate_no),
3265  "Error reading keyword '%s'", FLAMES_NEWPLATEID);
3266  }
3267  else if (uves_propertylist_contains(raw_header,
3268  FLAMES_INS_SHUT09))
3269  {
3270  plate_no = 1;
3271  }
3272  else if (uves_propertylist_contains(raw_header,
3273  FLAMES_INS_SHUT10))
3274  {
3275  plate_no = 2;
3276  }
3277  else
3278  {
3279  plate_no = 0;
3280  uves_msg_warning("Missing raw header keywords %s, %s, %s and %s, "
3281  "setting plate number = %d",
3282  FLAMES_NEWPLATEID,
3283  FLAMES_OBS_PLATE_ID,
3284  FLAMES_INS_SHUT09,
3285  FLAMES_INS_SHUT10,
3286  plate_no);
3287  }
3288 
3289  cleanup:
3290  return plate_no;
3291 }
3292 
3293 
3294 /*---------------------------------------------------------------------------*/
3300 /*---------------------------------------------------------------------------*/
3301 double
3303 {
3304  double returnvalue = 0;
3305 
3306  check( uves_get_property_value(plist, FLAMES_DIT, CPL_TYPE_DOUBLE, &returnvalue),
3307  "Error reading keyword '%s'", FLAMES_DIT);
3308 
3309  cleanup:
3310  return returnvalue;
3311 }
3312 
3313 /*---------------------------------------------------------------------------*/
3319 /*---------------------------------------------------------------------------*/
3320 void
3322 {
3323  check( uves_propertylist_update_int(plist, FLAMES_NEWPLATEID, plate_no),
3324  "Error writing keyword '%s'", FLAMES_NEWPLATEID);
3325  cleanup:
3326  return;
3327 }
3328