uves_pfits.c

00001 /*
00002  * This file is part of the UVES Pipeline
00003  * Copyright (C) 2002, 2003, 2004, 2005 Europpean Southern Observatory
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00018  */
00019 
00020 /*
00021  * $Author: amodigli $
00022  * $Date: 2010/09/24 09:32:06 $
00023  * $Revision: 1.109 $
00024  * $Name: uves-4_9_1 $
00025  * $Log: uves_pfits.c,v $
00026  * Revision 1.109  2010/09/24 09:32:06  amodigli
00027  * put back QFITS dependency to fix problem spot by NRI on FIBER mode (with MIDAS calibs) data
00028  *
00029  * Revision 1.107  2010/06/01 13:30:20  amodigli
00030  * defined UVES_TUNIT, uves_pfits_set_tunit_no(), uves_pfits_set_bunit_no()
00031  *
00032  * Revision 1.106  2009/07/13 06:37:46  amodigli
00033  * added uves_ccd_is_new()
00034  *
00035  * Revision 1.105  2009/05/15 11:17:33  amodigli
00036  * replace irplib_vsprintf by cpl_vsprintf
00037  *
00038  * Revision 1.104  2008/09/29 06:58:49  amodigli
00039  * add #include <string.h>
00040  *
00041  * Revision 1.103  2007/10/08 14:10:31  amodigli
00042  * assumes 5 for DATANCOM if not found in FITS header
00043  *
00044  * Revision 1.102  2007/08/30 07:56:54  amodigli
00045  * fixed some doxygen warnings
00046  *
00047  * Revision 1.101  2007/08/21 13:08:26  jmlarsen
00048  * Removed irplib_access module, largely deprecated by CPL-4
00049  *
00050  * Revision 1.100  2007/06/28 09:18:21  jmlarsen
00051  * Added functions to write DPR keywords
00052  *
00053  * Revision 1.99  2007/06/06 08:17:33  amodigli
00054  * replace tab with 4 spaces
00055  *
00056  * Revision 1.98  2007/06/01 14:09:57  jmlarsen
00057  * Exported uves_pfits_get_pixelscale
00058  *
00059  * Revision 1.97  2007/05/23 13:03:19  jmlarsen
00060  * Added missing include directive
00061  *
00062  * Revision 1.96  2007/05/16 14:38:03  amodigli
00063  * added uves_flames_pfits_get_ident & uves_flames_pfits_get_object
00064  *
00065  * Revision 1.95  2007/05/14 09:36:50  amodigli
00066  * added checks on return types
00067  *
00068  * Revision 1.94  2007/05/04 08:53:49  amodigli
00069  * added uves_flames_pfits_get_nflats
00070  *
00071  * Revision 1.93  2007/05/03 15:21:33  jmlarsen
00072  * Added function to read wavecal offset
00073  *
00074  * Revision 1.92  2007/04/26 13:19:40  jmlarsen
00075  * Added uves_pfits_set_ocs_simcal()
00076  *
00077  * Revision 1.91  2007/04/25 08:37:19  amodigli
00078  * added uves_pfits_get_origfile
00079  *
00080  * Revision 1.90  2007/04/24 12:50:29  jmlarsen
00081  * Replaced cpl_propertylist -> uves_propertylist which is much faster
00082  *
00083  * Revision 1.89  2007/04/24 09:41:09  jmlarsen
00084  * Renamed irplib_vsnprintf_create -> irplib_vsprintf
00085  *
00086  * Revision 1.88  2007/03/05 10:18:16  jmlarsen
00087  * Write 2d extraion slit length
00088  *
00089  * Revision 1.87  2007/01/31 13:11:27  jmlarsen
00090  * Added SIMCAL accessor functions
00091  *
00092  * Revision 1.86  2007/01/29 12:10:19  jmlarsen
00093  * Exported set_history_val() for usage by FLAMES
00094  *
00095  * Revision 1.85  2007/01/26 12:33:57  amodigli
00096  * added function for common QC
00097  *
00098  * Revision 1.84  2007/01/17 13:27:10  jmlarsen
00099  * Added BITPIX accessor function
00100  *
00101  * Revision 1.83  2007/01/10 14:16:15  jmlarsen
00102  * Fixed wrong format string
00103  *
00104  * Revision 1.82  2007/01/10 12:39:09  jmlarsen
00105  * Unified two get_plate_id functions
00106  *
00107  * Revision 1.81  2006/12/27 13:55:29  amodigli
00108  * added flames_pfits_get_plate_id and some FLAMES_ defines for FIBER mode
00109  *
00110  * Revision 1.80  2006/12/07 08:25:07  jmlarsen
00111  * Added uves_pfits_get_readspeed
00112  *
00113  * Revision 1.79  2006/12/01 12:27:25  jmlarsen
00114  * Factored out FLAMES plate-id code
00115  *
00116  * Revision 1.78  2006/11/24 09:36:25  jmlarsen
00117  * Workaround for slow uves_propertylist_get_size
00118  *
00119  * Revision 1.77  2006/11/15 15:02:14  jmlarsen
00120  * Implemented const safe workarounds for CPL functions
00121  *
00122  * Revision 1.75  2006/11/15 14:04:08  jmlarsen
00123  * Removed non-const version of parameterlist_get_first/last/next which is
00124  * already in CPL, added const-safe wrapper, unwrapper and deallocator functions
00125  *
00126  * Revision 1.74  2006/11/13 14:23:55  jmlarsen
00127  * Removed workarounds for CPL const bugs
00128  *
00129  * Revision 1.73  2006/11/06 15:19:41  jmlarsen
00130  * Removed unused include directives
00131  *
00132  * Revision 1.72  2006/10/25 07:21:35  jmlarsen
00133  * Documentation bug fix
00134  *
00135  * Revision 1.71  2006/10/24 14:05:47  jmlarsen
00136  * Added OBSPLATE
00137  *
00138  * Revision 1.70  2006/10/05 06:50:23  jmlarsen
00139  * Renamed function format_is_new -> uves_format_is_new
00140  *
00141  * Revision 1.69  2006/10/04 10:55:33  jmlarsen
00142  * Added telescope lat-/longitude accessor functions
00143  *
00144  * Revision 1.68  2006/09/27 13:14:15  jmlarsen
00145  * Added accessor functions for RA/DEC
00146  *
00147  * Revision 1.67  2006/09/20 10:57:36  jmlarsen
00148  * Propagate DATAMEAN/DATAMED/DATARMS if present
00149  *
00150  * Revision 1.66  2006/09/19 07:19:30  jmlarsen
00151  * Changed function set_history_int -> set_history_val to support writing values of any type
00152  *
00153  * Revision 1.65  2006/08/24 11:37:12  jmlarsen
00154  * Write recipe start/stop time to header
00155  *
00156  * Revision 1.64  2006/08/21 12:51:02  jmlarsen
00157  * Renamed shadowing variable
00158  *
00159  * Revision 1.63  2006/08/21 07:45:51  jmlarsen
00160  * Update HISTORY FABSORD keyword if it already exists, rather than adding a new keyword
00161  *
00162  * Revision 1.62  2006/08/21 07:06:16  jmlarsen
00163  * Fixed documantation bug
00164  *
00165  * Revision 1.61  2006/08/18 13:32:37  jmlarsen
00166  * Fixed memory leak
00167  *
00168  * Revision 1.60  2006/08/18 10:14:04  jmlarsen
00169  * Use legal FITS keywords for TRACEID/WINDOW/FABSORD/LABSORD
00170  *
00171  * Revision 1.59  2006/08/17 14:40:06  jmlarsen
00172  * Added missing documentation
00173  *
00174  * Revision 1.58  2006/08/17 14:11:25  jmlarsen
00175  * Use assure_mem macro to check for memory allocation failure
00176  *
00177  * Revision 1.57  2006/08/17 13:56:53  jmlarsen
00178  * Reduced max line length
00179  *
00180  * Revision 1.56  2006/08/09 14:23:19  jmlarsen
00181  * Removed unused function argument
00182  *
00183  * Revision 1.55  2006/07/31 06:29:26  amodigli
00184  * added QC on stability test
00185  *
00186  * Revision 1.54  2006/07/14 12:24:49  jmlarsen
00187  * Added conad, target name
00188  *
00189  * Revision 1.53  2006/06/13 11:58:55  jmlarsen
00190  * Bugfix: Use proper chipname keyword for REDL chip
00191  *
00192  * Revision 1.52  2006/06/02 06:42:12  jmlarsen
00193  * Added missing cleanup label
00194  *
00195  * Revision 1.51  2006/06/01 14:43:17  jmlarsen
00196  * Added missing documentation
00197  *
00198  * Revision 1.50  2006/06/01 14:22:48  amodigli
00199  * moved format_is_new to c module and made it static
00200  *
00201  * Revision 1.49  2006/05/31 09:26:40  amodigli
00202  * fixed some problem dumping QC log
00203  *
00204  * Revision 1.48  2006/05/19 13:07:20  amodigli
00205  * added uves_pfits_get_slit3_x1encoder
00206  *
00207  * Revision 1.47  2006/05/09 15:43:13  amodigli
00208  * added useful key/functions
00209  *
00210  * Revision 1.46  2006/04/26 12:25:20  amodigli
00211  * fixed a problem with ARCFILE keyword
00212  *
00213  * Revision 1.45  2006/04/25 14:58:48  amodigli
00214  * added paf creation functionalities
00215  *
00216  * Revision 1.44  2006/04/20 10:48:58  amodigli
00217  * added uves_pfits_get_tpl_start
00218  *
00219  * Revision 1.43  2006/03/24 13:59:41  jmlarsen
00220  * Added check that central wavelength is always positive
00221  *
00222  * Revision 1.42  2006/03/03 13:54:11  jmlarsen
00223  * Changed syntax of check macro
00224  *
00225  * Revision 1.41  2005/12/20 16:10:32  jmlarsen
00226  * Added some documentation
00227  *
00228  * Revision 1.40  2005/12/19 16:17:56  jmlarsen
00229  * Replaced bool -> int
00230  *
00231  */
00232 
00233 #ifdef HAVE_CONFIG_H
00234 #include <config.h>
00235 #endif
00236 
00237 /*----------------------------------------------------------------------------*/
00243 /*----------------------------------------------------------------------------*/
00246 /*-----------------------------------------------------------------------------
00247                 Defines
00248  -----------------------------------------------------------------------------*/
00249 
00250 /*-----------------------------------------------------------------------------
00251                 Includes
00252  -----------------------------------------------------------------------------*/
00253 #include <stdio.h>
00254 #include <uves_pfits.h>
00255 
00256 #include <uves_utils.h>
00257 #include <uves_utils_wrappers.h>
00258 #include <uves_dump.h>
00259 #include <uves_error.h>
00260 
00261 #include <irplib_utils.h>
00262 
00263 #include <cpl.h>
00264 
00265 #include <stdio.h>
00266 #include <stdbool.h>
00267 #include <errno.h>
00268 #include <string.h>
00269 /*-----------------------------------------------------------------------------
00270                 Forward declarations
00271  -----------------------------------------------------------------------------*/
00272 
00273 /*-----------------------------------------------------------------------------
00274                 Function codes
00275  -----------------------------------------------------------------------------*/
00276 
00277 /*----------------------------------------------------------------------------*/
00283 /*----------------------------------------------------------------------------*/
00284 int uves_pfits_get_slit3_x1encoder(const uves_propertylist * plist)
00285 {
00286   int result=0;
00287   check(result=uves_propertylist_get_int(plist,UVES_ENCODER_REF1),
00288         "Error getting %s", UVES_ENCODER_REF1);
00289 
00290  cleanup:
00291     return result; 
00292 
00293 }
00294 
00295 /*----------------------------------------------------------------------------*/
00301 /*----------------------------------------------------------------------------*/
00302 int uves_pfits_get_slit3_x2encoder(const uves_propertylist * plist)
00303 {
00304   int result=0;
00305   check(result=uves_propertylist_get_int(plist,UVES_ENCODER_REF2),
00306         "Error getting %s",UVES_ENCODER_REF2);
00307 
00308 
00309  cleanup:
00310     return result; 
00311 
00312 }
00313 
00314 /*----------------------------------------------------------------------------*/
00320 /*----------------------------------------------------------------------------*/
00321 int  uves_pfits_get_maxfibres(const uves_propertylist * plist)
00322 {
00323   int result=0;
00324    check(uves_get_property_value(plist, "MAXFIBRES", 
00325                  CPL_TYPE_INT, &result),
00326     "Error reading MAXFIBRES");
00327 
00328  cleanup:
00329     return result; 
00330 
00331 }
00332 
00333 /*----------------------------------------------------------------------------*/
00339 /*----------------------------------------------------------------------------*/
00340 char  uves_pfits_get_chipchoice(const uves_propertylist * plist)
00341 {
00342   char result=0;
00343   check(result=uves_propertylist_get_char(plist,"CHIPCHOICE"),
00344     "Error getting CHIPCHOICE");
00345 
00346  cleanup:
00347     return result; 
00348 
00349 }
00350 /*----------------------------------------------------------------------------*/
00356 /*----------------------------------------------------------------------------*/
00357 const char * uves_pfits_get_badpxframe(const uves_propertylist * plist)
00358 {
00359 
00360   const char* result=NULL;
00361 
00362   check(uves_get_property_value(plist, "BADPXFRAME", 
00363                  CPL_TYPE_STRING, &result),
00364     "Error reading BADPXFRAME");
00365 
00366  cleanup:
00367     return result; 
00368 
00369 }
00370 
00371 
00372 /*----------------------------------------------------------------------------*/
00378 /*----------------------------------------------------------------------------*/
00379 double uves_pfits_get_ambipress(const uves_propertylist * plist)
00380 {
00381   double result=0;
00382 
00383   check(uves_get_property_value(plist, "ESO INS SENS26 MEAN", 
00384                  CPL_TYPE_DOUBLE, &result),
00385     "Error reading ESO INS SENS26 MEAN");
00386 
00387  cleanup:
00388     return result; 
00389 
00390 }
00391 
00392 
00393 /*---------------------------------------------------------------------------*/
00399 /*---------------------------------------------------------------------------*/
00400 const char * uves_pfits_get_arcfile(const uves_propertylist * plist)
00401 {
00402 
00403   const char* result=NULL;
00404 
00405 
00406   check(uves_get_property_value(plist, "ARCFILE", 
00407                  CPL_TYPE_STRING, &result),
00408     "Error reading ARCFILE");
00409 
00410  cleanup:
00411     return result; 
00412 
00413 }
00414 
00415 /*---------------------------------------------------------------------------*/
00421 /*---------------------------------------------------------------------------*/
00422 const char * uves_flames_pfits_get_ident(const uves_propertylist * plist)
00423 {
00424 
00425   const char* result=NULL;
00426 
00427   check(result=uves_propertylist_get_string(plist,"IDENT"),
00428     "Error getting IDENT");
00429 
00430  cleanup:
00431     return result; 
00432 
00433 }
00434 
00435 /*---------------------------------------------------------------------------*/
00441 /*---------------------------------------------------------------------------*/
00442 const char * uves_flames_pfits_get_object(const uves_propertylist * plist)
00443 {
00444 
00445   const char* result=NULL;
00446 
00447   check(result=uves_propertylist_get_string(plist,UVES_OBJECT),
00448     "Error getting OBJECT");
00449 
00450  cleanup:
00451     return result; 
00452 
00453 }
00454 
00455 /*---------------------------------------------------------------------------*/
00461 /*---------------------------------------------------------------------------*/
00462 const char * uves_pfits_get_origfile(const uves_propertylist * plist)
00463 {
00464 
00465   const char* result=NULL;
00466 
00467   check(uves_get_property_value(plist, "ORIGFILE", 
00468                  CPL_TYPE_STRING, &result),
00469     "Error reading ORIGFILE");
00470 
00471  cleanup:
00472     return result; 
00473 
00474 }
00475 
00476 /*----------------------------------------------------------------------------*/
00482 /*----------------------------------------------------------------------------*/
00483 const char * uves_pfits_get_pipefile(const uves_propertylist * plist)
00484 {
00485 
00486   const char* result=NULL;
00487 
00488 
00489   check(uves_get_property_value(plist, "PIPEFILE", 
00490                  CPL_TYPE_STRING, &result),
00491     "Error reading PIPEFILE");
00492 
00493  cleanup:
00494     return result; 
00495 
00496 }
00497 
00498 
00499 
00500 
00501 /*----------------------------------------------------------------------------*/
00507 /*----------------------------------------------------------------------------*/
00508 const char * uves_pfits_get_rec1raw1name(const uves_propertylist * plist)
00509 {
00510   const char* result=NULL;
00511 
00512   check(uves_get_property_value(plist, "ESO PRO REC1 RAW1 NAME", 
00513                  CPL_TYPE_STRING, &result),
00514     "Error reading ESO PRO REC1 RAW1 NAME");
00515 
00516 
00517  cleanup:
00518     return result;
00519 }
00520 /*----------------------------------------------------------------------------*/
00526 /*----------------------------------------------------------------------------*/
00527 const char * uves_pfits_get_templateid(const uves_propertylist * plist)
00528 {
00529   const char* result=NULL;
00530 
00531   check(uves_get_property_value(plist, "ESO TPL ID", 
00532                  CPL_TYPE_STRING, &result),
00533     "Error reading ESO TPL ID");
00534 
00535 
00536  cleanup:
00537 
00538     return result; 
00539 }
00540 
00541 
00542 /*----------------------------------------------------------------------------*/
00548 /*----------------------------------------------------------------------------*/
00549 const char * uves_pfits_get_date_obs(const uves_propertylist * plist)
00550 {
00551 
00552   const char* result=NULL;
00553   check(uves_get_property_value(plist, "DATE-OBS", 
00554                  CPL_TYPE_STRING, &result),
00555     "Error reading DATE-OBS");
00556 
00557  cleanup:
00558     return result;
00559 
00560 }
00561 /*----------------------------------------------------------------------------*/
00567 /*----------------------------------------------------------------------------*/
00568 const char * uves_pfits_get_dpr_catg(const uves_propertylist * plist)
00569 {
00570   const char* result=NULL;
00571 
00572   check(uves_get_property_value(plist, UVES_DPR_CATG, 
00573                  CPL_TYPE_STRING, &result),
00574     "Error reading %s", UVES_DPR_CATG);
00575 
00576  cleanup:
00577     return result;
00578 }
00579 
00580 /*----------------------------------------------------------------------------*/
00586 /*----------------------------------------------------------------------------*/
00587 int uves_pfits_get_ocs_simcal(const uves_propertylist * plist)
00588 {
00589     int returnvalue = 0;
00590     
00591     check( uves_get_property_value(plist, UVES_OCS_SIMCAL, CPL_TYPE_INT, &returnvalue), 
00592        "Error reading keyword '%s'", UVES_OCS_SIMCAL);
00593     
00594   cleanup:
00595     return returnvalue;
00596 }
00597 
00598 /*----------------------------------------------------------------------------*/
00604 /*----------------------------------------------------------------------------*/
00605 void uves_pfits_set_ocs_simcal(uves_propertylist * plist, int simcal)
00606 {
00607     check( uves_propertylist_update_int(plist, UVES_OCS_SIMCAL, simcal),
00608            "Error writing keyword '%s'", UVES_OCS_SIMCAL);
00609 
00610   cleanup:
00611     return;
00612     
00613 }
00614 
00615 /*----------------------------------------------------------------------------*/
00621 /*----------------------------------------------------------------------------*/
00622 const char * uves_pfits_get_pro_catg(const uves_propertylist * plist)
00623 {
00624   const char* result=NULL;
00625 
00626   check(uves_get_property_value(plist, "ESO PRO CATG", 
00627                  CPL_TYPE_STRING, &result),
00628     "Error reading ESO PRO CATG");
00629 
00630  cleanup:
00631     return result;
00632 }
00633 
00634 /*----------------------------------------------------------------------------*/
00640 /*----------------------------------------------------------------------------*/
00641 const char * uves_pfits_get_dpr_tech(const uves_propertylist * plist)
00642 {
00643   const char* result=NULL;
00644 
00645   check( uves_get_property_value(plist, UVES_DPR_TECH, 
00646                  CPL_TYPE_STRING, &result),
00647      "Error reading %s", UVES_DPR_TECH);
00648 
00649  cleanup:
00650     return result;
00651 }
00652 
00653 /*----------------------------------------------------------------------------*/
00659 /*----------------------------------------------------------------------------*/
00660 const char * uves_pfits_get_dpr_type(const uves_propertylist * plist)
00661 {
00662   const char* result=NULL;
00663 
00664 
00665   check( uves_get_property_value(plist, UVES_DPR_TYPE, 
00666                  CPL_TYPE_STRING, &result),
00667      "Error reading %s", UVES_DPR_TYPE);
00668 
00669  cleanup:
00670     return result;
00671 }
00672 
00673 /*----------------------------------------------------------------------------*/
00680 /*----------------------------------------------------------------------------*/
00681 bool uves_ccd_is_new(const uves_propertylist * plist)
00682 {    
00683     double mjd_obs = 0.0; /* Observation date */
00684 
00685     check( mjd_obs = uves_pfits_get_mjdobs(plist),
00686        "Could not read observation date");
00687 
00688   cleanup:
00689     /* New format iff modified julian date is after April 1st, 2004 = 53096 mjd */
00690     return (mjd_obs > 55018.0);  
00691 }
00692 
00693 /*----------------------------------------------------------------------------*/
00700 /*----------------------------------------------------------------------------*/
00701 bool uves_format_is_new(const uves_propertylist * plist)
00702 {    
00703     double mjd_obs = 0.0; /* Observation date */
00704 
00705     check( mjd_obs = uves_pfits_get_mjdobs(plist),
00706        "Could not read observation date");
00707 
00708   cleanup:
00709     /* New format iff modified julian date is after April 1st, 2004 = 53096 mjd */
00710     return (mjd_obs > 53096.0);  
00711 }
00712 
00713 /*----------------------------------------------------------------------------*/
00721 /*----------------------------------------------------------------------------*/
00722 int uves_pfits_get_prescanx(const uves_propertylist * plist, enum uves_chip chip)
00723 {
00724     int returnvalue = 0;
00725     bool new_format;
00726     
00727     check( new_format = uves_format_is_new(plist),
00728        "Error determining FITS header format");
00729     
00730     check( uves_get_property_value(plist, UVES_PRESCANX(new_format, chip), 
00731                    CPL_TYPE_INT, &returnvalue), 
00732        "Error reading keyword %s", UVES_PRESCANX(new_format, chip));
00733     
00734   cleanup:
00735     return returnvalue;
00736 }
00737 
00738 /*----------------------------------------------------------------------------*/
00746 /*----------------------------------------------------------------------------*/
00747 const char* uves_pfits_get_chipid(const uves_propertylist * plist, enum uves_chip chip)
00748 {
00749     const char* returnvalue = "";
00750 
00751     check( uves_get_property_value(plist, UVES_CHIP_ID(chip), CPL_TYPE_STRING, &returnvalue), 
00752        "Error reading keyword %s", UVES_CHIP_ID(chip));
00753     
00754   cleanup:
00755     return returnvalue;
00756 }
00757 
00758 /*----------------------------------------------------------------------------*/
00766 /*----------------------------------------------------------------------------*/
00767 const char* uves_pfits_get_chip_name(const uves_propertylist * plist, enum uves_chip chip)
00768 {
00769     const char* returnvalue = "";
00770 
00771     check( uves_get_property_value(plist, UVES_CHIP_NAME(chip), CPL_TYPE_STRING, &returnvalue), 
00772        "Error reading keyword %s", UVES_CHIP_NAME(chip));
00773     
00774   cleanup:
00775     return returnvalue;
00776 }
00777 
00778 /*----------------------------------------------------------------------------*/
00786 /*----------------------------------------------------------------------------*/
00787 int uves_pfits_get_ovrscanx(const uves_propertylist * plist, enum uves_chip chip)
00788 {
00789     int returnvalue = 0;
00790     bool new_format;
00791 
00792     check( new_format = uves_format_is_new(plist),
00793        "Error determining FITS header format");
00794     
00795     check( uves_get_property_value(plist, UVES_OVRSCANX(new_format, chip), 
00796                    CPL_TYPE_INT, &returnvalue), 
00797        "Error reading keyword %s", UVES_OVRSCANX(new_format, chip));
00798     
00799   cleanup:
00800     return returnvalue;
00801 }
00802 
00803 /*----------------------------------------------------------------------------*/
00811 /*----------------------------------------------------------------------------*/
00812 int uves_pfits_get_prescany(const uves_propertylist * plist, enum uves_chip chip)
00813 {
00814     int returnvalue = 0;
00815     bool new_format;
00816     
00817 
00818     check( new_format = uves_format_is_new(plist),
00819        "Error determining FITS header format");
00820     
00821     check( uves_get_property_value(plist, UVES_PRESCANY(new_format, chip), 
00822                    CPL_TYPE_INT, &returnvalue), 
00823        "Error reading keyword %s", UVES_PRESCANY(new_format, chip));
00824     
00825   cleanup:
00826     return returnvalue;
00827 }
00828 
00829 /*----------------------------------------------------------------------------*/
00837 /*----------------------------------------------------------------------------*/
00838 int uves_pfits_get_ovrscany(const uves_propertylist * plist, enum uves_chip chip)
00839 {
00840     int returnvalue = 0;
00841     bool new_format;
00842 
00843     check( new_format = uves_format_is_new(plist),
00844        "Error determining FITS header format");
00845     
00846     check( uves_get_property_value(plist, UVES_OVRSCANY(new_format, chip), 
00847                    CPL_TYPE_INT, &returnvalue), 
00848        "Error reading keyword %s", UVES_OVRSCANY(new_format, chip));
00849     
00850   cleanup:
00851     return returnvalue;
00852 }
00853 
00854 /*----------------------------------------------------------------------------*/
00867 /*----------------------------------------------------------------------------*/
00868 double uves_pfits_get_ron_adu(const uves_propertylist * plist, enum uves_chip chip)
00869 {
00870     double ron_el = 0;          /* Read-out noise in electron units  */
00871     double default_ron_el = 5.0;/* Number converted from MIDAS       */
00872     double gain = 0;            /* Conversion from electrons to ADUs */
00873     bool new_format;
00874 
00875     check( new_format = uves_format_is_new(plist),
00876        "Error determining FITS header format");
00877     
00878     check( uves_get_property_value(plist, UVES_RON(new_format, chip), CPL_TYPE_DOUBLE, &ron_el),
00879        "Error reading keyword '%s'", UVES_RON(new_format, chip));
00880 
00881     if (ron_el <= 0)
00882     {
00883         uves_msg_warning("Read-out-noise is "
00884                  "non-positive (%e electrons). Using default value %e",
00885                  ron_el, default_ron_el);
00886         ron_el = default_ron_el;
00887     }
00888     
00889     check( gain = uves_pfits_get_gain(plist, chip),
00890        "Error reading gain");
00891     
00892     assure( ron_el * gain > 0, CPL_ERROR_ILLEGAL_INPUT,
00893         "Non-positive read-out noise: %f ADU", ron_el * gain);
00894     
00895   cleanup:
00896     return ron_el * gain;
00897 }
00898 /*----------------------------------------------------------------------------*/
00906 /*----------------------------------------------------------------------------*/
00907 double uves_pfits_get_airmass_start(const uves_propertylist * plist)
00908 {
00909     double result = 0;
00910     
00911     check( uves_get_property_value(plist, UVES_AIRMASS_START, CPL_TYPE_DOUBLE, &result),
00912        "Error reading keyword '%s'", UVES_AIRMASS_START);
00913     
00914   cleanup:
00915     return result;
00916 }
00917 /*----------------------------------------------------------------------------*/
00925 /*----------------------------------------------------------------------------*/
00926 double uves_pfits_get_airmass_end(const uves_propertylist * plist)
00927 {
00928     double result = 0;
00929     
00930     check( uves_get_property_value(plist, UVES_AIRMASS_END, CPL_TYPE_DOUBLE, &result),
00931        "Error reading keyword '%s'", UVES_AIRMASS_END);
00932     
00933   cleanup:
00934     return result;
00935 }
00936 /*----------------------------------------------------------------------------*/
00945 /*----------------------------------------------------------------------------*/
00946 double uves_pfits_get_conad(const uves_propertylist * plist, enum uves_chip chip)
00947 {
00948     double result = 0;
00949     
00950     bool new_format;
00951 
00952     check( new_format = uves_format_is_new(plist),
00953        "Error determining FITS header format");
00954     
00955     check( uves_get_property_value(plist, UVES_CONAD(new_format, chip),
00956                    CPL_TYPE_DOUBLE, &result),
00957        "Error reading keyword '%s'", UVES_CONAD(new_format, chip));
00958     
00959   cleanup:
00960     return result;
00961 }
00962 /*----------------------------------------------------------------------------*/
00970 /*----------------------------------------------------------------------------*/
00971 const char *uves_pfits_get_targ_name(const uves_propertylist * plist)
00972 {
00973     const char* returnvalue = "";
00974 
00975     check( uves_get_property_value(plist, UVES_TARG_NAME, CPL_TYPE_STRING, &returnvalue), 
00976        "Error reading keyword %s", UVES_TARG_NAME);
00977     
00978   cleanup:
00979     return returnvalue;
00980 }
00981 
00982 /*----------------------------------------------------------------------------*/
00992 /*----------------------------------------------------------------------------*/
00993 double uves_pfits_get_gain(const uves_propertylist * plist, enum uves_chip chip)
00994 {
00995     double result = 0;
00996     double default_gain = 2.1;        /* Adopted from MIDAS */
00997     bool new_format;
00998 
00999     check( new_format = uves_format_is_new(plist),
01000        "Error determining FITS header format");
01001     
01002     check( uves_get_property_value(plist, UVES_GAIN(new_format, chip),
01003                    CPL_TYPE_DOUBLE, &result),
01004        "Error reading keyword '%s'", UVES_GAIN(new_format, chip));
01005     
01006     if (result <= 0)
01007     {
01008         uves_msg_warning("Gain factor from header is "
01009                  "non-positive (%e). Using default value %e",
01010                  result, default_gain);
01011         result = default_gain;
01012     }
01013 
01014   cleanup:
01015     return result;
01016 }
01017 /*----------------------------------------------------------------------------*/
01027 /*----------------------------------------------------------------------------*/
01028 double uves_pfits_get_exptime(const uves_propertylist * plist)
01029 {
01030     double result = 0;            /* Conversion from electrons to ADUs */
01031     
01032     check( uves_get_property_value(plist, UVES_EXPTIME, CPL_TYPE_DOUBLE, &result), 
01033        "Error reading keyword '%s'", UVES_EXPTIME);
01034     assure( result >= 0, CPL_ERROR_ILLEGAL_OUTPUT, "Exposure time is negative: %f", result);
01035     
01036   cleanup:
01037     return result;
01038 }
01039 
01040 /*----------------------------------------------------------------------------*/
01048 /*----------------------------------------------------------------------------*/
01049 cpl_error_code
01050 uves_pfits_set_exptime(uves_propertylist *plist, double exptime)
01051 {
01052     check(( uves_propertylist_update_double(plist, UVES_EXPTIME, exptime),
01053         uves_propertylist_set_comment(plist, UVES_EXPTIME, "Total integration time")),
01054        "Error writing keyword '%s'", UVES_EXPTIME);
01055   cleanup:
01056     return cpl_error_get_code();
01057 }
01058 
01059 
01060 /*----------------------------------------------------------------------------*/
01068 /*----------------------------------------------------------------------------*/
01069 void
01070 uves_pfits_set_dec(uves_propertylist *plist, double dec)
01071 {
01072     check( uves_propertylist_update_double(plist, UVES_DEC, dec),
01073        "Error writing keyword '%s'", UVES_DEC);
01074   cleanup:
01075     return;
01076 }
01077 
01078 /*----------------------------------------------------------------------------*/
01086 /*----------------------------------------------------------------------------*/
01087 void
01088 uves_pfits_set_ra(uves_propertylist *plist, double ra)
01089 {
01090     check( uves_propertylist_update_double(plist, UVES_RA, ra),
01091        "Error writing keyword '%s'", UVES_RA);
01092   cleanup:
01093     return;
01094 }
01095 
01096 /*----------------------------------------------------------------------------*/
01104 /*----------------------------------------------------------------------------*/
01105 cpl_error_code
01106 uves_pfits_set_ordpred(uves_propertylist *plist, int nord)
01107 {
01108     check(( uves_propertylist_update_int(plist, UVES_ORD_PRED, nord),
01109         uves_propertylist_set_comment(plist, UVES_ORD_PRED, "Predicted no of orders")),
01110        "Error writing keyword '%s'", UVES_ORD_PRED);
01111   cleanup:
01112     return cpl_error_get_code();
01113 }
01114 
01115 /*----------------------------------------------------------------------------*/
01121 /*----------------------------------------------------------------------------*/
01122 const char *
01123 uves_pfits_get_drs_id(const uves_propertylist * plist)
01124 {
01125     const char *result = "";
01126     
01127     check( uves_get_property_value(plist, UVES_DRS_ID, CPL_TYPE_STRING, &result), 
01128        "Error reading keyword '%s'", UVES_DRS_ID);
01129     
01130   cleanup:
01131     if (cpl_error_get_code() != CPL_ERROR_NONE) 
01132     {
01133         result = NULL;
01134     }
01135 
01136     return result;
01137 }
01138 
01139 
01140 
01141 /*----------------------------------------------------------------------------*/
01147 /*----------------------------------------------------------------------------*/
01148 const char *
01149 uves_pfits_get_tpl_start(const uves_propertylist * plist)
01150 {
01151     const char *result = "";
01152     
01153     check( uves_get_property_value(plist, UVES_TPL_START, CPL_TYPE_STRING, &result),
01154        "Error reading keyword '%s'", UVES_TPL_START);
01155     
01156   cleanup:
01157     if (cpl_error_get_code() != CPL_ERROR_NONE) 
01158     {
01159         result = NULL;
01160     }
01161 
01162     return result;
01163 }
01164 
01165 
01166 /*----------------------------------------------------------------------------*/
01172 /*----------------------------------------------------------------------------*/
01173 double uves_pfits_get_utc(const uves_propertylist * plist)
01174 {
01175     double returnvalue = 0;
01176     
01177     check( uves_get_property_value(plist, UVES_UTC, CPL_TYPE_DOUBLE, &returnvalue), 
01178        "Error reading keyword '%s'", UVES_UTC);
01179     
01180   cleanup:
01181     return returnvalue;
01182 }
01183 
01184 
01185 /*----------------------------------------------------------------------------*/
01191 /*----------------------------------------------------------------------------*/
01192 double uves_pfits_get_mjdobs(const uves_propertylist * plist)
01193 {
01194     double returnvalue = 0;
01195     
01196     check( uves_get_property_value(plist, UVES_MJDOBS, CPL_TYPE_DOUBLE, &returnvalue), 
01197        "Error reading keyword '%s'", UVES_MJDOBS);
01198     
01199   cleanup:
01200     return returnvalue;
01201 }
01202 
01203 /*----------------------------------------------------------------------------*/
01209 /*----------------------------------------------------------------------------*/
01210 double uves_pfits_get_geolat(const uves_propertylist * plist)
01211 {
01212     double returnvalue = 0;
01213     
01214     check( uves_get_property_value(plist, UVES_GEOLAT, CPL_TYPE_DOUBLE, &returnvalue), 
01215        "Error reading keyword '%s'", UVES_GEOLAT);
01216     
01217   cleanup:
01218     return returnvalue;
01219 }
01220 
01221 /*----------------------------------------------------------------------------*/
01227 /*----------------------------------------------------------------------------*/
01228 double uves_pfits_get_geolon(const uves_propertylist * plist)
01229 {
01230     double returnvalue = 0;
01231     
01232     check( uves_get_property_value(plist, UVES_GEOLON, CPL_TYPE_DOUBLE, &returnvalue), 
01233        "Error reading keyword '%s'", UVES_GEOLON);
01234     
01235   cleanup:
01236     return returnvalue;
01237 }
01238 
01239 /*----------------------------------------------------------------------------*/
01245 /*----------------------------------------------------------------------------*/
01246 double uves_pfits_get_ra(const uves_propertylist * plist)
01247 {
01248     double returnvalue = 0;
01249     
01250     check( uves_get_property_value(plist, UVES_RA, CPL_TYPE_DOUBLE, &returnvalue), 
01251        "Error reading keyword '%s'", UVES_RA);
01252     
01253   cleanup:
01254     return returnvalue;
01255 }
01256 
01257 /*----------------------------------------------------------------------------*/
01263 /*----------------------------------------------------------------------------*/
01264 double uves_pfits_get_dec(const uves_propertylist * plist)
01265 {
01266     double returnvalue = 0;
01267     
01268     check( uves_get_property_value(plist, UVES_DEC, CPL_TYPE_DOUBLE, &returnvalue), 
01269        "Error reading keyword '%s'", UVES_DEC);
01270     
01271   cleanup:
01272     return returnvalue;
01273 }
01274 
01275 /*----------------------------------------------------------------------------*/
01281 /*----------------------------------------------------------------------------*/
01282 int uves_pfits_get_binx(const uves_propertylist * plist)
01283 {
01284     int returnvalue = 0;
01285     
01286     check( uves_get_property_value(plist, UVES_BINX, CPL_TYPE_INT, &returnvalue), 
01287        "Error reading keyword '%s'", UVES_BINX);
01288     
01289   cleanup:
01290     return returnvalue;
01291 }
01292 
01293 /*----------------------------------------------------------------------------*/
01299 /*----------------------------------------------------------------------------*/
01300 int uves_pfits_get_biny(const uves_propertylist * plist)
01301 {
01302     int returnvalue = 0;
01303     
01304     check( uves_get_property_value(plist, UVES_BINY, CPL_TYPE_INT, &returnvalue), 
01305        "Error reading keyword '%s'", UVES_BINY);
01306     
01307   cleanup:
01308     return returnvalue;
01309 }
01310 
01311 /*----------------------------------------------------------------------------*/
01317 /*----------------------------------------------------------------------------*/
01318 int uves_pfits_get_datancom(const uves_propertylist * plist)
01319 {
01320     int returnvalue = 0;
01321     
01322     /* This keyword changed name at some point. For support of older products, try to
01323        first new then old FITS card */
01324 
01325     assure( plist != NULL, CPL_ERROR_NULL_INPUT, "Null plist");
01326 
01327     if (uves_propertylist_contains(plist, UVES_DATANCOM))
01328     {
01329         check( uves_get_property_value(plist, UVES_DATANCOM, CPL_TYPE_INT, &returnvalue),
01330            "Error reading keyword '%s'", UVES_DATANCOM);
01331     }
01332     else if( uves_propertylist_contains(plist, UVES_DATANCOM_OLD)) 
01333     {
01334         
01335         check( uves_get_property_value(plist, UVES_DATANCOM_OLD, CPL_TYPE_INT, &returnvalue),
01336            "Error reading keyword '%s'", UVES_DATANCOM_OLD);
01337     } else {
01338 
01339       uves_msg_warning("Neither %s nor %s found! We assume a value of 5! This may affect noise/error propagation",
01340                UVES_DATANCOM,UVES_DATANCOM_OLD);
01341       returnvalue=5;
01342     }
01343     
01344   cleanup:
01345     return returnvalue;
01346 }
01347 
01348 
01349 
01350 /*----------------------------------------------------------------------------*/
01356 /*----------------------------------------------------------------------------*/
01357 const char* uves_pfits_get_ccdid(const uves_propertylist * plist)
01358 {
01359     const char* result="";
01360     
01361     check( uves_get_property_value(plist, UVES_CCDID, CPL_TYPE_STRING, &result), 
01362        "Error reading keyword '%s'", UVES_CCDID);
01363     
01364   cleanup:
01365     return result;
01366 }
01367 
01368 /*----------------------------------------------------------------------------*/
01374 /*----------------------------------------------------------------------------*/
01375 double uves_pfits_get_pressure(const uves_propertylist * plist)
01376 {
01377     double returnvalue;
01378     
01379     check( uves_get_property_value(plist, UVES_PRESSURE, CPL_TYPE_DOUBLE, &returnvalue), 
01380        "Error reading keyword '%s'", UVES_PRESSURE);
01381     
01382   cleanup:
01383     return returnvalue;
01384 }
01385 /*----------------------------------------------------------------------------*/
01393 /*----------------------------------------------------------------------------*/
01394 const char * uves_chop_eso_prefix(const char* key)
01395 {
01396     const char *result = NULL;
01397     const char *prefix = "ESO ";
01398     unsigned int pref_len = strlen(prefix);
01399     
01400     assure( strlen(key) >= pref_len && 
01401         strncmp(key, prefix, pref_len) == 0,
01402         CPL_ERROR_ILLEGAL_INPUT,
01403         "Keyword %s does not contain 'ESO ' prefix", key);
01404 
01405     result = key + pref_len;
01406 
01407   cleanup:
01408     return result;
01409 }
01410 
01411 /*----------------------------------------------------------------------------*/
01418 /*----------------------------------------------------------------------------*/
01419 double uves_pfits_get_tempcam(const uves_propertylist * plist, enum uves_chip chip)
01420 {
01421     double returnvalue;
01422     
01423     check( uves_get_property_value(plist, UVES_TEMPCAM(chip), CPL_TYPE_DOUBLE, &returnvalue),
01424        "Error reading keyword '%s'", UVES_TEMPCAM(chip));
01425     
01426   cleanup:
01427     return returnvalue;
01428 }
01429 
01430 
01431 /*----------------------------------------------------------------------------*/
01437 /*----------------------------------------------------------------------------*/
01438 double uves_pfits_get_humidity(const uves_propertylist * plist)
01439 {
01440     double returnvalue;
01441     
01442     check( uves_get_property_value(plist, UVES_HUMIDITY, CPL_TYPE_DOUBLE, &returnvalue),
01443        "Error reading keyword '%s'", UVES_HUMIDITY);
01444     
01445   cleanup:
01446     return returnvalue;
01447 }
01448 
01449 /*----------------------------------------------------------------------------*/
01456 /*----------------------------------------------------------------------------*/
01457 double uves_pfits_get_gratwlen(const uves_propertylist * plist, enum uves_chip chip)
01458 {
01459     double returnvalue;
01460     
01461     check( uves_get_property_value(plist, UVES_GRATWLEN(chip), CPL_TYPE_DOUBLE, &returnvalue), 
01462        "Error reading keyword '%s'", UVES_GRATWLEN(chip));
01463 
01464     assure(returnvalue > 0, CPL_ERROR_ILLEGAL_INPUT, "Non-positive wavelength: %e", returnvalue);
01465        
01466   cleanup:
01467     return returnvalue;
01468 }
01469 
01470 /*----------------------------------------------------------------------------*/
01476 /*----------------------------------------------------------------------------*/
01477 const char* uves_pfits_get_insmode(const uves_propertylist * plist)
01478 {
01479     const char* returnvalue="";
01480     
01481     check( uves_get_property_value(plist, UVES_INSMODE, CPL_TYPE_STRING, &returnvalue), 
01482        "Error reading keyword '%s'", UVES_INSMODE);
01483     
01484   cleanup:
01485     return returnvalue;
01486 }
01487 
01488 /*----------------------------------------------------------------------------*/
01494 /*----------------------------------------------------------------------------*/
01495 const char* uves_pfits_get_inspath(const uves_propertylist * plist)
01496 {
01497     const char* returnvalue="";
01498     
01499     check( uves_get_property_value(plist, UVES_INSPATH, CPL_TYPE_STRING, &returnvalue),
01500        "Error reading keyword '%s'", UVES_INSPATH);
01501     
01502   cleanup:
01503     return returnvalue;
01504 }
01505 /*----------------------------------------------------------------------------*/
01512 /*----------------------------------------------------------------------------*/
01513 const char* uves_pfits_get_gratname(const uves_propertylist * plist, enum uves_chip chip)
01514 {
01515     const char* returnvalue="";
01516     
01517     check( uves_get_property_value(plist, UVES_GRATNAME(chip), CPL_TYPE_STRING, &returnvalue),
01518        "Error reading keyword '%s'", UVES_GRATNAME(chip));
01519     
01520   cleanup:
01521     return returnvalue;
01522 }
01523 
01524 /*----------------------------------------------------------------------------*/
01531 /*----------------------------------------------------------------------------*/
01532 const char* uves_pfits_get_readspeed(const uves_propertylist * plist)
01533 {
01534     const char* returnvalue="";
01535     
01536     check( uves_get_property_value(plist, UVES_READ_SPEED, CPL_TYPE_STRING, &returnvalue),
01537        "Error reading keyword '%s'", UVES_READ_SPEED);
01538     
01539   cleanup:
01540     return returnvalue;
01541 }
01542 
01543 /*----------------------------------------------------------------------------*/
01550 /*----------------------------------------------------------------------------*/
01551 const char* uves_pfits_get_gratid(const uves_propertylist * plist, enum uves_chip chip)
01552 {
01553     const char* returnvalue="";
01554     
01555     check( uves_get_property_value(plist, UVES_GRATID(chip), CPL_TYPE_STRING, &returnvalue), 
01556        "Error reading keyword '%s'", UVES_GRATID(chip));
01557     
01558   cleanup:
01559     return returnvalue;
01560 }
01561 
01562 /*----------------------------------------------------------------------------*/
01569 /*----------------------------------------------------------------------------*/
01570 double uves_pfits_get_slitlength(const uves_propertylist * plist, enum uves_chip chip)
01571 {
01572     double returnvalue;
01573     
01574     check( uves_get_property_value(plist, UVES_SLITLENGTH(chip), CPL_TYPE_DOUBLE, &returnvalue), 
01575        "Error reading keyword '%s'", UVES_SLITLENGTH(chip));
01576     
01577   cleanup:
01578     return returnvalue;
01579 }
01580 
01581 
01582 /*----------------------------------------------------------------------------*/
01589 /*----------------------------------------------------------------------------*/
01590 double uves_pfits_get_slitwidth(const uves_propertylist * plist, enum uves_chip chip)
01591 {
01592     double returnvalue;
01593     
01594     check( uves_get_property_value(plist, UVES_SLITWIDTH(chip), CPL_TYPE_DOUBLE, &returnvalue),
01595        "Error reading keyword '%s'", UVES_SLITWIDTH(chip));
01596     
01597   cleanup:
01598     return returnvalue;
01599 }
01600 
01601 /*----------------------------------------------------------------------------*/
01607 /*----------------------------------------------------------------------------*/
01608 int uves_pfits_get_ordpred(const uves_propertylist * plist)
01609 {
01610     cpl_type type;
01611     int returnvalue;
01612 
01613     assure( plist != NULL, CPL_ERROR_NULL_INPUT, "Null plist");
01614     
01615     /* In the UVES calibration data base this keyword
01616        is sometimes integer (e.g. '33'), sometimes a floating 
01617        point value (e.g. '33.'), so support both types */
01618     
01619     assure( uves_propertylist_contains(plist, UVES_ORD_PRED), 
01620         CPL_ERROR_DATA_NOT_FOUND,
01621         "Keyword %s does not exist", UVES_ORD_PRED);
01622     check ( type = uves_propertylist_get_type(plist, UVES_ORD_PRED), 
01623         "Error reading type of property '%s'", UVES_ORD_PRED);
01624     
01625     if (type == CPL_TYPE_INT)
01626     {
01627         check( uves_get_property_value(
01628                plist, UVES_ORD_PRED, CPL_TYPE_INT, &returnvalue), 
01629            "Error reading keyword '%s'", UVES_ORD_PRED);
01630     }
01631     else if (type == CPL_TYPE_DOUBLE)
01632     {
01633         double dvalue;
01634         check( uves_get_property_value(
01635                plist, UVES_ORD_PRED, CPL_TYPE_DOUBLE, &dvalue), 
01636            "Error reading keyword '%s'", UVES_ORD_PRED);
01637         returnvalue = uves_round_double(dvalue);
01638     }
01639     else
01640     {
01641         assure( false, CPL_ERROR_TYPE_MISMATCH,
01642             "Keyword '%s' has wrong type '%s'",
01643             UVES_ORD_PRED, uves_tostring_cpl_type(type));
01644     }
01645     
01646   cleanup:
01647     return returnvalue;
01648 }
01649 
01650 /*----------------------------------------------------------------------------*/
01663 /*----------------------------------------------------------------------------*/
01664 void
01665 uves_pfits_set_history_val(uves_propertylist *plist, const char *name, const char *format, ...)
01666 {
01667     char *val_str = NULL;
01668     char *number_str = NULL;
01669     cpl_property *existing = NULL;
01670     va_list arglist;
01671     const long int plist_size = uves_propertylist_get_size(plist);
01672     int i;
01673 
01674     for (i = 0;
01675      existing == NULL && i < plist_size; i++)
01676     {
01677         cpl_property *p = uves_propertylist_get(plist, i);
01678         const char *pname = cpl_property_get_name(p);
01679         
01680         if (strcmp(pname, "HISTORY") == 0)
01681         {
01682             const char *pval;
01683             check( pval = cpl_property_get_string(p),
01684                "Error reading property value");
01685             
01686             /* match the string  "<name> " */
01687             
01688             if (strlen(pval) > strlen(name) + strlen(" ") &&
01689             strncmp(pval, name, strlen(name)) == 0 &&
01690             pval[strlen(name)] == ' ')
01691             {
01692                 /* Remember this one and stop searching */
01693                 existing = p;
01694             }
01695         }
01696     }
01697 
01698     va_start(arglist, format);
01699     number_str = cpl_vsprintf(format, arglist);
01700     va_end(arglist);
01701 
01702     val_str = uves_sprintf("%s %s", name, number_str);
01703 
01704     if (existing != NULL)
01705     {
01706         check( cpl_property_set_string(existing, val_str),
01707            "Error updating HISTORY keyword with value '%s'", val_str);
01708     }
01709     else
01710     {
01711         check( uves_propertylist_append_string(plist, "HISTORY", val_str),
01712            "Error writing HISTORY keyword with value '%s'", val_str);
01713     }
01714 
01715   cleanup:
01716     cpl_free(val_str);
01717     cpl_free(number_str);
01718     return;
01719 }
01720 /*----------------------------------------------------------------------------*/
01737 /*----------------------------------------------------------------------------*/
01738 static double
01739 parse_history(const uves_propertylist *plist, const char *name, cpl_type type)
01740 {
01741     double returnvalue = 0;
01742     const long int plist_size = uves_propertylist_get_size(plist);
01743     int i;
01744     bool found;
01745 
01746     found = false;
01747     for (i = 0; !found && i < plist_size; i++) {
01748         const cpl_property *p = uves_propertylist_get_const(plist, i);
01749         const char *value = cpl_property_get_name(p);
01750         
01751         if (strcmp(value, "HISTORY") == 0) {
01752             check( value = cpl_property_get_string(p),
01753                    "Error reading property value");
01754             
01755             /* match the string  "<name> " */
01756             
01757             if (strlen(value) > strlen(name) + strlen(" ") &&
01758                 strncmp(value, name, strlen(name)) == 0 &&
01759                 value[strlen(name)] == ' ') {
01760                 errno = 0;
01761                 switch(type) {
01762                 case CPL_TYPE_INT:
01763                     returnvalue = atoi(value + strlen(name) + strlen(" "));
01764                     assure(errno == 0, CPL_ERROR_ILLEGAL_INPUT, 
01765                            "Could not parse string '%s' as integer. "
01766                            "atoi() returned %d",
01767                            value + strlen(name) + strlen(" "), errno);
01768                     break;
01769                 case CPL_TYPE_DOUBLE:
01770                     returnvalue = strtod(value + strlen(name) + strlen(" "), NULL);
01771                     assure(errno == 0, CPL_ERROR_ILLEGAL_INPUT, 
01772                            "Could not parse string '%s' as double. "
01773                            "strtod() returned %d",
01774                            value + strlen(name) + strlen(" "), errno);
01775                     break;
01776                 default:
01777                     assure( false, CPL_ERROR_UNSUPPORTED_MODE,
01778                             "Type is %s", uves_tostring_cpl_type(type));
01779                     break;
01780                 }
01781                 found = true;
01782             }
01783         }
01784     }
01785     
01786     assure( found, CPL_ERROR_DATA_NOT_FOUND, "Missing record 'HISTORY %s '",
01787         name );
01788 
01789   cleanup:
01790     return returnvalue;
01791 }
01792     
01793 /*----------------------------------------------------------------------------*/
01801 /*----------------------------------------------------------------------------*/
01802 void
01803 uves_pfits_set_firstabsorder(uves_propertylist *plist, int first_abs_order)
01804 {
01805     uves_pfits_set_history_val(plist, UVES_FIRSTABSORDER, "%d", first_abs_order);
01806 
01807     return;
01808 }
01809 
01810 /*----------------------------------------------------------------------------*/
01816 /*----------------------------------------------------------------------------*/
01817 int
01818 uves_pfits_get_firstabsorder(const uves_propertylist * plist)
01819 {
01820     return uves_round_double(parse_history(plist, UVES_FIRSTABSORDER, CPL_TYPE_INT));
01821 }
01822 
01823 
01824 /*----------------------------------------------------------------------------*/
01832 /*----------------------------------------------------------------------------*/
01833 void
01834 uves_pfits_set_lastabsorder(uves_propertylist *plist, int last_abs_order)
01835 {
01836     uves_pfits_set_history_val(plist, UVES_LASTABSORDER, "%d", last_abs_order);
01837 
01838     return;
01839 }
01840 /*----------------------------------------------------------------------------*/
01846 /*----------------------------------------------------------------------------*/
01847 int
01848 uves_pfits_get_lastabsorder(const uves_propertylist * plist)
01849 {
01850     return uves_round_double(parse_history(plist, UVES_LASTABSORDER, CPL_TYPE_INT));
01851 }
01852 
01853 /*---------------------------------------------------------------------------*/
01860 /*---------------------------------------------------------------------------*/
01861 cpl_error_code 
01862 uves_pfits_set_data_average(uves_propertylist * plist, double average)
01863 {
01864     check(( uves_propertylist_update_double(plist, UVES_PRO_DATAAVG, average),
01865         uves_propertylist_set_comment  (plist, UVES_PRO_DATAAVG, "Mean of pixel values")),
01866        "Error writing keyword '%s'", UVES_PRO_DATAAVG);
01867   cleanup:
01868     return cpl_error_get_code();
01869 }
01870 
01871 /*---------------------------------------------------------------------------*/
01878 /*---------------------------------------------------------------------------*/
01879 cpl_error_code 
01880 uves_pfits_set_data_stddev(uves_propertylist * plist, double stddev)
01881 {
01882     check(( uves_propertylist_update_double(plist, UVES_PRO_DATARMS, stddev),
01883         uves_propertylist_set_comment  (plist, UVES_PRO_DATARMS, 
01884                        "Standard deviation of pixel values")),
01885        "Error writing keyword '%s'", UVES_PRO_DATARMS);
01886   
01887   cleanup:
01888     return cpl_error_get_code();
01889 }
01890 
01891 /*---------------------------------------------------------------------------*/
01898 /*---------------------------------------------------------------------------*/
01899 cpl_error_code 
01900 uves_pfits_set_data_median(uves_propertylist * plist, double median)
01901 {
01902     check(( uves_propertylist_update_double(plist, UVES_PRO_DATAMED, median),
01903         uves_propertylist_set_comment  (plist, UVES_PRO_DATAMED, "Median of pixel values")),
01904        "Error writing keyword '%s'", UVES_PRO_DATAMED);
01905 
01906   cleanup:
01907     return cpl_error_get_code();
01908 }
01909 /*---------------------------------------------------------------------------*/
01916 /*---------------------------------------------------------------------------*/
01917 cpl_error_code 
01918 uves_pfits_set_data_min(uves_propertylist * plist, double min)
01919 {
01920     check(( uves_propertylist_update_double(plist, UVES_DATAMIN, min),
01921         uves_propertylist_set_comment  (plist, UVES_DATAMIN, "Minimum of pixel values")),
01922         "Error writing keyword '%s'", UVES_DATAMIN);
01923   
01924   cleanup:
01925     return cpl_error_get_code();
01926 }
01927 /*---------------------------------------------------------------------------*/
01934 /*---------------------------------------------------------------------------*/
01935 cpl_error_code 
01936 uves_pfits_set_data_max(uves_propertylist * plist, double max)
01937 {
01938     check(( uves_propertylist_update_double(plist, UVES_DATAMAX, max),
01939         uves_propertylist_set_comment  (plist, UVES_DATAMAX, 
01940                                             "Maximum of pixel values")),
01941           "Error writing keyword '%s'", UVES_DATAMAX);
01942   
01943   cleanup:
01944     return cpl_error_get_code();
01945 }
01946 
01947 /*---------------------------------------------------------------------------*/
01954 /*---------------------------------------------------------------------------*/
01955 void
01956 uves_pfits_set_traceid(uves_propertylist * plist, int trace_id)
01957 {
01958     uves_pfits_set_history_val(plist, UVES_TRACEID, "%d", trace_id);    
01959     return;
01960 }
01961 
01962 /*---------------------------------------------------------------------------*/
01968 /*---------------------------------------------------------------------------*/
01969 double
01970 uves_pfits_get_offset(const uves_propertylist *plist)
01971 {
01972     double offset;
01973     if (uves_propertylist_contains(plist, UVES_TRACE_OFFSET)) 
01974         /* MIDAS format */
01975         {
01976             check( uves_get_property_value(plist, UVES_TRACE_OFFSET, CPL_TYPE_DOUBLE,
01977                                            &offset), 
01978                    "Error reading keyword %s", UVES_TRACE_OFFSET);
01979         }
01980     else
01981         {
01982             offset = parse_history(plist, UVES_TRACE_OFFSET, CPL_TYPE_DOUBLE);
01983         }
01984 
01985   cleanup:    
01986     return offset;
01987 }
01988 /*---------------------------------------------------------------------------*/
01995 /*---------------------------------------------------------------------------*/
01996 void
01997 uves_pfits_set_offset(uves_propertylist * plist, double trace_offset)
01998 {
01999     uves_pfits_set_history_val(plist, UVES_TRACE_OFFSET, "%f", trace_offset);
02000     return;
02001 }
02002 
02003 /*---------------------------------------------------------------------------*/
02010 /*---------------------------------------------------------------------------*/
02011 void
02012 uves_pfits_set_windownumber(uves_propertylist * plist, int window_number)
02013 {
02014     uves_pfits_set_history_val(plist, UVES_WINDOWNUMBER, "%d", window_number);
02015     return;
02016 }
02017 
02018 
02019 /*---------------------------------------------------------------------------*/
02025 /*---------------------------------------------------------------------------*/
02026 int
02027 uves_pfits_get_traceid(const uves_propertylist * plist)
02028 {
02029     return uves_round_double(parse_history(plist, UVES_TRACEID, CPL_TYPE_INT));
02030 }
02031 
02032 /*---------------------------------------------------------------------------*/
02038 /*---------------------------------------------------------------------------*/
02039 int
02040 uves_pfits_get_windownumber(const uves_propertylist * plist)
02041 {
02042     return uves_round_double(parse_history(plist, UVES_WINDOWNUMBER, CPL_TYPE_INT));
02043 }
02044 
02045 /*---------------------------------------------------------------------------*/
02051 /*---------------------------------------------------------------------------*/
02052 const char* 
02053 uves_pfits_get_bunit(const uves_propertylist * plist)
02054 {
02055     const char* returnvalue="";
02056     
02057     check( uves_get_property_value(plist, UVES_BUNIT, CPL_TYPE_STRING, &returnvalue), 
02058        "Error reading keyword '%s'", UVES_BUNIT);
02059     
02060   cleanup:
02061     return returnvalue;
02062 }
02063 
02064 /*---------------------------------------------------------------------------*/
02070 /*---------------------------------------------------------------------------*/
02071 const char* 
02072 uves_pfits_get_ctype1(const uves_propertylist * plist)
02073 {
02074     const char* returnvalue="";
02075     
02076     check( uves_get_property_value(plist, UVES_CTYPE1, CPL_TYPE_STRING, &returnvalue), 
02077        "Error reading keyword '%s'", UVES_CTYPE1);
02078     
02079   cleanup:
02080     return returnvalue;
02081 }
02082 
02083 /*---------------------------------------------------------------------------*/
02089 /*---------------------------------------------------------------------------*/
02090 const 
02091 char* uves_pfits_get_ctype2(const uves_propertylist * plist)
02092 {
02093     const char* returnvalue="";
02094     
02095     check( uves_get_property_value(plist, UVES_CTYPE2, CPL_TYPE_STRING, &returnvalue), 
02096        "Error reading keyword '%s'", UVES_CTYPE2);
02097     
02098   cleanup:
02099     return returnvalue;
02100 }
02101 
02102 /*---------------------------------------------------------------------------*/
02108 /*---------------------------------------------------------------------------*/
02109 double 
02110 uves_pfits_get_uit(const uves_propertylist * plist)
02111 {
02112     double returnvalue = 0;
02113     bool new_format;
02114     
02115     check( new_format = uves_format_is_new(plist),
02116        "Error determining FITS header format");
02117     
02118     check( uves_get_property_value(plist, UVES_UIT(new_format), CPL_TYPE_DOUBLE, &returnvalue), 
02119        "Error reading keyword %s", UVES_UIT(new_format));
02120     
02121   cleanup:
02122     return returnvalue;
02123 
02124 }
02125 
02126 
02127 /*---------------------------------------------------------------------------*/
02134 /*---------------------------------------------------------------------------*/
02135 int 
02136 uves_pfits_get_nx(const uves_propertylist * plist,enum uves_chip chip)
02137 {
02138 
02139     int returnvalue = 0;
02140     bool new_format;
02141     
02142     check( new_format = uves_format_is_new(plist),
02143        "Error determining FITS header format");
02144     
02145     check( uves_get_property_value(plist, UVES_NX(new_format, chip), CPL_TYPE_INT, &returnvalue), 
02146        "Error reading keyword %s", UVES_NX(new_format, chip));
02147     
02148   cleanup:
02149     return returnvalue;
02150 
02151 }
02152 
02153 
02154 
02155 
02156 /*---------------------------------------------------------------------------*/
02163 /*---------------------------------------------------------------------------*/
02164 int 
02165 uves_pfits_get_ny(const uves_propertylist * plist,enum uves_chip chip)
02166 {
02167 
02168     int returnvalue = 0;
02169     bool new_format;
02170     
02171     check( new_format = uves_format_is_new(plist),
02172        "Error determining FITS header format");
02173     
02174     check( uves_get_property_value(plist, UVES_NY(new_format, chip), CPL_TYPE_INT, &returnvalue), 
02175        "Error reading keyword %s", UVES_NY(new_format, chip));
02176     
02177   cleanup:
02178     return returnvalue;
02179 
02180 }
02181 
02182 
02183 
02184 /*---------------------------------------------------------------------------*/
02190 /*---------------------------------------------------------------------------*/
02191 int 
02192 uves_pfits_get_out1nx(const uves_propertylist * plist)
02193 {
02194     int returnvalue = 0;
02195     
02196     check( uves_get_property_value(plist, UVES_OUT1NX, CPL_TYPE_INT, &returnvalue), 
02197        "Error reading keyword '%s'", UVES_OUT1NX);
02198     
02199   cleanup:
02200     return returnvalue;
02201 }
02202 
02203 /*---------------------------------------------------------------------------*/
02209 /*---------------------------------------------------------------------------*/
02210 int 
02211 uves_pfits_get_out1ny(const uves_propertylist * plist)
02212 {
02213     int returnvalue = 0;
02214     
02215     check( uves_get_property_value(plist, UVES_OUT1NY, CPL_TYPE_INT, &returnvalue), 
02216        "Error reading keyword '%s'", UVES_OUT1NY);
02217     
02218   cleanup:
02219     return returnvalue;
02220 }
02221 
02222 /*---------------------------------------------------------------------------*/
02228 /*---------------------------------------------------------------------------*/
02229 int 
02230 uves_pfits_get_out4nx(const uves_propertylist * plist)
02231 {
02232     int returnvalue = 0;
02233     
02234     check( uves_get_property_value(plist, UVES_OUT4NX, CPL_TYPE_INT, &returnvalue), 
02235        "Error reading keyword '%s'", UVES_OUT4NX);
02236     
02237   cleanup:
02238     return returnvalue;
02239 }
02240 
02241 /*---------------------------------------------------------------------------*/
02247 /*---------------------------------------------------------------------------*/
02248 int 
02249 uves_pfits_get_out4ny(const uves_propertylist * plist)
02250 {
02251     int returnvalue = 0;
02252     
02253     check( uves_get_property_value(plist, UVES_OUT4NY, CPL_TYPE_INT, &returnvalue), 
02254        "Error reading keyword '%s'", UVES_OUT4NY);
02255     
02256   cleanup:
02257     return returnvalue;
02258 }
02259 
02260 
02261 /*---------------------------------------------------------------------------*/
02267 /*---------------------------------------------------------------------------*/
02268 int 
02269 uves_pfits_get_naxis(const uves_propertylist * plist)
02270 {
02271     int returnvalue = 0;
02272     
02273     check( uves_get_property_value(plist, UVES_NAXIS, CPL_TYPE_INT, &returnvalue), 
02274        "Error reading keyword '%s'", UVES_NAXIS);
02275     
02276   cleanup:
02277     return returnvalue;
02278 }
02279 
02280 /*---------------------------------------------------------------------------*/
02286 /*---------------------------------------------------------------------------*/
02287 int 
02288 uves_flames_pfits_get_nflats(const uves_propertylist * plist)
02289 {
02290     int returnvalue = 0;
02291     
02292     check( uves_get_property_value(plist, FLAMES_NFLATS, CPL_TYPE_INT, &returnvalue), 
02293        "Error reading keyword '%s'", FLAMES_NFLATS);
02294     
02295   cleanup:
02296     return returnvalue;
02297 }
02298 
02299 
02300 /*---------------------------------------------------------------------------*/
02306 /*---------------------------------------------------------------------------*/
02307 int 
02308 uves_pfits_get_bitpix(const uves_propertylist * plist)
02309 {
02310     int returnvalue = 0;
02311     
02312     check( uves_get_property_value(plist, UVES_BITPIX, CPL_TYPE_INT, &returnvalue), 
02313        "Error reading keyword '%s'", UVES_BITPIX);
02314     
02315   cleanup:
02316     return returnvalue;
02317 }
02318 
02319 /*---------------------------------------------------------------------------*/
02325 /*---------------------------------------------------------------------------*/
02326 int uves_pfits_get_naxis1(const uves_propertylist * plist)
02327 {
02328     int returnvalue = 0;
02329     
02330     check( uves_get_property_value(plist, UVES_NAXIS1, CPL_TYPE_INT, &returnvalue), 
02331        "Error reading keyword '%s'", UVES_NAXIS1);
02332     
02333   cleanup:
02334     return returnvalue;
02335 }
02336 
02337 
02338 /*---------------------------------------------------------------------------*/
02344 /*---------------------------------------------------------------------------*/
02345 double 
02346 uves_pfits_get_startx(const uves_propertylist * plist)
02347 {
02348     double returnvalue = 0;
02349     
02350     check( uves_get_property_value(plist, UVES_STARTX, CPL_TYPE_DOUBLE, &returnvalue), 
02351        "Error reading keyword '%s'", UVES_STARTX);
02352     
02353   cleanup:
02354     return returnvalue;
02355 }
02356 
02357 
02358 /*---------------------------------------------------------------------------*/
02364 /*---------------------------------------------------------------------------*/
02365 double 
02366 uves_pfits_get_starty(const uves_propertylist * plist)
02367 {
02368     double returnvalue = 0;
02369     
02370     check( uves_get_property_value(plist, UVES_STARTY, CPL_TYPE_DOUBLE, &returnvalue), 
02371        "Error reading keyword '%s'", UVES_STARTY);
02372     
02373   cleanup:
02374     return returnvalue;
02375 }
02376 
02377 /*---------------------------------------------------------------------------*/
02383 /*---------------------------------------------------------------------------*/
02384 int 
02385 uves_pfits_get_naxis2(const uves_propertylist * plist)
02386 {
02387     int returnvalue = 0;
02388     
02389     check( uves_get_property_value(plist, UVES_NAXIS2, CPL_TYPE_INT, &returnvalue), 
02390        "Error reading keyword '%s'", UVES_NAXIS2);
02391     
02392   cleanup:
02393     return returnvalue;
02394 }
02395 /*---------------------------------------------------------------------------*/
02401 /*---------------------------------------------------------------------------*/
02402 double 
02403 uves_pfits_get_crval1(const uves_propertylist * plist)
02404 {
02405     double returnvalue = 0.0;
02406     
02407     check( uves_get_property_value(plist, UVES_CRVAL1, CPL_TYPE_DOUBLE, &returnvalue), 
02408        "Error reading keyword '%s'", UVES_CRVAL1);
02409     
02410   cleanup:
02411     return returnvalue;
02412 }
02413 /*---------------------------------------------------------------------------*/
02419 /*---------------------------------------------------------------------------*/
02420 double 
02421 uves_pfits_get_crval2(const uves_propertylist * plist)
02422 {
02423     double returnvalue = 0.0;
02424     
02425     check( uves_get_property_value(plist, UVES_CRVAL2, CPL_TYPE_DOUBLE, &returnvalue), 
02426        "Error reading keyword '%s'", UVES_CRVAL2);
02427     
02428   cleanup:
02429     return returnvalue;
02430 }
02431 /*---------------------------------------------------------------------------*/
02437 /*---------------------------------------------------------------------------*/
02438 double 
02439 uves_pfits_get_crpix1(const uves_propertylist * plist)
02440 {
02441     double returnvalue = 0.0;
02442     
02443     check( uves_get_property_value(plist, UVES_CRPIX1, CPL_TYPE_DOUBLE, &returnvalue), 
02444        "Error reading keyword '%s'", UVES_CRPIX1);
02445     
02446   cleanup:
02447     return returnvalue;
02448 }
02449 /*---------------------------------------------------------------------------*/
02455 /*---------------------------------------------------------------------------*/
02456 double 
02457 uves_pfits_get_crpix2(const uves_propertylist * plist)
02458 {
02459     double returnvalue = 0.0;
02460     
02461     check( uves_get_property_value(plist, UVES_CRPIX2, CPL_TYPE_DOUBLE, &returnvalue), 
02462        "Error reading keyword '%s'", UVES_CRPIX2);
02463     
02464   cleanup:
02465     return returnvalue;
02466 }
02467 /*---------------------------------------------------------------------------*/
02473 /*---------------------------------------------------------------------------*/
02474 double 
02475 uves_pfits_get_cdelt1(const uves_propertylist * plist)
02476 {
02477     double returnvalue = 0.0;
02478     
02479     check( uves_get_property_value(plist, UVES_CDELT1, CPL_TYPE_DOUBLE, &returnvalue), 
02480        "Error reading keyword '%s'", UVES_CDELT1);
02481     
02482   cleanup:
02483     return returnvalue;
02484 }
02485 /*---------------------------------------------------------------------------*/
02491 /*---------------------------------------------------------------------------*/
02492 double 
02493 uves_pfits_get_cdelt2(const uves_propertylist * plist)
02494 {
02495     double returnvalue = 0.0;
02496     
02497     check( uves_get_property_value(plist, UVES_CDELT2, CPL_TYPE_DOUBLE, &returnvalue), 
02498        "Error reading keyword '%s'", UVES_CDELT2);
02499     
02500   cleanup:
02501     return returnvalue;
02502 }
02503 
02504 
02505 /*---------------------------------------------------------------------------*/
02512 /*---------------------------------------------------------------------------*/
02513 void 
02514 uves_pfits_set_dpr_catg(uves_propertylist * plist, const char *catg)
02515 {
02516     check( uves_propertylist_update_string(plist, UVES_DPR_CATG, catg),
02517            "Error writing %s", UVES_DPR_CATG);
02518   cleanup:
02519     return;
02520 }
02521 
02522 /*---------------------------------------------------------------------------*/
02529 /*---------------------------------------------------------------------------*/
02530 void 
02531 uves_pfits_set_dpr_tech(uves_propertylist * plist, const char *tech)
02532 {
02533     check( uves_propertylist_update_string(plist, UVES_DPR_TECH, tech),
02534            "Error writing %s", UVES_DPR_TECH);
02535   cleanup:
02536     return;
02537 }
02538 /*---------------------------------------------------------------------------*/
02545 /*---------------------------------------------------------------------------*/
02546 void 
02547 uves_pfits_set_dpr_type(uves_propertylist * plist, const char *type)
02548 {
02549     check( uves_propertylist_update_string(plist, UVES_DPR_TYPE, type),
02550            "Error writing %s", UVES_DPR_TYPE);
02551   cleanup:
02552     return;
02553 }
02554 
02555 /*---------------------------------------------------------------------------*/
02562 /*---------------------------------------------------------------------------*/
02563 cpl_error_code 
02564 uves_pfits_set_object(uves_propertylist * plist, const char *object)
02565 {
02566     check( uves_propertylist_update_string(plist, UVES_OBJECT, object),
02567        "Error writing keyword '%s'", UVES_OBJECT);
02568     
02569   cleanup:
02570     return cpl_error_get_code();
02571 }
02572 /*---------------------------------------------------------------------------*/
02579 /*---------------------------------------------------------------------------*/
02580 cpl_error_code 
02581 uves_pfits_set_badpixcorr(uves_propertylist * plist, const char *corr)
02582 {
02583     check( uves_propertylist_update_string(plist, UVES_QC_BADPIXCORR, corr),
02584        "Error writing keyword '%s'", UVES_QC_BADPIXCORR);
02585     
02586   cleanup:
02587     return cpl_error_get_code();
02588 }
02589 
02590 /*---------------------------------------------------------------------------*/
02597 /*---------------------------------------------------------------------------*/
02598 cpl_error_code 
02599 uves_pfits_set_redlevel(uves_propertylist * plist, const char *redlevel)
02600 {
02601     check( uves_propertylist_update_string(plist, UVES_REDLEVEL, redlevel),
02602        "Error writing keyword '%s'", UVES_REDLEVEL);
02603     
02604   cleanup:
02605     return cpl_error_get_code();
02606 }
02607 
02608 /*---------------------------------------------------------------------------*/
02615 /*---------------------------------------------------------------------------*/
02616 cpl_error_code 
02617 uves_pfits_set_status(uves_propertylist * plist, const char *status)
02618 {
02619     check( uves_propertylist_update_string(plist, UVES_STATUS, status),
02620        "Error writing keyword '%s'", UVES_STATUS);
02621     
02622   cleanup:
02623     return cpl_error_get_code();
02624 }
02625 
02626 /*---------------------------------------------------------------------------*/
02633 /*---------------------------------------------------------------------------*/
02634 cpl_error_code 
02635 uves_pfits_set_starttime(uves_propertylist * plist, const char *start_time)
02636 {
02637     check( uves_propertylist_update_string(plist, UVES_START, start_time),
02638        "Error writing keyword '%s'", UVES_START);
02639     
02640   cleanup:
02641     return cpl_error_get_code();
02642 }
02643 /*---------------------------------------------------------------------------*/
02650 /*---------------------------------------------------------------------------*/
02651 cpl_error_code 
02652 uves_pfits_set_stoptime(uves_propertylist * plist, const char *stop_time)
02653 {
02654     check( uves_propertylist_update_string(plist, UVES_STOP, stop_time),
02655        "Error writing keyword '%s'", UVES_STOP);
02656     
02657   cleanup:
02658     return cpl_error_get_code();
02659 }
02660 
02661 /*---------------------------------------------------------------------------*/
02668 /*---------------------------------------------------------------------------*/
02669 cpl_error_code 
02670 uves_pfits_set_bunit(uves_propertylist * plist, const char *bunit)
02671 {
02672     check( uves_propertylist_update_string(plist, UVES_BUNIT, bunit),
02673        "Error writing keyword '%s'", UVES_BUNIT);
02674     
02675   cleanup:
02676     return cpl_error_get_code();
02677 }
02678 
02679 
02680 /*---------------------------------------------------------------------------*/
02687 /*---------------------------------------------------------------------------*/
02688 cpl_error_code 
02689 uves_pfits_set_tunit_no(uves_propertylist * plist, const int col_no, const char *tunit)
02690 {
02691    char key_name[20];
02692    sprintf(key_name,"%s%d",UVES_TUNIT,col_no);
02693    uves_msg("Filling key %s with value %s",key_name,tunit);
02694     check( uves_propertylist_update_string(plist, key_name, tunit),
02695        "Error writing keyword '%s'", key_name);
02696     
02697   cleanup:
02698     return cpl_error_get_code();
02699 }
02700 
02701 /*---------------------------------------------------------------------------*/
02708 /*---------------------------------------------------------------------------*/
02709 cpl_error_code 
02710 uves_pfits_set_bunit_no(uves_propertylist * plist, const int axis_no, const char *bunit)
02711 {
02712     check( uves_propertylist_update_string(plist, UVES_BUNIT, bunit),
02713        "Error writing keyword '%s'", UVES_BUNIT);
02714     
02715   cleanup:
02716     return cpl_error_get_code();
02717 }
02718 
02719 /*---------------------------------------------------------------------------*/
02726 /*---------------------------------------------------------------------------*/
02727 cpl_error_code 
02728 uves_pfits_set_ctype1(uves_propertylist * plist, const char *ctype1)
02729 {
02730     check( uves_propertylist_update_string(plist, UVES_CTYPE1, ctype1),
02731        "Error writing keyword '%s'", UVES_CTYPE1);
02732     
02733   cleanup:
02734     return cpl_error_get_code();
02735 }
02736 /*---------------------------------------------------------------------------*/
02743 /*---------------------------------------------------------------------------*/
02744 cpl_error_code 
02745 uves_pfits_set_ctype2(uves_propertylist * plist, const char *ctype2)
02746 {
02747     check( uves_propertylist_update_string(plist, UVES_CTYPE2, ctype2),
02748        "Error writing keyword '%s'", UVES_CTYPE2);
02749     
02750   cleanup:
02751     return cpl_error_get_code();
02752 }
02753 
02754 /*---------------------------------------------------------------------------*/
02761 /*---------------------------------------------------------------------------*/
02762 cpl_error_code 
02763 uves_pfits_set_crval1(uves_propertylist * plist, double crval1)
02764 {
02765     check( uves_propertylist_update_double(plist, UVES_CRVAL1, crval1),
02766        "Error writing keyword '%s'", UVES_CRVAL1);
02767     
02768   cleanup:
02769     return cpl_error_get_code();
02770 }
02771 
02772 /*---------------------------------------------------------------------------*/
02779 /*---------------------------------------------------------------------------*/
02780 cpl_error_code 
02781 uves_pfits_set_crval2(uves_propertylist * plist, double crval2)
02782 {
02783     check( uves_propertylist_update_double(plist, UVES_CRVAL2, crval2),
02784        "Error writing keyword '%s'", UVES_CRVAL2);
02785     
02786   cleanup:
02787     return cpl_error_get_code();
02788 }
02789 /*---------------------------------------------------------------------------*/
02796 /*---------------------------------------------------------------------------*/
02797 cpl_error_code 
02798 uves_pfits_set_crpix1(uves_propertylist * plist, double crpix1)
02799 {
02800     check( uves_propertylist_update_double(plist, UVES_CRPIX1, crpix1),
02801        "Error writing keyword '%s'", UVES_CRPIX1);
02802     
02803   cleanup:
02804     return cpl_error_get_code();
02805 }
02806 
02807 /*---------------------------------------------------------------------------*/
02814 /*---------------------------------------------------------------------------*/
02815 cpl_error_code 
02816 uves_pfits_set_crpix2(uves_propertylist * plist, double crpix2)
02817 {
02818     check( uves_propertylist_update_double(plist, UVES_CRPIX2, crpix2),
02819        "Error writing keyword '%s'", UVES_CRPIX2);
02820     
02821   cleanup:
02822     return cpl_error_get_code();
02823 }
02824 /*---------------------------------------------------------------------------*/
02831 /*---------------------------------------------------------------------------*/
02832 cpl_error_code 
02833 uves_pfits_set_cdelt1(uves_propertylist * plist, double cdelt1)
02834 {
02835     check( uves_propertylist_update_double(plist, UVES_CDELT1, cdelt1),
02836        "Error writing keyword '%s'", UVES_CDELT1);
02837     
02838   cleanup:
02839     return cpl_error_get_code();
02840 }
02841 
02842 /*---------------------------------------------------------------------------*/
02849 /*---------------------------------------------------------------------------*/
02850 void 
02851 uves_flames_pfits_set_ccfposmax(uves_propertylist *plist, double ccfposmax)
02852 {
02853     check( uves_propertylist_update_double(plist, FLAMES_CCFPOSMAX, ccfposmax),
02854        "Error writing keyword '%s'", FLAMES_CCFPOSMAX);
02855 
02856   cleanup:
02857     return;
02858 }
02859 
02860 /*---------------------------------------------------------------------------*/
02867 /*---------------------------------------------------------------------------*/
02868 cpl_error_code 
02869 uves_pfits_set_cdelt2(uves_propertylist * plist, double cdelt2)
02870 {
02871     check( uves_propertylist_update_double(plist, UVES_CDELT2, cdelt2),
02872        "Error writing keyword '%s'", UVES_CDELT2);
02873     
02874   cleanup:
02875     return cpl_error_get_code();
02876 }
02877 
02878 /*---------------------------------------------------------------------------*/
02884 /*---------------------------------------------------------------------------*/
02885 void 
02886 uves_pfits_set_hs(uves_propertylist * plist, int hs)
02887 {
02888     check( uves_propertylist_update_int(plist, UVES_HS, hs),
02889        "Error writing keyword '%s'", UVES_HS);
02890     
02891   cleanup:
02892     return;
02893 }
02894 
02895 
02896 /*---------------------------------------------------------------------------*/
02904 /*---------------------------------------------------------------------------*/
02905 cpl_error_code 
02906 uves_pfits_set_wstart(uves_propertylist * plist, int order, double wstart)
02907 {
02908     char *wstart_string = NULL;
02909 
02910     assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT, 
02911         "Illegal order number: %d. Allowed range is 1 to 99", order);
02912     
02913     /* allocate room for two digits and '\0' */
02914     wstart_string = cpl_malloc( strlen(UVES_WSTART) + 2 + 1);  
02915     assure_mem( wstart_string );
02916 
02917     snprintf(wstart_string, strlen(UVES_WSTART)+2+1, UVES_WSTART "%d", order);
02918     
02919     check( uves_propertylist_update_double(plist, wstart_string, wstart ),
02920        "Error updating product header");
02921         
02922   cleanup:
02923     cpl_free(wstart_string);
02924     return cpl_error_get_code();
02925 }
02926 
02927 
02928 /*---------------------------------------------------------------------------*/
02935 /*---------------------------------------------------------------------------*/
02936 
02937 double 
02938 uves_pfits_get_wstart(const uves_propertylist * plist, int order)
02939 {
02940     double returnvalue;
02941     char *wstart = NULL;
02942 
02943     assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT, 
02944         "Illegal order number: %d. Allowed range is 1 to 99", order);
02945     
02946     /* allocate room for two digits and '\0' */
02947     wstart = cpl_malloc( strlen(UVES_WSTART) + 2 + 1);  
02948     assure_mem( wstart );
02949     
02950     snprintf(wstart, strlen(UVES_WSTART)+2+1, UVES_WSTART "%d", order);
02951     
02952     check( uves_get_property_value(plist, wstart, CPL_TYPE_DOUBLE, &returnvalue), 
02953        "Error reading keyword '%s'", wstart);
02954     
02955   cleanup:
02956     cpl_free(wstart);
02957     return returnvalue;
02958 }
02959 /*---------------------------------------------------------------------------*/
02967 /*---------------------------------------------------------------------------*/
02968 cpl_error_code 
02969 uves_pfits_set_wend(uves_propertylist * plist, int order, double wend)
02970 {
02971     char *wend_string = NULL;
02972 
02973     assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT, 
02974         "Illegal order number: %d. Allowed range is 1 to 99", order);
02975     
02976     /* allocate room for two digits and '\0' */
02977     wend_string = cpl_malloc( strlen(UVES_WEND) + 2 + 1);  
02978     assure_mem( wend_string );
02979 
02980     snprintf(wend_string, strlen(UVES_WEND)+2+1, UVES_WEND "%d", order);
02981     
02982     check( uves_propertylist_update_double(plist, wend_string, wend ),
02983        "Error updating product header");
02984         
02985   cleanup:
02986     cpl_free(wend_string);
02987     return cpl_error_get_code();
02988 }
02989 
02990 
02991 /*---------------------------------------------------------------------------*/
02998 /*---------------------------------------------------------------------------*/
02999 
03000 double 
03001 uves_pfits_get_wend(const uves_propertylist * plist, int order)
03002 {
03003     double returnvalue;
03004     char *wend = NULL;
03005 
03006     assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT, 
03007         "Illegal order number: %d. Allowed range is 1 to 99", order);
03008     
03009     /* allocate room for two digits and '\0' */
03010     wend = cpl_malloc( strlen(UVES_WEND) + 2 + 1);  
03011     assure_mem( wend );
03012     
03013     snprintf(wend, strlen(UVES_WEND)+2+1, UVES_WEND "%d", order);
03014     
03015     check( uves_get_property_value(plist, wend, CPL_TYPE_DOUBLE, &returnvalue), 
03016        "Error reading keyword '%s'", wend);
03017     
03018   cleanup:
03019     cpl_free(wend);
03020     return returnvalue;
03021 }
03022 
03023 /*---------------------------------------------------------------------------*/
03029 /*---------------------------------------------------------------------------*/
03030 double 
03031 uves_pfits_get_pixelscale(const uves_propertylist *plist)
03032 {
03033     double pixelscale = 0;
03034     
03035     check( uves_get_property_value(plist, UVES_PIXELSCALE, CPL_TYPE_DOUBLE, &pixelscale),
03036            "Error reading keyword '%s'", UVES_PIXELSCALE);
03037     
03038   cleanup:
03039     return pixelscale;
03040 }
03041 
03042 /*---------------------------------------------------------------------------*/
03048 /*---------------------------------------------------------------------------*/
03049 const char* 
03050 uves_pfits_get_slit1_name(const uves_propertylist * plist)
03051 {
03052     const char* returnvalue = "";
03053     
03054     check( uves_get_property_value(plist, UVES_SLIT1NAME, CPL_TYPE_STRING, &returnvalue), 
03055        "Error reading keyword '%s'", UVES_SLIT1NAME);
03056     
03057   cleanup:
03058     return returnvalue;
03059 }
03060 
03061 
03062 /*---------------------------------------------------------------------------*/
03072 /*---------------------------------------------------------------------------*/
03073 
03074 double 
03075 uves_pfits_get_slitlength_pixels(const uves_propertylist * plist, 
03076                                  enum uves_chip chip)
03077 {
03078     double slitlength_pixels = 0;         /* Result */
03079     
03080     const char *slicer_name = "";
03081     double slitlength_arcsecs = 0;        /* Slit length in arc-seconds */
03082 
03083     check( slicer_name = uves_pfits_get_slit1_name(plist),
03084        "Could not read slicer id");
03085 
03086     if ( strncmp(slicer_name, "FREE", 4) != 0)
03087     {
03088         /* Slicer inserted */
03089         if      (strncmp(slicer_name, "SLIC#1", 6) == 0) slitlength_arcsecs = 8.0;
03090         else if (strncmp(slicer_name, "SLIC#2", 6) == 0) slitlength_arcsecs = 8.0;
03091         else if (strncmp(slicer_name, "SLIC#3", 6) == 0) slitlength_arcsecs = 10.0;
03092         else
03093         {
03094             assure( false, CPL_ERROR_ILLEGAL_INPUT, "Unrecognized slicer name: '%s'. "
03095                 "Recognized names are 'FREE', 'SLIC#1', 'SLIC#2', 'SLIC#3'.", 
03096                 slicer_name);
03097         }
03098     }
03099     else
03100     {
03101         /*  slicer_name = 'FREE', no slicer */
03102 
03103         check( uves_get_property_value(
03104                plist, UVES_SLITLENGTH(chip), CPL_TYPE_DOUBLE, &slitlength_arcsecs),
03105            "Error reading keyword '%s'", UVES_SLITLENGTH(chip));
03106     }
03107 
03108     /* Convert from arcseconds to pixels */
03109     {
03110     double pixelscale;         /* Arcseconds per pixel */
03111     int binx;                  /* The x-binning of the raw image 
03112                       is the y-binning of the extracted/rotated image */
03113     
03114     check_nomsg( pixelscale = uves_pfits_get_pixelscale(plist) );
03115 
03116     check( binx = uves_pfits_get_binx(plist),
03117            "Could not get x-binning");
03118 
03119     slitlength_pixels = slitlength_arcsecs / (pixelscale * binx);
03120     }
03121     
03122   cleanup:
03123     return slitlength_pixels;
03124 }
03125 
03126 
03127 /*---------------------------------------------------------------------------*/
03133 /*---------------------------------------------------------------------------*/
03134 int
03135 uves_flames_pfits_get_plateid(const uves_propertylist *raw_header)
03136 {
03137     int plate_no;
03138     
03139     if (uves_propertylist_contains(raw_header,
03140                   FLAMES_NEWPLATEID))
03141     {
03142         check( uves_get_property_value(raw_header, FLAMES_NEWPLATEID, 
03143                        CPL_TYPE_INT, &plate_no), 
03144            "Error reading keyword '%s'", FLAMES_NEWPLATEID);
03145     }
03146     else if(uves_propertylist_contains(raw_header, 
03147                       FLAMES_OBS_PLATE_ID))
03148     {
03149         check( uves_get_property_value(raw_header, FLAMES_OBS_PLATE_ID, 
03150                        CPL_TYPE_INT, &plate_no),
03151            "Error reading keyword '%s'", FLAMES_NEWPLATEID);
03152     }
03153     else if (uves_propertylist_contains(raw_header,
03154                        FLAMES_INS_SHUT09))
03155     {
03156         plate_no = 1;
03157     }
03158     else if (uves_propertylist_contains(raw_header,
03159                        FLAMES_INS_SHUT10))
03160     {
03161         plate_no = 2;
03162     }
03163     else
03164     {
03165         plate_no = 0;
03166         uves_msg_warning("Missing raw header keywords %s, %s, %s and %s, "
03167                  "setting plate number = %d",
03168                  FLAMES_NEWPLATEID, 
03169                  FLAMES_OBS_PLATE_ID,
03170                  FLAMES_INS_SHUT09,
03171                  FLAMES_INS_SHUT10,
03172                  plate_no);
03173     }
03174     
03175   cleanup:
03176     return plate_no;
03177 }
03178 
03179 
03180 /*---------------------------------------------------------------------------*/
03186 /*---------------------------------------------------------------------------*/
03187 double 
03188 uves_flames_pfits_get_dit(const uves_propertylist * plist)
03189 {
03190     double returnvalue = 0;
03191     
03192     check( uves_get_property_value(plist, FLAMES_DIT, CPL_TYPE_DOUBLE, &returnvalue), 
03193        "Error reading keyword '%s'", FLAMES_DIT);
03194     
03195   cleanup:
03196     return returnvalue;
03197 }
03198 
03199 /*---------------------------------------------------------------------------*/
03205 /*---------------------------------------------------------------------------*/
03206 void
03207 uves_flames_pfits_set_newplateid(uves_propertylist * plist, int plate_no)
03208 {
03209     check( uves_propertylist_update_int(plist, FLAMES_NEWPLATEID, plate_no),
03210        "Error writing keyword '%s'", FLAMES_NEWPLATEID);
03211   cleanup:
03212     return;
03213 }
03214 

Generated on 8 Mar 2011 for UVES Pipeline Reference Manual by  doxygen 1.6.1