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: 2007/06/06 08:17:33 $
00023  * $Revision: 1.99 $
00024  * $Name: uves-3_3_1 $
00025  * $Log: uves_pfits.c,v $
00026  * Revision 1.99  2007/06/06 08:17:33  amodigli
00027  * replace tab with 4 spaces
00028  *
00029  * Revision 1.98  2007/06/01 14:09:57  jmlarsen
00030  * Exported uves_pfits_get_pixelscale
00031  *
00032  * Revision 1.97  2007/05/23 13:03:19  jmlarsen
00033  * Added missing include directive
00034  *
00035  * Revision 1.96  2007/05/16 14:38:03  amodigli
00036  * added uves_flames_pfits_get_ident & uves_flames_pfits_get_object
00037  *
00038  * Revision 1.95  2007/05/14 09:36:50  amodigli
00039  * added checks on return types
00040  *
00041  * Revision 1.94  2007/05/04 08:53:49  amodigli
00042  * added uves_flames_pfits_get_nflats
00043  *
00044  * Revision 1.93  2007/05/03 15:21:33  jmlarsen
00045  * Added function to read wavecal offset
00046  *
00047  * Revision 1.92  2007/04/26 13:19:40  jmlarsen
00048  * Added uves_pfits_set_ocs_simcal()
00049  *
00050  * Revision 1.91  2007/04/25 08:37:19  amodigli
00051  * added uves_pfits_get_origfile
00052  *
00053  * Revision 1.90  2007/04/24 12:50:29  jmlarsen
00054  * Replaced cpl_propertylist -> uves_propertylist which is much faster
00055  *
00056  * Revision 1.89  2007/04/24 09:41:09  jmlarsen
00057  * Renamed irplib_vsnprintf_create -> irplib_vsprintf
00058  *
00059  * Revision 1.88  2007/03/05 10:18:16  jmlarsen
00060  * Write 2d extraion slit length
00061  *
00062  * Revision 1.87  2007/01/31 13:11:27  jmlarsen
00063  * Added SIMCAL accessor functions
00064  *
00065  * Revision 1.86  2007/01/29 12:10:19  jmlarsen
00066  * Exported set_history_val() for usage by FLAMES
00067  *
00068  * Revision 1.85  2007/01/26 12:33:57  amodigli
00069  * added function for common QC
00070  *
00071  * Revision 1.84  2007/01/17 13:27:10  jmlarsen
00072  * Added BITPIX accessor function
00073  *
00074  * Revision 1.83  2007/01/10 14:16:15  jmlarsen
00075  * Fixed wrong format string
00076  *
00077  * Revision 1.82  2007/01/10 12:39:09  jmlarsen
00078  * Unified two get_plate_id functions
00079  *
00080  * Revision 1.81  2006/12/27 13:55:29  amodigli
00081  * added flames_pfits_get_plate_id and some FLAMES_ defines for FIBER mode
00082  *
00083  * Revision 1.80  2006/12/07 08:25:07  jmlarsen
00084  * Added uves_pfits_get_readspeed
00085  *
00086  * Revision 1.79  2006/12/01 12:27:25  jmlarsen
00087  * Factored out FLAMES plate-id code
00088  *
00089  * Revision 1.78  2006/11/24 09:36:25  jmlarsen
00090  * Workaround for slow uves_propertylist_get_size
00091  *
00092  * Revision 1.77  2006/11/15 15:02:14  jmlarsen
00093  * Implemented const safe workarounds for CPL functions
00094  *
00095  * Revision 1.75  2006/11/15 14:04:08  jmlarsen
00096  * Removed non-const version of parameterlist_get_first/last/next which is
00097  * already in CPL, added const-safe wrapper, unwrapper and deallocator functions
00098  *
00099  * Revision 1.74  2006/11/13 14:23:55  jmlarsen
00100  * Removed workarounds for CPL const bugs
00101  *
00102  * Revision 1.73  2006/11/06 15:19:41  jmlarsen
00103  * Removed unused include directives
00104  *
00105  * Revision 1.72  2006/10/25 07:21:35  jmlarsen
00106  * Documentation bug fix
00107  *
00108  * Revision 1.71  2006/10/24 14:05:47  jmlarsen
00109  * Added OBSPLATE
00110  *
00111  * Revision 1.70  2006/10/05 06:50:23  jmlarsen
00112  * Renamed function format_is_new -> uves_format_is_new
00113  *
00114  * Revision 1.69  2006/10/04 10:55:33  jmlarsen
00115  * Added telescope lat-/longitude accessor functions
00116  *
00117  * Revision 1.68  2006/09/27 13:14:15  jmlarsen
00118  * Added accessor functions for RA/DEC
00119  *
00120  * Revision 1.67  2006/09/20 10:57:36  jmlarsen
00121  * Propagate DATAMEAN/DATAMED/DATARMS if present
00122  *
00123  * Revision 1.66  2006/09/19 07:19:30  jmlarsen
00124  * Changed function set_history_int -> set_history_val to support writing values of any type
00125  *
00126  * Revision 1.65  2006/08/24 11:37:12  jmlarsen
00127  * Write recipe start/stop time to header
00128  *
00129  * Revision 1.64  2006/08/21 12:51:02  jmlarsen
00130  * Renamed shadowing variable
00131  *
00132  * Revision 1.63  2006/08/21 07:45:51  jmlarsen
00133  * Update HISTORY FABSORD keyword if it already exists, rather than adding a new keyword
00134  *
00135  * Revision 1.62  2006/08/21 07:06:16  jmlarsen
00136  * Fixed documantation bug
00137  *
00138  * Revision 1.61  2006/08/18 13:32:37  jmlarsen
00139  * Fixed memory leak
00140  *
00141  * Revision 1.60  2006/08/18 10:14:04  jmlarsen
00142  * Use legal FITS keywords for TRACEID/WINDOW/FABSORD/LABSORD
00143  *
00144  * Revision 1.59  2006/08/17 14:40:06  jmlarsen
00145  * Added missing documentation
00146  *
00147  * Revision 1.58  2006/08/17 14:11:25  jmlarsen
00148  * Use assure_mem macro to check for memory allocation failure
00149  *
00150  * Revision 1.57  2006/08/17 13:56:53  jmlarsen
00151  * Reduced max line length
00152  *
00153  * Revision 1.56  2006/08/09 14:23:19  jmlarsen
00154  * Removed unused function argument
00155  *
00156  * Revision 1.55  2006/07/31 06:29:26  amodigli
00157  * added QC on stability test
00158  *
00159  * Revision 1.54  2006/07/14 12:24:49  jmlarsen
00160  * Added conad, target name
00161  *
00162  * Revision 1.53  2006/06/13 11:58:55  jmlarsen
00163  * Bugfix: Use proper chipname keyword for REDL chip
00164  *
00165  * Revision 1.52  2006/06/02 06:42:12  jmlarsen
00166  * Added missing cleanup label
00167  *
00168  * Revision 1.51  2006/06/01 14:43:17  jmlarsen
00169  * Added missing documentation
00170  *
00171  * Revision 1.50  2006/06/01 14:22:48  amodigli
00172  * moved format_is_new to c module and made it static
00173  *
00174  * Revision 1.49  2006/05/31 09:26:40  amodigli
00175  * fixed some problem dumping QC log
00176  *
00177  * Revision 1.48  2006/05/19 13:07:20  amodigli
00178  * added uves_pfits_get_slit3_x1encoder
00179  *
00180  * Revision 1.47  2006/05/09 15:43:13  amodigli
00181  * added useful key/functions
00182  *
00183  * Revision 1.46  2006/04/26 12:25:20  amodigli
00184  * fixed a problem with ARCFILE keyword
00185  *
00186  * Revision 1.45  2006/04/25 14:58:48  amodigli
00187  * added paf creation functionalities
00188  *
00189  * Revision 1.44  2006/04/20 10:48:58  amodigli
00190  * added uves_pfits_get_tpl_start
00191  *
00192  * Revision 1.43  2006/03/24 13:59:41  jmlarsen
00193  * Added check that central wavelength is always positive
00194  *
00195  * Revision 1.42  2006/03/03 13:54:11  jmlarsen
00196  * Changed syntax of check macro
00197  *
00198  * Revision 1.41  2005/12/20 16:10:32  jmlarsen
00199  * Added some documentation
00200  *
00201  * Revision 1.40  2005/12/19 16:17:56  jmlarsen
00202  * Replaced bool -> int
00203  *
00204  */
00205 
00206 #ifdef HAVE_CONFIG_H
00207 #include <config.h>
00208 #endif
00209 
00210 /*----------------------------------------------------------------------------*/
00216 /*----------------------------------------------------------------------------*/
00219 /*-----------------------------------------------------------------------------
00220                 Defines
00221  -----------------------------------------------------------------------------*/
00222 
00223 /*-----------------------------------------------------------------------------
00224                 Includes
00225  -----------------------------------------------------------------------------*/
00226 #include <stdio.h>
00227 #include <uves_pfits.h>
00228 
00229 #include <uves_utils.h>
00230 #include <uves_utils_wrappers.h>
00231 #include <uves_dump.h>
00232 #include <uves_error.h>
00233 
00234 #include <irplib_utils.h>
00235 #include <irplib_access.h>
00236 
00237 #include <cpl.h>
00238 
00239 #include <stdio.h>
00240 #include <stdbool.h>
00241 #include <errno.h>
00242 
00243 /*-----------------------------------------------------------------------------
00244                 Forward declarations
00245  -----------------------------------------------------------------------------*/
00246 
00247 /*-----------------------------------------------------------------------------
00248                 Function codes
00249  -----------------------------------------------------------------------------*/
00250 
00251 /*----------------------------------------------------------------------------*/
00257 /*----------------------------------------------------------------------------*/
00258 int uves_pfits_get_slit3_x1encoder(const uves_propertylist * plist)
00259 {
00260   int result=0;
00261   check(result=uves_propertylist_get_int(plist,UVES_ENCODER_REF1),
00262         "Error getting %s", UVES_ENCODER_REF1);
00263 
00264  cleanup:
00265     return result; 
00266 
00267 }
00268 
00269 /*----------------------------------------------------------------------------*/
00275 /*----------------------------------------------------------------------------*/
00276 int uves_pfits_get_slit3_x2encoder(const uves_propertylist * plist)
00277 {
00278   int result=0;
00279   check(result=uves_propertylist_get_int(plist,UVES_ENCODER_REF2),
00280         "Error getting %s",UVES_ENCODER_REF2);
00281 
00282 
00283  cleanup:
00284     return result; 
00285 
00286 }
00287 
00288 /*----------------------------------------------------------------------------*/
00294 /*----------------------------------------------------------------------------*/
00295 int  uves_pfits_get_maxfibres(const uves_propertylist * plist)
00296 {
00297   int result=0;
00298    check(uves_get_property_value(plist, "MAXFIBRES", 
00299                  CPL_TYPE_INT, &result),
00300     "Error reading MAXFIBRES");
00301 
00302  cleanup:
00303     return result; 
00304 
00305 }
00306 
00307 /*----------------------------------------------------------------------------*/
00313 /*----------------------------------------------------------------------------*/
00314 char  uves_pfits_get_chipchoice(const uves_propertylist * plist)
00315 {
00316   char result=0;
00317   check(result=uves_propertylist_get_char(plist,"CHIPCHOICE"),
00318     "Error getting CHIPCHOICE");
00319 
00320  cleanup:
00321     return result; 
00322 
00323 }
00324 /*----------------------------------------------------------------------------*/
00330 /*----------------------------------------------------------------------------*/
00331 const char * uves_pfits_get_badpxframe(const uves_propertylist * plist)
00332 {
00333 
00334   const char* result=NULL;
00335 
00336   check(uves_get_property_value(plist, "BADPXFRAME", 
00337                  CPL_TYPE_STRING, &result),
00338     "Error reading BADPXFRAME");
00339 
00340  cleanup:
00341     return result; 
00342 
00343 }
00344 
00345 
00346 /*----------------------------------------------------------------------------*/
00352 /*----------------------------------------------------------------------------*/
00353 double uves_pfits_get_ambipress(const uves_propertylist * plist)
00354 {
00355   double result=0;
00356 
00357   check(uves_get_property_value(plist, "ESO INS SENS26 MEAN", 
00358                  CPL_TYPE_DOUBLE, &result),
00359     "Error reading ESO INS SENS26 MEAN");
00360 
00361  cleanup:
00362     return result; 
00363 
00364 }
00365 
00366 
00367 /*---------------------------------------------------------------------------*/
00373 /*---------------------------------------------------------------------------*/
00374 const char * uves_pfits_get_arcfile(const uves_propertylist * plist)
00375 {
00376 
00377   const char* result=NULL;
00378 
00379 
00380   check(uves_get_property_value(plist, "ARCFILE", 
00381                  CPL_TYPE_STRING, &result),
00382     "Error reading ARCFILE");
00383 
00384  cleanup:
00385     return result; 
00386 
00387 }
00388 
00389 /*---------------------------------------------------------------------------*/
00395 /*---------------------------------------------------------------------------*/
00396 const char * uves_flames_pfits_get_ident(const uves_propertylist * plist)
00397 {
00398 
00399   const char* result=NULL;
00400 
00401   check(result=uves_propertylist_get_string(plist,"IDENT"),
00402     "Error getting IDENT");
00403 
00404  cleanup:
00405     return result; 
00406 
00407 }
00408 
00409 /*---------------------------------------------------------------------------*/
00415 /*---------------------------------------------------------------------------*/
00416 const char * uves_flames_pfits_get_object(const uves_propertylist * plist)
00417 {
00418 
00419   const char* result=NULL;
00420 
00421   check(result=uves_propertylist_get_string(plist,UVES_OBJECT),
00422     "Error getting OBJECT");
00423 
00424  cleanup:
00425     return result; 
00426 
00427 }
00428 
00429 /*---------------------------------------------------------------------------*/
00435 /*---------------------------------------------------------------------------*/
00436 const char * uves_pfits_get_origfile(const uves_propertylist * plist)
00437 {
00438 
00439   const char* result=NULL;
00440 
00441   check(uves_get_property_value(plist, "ORIGFILE", 
00442                  CPL_TYPE_STRING, &result),
00443     "Error reading ORIGFILE");
00444 
00445  cleanup:
00446     return result; 
00447 
00448 }
00449 
00450 /*----------------------------------------------------------------------------*/
00456 /*----------------------------------------------------------------------------*/
00457 const char * uves_pfits_get_pipefile(const uves_propertylist * plist)
00458 {
00459 
00460   const char* result=NULL;
00461 
00462 
00463   check(uves_get_property_value(plist, "PIPEFILE", 
00464                  CPL_TYPE_STRING, &result),
00465     "Error reading PIPEFILE");
00466 
00467  cleanup:
00468     return result; 
00469 
00470 }
00471 
00472 
00473 
00474 
00475 /*----------------------------------------------------------------------------*/
00481 /*----------------------------------------------------------------------------*/
00482 const char * uves_pfits_get_rec1raw1name(const uves_propertylist * plist)
00483 {
00484   const char* result=NULL;
00485 
00486   check(uves_get_property_value(plist, "ESO PRO REC1 RAW1 NAME", 
00487                  CPL_TYPE_STRING, &result),
00488     "Error reading ESO PRO REC1 RAW1 NAME");
00489 
00490 
00491  cleanup:
00492     return result;
00493 }
00494 /*----------------------------------------------------------------------------*/
00500 /*----------------------------------------------------------------------------*/
00501 const char * uves_pfits_get_templateid(const uves_propertylist * plist)
00502 {
00503   const char* result=NULL;
00504 
00505   check(uves_get_property_value(plist, "ESO TPL ID", 
00506                  CPL_TYPE_STRING, &result),
00507     "Error reading ESO TPL ID");
00508 
00509 
00510  cleanup:
00511 
00512     return result; 
00513 }
00514 
00515 
00516 /*----------------------------------------------------------------------------*/
00522 /*----------------------------------------------------------------------------*/
00523 const char * uves_pfits_get_date_obs(const uves_propertylist * plist)
00524 {
00525 
00526   const char* result=NULL;
00527   check(uves_get_property_value(plist, "DATE-OBS", 
00528                  CPL_TYPE_STRING, &result),
00529     "Error reading DATE-OBS");
00530 
00531  cleanup:
00532     return result;
00533 
00534 }
00535 /*----------------------------------------------------------------------------*/
00541 /*----------------------------------------------------------------------------*/
00542 const char * uves_pfits_get_dpr_catg(const uves_propertylist * plist)
00543 {
00544   const char* result=NULL;
00545 
00546   check(uves_get_property_value(plist, "ESO DPR CATG", 
00547                  CPL_TYPE_STRING, &result),
00548     "Error reading ESO DPR CATG");
00549 
00550  cleanup:
00551     return result;
00552 }
00553 
00554 /*----------------------------------------------------------------------------*/
00560 /*----------------------------------------------------------------------------*/
00561 int uves_pfits_get_ocs_simcal(const uves_propertylist * plist)
00562 {
00563     int returnvalue = 0;
00564     
00565     check( uves_get_property_value(plist, UVES_OCS_SIMCAL, CPL_TYPE_INT, &returnvalue), 
00566        "Error reading keyword '%s'", UVES_OCS_SIMCAL);
00567     
00568   cleanup:
00569     return returnvalue;
00570 }
00571 
00572 /*----------------------------------------------------------------------------*/
00578 /*----------------------------------------------------------------------------*/
00579 void uves_pfits_set_ocs_simcal(uves_propertylist * plist, int simcal)
00580 {
00581     check( uves_propertylist_update_int(plist, UVES_OCS_SIMCAL, simcal),
00582            "Error writing keyword '%s'", UVES_OCS_SIMCAL);
00583 
00584   cleanup:
00585     return;
00586     
00587 }
00588 
00589 /*----------------------------------------------------------------------------*/
00595 /*----------------------------------------------------------------------------*/
00596 const char * uves_pfits_get_pro_catg(const uves_propertylist * plist)
00597 {
00598   const char* result=NULL;
00599 
00600   check(uves_get_property_value(plist, "ESO PRO CATG", 
00601                  CPL_TYPE_STRING, &result),
00602     "Error reading ESO PRO CATG");
00603 
00604  cleanup:
00605     return result;
00606 }
00607 
00608 /*----------------------------------------------------------------------------*/
00614 /*----------------------------------------------------------------------------*/
00615 const char * uves_pfits_get_dpr_tech(const uves_propertylist * plist)
00616 {
00617   const char* result=NULL;
00618 
00619   check( uves_get_property_value(plist, UVES_DPR_TECH, 
00620                  CPL_TYPE_STRING, &result),
00621      "Error reading %s", UVES_DPR_TECH);
00622 
00623  cleanup:
00624     return result;
00625 }
00626 
00627 /*----------------------------------------------------------------------------*/
00633 /*----------------------------------------------------------------------------*/
00634 const char * uves_pfits_get_dpr_type(const uves_propertylist * plist)
00635 {
00636   const char* result=NULL;
00637 
00638 
00639   check( uves_get_property_value(plist, UVES_DPR_TYPE, 
00640                  CPL_TYPE_STRING, &result),
00641      "Error reading %s", UVES_DPR_TYPE);
00642 
00643  cleanup:
00644     return result;
00645 }
00646 
00647 /*----------------------------------------------------------------------------*/
00654 /*----------------------------------------------------------------------------*/
00655 bool uves_format_is_new(const uves_propertylist * plist)
00656 {    
00657     double mjd_obs = 0.0; /* Observation date */
00658 
00659     check( mjd_obs = uves_pfits_get_mjdobs(plist),
00660        "Could not read observation date");
00661 
00662   cleanup:
00663     /* New format iff modified julian date is after April 1st, 2004 = 53096 mjd */
00664     return (mjd_obs > 53096.0);  
00665 }
00666 
00667 /*----------------------------------------------------------------------------*/
00675 /*----------------------------------------------------------------------------*/
00676 int uves_pfits_get_prescanx(const uves_propertylist * plist, enum uves_chip chip)
00677 {
00678     int returnvalue = 0;
00679     bool new_format;
00680     
00681     check( new_format = uves_format_is_new(plist),
00682        "Error determining FITS header format");
00683     
00684     check( uves_get_property_value(plist, UVES_PRESCANX(new_format, chip), 
00685                    CPL_TYPE_INT, &returnvalue), 
00686        "Error reading keyword %s", UVES_PRESCANX(new_format, chip));
00687     
00688   cleanup:
00689     return returnvalue;
00690 }
00691 
00692 /*----------------------------------------------------------------------------*/
00700 /*----------------------------------------------------------------------------*/
00701 const char* uves_pfits_get_chipid(const uves_propertylist * plist, enum uves_chip chip)
00702 {
00703     const char* returnvalue = "";
00704 
00705     check( uves_get_property_value(plist, UVES_CHIP_ID(chip), CPL_TYPE_STRING, &returnvalue), 
00706        "Error reading keyword %s", UVES_CHIP_ID(chip));
00707     
00708   cleanup:
00709     return returnvalue;
00710 }
00711 
00712 /*----------------------------------------------------------------------------*/
00720 /*----------------------------------------------------------------------------*/
00721 const char* uves_pfits_get_chip_name(const uves_propertylist * plist, enum uves_chip chip)
00722 {
00723     const char* returnvalue = "";
00724 
00725     check( uves_get_property_value(plist, UVES_CHIP_NAME(chip), CPL_TYPE_STRING, &returnvalue), 
00726        "Error reading keyword %s", UVES_CHIP_NAME(chip));
00727     
00728   cleanup:
00729     return returnvalue;
00730 }
00731 
00732 /*----------------------------------------------------------------------------*/
00740 /*----------------------------------------------------------------------------*/
00741 int uves_pfits_get_ovrscanx(const uves_propertylist * plist, enum uves_chip chip)
00742 {
00743     int returnvalue = 0;
00744     bool new_format;
00745 
00746     check( new_format = uves_format_is_new(plist),
00747        "Error determining FITS header format");
00748     
00749     check( uves_get_property_value(plist, UVES_OVRSCANX(new_format, chip), 
00750                    CPL_TYPE_INT, &returnvalue), 
00751        "Error reading keyword %s", UVES_OVRSCANX(new_format, chip));
00752     
00753   cleanup:
00754     return returnvalue;
00755 }
00756 
00757 /*----------------------------------------------------------------------------*/
00765 /*----------------------------------------------------------------------------*/
00766 int uves_pfits_get_prescany(const uves_propertylist * plist, enum uves_chip chip)
00767 {
00768     int returnvalue = 0;
00769     bool new_format;
00770     
00771 
00772     check( new_format = uves_format_is_new(plist),
00773        "Error determining FITS header format");
00774     
00775     check( uves_get_property_value(plist, UVES_PRESCANY(new_format, chip), 
00776                    CPL_TYPE_INT, &returnvalue), 
00777        "Error reading keyword %s", UVES_PRESCANY(new_format, chip));
00778     
00779   cleanup:
00780     return returnvalue;
00781 }
00782 
00783 /*----------------------------------------------------------------------------*/
00791 /*----------------------------------------------------------------------------*/
00792 int uves_pfits_get_ovrscany(const uves_propertylist * plist, enum uves_chip chip)
00793 {
00794     int returnvalue = 0;
00795     bool new_format;
00796 
00797     check( new_format = uves_format_is_new(plist),
00798        "Error determining FITS header format");
00799     
00800     check( uves_get_property_value(plist, UVES_OVRSCANY(new_format, chip), 
00801                    CPL_TYPE_INT, &returnvalue), 
00802        "Error reading keyword %s", UVES_OVRSCANY(new_format, chip));
00803     
00804   cleanup:
00805     return returnvalue;
00806 }
00807 
00808 /*----------------------------------------------------------------------------*/
00821 /*----------------------------------------------------------------------------*/
00822 double uves_pfits_get_ron_adu(const uves_propertylist * plist, enum uves_chip chip)
00823 {
00824     double ron_el = 0;          /* Read-out noise in electron units  */
00825     double default_ron_el = 5.0;/* Number converted from MIDAS       */
00826     double gain = 0;            /* Conversion from electrons to ADUs */
00827     bool new_format;
00828 
00829     check( new_format = uves_format_is_new(plist),
00830        "Error determining FITS header format");
00831     
00832     check( uves_get_property_value(plist, UVES_RON(new_format, chip), CPL_TYPE_DOUBLE, &ron_el),
00833        "Error reading keyword '%s'", UVES_RON(new_format, chip));
00834 
00835     if (ron_el <= 0)
00836     {
00837         uves_msg_warning("Read-out-noise is "
00838                  "non-positive (%e electrons). Using default value %e",
00839                  ron_el, default_ron_el);
00840         ron_el = default_ron_el;
00841     }
00842     
00843     check( gain = uves_pfits_get_gain(plist, chip),
00844        "Error reading gain");
00845     
00846     assure( ron_el * gain > 0, CPL_ERROR_ILLEGAL_INPUT,
00847         "Non-positive read-out noise: %f ADU", ron_el * gain);
00848     
00849   cleanup:
00850     return ron_el * gain;
00851 }
00852 /*----------------------------------------------------------------------------*/
00860 /*----------------------------------------------------------------------------*/
00861 double uves_pfits_get_airmass_start(const uves_propertylist * plist)
00862 {
00863     double result = 0;
00864     
00865     check( uves_get_property_value(plist, UVES_AIRMASS_START, CPL_TYPE_DOUBLE, &result),
00866        "Error reading keyword '%s'", UVES_AIRMASS_START);
00867     
00868   cleanup:
00869     return result;
00870 }
00871 /*----------------------------------------------------------------------------*/
00879 /*----------------------------------------------------------------------------*/
00880 double uves_pfits_get_airmass_end(const uves_propertylist * plist)
00881 {
00882     double result = 0;
00883     
00884     check( uves_get_property_value(plist, UVES_AIRMASS_END, CPL_TYPE_DOUBLE, &result),
00885        "Error reading keyword '%s'", UVES_AIRMASS_END);
00886     
00887   cleanup:
00888     return result;
00889 }
00890 /*----------------------------------------------------------------------------*/
00899 /*----------------------------------------------------------------------------*/
00900 double uves_pfits_get_conad(const uves_propertylist * plist, enum uves_chip chip)
00901 {
00902     double result = 0;
00903     
00904     bool new_format;
00905 
00906     check( new_format = uves_format_is_new(plist),
00907        "Error determining FITS header format");
00908     
00909     check( uves_get_property_value(plist, UVES_CONAD(new_format, chip),
00910                    CPL_TYPE_DOUBLE, &result),
00911        "Error reading keyword '%s'", UVES_CONAD(new_format, chip));
00912     
00913   cleanup:
00914     return result;
00915 }
00916 /*----------------------------------------------------------------------------*/
00924 /*----------------------------------------------------------------------------*/
00925 const char *uves_pfits_get_targ_name(const uves_propertylist * plist)
00926 {
00927     const char* returnvalue = "";
00928 
00929     check( uves_get_property_value(plist, UVES_TARG_NAME, CPL_TYPE_STRING, &returnvalue), 
00930        "Error reading keyword %s", UVES_TARG_NAME);
00931     
00932   cleanup:
00933     return returnvalue;
00934 }
00935 
00936 /*----------------------------------------------------------------------------*/
00946 /*----------------------------------------------------------------------------*/
00947 double uves_pfits_get_gain(const uves_propertylist * plist, enum uves_chip chip)
00948 {
00949     double result = 0;
00950     double default_gain = 2.1;        /* Adopted from MIDAS */
00951     bool new_format;
00952 
00953     check( new_format = uves_format_is_new(plist),
00954        "Error determining FITS header format");
00955     
00956     check( uves_get_property_value(plist, UVES_GAIN(new_format, chip),
00957                    CPL_TYPE_DOUBLE, &result),
00958        "Error reading keyword '%s'", UVES_GAIN(new_format, chip));
00959     
00960     if (result <= 0)
00961     {
00962         uves_msg_warning("Gain factor from header is "
00963                  "non-positive (%e). Using default value %e",
00964                  result, default_gain);
00965         result = default_gain;
00966     }
00967 
00968   cleanup:
00969     return result;
00970 }
00971 /*----------------------------------------------------------------------------*/
00981 /*----------------------------------------------------------------------------*/
00982 double uves_pfits_get_exptime(const uves_propertylist * plist)
00983 {
00984     double result = 0;            /* Conversion from electrons to ADUs */
00985     
00986     check( uves_get_property_value(plist, UVES_EXPTIME, CPL_TYPE_DOUBLE, &result), 
00987        "Error reading keyword '%s'", UVES_EXPTIME);
00988     assure( result >= 0, CPL_ERROR_ILLEGAL_OUTPUT, "Exposure time is negative: %f", result);
00989     
00990   cleanup:
00991     return result;
00992 }
00993 
00994 /*----------------------------------------------------------------------------*/
01002 /*----------------------------------------------------------------------------*/
01003 cpl_error_code
01004 uves_pfits_set_exptime(uves_propertylist *plist, double exptime)
01005 {
01006     check(( uves_propertylist_update_double(plist, UVES_EXPTIME, exptime),
01007         uves_propertylist_set_comment(plist, UVES_EXPTIME, "Total integration time")),
01008        "Error writing keyword '%s'", UVES_EXPTIME);
01009   cleanup:
01010     return cpl_error_get_code();
01011 }
01012 
01013 
01014 /*----------------------------------------------------------------------------*/
01022 /*----------------------------------------------------------------------------*/
01023 void
01024 uves_pfits_set_dec(uves_propertylist *plist, double dec)
01025 {
01026     check( uves_propertylist_update_double(plist, UVES_DEC, dec),
01027        "Error writing keyword '%s'", UVES_DEC);
01028   cleanup:
01029     return;
01030 }
01031 
01032 /*----------------------------------------------------------------------------*/
01040 /*----------------------------------------------------------------------------*/
01041 void
01042 uves_pfits_set_ra(uves_propertylist *plist, double ra)
01043 {
01044     check( uves_propertylist_update_double(plist, UVES_RA, ra),
01045        "Error writing keyword '%s'", UVES_RA);
01046   cleanup:
01047     return;
01048 }
01049 
01050 /*----------------------------------------------------------------------------*/
01058 /*----------------------------------------------------------------------------*/
01059 cpl_error_code
01060 uves_pfits_set_ordpred(uves_propertylist *plist, int nord)
01061 {
01062     check(( uves_propertylist_update_int(plist, UVES_ORD_PRED, nord),
01063         uves_propertylist_set_comment(plist, UVES_ORD_PRED, "Predicted no of orders")),
01064        "Error writing keyword '%s'", UVES_ORD_PRED);
01065   cleanup:
01066     return cpl_error_get_code();
01067 }
01068 
01069 /*----------------------------------------------------------------------------*/
01075 /*----------------------------------------------------------------------------*/
01076 const char *
01077 uves_pfits_get_drs_id(const uves_propertylist * plist)
01078 {
01079     const char *result = "";
01080     
01081     check( uves_get_property_value(plist, UVES_DRS_ID, CPL_TYPE_STRING, &result), 
01082        "Error reading keyword '%s'", UVES_DRS_ID);
01083     
01084   cleanup:
01085     if (cpl_error_get_code() != CPL_ERROR_NONE) 
01086     {
01087         result = NULL;
01088     }
01089 
01090     return result;
01091 }
01092 
01093 
01094 
01095 /*----------------------------------------------------------------------------*/
01101 /*----------------------------------------------------------------------------*/
01102 const char *
01103 uves_pfits_get_tpl_start(const uves_propertylist * plist)
01104 {
01105     const char *result = "";
01106     
01107     check( uves_get_property_value(plist, UVES_TPL_START, CPL_TYPE_STRING, &result),
01108        "Error reading keyword '%s'", UVES_TPL_START);
01109     
01110   cleanup:
01111     if (cpl_error_get_code() != CPL_ERROR_NONE) 
01112     {
01113         result = NULL;
01114     }
01115 
01116     return result;
01117 }
01118 
01119 
01120 /*----------------------------------------------------------------------------*/
01126 /*----------------------------------------------------------------------------*/
01127 double uves_pfits_get_utc(const uves_propertylist * plist)
01128 {
01129     double returnvalue = 0;
01130     
01131     check( uves_get_property_value(plist, UVES_UTC, CPL_TYPE_DOUBLE, &returnvalue), 
01132        "Error reading keyword '%s'", UVES_UTC);
01133     
01134   cleanup:
01135     return returnvalue;
01136 }
01137 
01138 
01139 /*----------------------------------------------------------------------------*/
01145 /*----------------------------------------------------------------------------*/
01146 double uves_pfits_get_mjdobs(const uves_propertylist * plist)
01147 {
01148     double returnvalue = 0;
01149     
01150     check( uves_get_property_value(plist, UVES_MJDOBS, CPL_TYPE_DOUBLE, &returnvalue), 
01151        "Error reading keyword '%s'", UVES_MJDOBS);
01152     
01153   cleanup:
01154     return returnvalue;
01155 }
01156 
01157 /*----------------------------------------------------------------------------*/
01163 /*----------------------------------------------------------------------------*/
01164 double uves_pfits_get_geolat(const uves_propertylist * plist)
01165 {
01166     double returnvalue = 0;
01167     
01168     check( uves_get_property_value(plist, UVES_GEOLAT, CPL_TYPE_DOUBLE, &returnvalue), 
01169        "Error reading keyword '%s'", UVES_GEOLAT);
01170     
01171   cleanup:
01172     return returnvalue;
01173 }
01174 
01175 /*----------------------------------------------------------------------------*/
01181 /*----------------------------------------------------------------------------*/
01182 double uves_pfits_get_geolon(const uves_propertylist * plist)
01183 {
01184     double returnvalue = 0;
01185     
01186     check( uves_get_property_value(plist, UVES_GEOLON, CPL_TYPE_DOUBLE, &returnvalue), 
01187        "Error reading keyword '%s'", UVES_GEOLON);
01188     
01189   cleanup:
01190     return returnvalue;
01191 }
01192 
01193 /*----------------------------------------------------------------------------*/
01199 /*----------------------------------------------------------------------------*/
01200 double uves_pfits_get_ra(const uves_propertylist * plist)
01201 {
01202     double returnvalue = 0;
01203     
01204     check( uves_get_property_value(plist, UVES_RA, CPL_TYPE_DOUBLE, &returnvalue), 
01205        "Error reading keyword '%s'", UVES_RA);
01206     
01207   cleanup:
01208     return returnvalue;
01209 }
01210 
01211 /*----------------------------------------------------------------------------*/
01217 /*----------------------------------------------------------------------------*/
01218 double uves_pfits_get_dec(const uves_propertylist * plist)
01219 {
01220     double returnvalue = 0;
01221     
01222     check( uves_get_property_value(plist, UVES_DEC, CPL_TYPE_DOUBLE, &returnvalue), 
01223        "Error reading keyword '%s'", UVES_DEC);
01224     
01225   cleanup:
01226     return returnvalue;
01227 }
01228 
01229 /*----------------------------------------------------------------------------*/
01235 /*----------------------------------------------------------------------------*/
01236 int uves_pfits_get_binx(const uves_propertylist * plist)
01237 {
01238     int returnvalue = 0;
01239     
01240     check( uves_get_property_value(plist, UVES_BINX, CPL_TYPE_INT, &returnvalue), 
01241        "Error reading keyword '%s'", UVES_BINX);
01242     
01243   cleanup:
01244     return returnvalue;
01245 }
01246 
01247 /*----------------------------------------------------------------------------*/
01253 /*----------------------------------------------------------------------------*/
01254 int uves_pfits_get_biny(const uves_propertylist * plist)
01255 {
01256     int returnvalue = 0;
01257     
01258     check( uves_get_property_value(plist, UVES_BINY, CPL_TYPE_INT, &returnvalue), 
01259        "Error reading keyword '%s'", UVES_BINY);
01260     
01261   cleanup:
01262     return returnvalue;
01263 }
01264 
01265 /*----------------------------------------------------------------------------*/
01271 /*----------------------------------------------------------------------------*/
01272 int uves_pfits_get_datancom(const uves_propertylist * plist)
01273 {
01274     int returnvalue = 0;
01275     
01276     /* This keyword changed name at some point. For support of older products, try to
01277        first new then old FITS card */
01278 
01279     assure( plist != NULL, CPL_ERROR_NULL_INPUT, "Null plist");
01280 
01281     if (uves_propertylist_contains(plist, UVES_DATANCOM))
01282     {
01283         check( uves_get_property_value(plist, UVES_DATANCOM, CPL_TYPE_INT, &returnvalue),
01284            "Error reading keyword '%s'", UVES_DATANCOM);
01285     }
01286     else
01287     {
01288         assure( uves_propertylist_contains(plist, UVES_DATANCOM_OLD), CPL_ERROR_DATA_NOT_FOUND,
01289             "No keyword '%s' or '%s' in header", UVES_DATANCOM, UVES_DATANCOM_OLD);
01290         
01291         check( uves_get_property_value(plist, UVES_DATANCOM_OLD, CPL_TYPE_INT, &returnvalue),
01292            "Error reading keyword '%s'", UVES_DATANCOM_OLD);
01293     }
01294     
01295   cleanup:
01296     return returnvalue;
01297 }
01298 
01299 
01300 
01301 /*----------------------------------------------------------------------------*/
01307 /*----------------------------------------------------------------------------*/
01308 const char* uves_pfits_get_ccdid(const uves_propertylist * plist)
01309 {
01310     const char* result="";
01311     
01312     check( uves_get_property_value(plist, UVES_CCDID, CPL_TYPE_STRING, &result), 
01313        "Error reading keyword '%s'", UVES_CCDID);
01314     
01315   cleanup:
01316     return result;
01317 }
01318 
01319 /*----------------------------------------------------------------------------*/
01325 /*----------------------------------------------------------------------------*/
01326 double uves_pfits_get_pressure(const uves_propertylist * plist)
01327 {
01328     double returnvalue;
01329     
01330     check( uves_get_property_value(plist, UVES_PRESSURE, CPL_TYPE_DOUBLE, &returnvalue), 
01331        "Error reading keyword '%s'", UVES_PRESSURE);
01332     
01333   cleanup:
01334     return returnvalue;
01335 }
01336 /*----------------------------------------------------------------------------*/
01344 /*----------------------------------------------------------------------------*/
01345 const char * uves_chop_eso_prefix(const char* key)
01346 {
01347     const char *result = NULL;
01348     const char *prefix = "ESO ";
01349     unsigned int pref_len = strlen(prefix);
01350     
01351     assure( strlen(key) >= pref_len && 
01352         strncmp(key, prefix, pref_len) == 0,
01353         CPL_ERROR_ILLEGAL_INPUT,
01354         "Keyword %s does not contain 'ESO ' prefix", key);
01355 
01356     result = key + pref_len;
01357 
01358   cleanup:
01359     return result;
01360 }
01361 
01362 /*----------------------------------------------------------------------------*/
01369 /*----------------------------------------------------------------------------*/
01370 double uves_pfits_get_tempcam(const uves_propertylist * plist, enum uves_chip chip)
01371 {
01372     double returnvalue;
01373     
01374     check( uves_get_property_value(plist, UVES_TEMPCAM(chip), CPL_TYPE_DOUBLE, &returnvalue),
01375        "Error reading keyword '%s'", UVES_TEMPCAM(chip));
01376     
01377   cleanup:
01378     return returnvalue;
01379 }
01380 
01381 
01382 /*----------------------------------------------------------------------------*/
01388 /*----------------------------------------------------------------------------*/
01389 double uves_pfits_get_humidity(const uves_propertylist * plist)
01390 {
01391     double returnvalue;
01392     
01393     check( uves_get_property_value(plist, UVES_HUMIDITY, CPL_TYPE_DOUBLE, &returnvalue),
01394        "Error reading keyword '%s'", UVES_HUMIDITY);
01395     
01396   cleanup:
01397     return returnvalue;
01398 }
01399 
01400 /*----------------------------------------------------------------------------*/
01407 /*----------------------------------------------------------------------------*/
01408 double uves_pfits_get_gratwlen(const uves_propertylist * plist, enum uves_chip chip)
01409 {
01410     double returnvalue;
01411     
01412     check( uves_get_property_value(plist, UVES_GRATWLEN(chip), CPL_TYPE_DOUBLE, &returnvalue), 
01413        "Error reading keyword '%s'", UVES_GRATWLEN(chip));
01414 
01415     assure(returnvalue > 0, CPL_ERROR_ILLEGAL_INPUT, "Non-positive wavelength: %e", returnvalue);
01416        
01417   cleanup:
01418     return returnvalue;
01419 }
01420 
01421 /*----------------------------------------------------------------------------*/
01427 /*----------------------------------------------------------------------------*/
01428 const char* uves_pfits_get_insmode(const uves_propertylist * plist)
01429 {
01430     const char* returnvalue="";
01431     
01432     check( uves_get_property_value(plist, UVES_INSMODE, CPL_TYPE_STRING, &returnvalue), 
01433        "Error reading keyword '%s'", UVES_INSMODE);
01434     
01435   cleanup:
01436     return returnvalue;
01437 }
01438 
01439 /*----------------------------------------------------------------------------*/
01445 /*----------------------------------------------------------------------------*/
01446 const char* uves_pfits_get_inspath(const uves_propertylist * plist)
01447 {
01448     const char* returnvalue="";
01449     
01450     check( uves_get_property_value(plist, UVES_INSPATH, CPL_TYPE_STRING, &returnvalue),
01451        "Error reading keyword '%s'", UVES_INSPATH);
01452     
01453   cleanup:
01454     return returnvalue;
01455 }
01456 /*----------------------------------------------------------------------------*/
01463 /*----------------------------------------------------------------------------*/
01464 const char* uves_pfits_get_gratname(const uves_propertylist * plist, enum uves_chip chip)
01465 {
01466     const char* returnvalue="";
01467     
01468     check( uves_get_property_value(plist, UVES_GRATNAME(chip), CPL_TYPE_STRING, &returnvalue),
01469        "Error reading keyword '%s'", UVES_GRATNAME(chip));
01470     
01471   cleanup:
01472     return returnvalue;
01473 }
01474 
01475 /*----------------------------------------------------------------------------*/
01482 /*----------------------------------------------------------------------------*/
01483 const char* uves_pfits_get_readspeed(const uves_propertylist * plist)
01484 {
01485     const char* returnvalue="";
01486     
01487     check( uves_get_property_value(plist, UVES_READ_SPEED, CPL_TYPE_STRING, &returnvalue),
01488        "Error reading keyword '%s'", UVES_READ_SPEED);
01489     
01490   cleanup:
01491     return returnvalue;
01492 }
01493 
01494 /*----------------------------------------------------------------------------*/
01501 /*----------------------------------------------------------------------------*/
01502 const char* uves_pfits_get_gratid(const uves_propertylist * plist, enum uves_chip chip)
01503 {
01504     const char* returnvalue="";
01505     
01506     check( uves_get_property_value(plist, UVES_GRATID(chip), CPL_TYPE_STRING, &returnvalue), 
01507        "Error reading keyword '%s'", UVES_GRATID(chip));
01508     
01509   cleanup:
01510     return returnvalue;
01511 }
01512 
01513 /*----------------------------------------------------------------------------*/
01520 /*----------------------------------------------------------------------------*/
01521 double uves_pfits_get_slitlength(const uves_propertylist * plist, enum uves_chip chip)
01522 {
01523     double returnvalue;
01524     
01525     check( uves_get_property_value(plist, UVES_SLITLENGTH(chip), CPL_TYPE_DOUBLE, &returnvalue), 
01526        "Error reading keyword '%s'", UVES_SLITLENGTH(chip));
01527     
01528   cleanup:
01529     return returnvalue;
01530 }
01531 
01532 
01533 /*----------------------------------------------------------------------------*/
01540 /*----------------------------------------------------------------------------*/
01541 double uves_pfits_get_slitwidth(const uves_propertylist * plist, enum uves_chip chip)
01542 {
01543     double returnvalue;
01544     
01545     check( uves_get_property_value(plist, UVES_SLITWIDTH(chip), CPL_TYPE_DOUBLE, &returnvalue),
01546        "Error reading keyword '%s'", UVES_SLITWIDTH(chip));
01547     
01548   cleanup:
01549     return returnvalue;
01550 }
01551 
01552 /*----------------------------------------------------------------------------*/
01558 /*----------------------------------------------------------------------------*/
01559 int uves_pfits_get_ordpred(const uves_propertylist * plist)
01560 {
01561     cpl_type type;
01562     int returnvalue;
01563 
01564     assure( plist != NULL, CPL_ERROR_NULL_INPUT, "Null plist");
01565     
01566     /* In the UVES calibration data base this keyword
01567        is sometimes integer (e.g. '33'), sometimes a floating 
01568        point value (e.g. '33.'), so support both types */
01569     
01570     assure( uves_propertylist_contains(plist, UVES_ORD_PRED), 
01571         CPL_ERROR_DATA_NOT_FOUND,
01572         "Keyword %s does not exist", UVES_ORD_PRED);
01573     check ( type = uves_propertylist_get_type(plist, UVES_ORD_PRED), 
01574         "Error reading type of property '%s'", UVES_ORD_PRED);
01575     
01576     if (type == CPL_TYPE_INT)
01577     {
01578         check( uves_get_property_value(
01579                plist, UVES_ORD_PRED, CPL_TYPE_INT, &returnvalue), 
01580            "Error reading keyword '%s'", UVES_ORD_PRED);
01581     }
01582     else if (type == CPL_TYPE_DOUBLE)
01583     {
01584         double dvalue;
01585         check( uves_get_property_value(
01586                plist, UVES_ORD_PRED, CPL_TYPE_DOUBLE, &dvalue), 
01587            "Error reading keyword '%s'", UVES_ORD_PRED);
01588         returnvalue = uves_round_double(dvalue);
01589     }
01590     else
01591     {
01592         assure( false, CPL_ERROR_TYPE_MISMATCH,
01593             "Keyword '%s' has wrong type '%s'",
01594             UVES_ORD_PRED, uves_tostring_cpl_type(type));
01595     }
01596     
01597   cleanup:
01598     return returnvalue;
01599 }
01600 
01601 /*----------------------------------------------------------------------------*/
01614 /*----------------------------------------------------------------------------*/
01615 void
01616 uves_pfits_set_history_val(uves_propertylist *plist, const char *name, const char *format, ...)
01617 {
01618     char *val_str = NULL;
01619     char *number_str = NULL;
01620     cpl_property *existing = NULL;
01621     va_list arglist;
01622     const long int plist_size = uves_propertylist_get_size(plist);
01623     int i;
01624 
01625     for (i = 0;
01626      existing == NULL && i < plist_size; i++)
01627     {
01628         cpl_property *p = uves_propertylist_get(plist, i);
01629         const char *pname = cpl_property_get_name(p);
01630         
01631         if (strcmp(pname, "HISTORY") == 0)
01632         {
01633             const char *pval;
01634             check( pval = cpl_property_get_string(p),
01635                "Error reading property value");
01636             
01637             /* match the string  "<name> " */
01638             
01639             if (strlen(pval) > strlen(name) + strlen(" ") &&
01640             strncmp(pval, name, strlen(name)) == 0 &&
01641             pval[strlen(name)] == ' ')
01642             {
01643                 /* Remember this one and stop searching */
01644                 existing = p;
01645             }
01646         }
01647     }
01648 
01649     va_start(arglist, format);
01650     number_str = irplib_vsprintf(format, arglist);
01651     va_end(arglist);
01652 
01653     val_str = uves_sprintf("%s %s", name, number_str);
01654 
01655     if (existing != NULL)
01656     {
01657         check( cpl_property_set_string(existing, val_str),
01658            "Error updating HISTORY keyword with value '%s'", val_str);
01659     }
01660     else
01661     {
01662         check( uves_propertylist_append_string(plist, "HISTORY", val_str),
01663            "Error writing HISTORY keyword with value '%s'", val_str);
01664     }
01665 
01666   cleanup:
01667     cpl_free(val_str);
01668     cpl_free(number_str);
01669     return;
01670 }
01671 /*----------------------------------------------------------------------------*/
01688 /*----------------------------------------------------------------------------*/
01689 static double
01690 parse_history(const uves_propertylist *plist, const char *name, cpl_type type)
01691 {
01692     double returnvalue = 0;
01693     const long int plist_size = uves_propertylist_get_size(plist);
01694     int i;
01695     bool found;
01696 
01697     found = false;
01698     for (i = 0; !found && i < plist_size; i++) {
01699         const cpl_property *p = uves_propertylist_get_const(plist, i);
01700         const char *value = cpl_property_get_name(p);
01701         
01702         if (strcmp(value, "HISTORY") == 0) {
01703             check( value = cpl_property_get_string(p),
01704                    "Error reading property value");
01705             
01706             /* match the string  "<name> " */
01707             
01708             if (strlen(value) > strlen(name) + strlen(" ") &&
01709                 strncmp(value, name, strlen(name)) == 0 &&
01710                 value[strlen(name)] == ' ') {
01711                 errno = 0;
01712                 switch(type) {
01713                 case CPL_TYPE_INT:
01714                     returnvalue = atoi(value + strlen(name) + strlen(" "));
01715                     assure(errno == 0, CPL_ERROR_ILLEGAL_INPUT, 
01716                            "Could not parse string '%s' as integer. "
01717                            "atoi() returned %d",
01718                            value + strlen(name) + strlen(" "), errno);
01719                     break;
01720                 case CPL_TYPE_DOUBLE:
01721                     returnvalue = strtod(value + strlen(name) + strlen(" "), NULL);
01722                     assure(errno == 0, CPL_ERROR_ILLEGAL_INPUT, 
01723                            "Could not parse string '%s' as double. "
01724                            "strtod() returned %d",
01725                            value + strlen(name) + strlen(" "), errno);
01726                     break;
01727                 default:
01728                     assure( false, CPL_ERROR_UNSUPPORTED_MODE,
01729                             "Type is %s", uves_tostring_cpl_type(type));
01730                     break;
01731                 }
01732                 found = true;
01733             }
01734         }
01735     }
01736     
01737     assure( found, CPL_ERROR_DATA_NOT_FOUND, "Missing record 'HISTORY %s '",
01738         name );
01739 
01740   cleanup:
01741     return returnvalue;
01742 }
01743     
01744 /*----------------------------------------------------------------------------*/
01752 /*----------------------------------------------------------------------------*/
01753 void
01754 uves_pfits_set_firstabsorder(uves_propertylist *plist, int first_abs_order)
01755 {
01756     uves_pfits_set_history_val(plist, UVES_FIRSTABSORDER, "%d", first_abs_order);
01757 
01758     return;
01759 }
01760 
01761 /*----------------------------------------------------------------------------*/
01767 /*----------------------------------------------------------------------------*/
01768 int
01769 uves_pfits_get_firstabsorder(const uves_propertylist * plist)
01770 {
01771     return uves_round_double(parse_history(plist, UVES_FIRSTABSORDER, CPL_TYPE_INT));
01772 }
01773 
01774 
01775 /*----------------------------------------------------------------------------*/
01783 /*----------------------------------------------------------------------------*/
01784 void
01785 uves_pfits_set_lastabsorder(uves_propertylist *plist, int last_abs_order)
01786 {
01787     uves_pfits_set_history_val(plist, UVES_LASTABSORDER, "%d", last_abs_order);
01788 
01789     return;
01790 }
01791 /*----------------------------------------------------------------------------*/
01797 /*----------------------------------------------------------------------------*/
01798 int
01799 uves_pfits_get_lastabsorder(const uves_propertylist * plist)
01800 {
01801     return uves_round_double(parse_history(plist, UVES_LASTABSORDER, CPL_TYPE_INT));
01802 }
01803 
01804 /*----------------------------------------------------------------------------*/
01811 /*----------------------------------------------------------------------------*/
01812 cpl_error_code uves_pfits_set_data_average(uves_propertylist * plist, double average)
01813 {
01814     check(( uves_propertylist_update_double(plist, UVES_PRO_DATAAVG, average),
01815         uves_propertylist_set_comment  (plist, UVES_PRO_DATAAVG, "Mean of pixel values")),
01816        "Error writing keyword '%s'", UVES_PRO_DATAAVG);
01817   cleanup:
01818     return cpl_error_get_code();
01819 }
01820 
01821 /*----------------------------------------------------------------------------*/
01828 /*----------------------------------------------------------------------------*/
01829 cpl_error_code uves_pfits_set_data_stddev(uves_propertylist * plist, double stddev)
01830 {
01831     check(( uves_propertylist_update_double(plist, UVES_PRO_DATARMS, stddev),
01832         uves_propertylist_set_comment  (plist, UVES_PRO_DATARMS, 
01833                        "Standard deviation of pixel values")),
01834        "Error writing keyword '%s'", UVES_PRO_DATARMS);
01835   
01836   cleanup:
01837     return cpl_error_get_code();
01838 }
01839 
01840 /*----------------------------------------------------------------------------*/
01847 /*----------------------------------------------------------------------------*/
01848 cpl_error_code uves_pfits_set_data_median(uves_propertylist * plist, double median)
01849 {
01850     check(( uves_propertylist_update_double(plist, UVES_PRO_DATAMED, median),
01851         uves_propertylist_set_comment  (plist, UVES_PRO_DATAMED, "Median of pixel values")),
01852        "Error writing keyword '%s'", UVES_PRO_DATAMED);
01853 
01854   cleanup:
01855     return cpl_error_get_code();
01856 }
01857 /*----------------------------------------------------------------------------*/
01864 /*----------------------------------------------------------------------------*/
01865 cpl_error_code uves_pfits_set_data_min(uves_propertylist * plist, double min)
01866 {
01867     check(( uves_propertylist_update_double(plist, UVES_DATAMIN, min),
01868         uves_propertylist_set_comment  (plist, UVES_DATAMIN, "Minimum of pixel values")),
01869         "Error writing keyword '%s'", UVES_DATAMIN);
01870   
01871   cleanup:
01872     return cpl_error_get_code();
01873 }
01874 /*----------------------------------------------------------------------------*/
01881 /*----------------------------------------------------------------------------*/
01882 cpl_error_code uves_pfits_set_data_max(uves_propertylist * plist, double max)
01883 {
01884     check(( uves_propertylist_update_double(plist, UVES_DATAMAX, max),
01885         uves_propertylist_set_comment  (plist, UVES_DATAMAX, 
01886                                             "Maximum of pixel values")),
01887           "Error writing keyword '%s'", UVES_DATAMAX);
01888   
01889   cleanup:
01890     return cpl_error_get_code();
01891 }
01892 
01893 /*----------------------------------------------------------------------------*/
01900 /*----------------------------------------------------------------------------*/
01901 void
01902 uves_pfits_set_traceid(uves_propertylist * plist, int trace_id)
01903 {
01904     uves_pfits_set_history_val(plist, UVES_TRACEID, "%d", trace_id);    
01905     return;
01906 }
01907 
01908 /*----------------------------------------------------------------------------*/
01914 /*----------------------------------------------------------------------------*/
01915 double
01916 uves_pfits_get_offset(const uves_propertylist *plist)
01917 {
01918     double offset;
01919     if (uves_propertylist_contains(plist, UVES_TRACE_OFFSET)) 
01920         /* MIDAS format */
01921         {
01922             check( uves_get_property_value(plist, UVES_TRACE_OFFSET, CPL_TYPE_DOUBLE,
01923                                            &offset), 
01924                    "Error reading keyword %s", UVES_TRACE_OFFSET);
01925         }
01926     else
01927         {
01928             offset = parse_history(plist, UVES_TRACE_OFFSET, CPL_TYPE_DOUBLE);
01929         }
01930 
01931   cleanup:    
01932     return offset;
01933 }
01934 /*----------------------------------------------------------------------------*/
01941 /*----------------------------------------------------------------------------*/
01942 void
01943 uves_pfits_set_offset(uves_propertylist * plist, double trace_offset)
01944 {
01945     uves_pfits_set_history_val(plist, UVES_TRACE_OFFSET, "%f", trace_offset);
01946     return;
01947 }
01948 
01949 /*----------------------------------------------------------------------------*/
01956 /*----------------------------------------------------------------------------*/
01957 void
01958 uves_pfits_set_windownumber(uves_propertylist * plist, int window_number)
01959 {
01960     uves_pfits_set_history_val(plist, UVES_WINDOWNUMBER, "%d", window_number);
01961     return;
01962 }
01963 
01964 
01965 /*----------------------------------------------------------------------------*/
01971 /*----------------------------------------------------------------------------*/
01972 int
01973 uves_pfits_get_traceid(const uves_propertylist * plist)
01974 {
01975     return uves_round_double(parse_history(plist, UVES_TRACEID, CPL_TYPE_INT));
01976 }
01977 
01978 /*----------------------------------------------------------------------------*/
01984 /*----------------------------------------------------------------------------*/
01985 int
01986 uves_pfits_get_windownumber(const uves_propertylist * plist)
01987 {
01988     return uves_round_double(parse_history(plist, UVES_WINDOWNUMBER, CPL_TYPE_INT));
01989 }
01990 
01991 /*----------------------------------------------------------------------------*/
01997 /*----------------------------------------------------------------------------*/
01998 const char* uves_pfits_get_bunit(const uves_propertylist * plist)
01999 {
02000     const char* returnvalue="";
02001     
02002     check( uves_get_property_value(plist, UVES_BUNIT, CPL_TYPE_STRING, &returnvalue), 
02003        "Error reading keyword '%s'", UVES_BUNIT);
02004     
02005   cleanup:
02006     return returnvalue;
02007 }
02008 
02009 /*----------------------------------------------------------------------------*/
02015 /*----------------------------------------------------------------------------*/
02016 const char* uves_pfits_get_ctype1(const uves_propertylist * plist)
02017 {
02018     const char* returnvalue="";
02019     
02020     check( uves_get_property_value(plist, UVES_CTYPE1, CPL_TYPE_STRING, &returnvalue), 
02021        "Error reading keyword '%s'", UVES_CTYPE1);
02022     
02023   cleanup:
02024     return returnvalue;
02025 }
02026 
02027 /*----------------------------------------------------------------------------*/
02033 /*----------------------------------------------------------------------------*/
02034 const char* uves_pfits_get_ctype2(const uves_propertylist * plist)
02035 {
02036     const char* returnvalue="";
02037     
02038     check( uves_get_property_value(plist, UVES_CTYPE2, CPL_TYPE_STRING, &returnvalue), 
02039        "Error reading keyword '%s'", UVES_CTYPE2);
02040     
02041   cleanup:
02042     return returnvalue;
02043 }
02044 
02045 /*----------------------------------------------------------------------------*/
02051 /*----------------------------------------------------------------------------*/
02052 double uves_pfits_get_uit(const uves_propertylist * plist)
02053 {
02054     double returnvalue = 0;
02055     bool new_format;
02056     
02057     check( new_format = uves_format_is_new(plist),
02058        "Error determining FITS header format");
02059     
02060     check( uves_get_property_value(plist, UVES_UIT(new_format), CPL_TYPE_DOUBLE, &returnvalue), 
02061        "Error reading keyword %s", UVES_UIT(new_format));
02062     
02063   cleanup:
02064     return returnvalue;
02065 
02066 }
02067 
02068 
02069 /*----------------------------------------------------------------------------*/
02076 /*----------------------------------------------------------------------------*/
02077 int uves_pfits_get_nx(const uves_propertylist * plist,enum uves_chip chip)
02078 {
02079 
02080     int returnvalue = 0;
02081     bool new_format;
02082     
02083     check( new_format = uves_format_is_new(plist),
02084        "Error determining FITS header format");
02085     
02086     check( uves_get_property_value(plist, UVES_NX(new_format, chip), CPL_TYPE_INT, &returnvalue), 
02087        "Error reading keyword %s", UVES_NX(new_format, chip));
02088     
02089   cleanup:
02090     return returnvalue;
02091 
02092 }
02093 
02094 
02095 
02096 
02097 /*----------------------------------------------------------------------------*/
02104 /*----------------------------------------------------------------------------*/
02105 int uves_pfits_get_ny(const uves_propertylist * plist,enum uves_chip chip)
02106 {
02107 
02108     int returnvalue = 0;
02109     bool new_format;
02110     
02111     check( new_format = uves_format_is_new(plist),
02112        "Error determining FITS header format");
02113     
02114     check( uves_get_property_value(plist, UVES_NY(new_format, chip), CPL_TYPE_INT, &returnvalue), 
02115        "Error reading keyword %s", UVES_NY(new_format, chip));
02116     
02117   cleanup:
02118     return returnvalue;
02119 
02120 }
02121 
02122 
02123 
02124 /*----------------------------------------------------------------------------*/
02130 /*----------------------------------------------------------------------------*/
02131 int uves_pfits_get_out1nx(const uves_propertylist * plist)
02132 {
02133     int returnvalue = 0;
02134     
02135     check( uves_get_property_value(plist, UVES_OUT1NX, CPL_TYPE_INT, &returnvalue), 
02136        "Error reading keyword '%s'", UVES_OUT1NX);
02137     
02138   cleanup:
02139     return returnvalue;
02140 }
02141 
02142 /*----------------------------------------------------------------------------*/
02148 /*----------------------------------------------------------------------------*/
02149 int uves_pfits_get_out1ny(const uves_propertylist * plist)
02150 {
02151     int returnvalue = 0;
02152     
02153     check( uves_get_property_value(plist, UVES_OUT1NY, CPL_TYPE_INT, &returnvalue), 
02154        "Error reading keyword '%s'", UVES_OUT1NY);
02155     
02156   cleanup:
02157     return returnvalue;
02158 }
02159 
02160 /*----------------------------------------------------------------------------*/
02166 /*----------------------------------------------------------------------------*/
02167 int uves_pfits_get_out4nx(const uves_propertylist * plist)
02168 {
02169     int returnvalue = 0;
02170     
02171     check( uves_get_property_value(plist, UVES_OUT4NX, CPL_TYPE_INT, &returnvalue), 
02172        "Error reading keyword '%s'", UVES_OUT4NX);
02173     
02174   cleanup:
02175     return returnvalue;
02176 }
02177 
02178 /*----------------------------------------------------------------------------*/
02184 /*----------------------------------------------------------------------------*/
02185 int uves_pfits_get_out4ny(const uves_propertylist * plist)
02186 {
02187     int returnvalue = 0;
02188     
02189     check( uves_get_property_value(plist, UVES_OUT4NY, CPL_TYPE_INT, &returnvalue), 
02190        "Error reading keyword '%s'", UVES_OUT4NY);
02191     
02192   cleanup:
02193     return returnvalue;
02194 }
02195 
02196 
02197 /*----------------------------------------------------------------------------*/
02203 /*----------------------------------------------------------------------------*/
02204 int uves_pfits_get_naxis(const uves_propertylist * plist)
02205 {
02206     int returnvalue = 0;
02207     
02208     check( uves_get_property_value(plist, UVES_NAXIS, CPL_TYPE_INT, &returnvalue), 
02209        "Error reading keyword '%s'", UVES_NAXIS);
02210     
02211   cleanup:
02212     return returnvalue;
02213 }
02214 
02215 /*----------------------------------------------------------------------------*/
02221 /*----------------------------------------------------------------------------*/
02222 int uves_flames_pfits_get_nflats(const uves_propertylist * plist)
02223 {
02224     int returnvalue = 0;
02225     
02226     check( uves_get_property_value(plist, FLAMES_NFLATS, CPL_TYPE_INT, &returnvalue), 
02227        "Error reading keyword '%s'", FLAMES_NFLATS);
02228     
02229   cleanup:
02230     return returnvalue;
02231 }
02232 
02233 
02234 /*----------------------------------------------------------------------------*/
02240 /*----------------------------------------------------------------------------*/
02241 int uves_pfits_get_bitpix(const uves_propertylist * plist)
02242 {
02243     int returnvalue = 0;
02244     
02245     check( uves_get_property_value(plist, UVES_BITPIX, CPL_TYPE_INT, &returnvalue), 
02246        "Error reading keyword '%s'", UVES_BITPIX);
02247     
02248   cleanup:
02249     return returnvalue;
02250 }
02251 
02252 /*----------------------------------------------------------------------------*/
02258 /*----------------------------------------------------------------------------*/
02259 int uves_pfits_get_naxis1(const uves_propertylist * plist)
02260 {
02261     int returnvalue = 0;
02262     
02263     check( uves_get_property_value(plist, UVES_NAXIS1, CPL_TYPE_INT, &returnvalue), 
02264        "Error reading keyword '%s'", UVES_NAXIS1);
02265     
02266   cleanup:
02267     return returnvalue;
02268 }
02269 
02270 
02271 /*----------------------------------------------------------------------------*/
02277 /*----------------------------------------------------------------------------*/
02278 double uves_pfits_get_startx(const uves_propertylist * plist)
02279 {
02280     double returnvalue = 0;
02281     
02282     check( uves_get_property_value(plist, UVES_STARTX, CPL_TYPE_DOUBLE, &returnvalue), 
02283        "Error reading keyword '%s'", UVES_STARTX);
02284     
02285   cleanup:
02286     return returnvalue;
02287 }
02288 
02289 
02290 /*----------------------------------------------------------------------------*/
02296 /*----------------------------------------------------------------------------*/
02297 double uves_pfits_get_starty(const uves_propertylist * plist)
02298 {
02299     double returnvalue = 0;
02300     
02301     check( uves_get_property_value(plist, UVES_STARTY, CPL_TYPE_DOUBLE, &returnvalue), 
02302        "Error reading keyword '%s'", UVES_STARTY);
02303     
02304   cleanup:
02305     return returnvalue;
02306 }
02307 
02308 /*----------------------------------------------------------------------------*/
02314 /*----------------------------------------------------------------------------*/
02315 int uves_pfits_get_naxis2(const uves_propertylist * plist)
02316 {
02317     int returnvalue = 0;
02318     
02319     check( uves_get_property_value(plist, UVES_NAXIS2, CPL_TYPE_INT, &returnvalue), 
02320        "Error reading keyword '%s'", UVES_NAXIS2);
02321     
02322   cleanup:
02323     return returnvalue;
02324 }
02325 /*----------------------------------------------------------------------------*/
02331 /*----------------------------------------------------------------------------*/
02332 double uves_pfits_get_crval1(const uves_propertylist * plist)
02333 {
02334     double returnvalue = 0.0;
02335     
02336     check( uves_get_property_value(plist, UVES_CRVAL1, CPL_TYPE_DOUBLE, &returnvalue), 
02337        "Error reading keyword '%s'", UVES_CRVAL1);
02338     
02339   cleanup:
02340     return returnvalue;
02341 }
02342 /*----------------------------------------------------------------------------*/
02348 /*----------------------------------------------------------------------------*/
02349 double uves_pfits_get_crval2(const uves_propertylist * plist)
02350 {
02351     double returnvalue = 0.0;
02352     
02353     check( uves_get_property_value(plist, UVES_CRVAL2, CPL_TYPE_DOUBLE, &returnvalue), 
02354        "Error reading keyword '%s'", UVES_CRVAL2);
02355     
02356   cleanup:
02357     return returnvalue;
02358 }
02359 /*----------------------------------------------------------------------------*/
02365 /*----------------------------------------------------------------------------*/
02366 double uves_pfits_get_crpix1(const uves_propertylist * plist)
02367 {
02368     double returnvalue = 0.0;
02369     
02370     check( uves_get_property_value(plist, UVES_CRPIX1, CPL_TYPE_DOUBLE, &returnvalue), 
02371        "Error reading keyword '%s'", UVES_CRPIX1);
02372     
02373   cleanup:
02374     return returnvalue;
02375 }
02376 /*----------------------------------------------------------------------------*/
02382 /*----------------------------------------------------------------------------*/
02383 double uves_pfits_get_crpix2(const uves_propertylist * plist)
02384 {
02385     double returnvalue = 0.0;
02386     
02387     check( uves_get_property_value(plist, UVES_CRPIX2, CPL_TYPE_DOUBLE, &returnvalue), 
02388        "Error reading keyword '%s'", UVES_CRPIX2);
02389     
02390   cleanup:
02391     return returnvalue;
02392 }
02393 /*----------------------------------------------------------------------------*/
02399 /*----------------------------------------------------------------------------*/
02400 double uves_pfits_get_cdelt1(const uves_propertylist * plist)
02401 {
02402     double returnvalue = 0.0;
02403     
02404     check( uves_get_property_value(plist, UVES_CDELT1, CPL_TYPE_DOUBLE, &returnvalue), 
02405        "Error reading keyword '%s'", UVES_CDELT1);
02406     
02407   cleanup:
02408     return returnvalue;
02409 }
02410 /*----------------------------------------------------------------------------*/
02416 /*----------------------------------------------------------------------------*/
02417 double uves_pfits_get_cdelt2(const uves_propertylist * plist)
02418 {
02419     double returnvalue = 0.0;
02420     
02421     check( uves_get_property_value(plist, UVES_CDELT2, CPL_TYPE_DOUBLE, &returnvalue), 
02422        "Error reading keyword '%s'", UVES_CDELT2);
02423     
02424   cleanup:
02425     return returnvalue;
02426 }
02427 /*----------------------------------------------------------------------------*/
02434 /*----------------------------------------------------------------------------*/
02435 cpl_error_code uves_pfits_set_object(uves_propertylist * plist, const char *object)
02436 {
02437     check( uves_propertylist_update_string(plist, UVES_OBJECT, object),
02438        "Error writing keyword '%s'", UVES_OBJECT);
02439     
02440   cleanup:
02441     return cpl_error_get_code();
02442 }
02443 /*----------------------------------------------------------------------------*/
02450 /*----------------------------------------------------------------------------*/
02451 cpl_error_code uves_pfits_set_badpixcorr(uves_propertylist * plist, const char *corr)
02452 {
02453     check( uves_propertylist_update_string(plist, UVES_QC_BADPIXCORR, corr),
02454        "Error writing keyword '%s'", UVES_QC_BADPIXCORR);
02455     
02456   cleanup:
02457     return cpl_error_get_code();
02458 }
02459 
02460 /*----------------------------------------------------------------------------*/
02467 /*----------------------------------------------------------------------------*/
02468 cpl_error_code uves_pfits_set_redlevel(uves_propertylist * plist, const char *redlevel)
02469 {
02470     check( uves_propertylist_update_string(plist, UVES_REDLEVEL, redlevel),
02471        "Error writing keyword '%s'", UVES_REDLEVEL);
02472     
02473   cleanup:
02474     return cpl_error_get_code();
02475 }
02476 
02477 /*----------------------------------------------------------------------------*/
02484 /*----------------------------------------------------------------------------*/
02485 cpl_error_code uves_pfits_set_status(uves_propertylist * plist, const char *status)
02486 {
02487     check( uves_propertylist_update_string(plist, UVES_STATUS, status),
02488        "Error writing keyword '%s'", UVES_STATUS);
02489     
02490   cleanup:
02491     return cpl_error_get_code();
02492 }
02493 
02494 /*----------------------------------------------------------------------------*/
02501 /*----------------------------------------------------------------------------*/
02502 cpl_error_code uves_pfits_set_starttime(uves_propertylist * plist, const char *start_time)
02503 {
02504     check( uves_propertylist_update_string(plist, UVES_START, start_time),
02505        "Error writing keyword '%s'", UVES_START);
02506     
02507   cleanup:
02508     return cpl_error_get_code();
02509 }
02510 /*----------------------------------------------------------------------------*/
02517 /*----------------------------------------------------------------------------*/
02518 cpl_error_code uves_pfits_set_stoptime(uves_propertylist * plist, const char *stop_time)
02519 {
02520     check( uves_propertylist_update_string(plist, UVES_STOP, stop_time),
02521        "Error writing keyword '%s'", UVES_STOP);
02522     
02523   cleanup:
02524     return cpl_error_get_code();
02525 }
02526 
02527 /*----------------------------------------------------------------------------*/
02534 /*----------------------------------------------------------------------------*/
02535 cpl_error_code uves_pfits_set_bunit(uves_propertylist * plist, const char *bunit)
02536 {
02537     check( uves_propertylist_update_string(plist, UVES_BUNIT, bunit),
02538        "Error writing keyword '%s'", UVES_BUNIT);
02539     
02540   cleanup:
02541     return cpl_error_get_code();
02542 }
02543 
02544 /*----------------------------------------------------------------------------*/
02551 /*----------------------------------------------------------------------------*/
02552 cpl_error_code uves_pfits_set_ctype1(uves_propertylist * plist, const char *ctype1)
02553 {
02554     check( uves_propertylist_update_string(plist, UVES_CTYPE1, ctype1),
02555        "Error writing keyword '%s'", UVES_CTYPE1);
02556     
02557   cleanup:
02558     return cpl_error_get_code();
02559 }
02560 /*----------------------------------------------------------------------------*/
02567 /*----------------------------------------------------------------------------*/
02568 cpl_error_code uves_pfits_set_ctype2(uves_propertylist * plist, const char *ctype2)
02569 {
02570     check( uves_propertylist_update_string(plist, UVES_CTYPE2, ctype2),
02571        "Error writing keyword '%s'", UVES_CTYPE2);
02572     
02573   cleanup:
02574     return cpl_error_get_code();
02575 }
02576 
02577 /*----------------------------------------------------------------------------*/
02584 /*----------------------------------------------------------------------------*/
02585 cpl_error_code uves_pfits_set_crval1(uves_propertylist * plist, double crval1)
02586 {
02587     check( uves_propertylist_update_double(plist, UVES_CRVAL1, crval1),
02588        "Error writing keyword '%s'", UVES_CRVAL1);
02589     
02590   cleanup:
02591     return cpl_error_get_code();
02592 }
02593 
02594 /*----------------------------------------------------------------------------*/
02601 /*----------------------------------------------------------------------------*/
02602 cpl_error_code uves_pfits_set_crval2(uves_propertylist * plist, double crval2)
02603 {
02604     check( uves_propertylist_update_double(plist, UVES_CRVAL2, crval2),
02605        "Error writing keyword '%s'", UVES_CRVAL2);
02606     
02607   cleanup:
02608     return cpl_error_get_code();
02609 }
02610 /*----------------------------------------------------------------------------*/
02617 /*----------------------------------------------------------------------------*/
02618 cpl_error_code uves_pfits_set_crpix1(uves_propertylist * plist, double crpix1)
02619 {
02620     check( uves_propertylist_update_double(plist, UVES_CRPIX1, crpix1),
02621        "Error writing keyword '%s'", UVES_CRPIX1);
02622     
02623   cleanup:
02624     return cpl_error_get_code();
02625 }
02626 
02627 /*----------------------------------------------------------------------------*/
02634 /*----------------------------------------------------------------------------*/
02635 cpl_error_code uves_pfits_set_crpix2(uves_propertylist * plist, double crpix2)
02636 {
02637     check( uves_propertylist_update_double(plist, UVES_CRPIX2, crpix2),
02638        "Error writing keyword '%s'", UVES_CRPIX2);
02639     
02640   cleanup:
02641     return cpl_error_get_code();
02642 }
02643 /*----------------------------------------------------------------------------*/
02650 /*----------------------------------------------------------------------------*/
02651 cpl_error_code uves_pfits_set_cdelt1(uves_propertylist * plist, double cdelt1)
02652 {
02653     check( uves_propertylist_update_double(plist, UVES_CDELT1, cdelt1),
02654        "Error writing keyword '%s'", UVES_CDELT1);
02655     
02656   cleanup:
02657     return cpl_error_get_code();
02658 }
02659 
02660 /*----------------------------------------------------------------------------*/
02667 /*----------------------------------------------------------------------------*/
02668 void uves_flames_pfits_set_ccfposmax(uves_propertylist *plist, double ccfposmax)
02669 {
02670     check( uves_propertylist_update_double(plist, FLAMES_CCFPOSMAX, ccfposmax),
02671        "Error writing keyword '%s'", FLAMES_CCFPOSMAX);
02672 
02673   cleanup:
02674     return;
02675 }
02676 
02677 /*----------------------------------------------------------------------------*/
02684 /*----------------------------------------------------------------------------*/
02685 cpl_error_code uves_pfits_set_cdelt2(uves_propertylist * plist, double cdelt2)
02686 {
02687     check( uves_propertylist_update_double(plist, UVES_CDELT2, cdelt2),
02688        "Error writing keyword '%s'", UVES_CDELT2);
02689     
02690   cleanup:
02691     return cpl_error_get_code();
02692 }
02693 
02694 /*----------------------------------------------------------------------------*/
02700 /*----------------------------------------------------------------------------*/
02701 void uves_pfits_set_hs(uves_propertylist * plist, int hs)
02702 {
02703     check( uves_propertylist_update_int(plist, UVES_HS, hs),
02704        "Error writing keyword '%s'", UVES_HS);
02705     
02706   cleanup:
02707     return;
02708 }
02709 
02710 
02711 /*----------------------------------------------------------------------------*/
02719 /*----------------------------------------------------------------------------*/
02720 cpl_error_code uves_pfits_set_wstart(uves_propertylist * plist, int order, double wstart)
02721 {
02722     char *wstart_string = NULL;
02723 
02724     assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT, 
02725         "Illegal order number: %d. Allowed range is 1 to 99", order);
02726     
02727     /* allocate room for two digits and '\0' */
02728     wstart_string = cpl_malloc( strlen(UVES_WSTART) + 2 + 1);  
02729     assure_mem( wstart_string );
02730 
02731     snprintf(wstart_string, strlen(UVES_WSTART)+2+1, UVES_WSTART "%d", order);
02732     
02733     check( uves_propertylist_update_double(plist, wstart_string, wstart ),
02734        "Error updating product header");
02735         
02736   cleanup:
02737     cpl_free(wstart_string);
02738     return cpl_error_get_code();
02739 }
02740 
02741 
02742 /*----------------------------------------------------------------------------*/
02749 /*----------------------------------------------------------------------------*/
02750 
02751 double uves_pfits_get_wstart(const uves_propertylist * plist, int order)
02752 {
02753     double returnvalue;
02754     char *wstart = NULL;
02755 
02756     assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT, 
02757         "Illegal order number: %d. Allowed range is 1 to 99", order);
02758     
02759     /* allocate room for two digits and '\0' */
02760     wstart = cpl_malloc( strlen(UVES_WSTART) + 2 + 1);  
02761     assure_mem( wstart );
02762     
02763     snprintf(wstart, strlen(UVES_WSTART)+2+1, UVES_WSTART "%d", order);
02764     
02765     check( uves_get_property_value(plist, wstart, CPL_TYPE_DOUBLE, &returnvalue), 
02766        "Error reading keyword '%s'", wstart);
02767     
02768   cleanup:
02769     cpl_free(wstart);
02770     return returnvalue;
02771 }
02772 /*----------------------------------------------------------------------------*/
02780 /*----------------------------------------------------------------------------*/
02781 cpl_error_code uves_pfits_set_wend(uves_propertylist * plist, int order, double wend)
02782 {
02783     char *wend_string = NULL;
02784 
02785     assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT, 
02786         "Illegal order number: %d. Allowed range is 1 to 99", order);
02787     
02788     /* allocate room for two digits and '\0' */
02789     wend_string = cpl_malloc( strlen(UVES_WEND) + 2 + 1);  
02790     assure_mem( wend_string );
02791 
02792     snprintf(wend_string, strlen(UVES_WEND)+2+1, UVES_WEND "%d", order);
02793     
02794     check( uves_propertylist_update_double(plist, wend_string, wend ),
02795        "Error updating product header");
02796         
02797   cleanup:
02798     cpl_free(wend_string);
02799     return cpl_error_get_code();
02800 }
02801 
02802 
02803 /*----------------------------------------------------------------------------*/
02810 /*----------------------------------------------------------------------------*/
02811 
02812 double uves_pfits_get_wend(const uves_propertylist * plist, int order)
02813 {
02814     double returnvalue;
02815     char *wend = NULL;
02816 
02817     assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT, 
02818         "Illegal order number: %d. Allowed range is 1 to 99", order);
02819     
02820     /* allocate room for two digits and '\0' */
02821     wend = cpl_malloc( strlen(UVES_WEND) + 2 + 1);  
02822     assure_mem( wend );
02823     
02824     snprintf(wend, strlen(UVES_WEND)+2+1, UVES_WEND "%d", order);
02825     
02826     check( uves_get_property_value(plist, wend, CPL_TYPE_DOUBLE, &returnvalue), 
02827        "Error reading keyword '%s'", wend);
02828     
02829   cleanup:
02830     cpl_free(wend);
02831     return returnvalue;
02832 }
02833 
02834 /*----------------------------------------------------------------------------*/
02840 /*----------------------------------------------------------------------------*/
02841 double uves_pfits_get_pixelscale(const uves_propertylist *plist)
02842 {
02843     double pixelscale = 0;
02844     
02845     check( uves_get_property_value(plist, UVES_PIXELSCALE, CPL_TYPE_DOUBLE, &pixelscale),
02846            "Error reading keyword '%s'", UVES_PIXELSCALE);
02847     
02848   cleanup:
02849     return pixelscale;
02850 }
02851 
02852 /*----------------------------------------------------------------------------*/
02858 /*----------------------------------------------------------------------------*/
02859 const char* uves_pfits_get_slit1_name(const uves_propertylist * plist)
02860 {
02861     const char* returnvalue = "";
02862     
02863     check( uves_get_property_value(plist, UVES_SLIT1NAME, CPL_TYPE_STRING, &returnvalue), 
02864        "Error reading keyword '%s'", UVES_SLIT1NAME);
02865     
02866   cleanup:
02867     return returnvalue;
02868 }
02869 
02870 
02871 /*----------------------------------------------------------------------------*/
02881 /*----------------------------------------------------------------------------*/
02882 
02883 double uves_pfits_get_slitlength_pixels(const uves_propertylist * plist, enum uves_chip chip)
02884 {
02885     double slitlength_pixels = 0;         /* Result */
02886     
02887     const char *slicer_name = "";
02888     double slitlength_arcsecs = 0;        /* Slit length in arc-seconds */
02889 
02890     check( slicer_name = uves_pfits_get_slit1_name(plist),
02891        "Could not read slicer id");
02892 
02893     if ( strncmp(slicer_name, "FREE", 4) != 0)
02894     {
02895         /* Slicer inserted */
02896         if      (strncmp(slicer_name, "SLIC#1", 6) == 0) slitlength_arcsecs = 8.0;
02897         else if (strncmp(slicer_name, "SLIC#2", 6) == 0) slitlength_arcsecs = 8.0;
02898         else if (strncmp(slicer_name, "SLIC#3", 6) == 0) slitlength_arcsecs = 10.0;
02899         else
02900         {
02901             assure( false, CPL_ERROR_ILLEGAL_INPUT, "Unrecognized slicer name: '%s'. "
02902                 "Recognized names are 'FREE', 'SLIC#1', 'SLIC#2', 'SLIC#3'.", 
02903                 slicer_name);
02904         }
02905     }
02906     else
02907     {
02908         /*  slicer_name = 'FREE', no slicer */
02909 
02910         check( uves_get_property_value(
02911                plist, UVES_SLITLENGTH(chip), CPL_TYPE_DOUBLE, &slitlength_arcsecs),
02912            "Error reading keyword '%s'", UVES_SLITLENGTH(chip));
02913     }
02914 
02915     /* Convert from arcseconds to pixels */
02916     {
02917     double pixelscale;         /* Arcseconds per pixel */
02918     int binx;                  /* The x-binning of the raw image 
02919                       is the y-binning of the extracted/rotated image */
02920     
02921     check_nomsg( pixelscale = uves_pfits_get_pixelscale(plist) );
02922 
02923     check( binx = uves_pfits_get_binx(plist),
02924            "Could not get x-binning");
02925 
02926     slitlength_pixels = slitlength_arcsecs / (pixelscale * binx);
02927     }
02928     
02929   cleanup:
02930     return slitlength_pixels;
02931 }
02932 
02933 
02934 /*----------------------------------------------------------------------------*/
02940 /*----------------------------------------------------------------------------*/
02941 int
02942 uves_flames_pfits_get_plateid(const uves_propertylist *raw_header)
02943 {
02944     int plate_no;
02945     
02946     if (uves_propertylist_contains(raw_header,
02947                   FLAMES_NEWPLATEID))
02948     {
02949         check( uves_get_property_value(raw_header, FLAMES_NEWPLATEID, 
02950                        CPL_TYPE_INT, &plate_no), 
02951            "Error reading keyword '%s'", FLAMES_NEWPLATEID);
02952     }
02953     else if(uves_propertylist_contains(raw_header, 
02954                       FLAMES_OBS_PLATE_ID))
02955     {
02956         check( uves_get_property_value(raw_header, FLAMES_OBS_PLATE_ID, 
02957                        CPL_TYPE_INT, &plate_no),
02958            "Error reading keyword '%s'", FLAMES_NEWPLATEID);
02959     }
02960     else if (uves_propertylist_contains(raw_header,
02961                        FLAMES_INS_SHUT09))
02962     {
02963         plate_no = 1;
02964     }
02965     else if (uves_propertylist_contains(raw_header,
02966                        FLAMES_INS_SHUT10))
02967     {
02968         plate_no = 2;
02969     }
02970     else
02971     {
02972         plate_no = 0;
02973         uves_msg_warning("Missing raw header keywords %s, %s, %s and %s, "
02974                  "setting plate number = %d",
02975                  FLAMES_NEWPLATEID, 
02976                  FLAMES_OBS_PLATE_ID,
02977                  FLAMES_INS_SHUT09,
02978                  FLAMES_INS_SHUT10,
02979                  plate_no);
02980     }
02981     
02982   cleanup:
02983     return plate_no;
02984 }
02985 
02986 
02987 /*----------------------------------------------------------------------------*/
02993 /*----------------------------------------------------------------------------*/
02994 double 
02995 uves_flames_pfits_get_dit(const uves_propertylist * plist)
02996 {
02997     double returnvalue = 0;
02998     
02999     check( uves_get_property_value(plist, FLAMES_DIT, CPL_TYPE_DOUBLE, &returnvalue), 
03000        "Error reading keyword '%s'", FLAMES_DIT);
03001     
03002   cleanup:
03003     return returnvalue;
03004 }
03005 
03006 /*----------------------------------------------------------------------------*/
03012 /*----------------------------------------------------------------------------*/
03013 void
03014 uves_flames_pfits_set_newplateid(uves_propertylist * plist, int plate_no)
03015 {
03016     check( uves_propertylist_update_int(plist, FLAMES_NEWPLATEID, plate_no),
03017        "Error writing keyword '%s'", FLAMES_NEWPLATEID);
03018   cleanup:
03019     return;
03020 }
03021 

Generated on Tue Jun 19 14:39:16 2007 for UVES Pipeline Reference Manual by  doxygen 1.4.6