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/10/08 14:10:31 $
00023  * $Revision: 1.103 $
00024  * $Name: uves-3_9_0 $
00025  * $Log: uves_pfits.c,v $
00026  * Revision 1.103  2007/10/08 14:10:31  amodigli
00027  * assumes 5 for DATANCOM if not found in FITS header
00028  *
00029  * Revision 1.102  2007/08/30 07:56:54  amodigli
00030  * fixed some doxygen warnings
00031  *
00032  * Revision 1.101  2007/08/21 13:08:26  jmlarsen
00033  * Removed irplib_access module, largely deprecated by CPL-4
00034  *
00035  * Revision 1.100  2007/06/28 09:18:21  jmlarsen
00036  * Added functions to write DPR keywords
00037  *
00038  * Revision 1.99  2007/06/06 08:17:33  amodigli
00039  * replace tab with 4 spaces
00040  *
00041  * Revision 1.98  2007/06/01 14:09:57  jmlarsen
00042  * Exported uves_pfits_get_pixelscale
00043  *
00044  * Revision 1.97  2007/05/23 13:03:19  jmlarsen
00045  * Added missing include directive
00046  *
00047  * Revision 1.96  2007/05/16 14:38:03  amodigli
00048  * added uves_flames_pfits_get_ident & uves_flames_pfits_get_object
00049  *
00050  * Revision 1.95  2007/05/14 09:36:50  amodigli
00051  * added checks on return types
00052  *
00053  * Revision 1.94  2007/05/04 08:53:49  amodigli
00054  * added uves_flames_pfits_get_nflats
00055  *
00056  * Revision 1.93  2007/05/03 15:21:33  jmlarsen
00057  * Added function to read wavecal offset
00058  *
00059  * Revision 1.92  2007/04/26 13:19:40  jmlarsen
00060  * Added uves_pfits_set_ocs_simcal()
00061  *
00062  * Revision 1.91  2007/04/25 08:37:19  amodigli
00063  * added uves_pfits_get_origfile
00064  *
00065  * Revision 1.90  2007/04/24 12:50:29  jmlarsen
00066  * Replaced cpl_propertylist -> uves_propertylist which is much faster
00067  *
00068  * Revision 1.89  2007/04/24 09:41:09  jmlarsen
00069  * Renamed irplib_vsnprintf_create -> irplib_vsprintf
00070  *
00071  * Revision 1.88  2007/03/05 10:18:16  jmlarsen
00072  * Write 2d extraion slit length
00073  *
00074  * Revision 1.87  2007/01/31 13:11:27  jmlarsen
00075  * Added SIMCAL accessor functions
00076  *
00077  * Revision 1.86  2007/01/29 12:10:19  jmlarsen
00078  * Exported set_history_val() for usage by FLAMES
00079  *
00080  * Revision 1.85  2007/01/26 12:33:57  amodigli
00081  * added function for common QC
00082  *
00083  * Revision 1.84  2007/01/17 13:27:10  jmlarsen
00084  * Added BITPIX accessor function
00085  *
00086  * Revision 1.83  2007/01/10 14:16:15  jmlarsen
00087  * Fixed wrong format string
00088  *
00089  * Revision 1.82  2007/01/10 12:39:09  jmlarsen
00090  * Unified two get_plate_id functions
00091  *
00092  * Revision 1.81  2006/12/27 13:55:29  amodigli
00093  * added flames_pfits_get_plate_id and some FLAMES_ defines for FIBER mode
00094  *
00095  * Revision 1.80  2006/12/07 08:25:07  jmlarsen
00096  * Added uves_pfits_get_readspeed
00097  *
00098  * Revision 1.79  2006/12/01 12:27:25  jmlarsen
00099  * Factored out FLAMES plate-id code
00100  *
00101  * Revision 1.78  2006/11/24 09:36:25  jmlarsen
00102  * Workaround for slow uves_propertylist_get_size
00103  *
00104  * Revision 1.77  2006/11/15 15:02:14  jmlarsen
00105  * Implemented const safe workarounds for CPL functions
00106  *
00107  * Revision 1.75  2006/11/15 14:04:08  jmlarsen
00108  * Removed non-const version of parameterlist_get_first/last/next which is
00109  * already in CPL, added const-safe wrapper, unwrapper and deallocator functions
00110  *
00111  * Revision 1.74  2006/11/13 14:23:55  jmlarsen
00112  * Removed workarounds for CPL const bugs
00113  *
00114  * Revision 1.73  2006/11/06 15:19:41  jmlarsen
00115  * Removed unused include directives
00116  *
00117  * Revision 1.72  2006/10/25 07:21:35  jmlarsen
00118  * Documentation bug fix
00119  *
00120  * Revision 1.71  2006/10/24 14:05:47  jmlarsen
00121  * Added OBSPLATE
00122  *
00123  * Revision 1.70  2006/10/05 06:50:23  jmlarsen
00124  * Renamed function format_is_new -> uves_format_is_new
00125  *
00126  * Revision 1.69  2006/10/04 10:55:33  jmlarsen
00127  * Added telescope lat-/longitude accessor functions
00128  *
00129  * Revision 1.68  2006/09/27 13:14:15  jmlarsen
00130  * Added accessor functions for RA/DEC
00131  *
00132  * Revision 1.67  2006/09/20 10:57:36  jmlarsen
00133  * Propagate DATAMEAN/DATAMED/DATARMS if present
00134  *
00135  * Revision 1.66  2006/09/19 07:19:30  jmlarsen
00136  * Changed function set_history_int -> set_history_val to support writing values of any type
00137  *
00138  * Revision 1.65  2006/08/24 11:37:12  jmlarsen
00139  * Write recipe start/stop time to header
00140  *
00141  * Revision 1.64  2006/08/21 12:51:02  jmlarsen
00142  * Renamed shadowing variable
00143  *
00144  * Revision 1.63  2006/08/21 07:45:51  jmlarsen
00145  * Update HISTORY FABSORD keyword if it already exists, rather than adding a new keyword
00146  *
00147  * Revision 1.62  2006/08/21 07:06:16  jmlarsen
00148  * Fixed documantation bug
00149  *
00150  * Revision 1.61  2006/08/18 13:32:37  jmlarsen
00151  * Fixed memory leak
00152  *
00153  * Revision 1.60  2006/08/18 10:14:04  jmlarsen
00154  * Use legal FITS keywords for TRACEID/WINDOW/FABSORD/LABSORD
00155  *
00156  * Revision 1.59  2006/08/17 14:40:06  jmlarsen
00157  * Added missing documentation
00158  *
00159  * Revision 1.58  2006/08/17 14:11:25  jmlarsen
00160  * Use assure_mem macro to check for memory allocation failure
00161  *
00162  * Revision 1.57  2006/08/17 13:56:53  jmlarsen
00163  * Reduced max line length
00164  *
00165  * Revision 1.56  2006/08/09 14:23:19  jmlarsen
00166  * Removed unused function argument
00167  *
00168  * Revision 1.55  2006/07/31 06:29:26  amodigli
00169  * added QC on stability test
00170  *
00171  * Revision 1.54  2006/07/14 12:24:49  jmlarsen
00172  * Added conad, target name
00173  *
00174  * Revision 1.53  2006/06/13 11:58:55  jmlarsen
00175  * Bugfix: Use proper chipname keyword for REDL chip
00176  *
00177  * Revision 1.52  2006/06/02 06:42:12  jmlarsen
00178  * Added missing cleanup label
00179  *
00180  * Revision 1.51  2006/06/01 14:43:17  jmlarsen
00181  * Added missing documentation
00182  *
00183  * Revision 1.50  2006/06/01 14:22:48  amodigli
00184  * moved format_is_new to c module and made it static
00185  *
00186  * Revision 1.49  2006/05/31 09:26:40  amodigli
00187  * fixed some problem dumping QC log
00188  *
00189  * Revision 1.48  2006/05/19 13:07:20  amodigli
00190  * added uves_pfits_get_slit3_x1encoder
00191  *
00192  * Revision 1.47  2006/05/09 15:43:13  amodigli
00193  * added useful key/functions
00194  *
00195  * Revision 1.46  2006/04/26 12:25:20  amodigli
00196  * fixed a problem with ARCFILE keyword
00197  *
00198  * Revision 1.45  2006/04/25 14:58:48  amodigli
00199  * added paf creation functionalities
00200  *
00201  * Revision 1.44  2006/04/20 10:48:58  amodigli
00202  * added uves_pfits_get_tpl_start
00203  *
00204  * Revision 1.43  2006/03/24 13:59:41  jmlarsen
00205  * Added check that central wavelength is always positive
00206  *
00207  * Revision 1.42  2006/03/03 13:54:11  jmlarsen
00208  * Changed syntax of check macro
00209  *
00210  * Revision 1.41  2005/12/20 16:10:32  jmlarsen
00211  * Added some documentation
00212  *
00213  * Revision 1.40  2005/12/19 16:17:56  jmlarsen
00214  * Replaced bool -> int
00215  *
00216  */
00217 
00218 #ifdef HAVE_CONFIG_H
00219 #include <config.h>
00220 #endif
00221 
00222 /*----------------------------------------------------------------------------*/
00228 /*----------------------------------------------------------------------------*/
00231 /*-----------------------------------------------------------------------------
00232                 Defines
00233  -----------------------------------------------------------------------------*/
00234 
00235 /*-----------------------------------------------------------------------------
00236                 Includes
00237  -----------------------------------------------------------------------------*/
00238 #include <stdio.h>
00239 #include <uves_pfits.h>
00240 
00241 #include <uves_utils.h>
00242 #include <uves_utils_wrappers.h>
00243 #include <uves_dump.h>
00244 #include <uves_error.h>
00245 
00246 #include <irplib_utils.h>
00247 
00248 #include <cpl.h>
00249 
00250 #include <stdio.h>
00251 #include <stdbool.h>
00252 #include <errno.h>
00253 
00254 /*-----------------------------------------------------------------------------
00255                 Forward declarations
00256  -----------------------------------------------------------------------------*/
00257 
00258 /*-----------------------------------------------------------------------------
00259                 Function codes
00260  -----------------------------------------------------------------------------*/
00261 
00262 /*----------------------------------------------------------------------------*/
00268 /*----------------------------------------------------------------------------*/
00269 int uves_pfits_get_slit3_x1encoder(const uves_propertylist * plist)
00270 {
00271   int result=0;
00272   check(result=uves_propertylist_get_int(plist,UVES_ENCODER_REF1),
00273         "Error getting %s", UVES_ENCODER_REF1);
00274 
00275  cleanup:
00276     return result; 
00277 
00278 }
00279 
00280 /*----------------------------------------------------------------------------*/
00286 /*----------------------------------------------------------------------------*/
00287 int uves_pfits_get_slit3_x2encoder(const uves_propertylist * plist)
00288 {
00289   int result=0;
00290   check(result=uves_propertylist_get_int(plist,UVES_ENCODER_REF2),
00291         "Error getting %s",UVES_ENCODER_REF2);
00292 
00293 
00294  cleanup:
00295     return result; 
00296 
00297 }
00298 
00299 /*----------------------------------------------------------------------------*/
00305 /*----------------------------------------------------------------------------*/
00306 int  uves_pfits_get_maxfibres(const uves_propertylist * plist)
00307 {
00308   int result=0;
00309    check(uves_get_property_value(plist, "MAXFIBRES", 
00310                  CPL_TYPE_INT, &result),
00311     "Error reading MAXFIBRES");
00312 
00313  cleanup:
00314     return result; 
00315 
00316 }
00317 
00318 /*----------------------------------------------------------------------------*/
00324 /*----------------------------------------------------------------------------*/
00325 char  uves_pfits_get_chipchoice(const uves_propertylist * plist)
00326 {
00327   char result=0;
00328   check(result=uves_propertylist_get_char(plist,"CHIPCHOICE"),
00329     "Error getting CHIPCHOICE");
00330 
00331  cleanup:
00332     return result; 
00333 
00334 }
00335 /*----------------------------------------------------------------------------*/
00341 /*----------------------------------------------------------------------------*/
00342 const char * uves_pfits_get_badpxframe(const uves_propertylist * plist)
00343 {
00344 
00345   const char* result=NULL;
00346 
00347   check(uves_get_property_value(plist, "BADPXFRAME", 
00348                  CPL_TYPE_STRING, &result),
00349     "Error reading BADPXFRAME");
00350 
00351  cleanup:
00352     return result; 
00353 
00354 }
00355 
00356 
00357 /*----------------------------------------------------------------------------*/
00363 /*----------------------------------------------------------------------------*/
00364 double uves_pfits_get_ambipress(const uves_propertylist * plist)
00365 {
00366   double result=0;
00367 
00368   check(uves_get_property_value(plist, "ESO INS SENS26 MEAN", 
00369                  CPL_TYPE_DOUBLE, &result),
00370     "Error reading ESO INS SENS26 MEAN");
00371 
00372  cleanup:
00373     return result; 
00374 
00375 }
00376 
00377 
00378 /*---------------------------------------------------------------------------*/
00384 /*---------------------------------------------------------------------------*/
00385 const char * uves_pfits_get_arcfile(const uves_propertylist * plist)
00386 {
00387 
00388   const char* result=NULL;
00389 
00390 
00391   check(uves_get_property_value(plist, "ARCFILE", 
00392                  CPL_TYPE_STRING, &result),
00393     "Error reading ARCFILE");
00394 
00395  cleanup:
00396     return result; 
00397 
00398 }
00399 
00400 /*---------------------------------------------------------------------------*/
00406 /*---------------------------------------------------------------------------*/
00407 const char * uves_flames_pfits_get_ident(const uves_propertylist * plist)
00408 {
00409 
00410   const char* result=NULL;
00411 
00412   check(result=uves_propertylist_get_string(plist,"IDENT"),
00413     "Error getting IDENT");
00414 
00415  cleanup:
00416     return result; 
00417 
00418 }
00419 
00420 /*---------------------------------------------------------------------------*/
00426 /*---------------------------------------------------------------------------*/
00427 const char * uves_flames_pfits_get_object(const uves_propertylist * plist)
00428 {
00429 
00430   const char* result=NULL;
00431 
00432   check(result=uves_propertylist_get_string(plist,UVES_OBJECT),
00433     "Error getting OBJECT");
00434 
00435  cleanup:
00436     return result; 
00437 
00438 }
00439 
00440 /*---------------------------------------------------------------------------*/
00446 /*---------------------------------------------------------------------------*/
00447 const char * uves_pfits_get_origfile(const uves_propertylist * plist)
00448 {
00449 
00450   const char* result=NULL;
00451 
00452   check(uves_get_property_value(plist, "ORIGFILE", 
00453                  CPL_TYPE_STRING, &result),
00454     "Error reading ORIGFILE");
00455 
00456  cleanup:
00457     return result; 
00458 
00459 }
00460 
00461 /*----------------------------------------------------------------------------*/
00467 /*----------------------------------------------------------------------------*/
00468 const char * uves_pfits_get_pipefile(const uves_propertylist * plist)
00469 {
00470 
00471   const char* result=NULL;
00472 
00473 
00474   check(uves_get_property_value(plist, "PIPEFILE", 
00475                  CPL_TYPE_STRING, &result),
00476     "Error reading PIPEFILE");
00477 
00478  cleanup:
00479     return result; 
00480 
00481 }
00482 
00483 
00484 
00485 
00486 /*----------------------------------------------------------------------------*/
00492 /*----------------------------------------------------------------------------*/
00493 const char * uves_pfits_get_rec1raw1name(const uves_propertylist * plist)
00494 {
00495   const char* result=NULL;
00496 
00497   check(uves_get_property_value(plist, "ESO PRO REC1 RAW1 NAME", 
00498                  CPL_TYPE_STRING, &result),
00499     "Error reading ESO PRO REC1 RAW1 NAME");
00500 
00501 
00502  cleanup:
00503     return result;
00504 }
00505 /*----------------------------------------------------------------------------*/
00511 /*----------------------------------------------------------------------------*/
00512 const char * uves_pfits_get_templateid(const uves_propertylist * plist)
00513 {
00514   const char* result=NULL;
00515 
00516   check(uves_get_property_value(plist, "ESO TPL ID", 
00517                  CPL_TYPE_STRING, &result),
00518     "Error reading ESO TPL ID");
00519 
00520 
00521  cleanup:
00522 
00523     return result; 
00524 }
00525 
00526 
00527 /*----------------------------------------------------------------------------*/
00533 /*----------------------------------------------------------------------------*/
00534 const char * uves_pfits_get_date_obs(const uves_propertylist * plist)
00535 {
00536 
00537   const char* result=NULL;
00538   check(uves_get_property_value(plist, "DATE-OBS", 
00539                  CPL_TYPE_STRING, &result),
00540     "Error reading DATE-OBS");
00541 
00542  cleanup:
00543     return result;
00544 
00545 }
00546 /*----------------------------------------------------------------------------*/
00552 /*----------------------------------------------------------------------------*/
00553 const char * uves_pfits_get_dpr_catg(const uves_propertylist * plist)
00554 {
00555   const char* result=NULL;
00556 
00557   check(uves_get_property_value(plist, UVES_DPR_CATG, 
00558                  CPL_TYPE_STRING, &result),
00559     "Error reading %s", UVES_DPR_CATG);
00560 
00561  cleanup:
00562     return result;
00563 }
00564 
00565 /*----------------------------------------------------------------------------*/
00571 /*----------------------------------------------------------------------------*/
00572 int uves_pfits_get_ocs_simcal(const uves_propertylist * plist)
00573 {
00574     int returnvalue = 0;
00575     
00576     check( uves_get_property_value(plist, UVES_OCS_SIMCAL, CPL_TYPE_INT, &returnvalue), 
00577        "Error reading keyword '%s'", UVES_OCS_SIMCAL);
00578     
00579   cleanup:
00580     return returnvalue;
00581 }
00582 
00583 /*----------------------------------------------------------------------------*/
00589 /*----------------------------------------------------------------------------*/
00590 void uves_pfits_set_ocs_simcal(uves_propertylist * plist, int simcal)
00591 {
00592     check( uves_propertylist_update_int(plist, UVES_OCS_SIMCAL, simcal),
00593            "Error writing keyword '%s'", UVES_OCS_SIMCAL);
00594 
00595   cleanup:
00596     return;
00597     
00598 }
00599 
00600 /*----------------------------------------------------------------------------*/
00606 /*----------------------------------------------------------------------------*/
00607 const char * uves_pfits_get_pro_catg(const uves_propertylist * plist)
00608 {
00609   const char* result=NULL;
00610 
00611   check(uves_get_property_value(plist, "ESO PRO CATG", 
00612                  CPL_TYPE_STRING, &result),
00613     "Error reading ESO PRO CATG");
00614 
00615  cleanup:
00616     return result;
00617 }
00618 
00619 /*----------------------------------------------------------------------------*/
00625 /*----------------------------------------------------------------------------*/
00626 const char * uves_pfits_get_dpr_tech(const uves_propertylist * plist)
00627 {
00628   const char* result=NULL;
00629 
00630   check( uves_get_property_value(plist, UVES_DPR_TECH, 
00631                  CPL_TYPE_STRING, &result),
00632      "Error reading %s", UVES_DPR_TECH);
00633 
00634  cleanup:
00635     return result;
00636 }
00637 
00638 /*----------------------------------------------------------------------------*/
00644 /*----------------------------------------------------------------------------*/
00645 const char * uves_pfits_get_dpr_type(const uves_propertylist * plist)
00646 {
00647   const char* result=NULL;
00648 
00649 
00650   check( uves_get_property_value(plist, UVES_DPR_TYPE, 
00651                  CPL_TYPE_STRING, &result),
00652      "Error reading %s", UVES_DPR_TYPE);
00653 
00654  cleanup:
00655     return result;
00656 }
00657 
00658 /*----------------------------------------------------------------------------*/
00665 /*----------------------------------------------------------------------------*/
00666 bool uves_format_is_new(const uves_propertylist * plist)
00667 {    
00668     double mjd_obs = 0.0; /* Observation date */
00669 
00670     check( mjd_obs = uves_pfits_get_mjdobs(plist),
00671        "Could not read observation date");
00672 
00673   cleanup:
00674     /* New format iff modified julian date is after April 1st, 2004 = 53096 mjd */
00675     return (mjd_obs > 53096.0);  
00676 }
00677 
00678 /*----------------------------------------------------------------------------*/
00686 /*----------------------------------------------------------------------------*/
00687 int uves_pfits_get_prescanx(const uves_propertylist * plist, enum uves_chip chip)
00688 {
00689     int returnvalue = 0;
00690     bool new_format;
00691     
00692     check( new_format = uves_format_is_new(plist),
00693        "Error determining FITS header format");
00694     
00695     check( uves_get_property_value(plist, UVES_PRESCANX(new_format, chip), 
00696                    CPL_TYPE_INT, &returnvalue), 
00697        "Error reading keyword %s", UVES_PRESCANX(new_format, chip));
00698     
00699   cleanup:
00700     return returnvalue;
00701 }
00702 
00703 /*----------------------------------------------------------------------------*/
00711 /*----------------------------------------------------------------------------*/
00712 const char* uves_pfits_get_chipid(const uves_propertylist * plist, enum uves_chip chip)
00713 {
00714     const char* returnvalue = "";
00715 
00716     check( uves_get_property_value(plist, UVES_CHIP_ID(chip), CPL_TYPE_STRING, &returnvalue), 
00717        "Error reading keyword %s", UVES_CHIP_ID(chip));
00718     
00719   cleanup:
00720     return returnvalue;
00721 }
00722 
00723 /*----------------------------------------------------------------------------*/
00731 /*----------------------------------------------------------------------------*/
00732 const char* uves_pfits_get_chip_name(const uves_propertylist * plist, enum uves_chip chip)
00733 {
00734     const char* returnvalue = "";
00735 
00736     check( uves_get_property_value(plist, UVES_CHIP_NAME(chip), CPL_TYPE_STRING, &returnvalue), 
00737        "Error reading keyword %s", UVES_CHIP_NAME(chip));
00738     
00739   cleanup:
00740     return returnvalue;
00741 }
00742 
00743 /*----------------------------------------------------------------------------*/
00751 /*----------------------------------------------------------------------------*/
00752 int uves_pfits_get_ovrscanx(const uves_propertylist * plist, enum uves_chip chip)
00753 {
00754     int returnvalue = 0;
00755     bool new_format;
00756 
00757     check( new_format = uves_format_is_new(plist),
00758        "Error determining FITS header format");
00759     
00760     check( uves_get_property_value(plist, UVES_OVRSCANX(new_format, chip), 
00761                    CPL_TYPE_INT, &returnvalue), 
00762        "Error reading keyword %s", UVES_OVRSCANX(new_format, chip));
00763     
00764   cleanup:
00765     return returnvalue;
00766 }
00767 
00768 /*----------------------------------------------------------------------------*/
00776 /*----------------------------------------------------------------------------*/
00777 int uves_pfits_get_prescany(const uves_propertylist * plist, enum uves_chip chip)
00778 {
00779     int returnvalue = 0;
00780     bool new_format;
00781     
00782 
00783     check( new_format = uves_format_is_new(plist),
00784        "Error determining FITS header format");
00785     
00786     check( uves_get_property_value(plist, UVES_PRESCANY(new_format, chip), 
00787                    CPL_TYPE_INT, &returnvalue), 
00788        "Error reading keyword %s", UVES_PRESCANY(new_format, chip));
00789     
00790   cleanup:
00791     return returnvalue;
00792 }
00793 
00794 /*----------------------------------------------------------------------------*/
00802 /*----------------------------------------------------------------------------*/
00803 int uves_pfits_get_ovrscany(const uves_propertylist * plist, enum uves_chip chip)
00804 {
00805     int returnvalue = 0;
00806     bool new_format;
00807 
00808     check( new_format = uves_format_is_new(plist),
00809        "Error determining FITS header format");
00810     
00811     check( uves_get_property_value(plist, UVES_OVRSCANY(new_format, chip), 
00812                    CPL_TYPE_INT, &returnvalue), 
00813        "Error reading keyword %s", UVES_OVRSCANY(new_format, chip));
00814     
00815   cleanup:
00816     return returnvalue;
00817 }
00818 
00819 /*----------------------------------------------------------------------------*/
00832 /*----------------------------------------------------------------------------*/
00833 double uves_pfits_get_ron_adu(const uves_propertylist * plist, enum uves_chip chip)
00834 {
00835     double ron_el = 0;          /* Read-out noise in electron units  */
00836     double default_ron_el = 5.0;/* Number converted from MIDAS       */
00837     double gain = 0;            /* Conversion from electrons to ADUs */
00838     bool new_format;
00839 
00840     check( new_format = uves_format_is_new(plist),
00841        "Error determining FITS header format");
00842     
00843     check( uves_get_property_value(plist, UVES_RON(new_format, chip), CPL_TYPE_DOUBLE, &ron_el),
00844        "Error reading keyword '%s'", UVES_RON(new_format, chip));
00845 
00846     if (ron_el <= 0)
00847     {
00848         uves_msg_warning("Read-out-noise is "
00849                  "non-positive (%e electrons). Using default value %e",
00850                  ron_el, default_ron_el);
00851         ron_el = default_ron_el;
00852     }
00853     
00854     check( gain = uves_pfits_get_gain(plist, chip),
00855        "Error reading gain");
00856     
00857     assure( ron_el * gain > 0, CPL_ERROR_ILLEGAL_INPUT,
00858         "Non-positive read-out noise: %f ADU", ron_el * gain);
00859     
00860   cleanup:
00861     return ron_el * gain;
00862 }
00863 /*----------------------------------------------------------------------------*/
00871 /*----------------------------------------------------------------------------*/
00872 double uves_pfits_get_airmass_start(const uves_propertylist * plist)
00873 {
00874     double result = 0;
00875     
00876     check( uves_get_property_value(plist, UVES_AIRMASS_START, CPL_TYPE_DOUBLE, &result),
00877        "Error reading keyword '%s'", UVES_AIRMASS_START);
00878     
00879   cleanup:
00880     return result;
00881 }
00882 /*----------------------------------------------------------------------------*/
00890 /*----------------------------------------------------------------------------*/
00891 double uves_pfits_get_airmass_end(const uves_propertylist * plist)
00892 {
00893     double result = 0;
00894     
00895     check( uves_get_property_value(plist, UVES_AIRMASS_END, CPL_TYPE_DOUBLE, &result),
00896        "Error reading keyword '%s'", UVES_AIRMASS_END);
00897     
00898   cleanup:
00899     return result;
00900 }
00901 /*----------------------------------------------------------------------------*/
00910 /*----------------------------------------------------------------------------*/
00911 double uves_pfits_get_conad(const uves_propertylist * plist, enum uves_chip chip)
00912 {
00913     double result = 0;
00914     
00915     bool new_format;
00916 
00917     check( new_format = uves_format_is_new(plist),
00918        "Error determining FITS header format");
00919     
00920     check( uves_get_property_value(plist, UVES_CONAD(new_format, chip),
00921                    CPL_TYPE_DOUBLE, &result),
00922        "Error reading keyword '%s'", UVES_CONAD(new_format, chip));
00923     
00924   cleanup:
00925     return result;
00926 }
00927 /*----------------------------------------------------------------------------*/
00935 /*----------------------------------------------------------------------------*/
00936 const char *uves_pfits_get_targ_name(const uves_propertylist * plist)
00937 {
00938     const char* returnvalue = "";
00939 
00940     check( uves_get_property_value(plist, UVES_TARG_NAME, CPL_TYPE_STRING, &returnvalue), 
00941        "Error reading keyword %s", UVES_TARG_NAME);
00942     
00943   cleanup:
00944     return returnvalue;
00945 }
00946 
00947 /*----------------------------------------------------------------------------*/
00957 /*----------------------------------------------------------------------------*/
00958 double uves_pfits_get_gain(const uves_propertylist * plist, enum uves_chip chip)
00959 {
00960     double result = 0;
00961     double default_gain = 2.1;        /* Adopted from MIDAS */
00962     bool new_format;
00963 
00964     check( new_format = uves_format_is_new(plist),
00965        "Error determining FITS header format");
00966     
00967     check( uves_get_property_value(plist, UVES_GAIN(new_format, chip),
00968                    CPL_TYPE_DOUBLE, &result),
00969        "Error reading keyword '%s'", UVES_GAIN(new_format, chip));
00970     
00971     if (result <= 0)
00972     {
00973         uves_msg_warning("Gain factor from header is "
00974                  "non-positive (%e). Using default value %e",
00975                  result, default_gain);
00976         result = default_gain;
00977     }
00978 
00979   cleanup:
00980     return result;
00981 }
00982 /*----------------------------------------------------------------------------*/
00992 /*----------------------------------------------------------------------------*/
00993 double uves_pfits_get_exptime(const uves_propertylist * plist)
00994 {
00995     double result = 0;            /* Conversion from electrons to ADUs */
00996     
00997     check( uves_get_property_value(plist, UVES_EXPTIME, CPL_TYPE_DOUBLE, &result), 
00998        "Error reading keyword '%s'", UVES_EXPTIME);
00999     assure( result >= 0, CPL_ERROR_ILLEGAL_OUTPUT, "Exposure time is negative: %f", result);
01000     
01001   cleanup:
01002     return result;
01003 }
01004 
01005 /*----------------------------------------------------------------------------*/
01013 /*----------------------------------------------------------------------------*/
01014 cpl_error_code
01015 uves_pfits_set_exptime(uves_propertylist *plist, double exptime)
01016 {
01017     check(( uves_propertylist_update_double(plist, UVES_EXPTIME, exptime),
01018         uves_propertylist_set_comment(plist, UVES_EXPTIME, "Total integration time")),
01019        "Error writing keyword '%s'", UVES_EXPTIME);
01020   cleanup:
01021     return cpl_error_get_code();
01022 }
01023 
01024 
01025 /*----------------------------------------------------------------------------*/
01033 /*----------------------------------------------------------------------------*/
01034 void
01035 uves_pfits_set_dec(uves_propertylist *plist, double dec)
01036 {
01037     check( uves_propertylist_update_double(plist, UVES_DEC, dec),
01038        "Error writing keyword '%s'", UVES_DEC);
01039   cleanup:
01040     return;
01041 }
01042 
01043 /*----------------------------------------------------------------------------*/
01051 /*----------------------------------------------------------------------------*/
01052 void
01053 uves_pfits_set_ra(uves_propertylist *plist, double ra)
01054 {
01055     check( uves_propertylist_update_double(plist, UVES_RA, ra),
01056        "Error writing keyword '%s'", UVES_RA);
01057   cleanup:
01058     return;
01059 }
01060 
01061 /*----------------------------------------------------------------------------*/
01069 /*----------------------------------------------------------------------------*/
01070 cpl_error_code
01071 uves_pfits_set_ordpred(uves_propertylist *plist, int nord)
01072 {
01073     check(( uves_propertylist_update_int(plist, UVES_ORD_PRED, nord),
01074         uves_propertylist_set_comment(plist, UVES_ORD_PRED, "Predicted no of orders")),
01075        "Error writing keyword '%s'", UVES_ORD_PRED);
01076   cleanup:
01077     return cpl_error_get_code();
01078 }
01079 
01080 /*----------------------------------------------------------------------------*/
01086 /*----------------------------------------------------------------------------*/
01087 const char *
01088 uves_pfits_get_drs_id(const uves_propertylist * plist)
01089 {
01090     const char *result = "";
01091     
01092     check( uves_get_property_value(plist, UVES_DRS_ID, CPL_TYPE_STRING, &result), 
01093        "Error reading keyword '%s'", UVES_DRS_ID);
01094     
01095   cleanup:
01096     if (cpl_error_get_code() != CPL_ERROR_NONE) 
01097     {
01098         result = NULL;
01099     }
01100 
01101     return result;
01102 }
01103 
01104 
01105 
01106 /*----------------------------------------------------------------------------*/
01112 /*----------------------------------------------------------------------------*/
01113 const char *
01114 uves_pfits_get_tpl_start(const uves_propertylist * plist)
01115 {
01116     const char *result = "";
01117     
01118     check( uves_get_property_value(plist, UVES_TPL_START, CPL_TYPE_STRING, &result),
01119        "Error reading keyword '%s'", UVES_TPL_START);
01120     
01121   cleanup:
01122     if (cpl_error_get_code() != CPL_ERROR_NONE) 
01123     {
01124         result = NULL;
01125     }
01126 
01127     return result;
01128 }
01129 
01130 
01131 /*----------------------------------------------------------------------------*/
01137 /*----------------------------------------------------------------------------*/
01138 double uves_pfits_get_utc(const uves_propertylist * plist)
01139 {
01140     double returnvalue = 0;
01141     
01142     check( uves_get_property_value(plist, UVES_UTC, CPL_TYPE_DOUBLE, &returnvalue), 
01143        "Error reading keyword '%s'", UVES_UTC);
01144     
01145   cleanup:
01146     return returnvalue;
01147 }
01148 
01149 
01150 /*----------------------------------------------------------------------------*/
01156 /*----------------------------------------------------------------------------*/
01157 double uves_pfits_get_mjdobs(const uves_propertylist * plist)
01158 {
01159     double returnvalue = 0;
01160     
01161     check( uves_get_property_value(plist, UVES_MJDOBS, CPL_TYPE_DOUBLE, &returnvalue), 
01162        "Error reading keyword '%s'", UVES_MJDOBS);
01163     
01164   cleanup:
01165     return returnvalue;
01166 }
01167 
01168 /*----------------------------------------------------------------------------*/
01174 /*----------------------------------------------------------------------------*/
01175 double uves_pfits_get_geolat(const uves_propertylist * plist)
01176 {
01177     double returnvalue = 0;
01178     
01179     check( uves_get_property_value(plist, UVES_GEOLAT, CPL_TYPE_DOUBLE, &returnvalue), 
01180        "Error reading keyword '%s'", UVES_GEOLAT);
01181     
01182   cleanup:
01183     return returnvalue;
01184 }
01185 
01186 /*----------------------------------------------------------------------------*/
01192 /*----------------------------------------------------------------------------*/
01193 double uves_pfits_get_geolon(const uves_propertylist * plist)
01194 {
01195     double returnvalue = 0;
01196     
01197     check( uves_get_property_value(plist, UVES_GEOLON, CPL_TYPE_DOUBLE, &returnvalue), 
01198        "Error reading keyword '%s'", UVES_GEOLON);
01199     
01200   cleanup:
01201     return returnvalue;
01202 }
01203 
01204 /*----------------------------------------------------------------------------*/
01210 /*----------------------------------------------------------------------------*/
01211 double uves_pfits_get_ra(const uves_propertylist * plist)
01212 {
01213     double returnvalue = 0;
01214     
01215     check( uves_get_property_value(plist, UVES_RA, CPL_TYPE_DOUBLE, &returnvalue), 
01216        "Error reading keyword '%s'", UVES_RA);
01217     
01218   cleanup:
01219     return returnvalue;
01220 }
01221 
01222 /*----------------------------------------------------------------------------*/
01228 /*----------------------------------------------------------------------------*/
01229 double uves_pfits_get_dec(const uves_propertylist * plist)
01230 {
01231     double returnvalue = 0;
01232     
01233     check( uves_get_property_value(plist, UVES_DEC, CPL_TYPE_DOUBLE, &returnvalue), 
01234        "Error reading keyword '%s'", UVES_DEC);
01235     
01236   cleanup:
01237     return returnvalue;
01238 }
01239 
01240 /*----------------------------------------------------------------------------*/
01246 /*----------------------------------------------------------------------------*/
01247 int uves_pfits_get_binx(const uves_propertylist * plist)
01248 {
01249     int returnvalue = 0;
01250     
01251     check( uves_get_property_value(plist, UVES_BINX, CPL_TYPE_INT, &returnvalue), 
01252        "Error reading keyword '%s'", UVES_BINX);
01253     
01254   cleanup:
01255     return returnvalue;
01256 }
01257 
01258 /*----------------------------------------------------------------------------*/
01264 /*----------------------------------------------------------------------------*/
01265 int uves_pfits_get_biny(const uves_propertylist * plist)
01266 {
01267     int returnvalue = 0;
01268     
01269     check( uves_get_property_value(plist, UVES_BINY, CPL_TYPE_INT, &returnvalue), 
01270        "Error reading keyword '%s'", UVES_BINY);
01271     
01272   cleanup:
01273     return returnvalue;
01274 }
01275 
01276 /*----------------------------------------------------------------------------*/
01282 /*----------------------------------------------------------------------------*/
01283 int uves_pfits_get_datancom(const uves_propertylist * plist)
01284 {
01285     int returnvalue = 0;
01286     
01287     /* This keyword changed name at some point. For support of older products, try to
01288        first new then old FITS card */
01289 
01290     assure( plist != NULL, CPL_ERROR_NULL_INPUT, "Null plist");
01291 
01292     if (uves_propertylist_contains(plist, UVES_DATANCOM))
01293     {
01294         check( uves_get_property_value(plist, UVES_DATANCOM, CPL_TYPE_INT, &returnvalue),
01295            "Error reading keyword '%s'", UVES_DATANCOM);
01296     }
01297     else if( uves_propertylist_contains(plist, UVES_DATANCOM_OLD)) 
01298     {
01299         
01300         check( uves_get_property_value(plist, UVES_DATANCOM_OLD, CPL_TYPE_INT, &returnvalue),
01301            "Error reading keyword '%s'", UVES_DATANCOM_OLD);
01302     } else {
01303 
01304       uves_msg_warning("Neither %s nor %s found! We assume a value of 5! This may affect noise/error propagation",
01305                UVES_DATANCOM,UVES_DATANCOM_OLD);
01306       returnvalue=5;
01307     }
01308     
01309   cleanup:
01310     return returnvalue;
01311 }
01312 
01313 
01314 
01315 /*----------------------------------------------------------------------------*/
01321 /*----------------------------------------------------------------------------*/
01322 const char* uves_pfits_get_ccdid(const uves_propertylist * plist)
01323 {
01324     const char* result="";
01325     
01326     check( uves_get_property_value(plist, UVES_CCDID, CPL_TYPE_STRING, &result), 
01327        "Error reading keyword '%s'", UVES_CCDID);
01328     
01329   cleanup:
01330     return result;
01331 }
01332 
01333 /*----------------------------------------------------------------------------*/
01339 /*----------------------------------------------------------------------------*/
01340 double uves_pfits_get_pressure(const uves_propertylist * plist)
01341 {
01342     double returnvalue;
01343     
01344     check( uves_get_property_value(plist, UVES_PRESSURE, CPL_TYPE_DOUBLE, &returnvalue), 
01345        "Error reading keyword '%s'", UVES_PRESSURE);
01346     
01347   cleanup:
01348     return returnvalue;
01349 }
01350 /*----------------------------------------------------------------------------*/
01358 /*----------------------------------------------------------------------------*/
01359 const char * uves_chop_eso_prefix(const char* key)
01360 {
01361     const char *result = NULL;
01362     const char *prefix = "ESO ";
01363     unsigned int pref_len = strlen(prefix);
01364     
01365     assure( strlen(key) >= pref_len && 
01366         strncmp(key, prefix, pref_len) == 0,
01367         CPL_ERROR_ILLEGAL_INPUT,
01368         "Keyword %s does not contain 'ESO ' prefix", key);
01369 
01370     result = key + pref_len;
01371 
01372   cleanup:
01373     return result;
01374 }
01375 
01376 /*----------------------------------------------------------------------------*/
01383 /*----------------------------------------------------------------------------*/
01384 double uves_pfits_get_tempcam(const uves_propertylist * plist, enum uves_chip chip)
01385 {
01386     double returnvalue;
01387     
01388     check( uves_get_property_value(plist, UVES_TEMPCAM(chip), CPL_TYPE_DOUBLE, &returnvalue),
01389        "Error reading keyword '%s'", UVES_TEMPCAM(chip));
01390     
01391   cleanup:
01392     return returnvalue;
01393 }
01394 
01395 
01396 /*----------------------------------------------------------------------------*/
01402 /*----------------------------------------------------------------------------*/
01403 double uves_pfits_get_humidity(const uves_propertylist * plist)
01404 {
01405     double returnvalue;
01406     
01407     check( uves_get_property_value(plist, UVES_HUMIDITY, CPL_TYPE_DOUBLE, &returnvalue),
01408        "Error reading keyword '%s'", UVES_HUMIDITY);
01409     
01410   cleanup:
01411     return returnvalue;
01412 }
01413 
01414 /*----------------------------------------------------------------------------*/
01421 /*----------------------------------------------------------------------------*/
01422 double uves_pfits_get_gratwlen(const uves_propertylist * plist, enum uves_chip chip)
01423 {
01424     double returnvalue;
01425     
01426     check( uves_get_property_value(plist, UVES_GRATWLEN(chip), CPL_TYPE_DOUBLE, &returnvalue), 
01427        "Error reading keyword '%s'", UVES_GRATWLEN(chip));
01428 
01429     assure(returnvalue > 0, CPL_ERROR_ILLEGAL_INPUT, "Non-positive wavelength: %e", returnvalue);
01430        
01431   cleanup:
01432     return returnvalue;
01433 }
01434 
01435 /*----------------------------------------------------------------------------*/
01441 /*----------------------------------------------------------------------------*/
01442 const char* uves_pfits_get_insmode(const uves_propertylist * plist)
01443 {
01444     const char* returnvalue="";
01445     
01446     check( uves_get_property_value(plist, UVES_INSMODE, CPL_TYPE_STRING, &returnvalue), 
01447        "Error reading keyword '%s'", UVES_INSMODE);
01448     
01449   cleanup:
01450     return returnvalue;
01451 }
01452 
01453 /*----------------------------------------------------------------------------*/
01459 /*----------------------------------------------------------------------------*/
01460 const char* uves_pfits_get_inspath(const uves_propertylist * plist)
01461 {
01462     const char* returnvalue="";
01463     
01464     check( uves_get_property_value(plist, UVES_INSPATH, CPL_TYPE_STRING, &returnvalue),
01465        "Error reading keyword '%s'", UVES_INSPATH);
01466     
01467   cleanup:
01468     return returnvalue;
01469 }
01470 /*----------------------------------------------------------------------------*/
01477 /*----------------------------------------------------------------------------*/
01478 const char* uves_pfits_get_gratname(const uves_propertylist * plist, enum uves_chip chip)
01479 {
01480     const char* returnvalue="";
01481     
01482     check( uves_get_property_value(plist, UVES_GRATNAME(chip), CPL_TYPE_STRING, &returnvalue),
01483        "Error reading keyword '%s'", UVES_GRATNAME(chip));
01484     
01485   cleanup:
01486     return returnvalue;
01487 }
01488 
01489 /*----------------------------------------------------------------------------*/
01496 /*----------------------------------------------------------------------------*/
01497 const char* uves_pfits_get_readspeed(const uves_propertylist * plist)
01498 {
01499     const char* returnvalue="";
01500     
01501     check( uves_get_property_value(plist, UVES_READ_SPEED, CPL_TYPE_STRING, &returnvalue),
01502        "Error reading keyword '%s'", UVES_READ_SPEED);
01503     
01504   cleanup:
01505     return returnvalue;
01506 }
01507 
01508 /*----------------------------------------------------------------------------*/
01515 /*----------------------------------------------------------------------------*/
01516 const char* uves_pfits_get_gratid(const uves_propertylist * plist, enum uves_chip chip)
01517 {
01518     const char* returnvalue="";
01519     
01520     check( uves_get_property_value(plist, UVES_GRATID(chip), CPL_TYPE_STRING, &returnvalue), 
01521        "Error reading keyword '%s'", UVES_GRATID(chip));
01522     
01523   cleanup:
01524     return returnvalue;
01525 }
01526 
01527 /*----------------------------------------------------------------------------*/
01534 /*----------------------------------------------------------------------------*/
01535 double uves_pfits_get_slitlength(const uves_propertylist * plist, enum uves_chip chip)
01536 {
01537     double returnvalue;
01538     
01539     check( uves_get_property_value(plist, UVES_SLITLENGTH(chip), CPL_TYPE_DOUBLE, &returnvalue), 
01540        "Error reading keyword '%s'", UVES_SLITLENGTH(chip));
01541     
01542   cleanup:
01543     return returnvalue;
01544 }
01545 
01546 
01547 /*----------------------------------------------------------------------------*/
01554 /*----------------------------------------------------------------------------*/
01555 double uves_pfits_get_slitwidth(const uves_propertylist * plist, enum uves_chip chip)
01556 {
01557     double returnvalue;
01558     
01559     check( uves_get_property_value(plist, UVES_SLITWIDTH(chip), CPL_TYPE_DOUBLE, &returnvalue),
01560        "Error reading keyword '%s'", UVES_SLITWIDTH(chip));
01561     
01562   cleanup:
01563     return returnvalue;
01564 }
01565 
01566 /*----------------------------------------------------------------------------*/
01572 /*----------------------------------------------------------------------------*/
01573 int uves_pfits_get_ordpred(const uves_propertylist * plist)
01574 {
01575     cpl_type type;
01576     int returnvalue;
01577 
01578     assure( plist != NULL, CPL_ERROR_NULL_INPUT, "Null plist");
01579     
01580     /* In the UVES calibration data base this keyword
01581        is sometimes integer (e.g. '33'), sometimes a floating 
01582        point value (e.g. '33.'), so support both types */
01583     
01584     assure( uves_propertylist_contains(plist, UVES_ORD_PRED), 
01585         CPL_ERROR_DATA_NOT_FOUND,
01586         "Keyword %s does not exist", UVES_ORD_PRED);
01587     check ( type = uves_propertylist_get_type(plist, UVES_ORD_PRED), 
01588         "Error reading type of property '%s'", UVES_ORD_PRED);
01589     
01590     if (type == CPL_TYPE_INT)
01591     {
01592         check( uves_get_property_value(
01593                plist, UVES_ORD_PRED, CPL_TYPE_INT, &returnvalue), 
01594            "Error reading keyword '%s'", UVES_ORD_PRED);
01595     }
01596     else if (type == CPL_TYPE_DOUBLE)
01597     {
01598         double dvalue;
01599         check( uves_get_property_value(
01600                plist, UVES_ORD_PRED, CPL_TYPE_DOUBLE, &dvalue), 
01601            "Error reading keyword '%s'", UVES_ORD_PRED);
01602         returnvalue = uves_round_double(dvalue);
01603     }
01604     else
01605     {
01606         assure( false, CPL_ERROR_TYPE_MISMATCH,
01607             "Keyword '%s' has wrong type '%s'",
01608             UVES_ORD_PRED, uves_tostring_cpl_type(type));
01609     }
01610     
01611   cleanup:
01612     return returnvalue;
01613 }
01614 
01615 /*----------------------------------------------------------------------------*/
01628 /*----------------------------------------------------------------------------*/
01629 void
01630 uves_pfits_set_history_val(uves_propertylist *plist, const char *name, const char *format, ...)
01631 {
01632     char *val_str = NULL;
01633     char *number_str = NULL;
01634     cpl_property *existing = NULL;
01635     va_list arglist;
01636     const long int plist_size = uves_propertylist_get_size(plist);
01637     int i;
01638 
01639     for (i = 0;
01640      existing == NULL && i < plist_size; i++)
01641     {
01642         cpl_property *p = uves_propertylist_get(plist, i);
01643         const char *pname = cpl_property_get_name(p);
01644         
01645         if (strcmp(pname, "HISTORY") == 0)
01646         {
01647             const char *pval;
01648             check( pval = cpl_property_get_string(p),
01649                "Error reading property value");
01650             
01651             /* match the string  "<name> " */
01652             
01653             if (strlen(pval) > strlen(name) + strlen(" ") &&
01654             strncmp(pval, name, strlen(name)) == 0 &&
01655             pval[strlen(name)] == ' ')
01656             {
01657                 /* Remember this one and stop searching */
01658                 existing = p;
01659             }
01660         }
01661     }
01662 
01663     va_start(arglist, format);
01664     number_str = irplib_vsprintf(format, arglist);
01665     va_end(arglist);
01666 
01667     val_str = uves_sprintf("%s %s", name, number_str);
01668 
01669     if (existing != NULL)
01670     {
01671         check( cpl_property_set_string(existing, val_str),
01672            "Error updating HISTORY keyword with value '%s'", val_str);
01673     }
01674     else
01675     {
01676         check( uves_propertylist_append_string(plist, "HISTORY", val_str),
01677            "Error writing HISTORY keyword with value '%s'", val_str);
01678     }
01679 
01680   cleanup:
01681     cpl_free(val_str);
01682     cpl_free(number_str);
01683     return;
01684 }
01685 /*----------------------------------------------------------------------------*/
01702 /*----------------------------------------------------------------------------*/
01703 static double
01704 parse_history(const uves_propertylist *plist, const char *name, cpl_type type)
01705 {
01706     double returnvalue = 0;
01707     const long int plist_size = uves_propertylist_get_size(plist);
01708     int i;
01709     bool found;
01710 
01711     found = false;
01712     for (i = 0; !found && i < plist_size; i++) {
01713         const cpl_property *p = uves_propertylist_get_const(plist, i);
01714         const char *value = cpl_property_get_name(p);
01715         
01716         if (strcmp(value, "HISTORY") == 0) {
01717             check( value = cpl_property_get_string(p),
01718                    "Error reading property value");
01719             
01720             /* match the string  "<name> " */
01721             
01722             if (strlen(value) > strlen(name) + strlen(" ") &&
01723                 strncmp(value, name, strlen(name)) == 0 &&
01724                 value[strlen(name)] == ' ') {
01725                 errno = 0;
01726                 switch(type) {
01727                 case CPL_TYPE_INT:
01728                     returnvalue = atoi(value + strlen(name) + strlen(" "));
01729                     assure(errno == 0, CPL_ERROR_ILLEGAL_INPUT, 
01730                            "Could not parse string '%s' as integer. "
01731                            "atoi() returned %d",
01732                            value + strlen(name) + strlen(" "), errno);
01733                     break;
01734                 case CPL_TYPE_DOUBLE:
01735                     returnvalue = strtod(value + strlen(name) + strlen(" "), NULL);
01736                     assure(errno == 0, CPL_ERROR_ILLEGAL_INPUT, 
01737                            "Could not parse string '%s' as double. "
01738                            "strtod() returned %d",
01739                            value + strlen(name) + strlen(" "), errno);
01740                     break;
01741                 default:
01742                     assure( false, CPL_ERROR_UNSUPPORTED_MODE,
01743                             "Type is %s", uves_tostring_cpl_type(type));
01744                     break;
01745                 }
01746                 found = true;
01747             }
01748         }
01749     }
01750     
01751     assure( found, CPL_ERROR_DATA_NOT_FOUND, "Missing record 'HISTORY %s '",
01752         name );
01753 
01754   cleanup:
01755     return returnvalue;
01756 }
01757     
01758 /*----------------------------------------------------------------------------*/
01766 /*----------------------------------------------------------------------------*/
01767 void
01768 uves_pfits_set_firstabsorder(uves_propertylist *plist, int first_abs_order)
01769 {
01770     uves_pfits_set_history_val(plist, UVES_FIRSTABSORDER, "%d", first_abs_order);
01771 
01772     return;
01773 }
01774 
01775 /*----------------------------------------------------------------------------*/
01781 /*----------------------------------------------------------------------------*/
01782 int
01783 uves_pfits_get_firstabsorder(const uves_propertylist * plist)
01784 {
01785     return uves_round_double(parse_history(plist, UVES_FIRSTABSORDER, CPL_TYPE_INT));
01786 }
01787 
01788 
01789 /*----------------------------------------------------------------------------*/
01797 /*----------------------------------------------------------------------------*/
01798 void
01799 uves_pfits_set_lastabsorder(uves_propertylist *plist, int last_abs_order)
01800 {
01801     uves_pfits_set_history_val(plist, UVES_LASTABSORDER, "%d", last_abs_order);
01802 
01803     return;
01804 }
01805 /*----------------------------------------------------------------------------*/
01811 /*----------------------------------------------------------------------------*/
01812 int
01813 uves_pfits_get_lastabsorder(const uves_propertylist * plist)
01814 {
01815     return uves_round_double(parse_history(plist, UVES_LASTABSORDER, CPL_TYPE_INT));
01816 }
01817 
01818 /*---------------------------------------------------------------------------*/
01825 /*---------------------------------------------------------------------------*/
01826 cpl_error_code 
01827 uves_pfits_set_data_average(uves_propertylist * plist, double average)
01828 {
01829     check(( uves_propertylist_update_double(plist, UVES_PRO_DATAAVG, average),
01830         uves_propertylist_set_comment  (plist, UVES_PRO_DATAAVG, "Mean of pixel values")),
01831        "Error writing keyword '%s'", UVES_PRO_DATAAVG);
01832   cleanup:
01833     return cpl_error_get_code();
01834 }
01835 
01836 /*---------------------------------------------------------------------------*/
01843 /*---------------------------------------------------------------------------*/
01844 cpl_error_code 
01845 uves_pfits_set_data_stddev(uves_propertylist * plist, double stddev)
01846 {
01847     check(( uves_propertylist_update_double(plist, UVES_PRO_DATARMS, stddev),
01848         uves_propertylist_set_comment  (plist, UVES_PRO_DATARMS, 
01849                        "Standard deviation of pixel values")),
01850        "Error writing keyword '%s'", UVES_PRO_DATARMS);
01851   
01852   cleanup:
01853     return cpl_error_get_code();
01854 }
01855 
01856 /*---------------------------------------------------------------------------*/
01863 /*---------------------------------------------------------------------------*/
01864 cpl_error_code 
01865 uves_pfits_set_data_median(uves_propertylist * plist, double median)
01866 {
01867     check(( uves_propertylist_update_double(plist, UVES_PRO_DATAMED, median),
01868         uves_propertylist_set_comment  (plist, UVES_PRO_DATAMED, "Median of pixel values")),
01869        "Error writing keyword '%s'", UVES_PRO_DATAMED);
01870 
01871   cleanup:
01872     return cpl_error_get_code();
01873 }
01874 /*---------------------------------------------------------------------------*/
01881 /*---------------------------------------------------------------------------*/
01882 cpl_error_code 
01883 uves_pfits_set_data_min(uves_propertylist * plist, double min)
01884 {
01885     check(( uves_propertylist_update_double(plist, UVES_DATAMIN, min),
01886         uves_propertylist_set_comment  (plist, UVES_DATAMIN, "Minimum of pixel values")),
01887         "Error writing keyword '%s'", UVES_DATAMIN);
01888   
01889   cleanup:
01890     return cpl_error_get_code();
01891 }
01892 /*---------------------------------------------------------------------------*/
01899 /*---------------------------------------------------------------------------*/
01900 cpl_error_code 
01901 uves_pfits_set_data_max(uves_propertylist * plist, double max)
01902 {
01903     check(( uves_propertylist_update_double(plist, UVES_DATAMAX, max),
01904         uves_propertylist_set_comment  (plist, UVES_DATAMAX, 
01905                                             "Maximum of pixel values")),
01906           "Error writing keyword '%s'", UVES_DATAMAX);
01907   
01908   cleanup:
01909     return cpl_error_get_code();
01910 }
01911 
01912 /*---------------------------------------------------------------------------*/
01919 /*---------------------------------------------------------------------------*/
01920 void
01921 uves_pfits_set_traceid(uves_propertylist * plist, int trace_id)
01922 {
01923     uves_pfits_set_history_val(plist, UVES_TRACEID, "%d", trace_id);    
01924     return;
01925 }
01926 
01927 /*---------------------------------------------------------------------------*/
01933 /*---------------------------------------------------------------------------*/
01934 double
01935 uves_pfits_get_offset(const uves_propertylist *plist)
01936 {
01937     double offset;
01938     if (uves_propertylist_contains(plist, UVES_TRACE_OFFSET)) 
01939         /* MIDAS format */
01940         {
01941             check( uves_get_property_value(plist, UVES_TRACE_OFFSET, CPL_TYPE_DOUBLE,
01942                                            &offset), 
01943                    "Error reading keyword %s", UVES_TRACE_OFFSET);
01944         }
01945     else
01946         {
01947             offset = parse_history(plist, UVES_TRACE_OFFSET, CPL_TYPE_DOUBLE);
01948         }
01949 
01950   cleanup:    
01951     return offset;
01952 }
01953 /*---------------------------------------------------------------------------*/
01960 /*---------------------------------------------------------------------------*/
01961 void
01962 uves_pfits_set_offset(uves_propertylist * plist, double trace_offset)
01963 {
01964     uves_pfits_set_history_val(plist, UVES_TRACE_OFFSET, "%f", trace_offset);
01965     return;
01966 }
01967 
01968 /*---------------------------------------------------------------------------*/
01975 /*---------------------------------------------------------------------------*/
01976 void
01977 uves_pfits_set_windownumber(uves_propertylist * plist, int window_number)
01978 {
01979     uves_pfits_set_history_val(plist, UVES_WINDOWNUMBER, "%d", window_number);
01980     return;
01981 }
01982 
01983 
01984 /*---------------------------------------------------------------------------*/
01990 /*---------------------------------------------------------------------------*/
01991 int
01992 uves_pfits_get_traceid(const uves_propertylist * plist)
01993 {
01994     return uves_round_double(parse_history(plist, UVES_TRACEID, CPL_TYPE_INT));
01995 }
01996 
01997 /*---------------------------------------------------------------------------*/
02003 /*---------------------------------------------------------------------------*/
02004 int
02005 uves_pfits_get_windownumber(const uves_propertylist * plist)
02006 {
02007     return uves_round_double(parse_history(plist, UVES_WINDOWNUMBER, CPL_TYPE_INT));
02008 }
02009 
02010 /*---------------------------------------------------------------------------*/
02016 /*---------------------------------------------------------------------------*/
02017 const char* 
02018 uves_pfits_get_bunit(const uves_propertylist * plist)
02019 {
02020     const char* returnvalue="";
02021     
02022     check( uves_get_property_value(plist, UVES_BUNIT, CPL_TYPE_STRING, &returnvalue), 
02023        "Error reading keyword '%s'", UVES_BUNIT);
02024     
02025   cleanup:
02026     return returnvalue;
02027 }
02028 
02029 /*---------------------------------------------------------------------------*/
02035 /*---------------------------------------------------------------------------*/
02036 const char* 
02037 uves_pfits_get_ctype1(const uves_propertylist * plist)
02038 {
02039     const char* returnvalue="";
02040     
02041     check( uves_get_property_value(plist, UVES_CTYPE1, CPL_TYPE_STRING, &returnvalue), 
02042        "Error reading keyword '%s'", UVES_CTYPE1);
02043     
02044   cleanup:
02045     return returnvalue;
02046 }
02047 
02048 /*---------------------------------------------------------------------------*/
02054 /*---------------------------------------------------------------------------*/
02055 const 
02056 char* uves_pfits_get_ctype2(const uves_propertylist * plist)
02057 {
02058     const char* returnvalue="";
02059     
02060     check( uves_get_property_value(plist, UVES_CTYPE2, CPL_TYPE_STRING, &returnvalue), 
02061        "Error reading keyword '%s'", UVES_CTYPE2);
02062     
02063   cleanup:
02064     return returnvalue;
02065 }
02066 
02067 /*---------------------------------------------------------------------------*/
02073 /*---------------------------------------------------------------------------*/
02074 double 
02075 uves_pfits_get_uit(const uves_propertylist * plist)
02076 {
02077     double returnvalue = 0;
02078     bool new_format;
02079     
02080     check( new_format = uves_format_is_new(plist),
02081        "Error determining FITS header format");
02082     
02083     check( uves_get_property_value(plist, UVES_UIT(new_format), CPL_TYPE_DOUBLE, &returnvalue), 
02084        "Error reading keyword %s", UVES_UIT(new_format));
02085     
02086   cleanup:
02087     return returnvalue;
02088 
02089 }
02090 
02091 
02092 /*---------------------------------------------------------------------------*/
02099 /*---------------------------------------------------------------------------*/
02100 int 
02101 uves_pfits_get_nx(const uves_propertylist * plist,enum uves_chip chip)
02102 {
02103 
02104     int returnvalue = 0;
02105     bool new_format;
02106     
02107     check( new_format = uves_format_is_new(plist),
02108        "Error determining FITS header format");
02109     
02110     check( uves_get_property_value(plist, UVES_NX(new_format, chip), CPL_TYPE_INT, &returnvalue), 
02111        "Error reading keyword %s", UVES_NX(new_format, chip));
02112     
02113   cleanup:
02114     return returnvalue;
02115 
02116 }
02117 
02118 
02119 
02120 
02121 /*---------------------------------------------------------------------------*/
02128 /*---------------------------------------------------------------------------*/
02129 int 
02130 uves_pfits_get_ny(const uves_propertylist * plist,enum uves_chip chip)
02131 {
02132 
02133     int returnvalue = 0;
02134     bool new_format;
02135     
02136     check( new_format = uves_format_is_new(plist),
02137        "Error determining FITS header format");
02138     
02139     check( uves_get_property_value(plist, UVES_NY(new_format, chip), CPL_TYPE_INT, &returnvalue), 
02140        "Error reading keyword %s", UVES_NY(new_format, chip));
02141     
02142   cleanup:
02143     return returnvalue;
02144 
02145 }
02146 
02147 
02148 
02149 /*---------------------------------------------------------------------------*/
02155 /*---------------------------------------------------------------------------*/
02156 int 
02157 uves_pfits_get_out1nx(const uves_propertylist * plist)
02158 {
02159     int returnvalue = 0;
02160     
02161     check( uves_get_property_value(plist, UVES_OUT1NX, CPL_TYPE_INT, &returnvalue), 
02162        "Error reading keyword '%s'", UVES_OUT1NX);
02163     
02164   cleanup:
02165     return returnvalue;
02166 }
02167 
02168 /*---------------------------------------------------------------------------*/
02174 /*---------------------------------------------------------------------------*/
02175 int 
02176 uves_pfits_get_out1ny(const uves_propertylist * plist)
02177 {
02178     int returnvalue = 0;
02179     
02180     check( uves_get_property_value(plist, UVES_OUT1NY, CPL_TYPE_INT, &returnvalue), 
02181        "Error reading keyword '%s'", UVES_OUT1NY);
02182     
02183   cleanup:
02184     return returnvalue;
02185 }
02186 
02187 /*---------------------------------------------------------------------------*/
02193 /*---------------------------------------------------------------------------*/
02194 int 
02195 uves_pfits_get_out4nx(const uves_propertylist * plist)
02196 {
02197     int returnvalue = 0;
02198     
02199     check( uves_get_property_value(plist, UVES_OUT4NX, CPL_TYPE_INT, &returnvalue), 
02200        "Error reading keyword '%s'", UVES_OUT4NX);
02201     
02202   cleanup:
02203     return returnvalue;
02204 }
02205 
02206 /*---------------------------------------------------------------------------*/
02212 /*---------------------------------------------------------------------------*/
02213 int 
02214 uves_pfits_get_out4ny(const uves_propertylist * plist)
02215 {
02216     int returnvalue = 0;
02217     
02218     check( uves_get_property_value(plist, UVES_OUT4NY, CPL_TYPE_INT, &returnvalue), 
02219        "Error reading keyword '%s'", UVES_OUT4NY);
02220     
02221   cleanup:
02222     return returnvalue;
02223 }
02224 
02225 
02226 /*---------------------------------------------------------------------------*/
02232 /*---------------------------------------------------------------------------*/
02233 int 
02234 uves_pfits_get_naxis(const uves_propertylist * plist)
02235 {
02236     int returnvalue = 0;
02237     
02238     check( uves_get_property_value(plist, UVES_NAXIS, CPL_TYPE_INT, &returnvalue), 
02239        "Error reading keyword '%s'", UVES_NAXIS);
02240     
02241   cleanup:
02242     return returnvalue;
02243 }
02244 
02245 /*---------------------------------------------------------------------------*/
02251 /*---------------------------------------------------------------------------*/
02252 int 
02253 uves_flames_pfits_get_nflats(const uves_propertylist * plist)
02254 {
02255     int returnvalue = 0;
02256     
02257     check( uves_get_property_value(plist, FLAMES_NFLATS, CPL_TYPE_INT, &returnvalue), 
02258        "Error reading keyword '%s'", FLAMES_NFLATS);
02259     
02260   cleanup:
02261     return returnvalue;
02262 }
02263 
02264 
02265 /*---------------------------------------------------------------------------*/
02271 /*---------------------------------------------------------------------------*/
02272 int 
02273 uves_pfits_get_bitpix(const uves_propertylist * plist)
02274 {
02275     int returnvalue = 0;
02276     
02277     check( uves_get_property_value(plist, UVES_BITPIX, CPL_TYPE_INT, &returnvalue), 
02278        "Error reading keyword '%s'", UVES_BITPIX);
02279     
02280   cleanup:
02281     return returnvalue;
02282 }
02283 
02284 /*---------------------------------------------------------------------------*/
02290 /*---------------------------------------------------------------------------*/
02291 int uves_pfits_get_naxis1(const uves_propertylist * plist)
02292 {
02293     int returnvalue = 0;
02294     
02295     check( uves_get_property_value(plist, UVES_NAXIS1, CPL_TYPE_INT, &returnvalue), 
02296        "Error reading keyword '%s'", UVES_NAXIS1);
02297     
02298   cleanup:
02299     return returnvalue;
02300 }
02301 
02302 
02303 /*---------------------------------------------------------------------------*/
02309 /*---------------------------------------------------------------------------*/
02310 double 
02311 uves_pfits_get_startx(const uves_propertylist * plist)
02312 {
02313     double returnvalue = 0;
02314     
02315     check( uves_get_property_value(plist, UVES_STARTX, CPL_TYPE_DOUBLE, &returnvalue), 
02316        "Error reading keyword '%s'", UVES_STARTX);
02317     
02318   cleanup:
02319     return returnvalue;
02320 }
02321 
02322 
02323 /*---------------------------------------------------------------------------*/
02329 /*---------------------------------------------------------------------------*/
02330 double 
02331 uves_pfits_get_starty(const uves_propertylist * plist)
02332 {
02333     double returnvalue = 0;
02334     
02335     check( uves_get_property_value(plist, UVES_STARTY, CPL_TYPE_DOUBLE, &returnvalue), 
02336        "Error reading keyword '%s'", UVES_STARTY);
02337     
02338   cleanup:
02339     return returnvalue;
02340 }
02341 
02342 /*---------------------------------------------------------------------------*/
02348 /*---------------------------------------------------------------------------*/
02349 int 
02350 uves_pfits_get_naxis2(const uves_propertylist * plist)
02351 {
02352     int returnvalue = 0;
02353     
02354     check( uves_get_property_value(plist, UVES_NAXIS2, CPL_TYPE_INT, &returnvalue), 
02355        "Error reading keyword '%s'", UVES_NAXIS2);
02356     
02357   cleanup:
02358     return returnvalue;
02359 }
02360 /*---------------------------------------------------------------------------*/
02366 /*---------------------------------------------------------------------------*/
02367 double 
02368 uves_pfits_get_crval1(const uves_propertylist * plist)
02369 {
02370     double returnvalue = 0.0;
02371     
02372     check( uves_get_property_value(plist, UVES_CRVAL1, CPL_TYPE_DOUBLE, &returnvalue), 
02373        "Error reading keyword '%s'", UVES_CRVAL1);
02374     
02375   cleanup:
02376     return returnvalue;
02377 }
02378 /*---------------------------------------------------------------------------*/
02384 /*---------------------------------------------------------------------------*/
02385 double 
02386 uves_pfits_get_crval2(const uves_propertylist * plist)
02387 {
02388     double returnvalue = 0.0;
02389     
02390     check( uves_get_property_value(plist, UVES_CRVAL2, CPL_TYPE_DOUBLE, &returnvalue), 
02391        "Error reading keyword '%s'", UVES_CRVAL2);
02392     
02393   cleanup:
02394     return returnvalue;
02395 }
02396 /*---------------------------------------------------------------------------*/
02402 /*---------------------------------------------------------------------------*/
02403 double 
02404 uves_pfits_get_crpix1(const uves_propertylist * plist)
02405 {
02406     double returnvalue = 0.0;
02407     
02408     check( uves_get_property_value(plist, UVES_CRPIX1, CPL_TYPE_DOUBLE, &returnvalue), 
02409        "Error reading keyword '%s'", UVES_CRPIX1);
02410     
02411   cleanup:
02412     return returnvalue;
02413 }
02414 /*---------------------------------------------------------------------------*/
02420 /*---------------------------------------------------------------------------*/
02421 double 
02422 uves_pfits_get_crpix2(const uves_propertylist * plist)
02423 {
02424     double returnvalue = 0.0;
02425     
02426     check( uves_get_property_value(plist, UVES_CRPIX2, CPL_TYPE_DOUBLE, &returnvalue), 
02427        "Error reading keyword '%s'", UVES_CRPIX2);
02428     
02429   cleanup:
02430     return returnvalue;
02431 }
02432 /*---------------------------------------------------------------------------*/
02438 /*---------------------------------------------------------------------------*/
02439 double 
02440 uves_pfits_get_cdelt1(const uves_propertylist * plist)
02441 {
02442     double returnvalue = 0.0;
02443     
02444     check( uves_get_property_value(plist, UVES_CDELT1, CPL_TYPE_DOUBLE, &returnvalue), 
02445        "Error reading keyword '%s'", UVES_CDELT1);
02446     
02447   cleanup:
02448     return returnvalue;
02449 }
02450 /*---------------------------------------------------------------------------*/
02456 /*---------------------------------------------------------------------------*/
02457 double 
02458 uves_pfits_get_cdelt2(const uves_propertylist * plist)
02459 {
02460     double returnvalue = 0.0;
02461     
02462     check( uves_get_property_value(plist, UVES_CDELT2, CPL_TYPE_DOUBLE, &returnvalue), 
02463        "Error reading keyword '%s'", UVES_CDELT2);
02464     
02465   cleanup:
02466     return returnvalue;
02467 }
02468 
02469 
02470 /*---------------------------------------------------------------------------*/
02477 /*---------------------------------------------------------------------------*/
02478 void 
02479 uves_pfits_set_dpr_catg(uves_propertylist * plist, const char *catg)
02480 {
02481     check( uves_propertylist_update_string(plist, UVES_DPR_CATG, catg),
02482            "Error writing %s", UVES_DPR_CATG);
02483   cleanup:
02484     return;
02485 }
02486 
02487 /*---------------------------------------------------------------------------*/
02494 /*---------------------------------------------------------------------------*/
02495 void 
02496 uves_pfits_set_dpr_tech(uves_propertylist * plist, const char *tech)
02497 {
02498     check( uves_propertylist_update_string(plist, UVES_DPR_TECH, tech),
02499            "Error writing %s", UVES_DPR_TECH);
02500   cleanup:
02501     return;
02502 }
02503 /*---------------------------------------------------------------------------*/
02510 /*---------------------------------------------------------------------------*/
02511 void 
02512 uves_pfits_set_dpr_type(uves_propertylist * plist, const char *type)
02513 {
02514     check( uves_propertylist_update_string(plist, UVES_DPR_TYPE, type),
02515            "Error writing %s", UVES_DPR_TYPE);
02516   cleanup:
02517     return;
02518 }
02519 
02520 /*---------------------------------------------------------------------------*/
02527 /*---------------------------------------------------------------------------*/
02528 cpl_error_code 
02529 uves_pfits_set_object(uves_propertylist * plist, const char *object)
02530 {
02531     check( uves_propertylist_update_string(plist, UVES_OBJECT, object),
02532        "Error writing keyword '%s'", UVES_OBJECT);
02533     
02534   cleanup:
02535     return cpl_error_get_code();
02536 }
02537 /*---------------------------------------------------------------------------*/
02544 /*---------------------------------------------------------------------------*/
02545 cpl_error_code 
02546 uves_pfits_set_badpixcorr(uves_propertylist * plist, const char *corr)
02547 {
02548     check( uves_propertylist_update_string(plist, UVES_QC_BADPIXCORR, corr),
02549        "Error writing keyword '%s'", UVES_QC_BADPIXCORR);
02550     
02551   cleanup:
02552     return cpl_error_get_code();
02553 }
02554 
02555 /*---------------------------------------------------------------------------*/
02562 /*---------------------------------------------------------------------------*/
02563 cpl_error_code 
02564 uves_pfits_set_redlevel(uves_propertylist * plist, const char *redlevel)
02565 {
02566     check( uves_propertylist_update_string(plist, UVES_REDLEVEL, redlevel),
02567        "Error writing keyword '%s'", UVES_REDLEVEL);
02568     
02569   cleanup:
02570     return cpl_error_get_code();
02571 }
02572 
02573 /*---------------------------------------------------------------------------*/
02580 /*---------------------------------------------------------------------------*/
02581 cpl_error_code 
02582 uves_pfits_set_status(uves_propertylist * plist, const char *status)
02583 {
02584     check( uves_propertylist_update_string(plist, UVES_STATUS, status),
02585        "Error writing keyword '%s'", UVES_STATUS);
02586     
02587   cleanup:
02588     return cpl_error_get_code();
02589 }
02590 
02591 /*---------------------------------------------------------------------------*/
02598 /*---------------------------------------------------------------------------*/
02599 cpl_error_code 
02600 uves_pfits_set_starttime(uves_propertylist * plist, const char *start_time)
02601 {
02602     check( uves_propertylist_update_string(plist, UVES_START, start_time),
02603        "Error writing keyword '%s'", UVES_START);
02604     
02605   cleanup:
02606     return cpl_error_get_code();
02607 }
02608 /*---------------------------------------------------------------------------*/
02615 /*---------------------------------------------------------------------------*/
02616 cpl_error_code 
02617 uves_pfits_set_stoptime(uves_propertylist * plist, const char *stop_time)
02618 {
02619     check( uves_propertylist_update_string(plist, UVES_STOP, stop_time),
02620        "Error writing keyword '%s'", UVES_STOP);
02621     
02622   cleanup:
02623     return cpl_error_get_code();
02624 }
02625 
02626 /*---------------------------------------------------------------------------*/
02633 /*---------------------------------------------------------------------------*/
02634 cpl_error_code 
02635 uves_pfits_set_bunit(uves_propertylist * plist, const char *bunit)
02636 {
02637     check( uves_propertylist_update_string(plist, UVES_BUNIT, bunit),
02638        "Error writing keyword '%s'", UVES_BUNIT);
02639     
02640   cleanup:
02641     return cpl_error_get_code();
02642 }
02643 
02644 /*---------------------------------------------------------------------------*/
02651 /*---------------------------------------------------------------------------*/
02652 cpl_error_code 
02653 uves_pfits_set_ctype1(uves_propertylist * plist, const char *ctype1)
02654 {
02655     check( uves_propertylist_update_string(plist, UVES_CTYPE1, ctype1),
02656        "Error writing keyword '%s'", UVES_CTYPE1);
02657     
02658   cleanup:
02659     return cpl_error_get_code();
02660 }
02661 /*---------------------------------------------------------------------------*/
02668 /*---------------------------------------------------------------------------*/
02669 cpl_error_code 
02670 uves_pfits_set_ctype2(uves_propertylist * plist, const char *ctype2)
02671 {
02672     check( uves_propertylist_update_string(plist, UVES_CTYPE2, ctype2),
02673        "Error writing keyword '%s'", UVES_CTYPE2);
02674     
02675   cleanup:
02676     return cpl_error_get_code();
02677 }
02678 
02679 /*---------------------------------------------------------------------------*/
02686 /*---------------------------------------------------------------------------*/
02687 cpl_error_code 
02688 uves_pfits_set_crval1(uves_propertylist * plist, double crval1)
02689 {
02690     check( uves_propertylist_update_double(plist, UVES_CRVAL1, crval1),
02691        "Error writing keyword '%s'", UVES_CRVAL1);
02692     
02693   cleanup:
02694     return cpl_error_get_code();
02695 }
02696 
02697 /*---------------------------------------------------------------------------*/
02704 /*---------------------------------------------------------------------------*/
02705 cpl_error_code 
02706 uves_pfits_set_crval2(uves_propertylist * plist, double crval2)
02707 {
02708     check( uves_propertylist_update_double(plist, UVES_CRVAL2, crval2),
02709        "Error writing keyword '%s'", UVES_CRVAL2);
02710     
02711   cleanup:
02712     return cpl_error_get_code();
02713 }
02714 /*---------------------------------------------------------------------------*/
02721 /*---------------------------------------------------------------------------*/
02722 cpl_error_code 
02723 uves_pfits_set_crpix1(uves_propertylist * plist, double crpix1)
02724 {
02725     check( uves_propertylist_update_double(plist, UVES_CRPIX1, crpix1),
02726        "Error writing keyword '%s'", UVES_CRPIX1);
02727     
02728   cleanup:
02729     return cpl_error_get_code();
02730 }
02731 
02732 /*---------------------------------------------------------------------------*/
02739 /*---------------------------------------------------------------------------*/
02740 cpl_error_code 
02741 uves_pfits_set_crpix2(uves_propertylist * plist, double crpix2)
02742 {
02743     check( uves_propertylist_update_double(plist, UVES_CRPIX2, crpix2),
02744        "Error writing keyword '%s'", UVES_CRPIX2);
02745     
02746   cleanup:
02747     return cpl_error_get_code();
02748 }
02749 /*---------------------------------------------------------------------------*/
02756 /*---------------------------------------------------------------------------*/
02757 cpl_error_code 
02758 uves_pfits_set_cdelt1(uves_propertylist * plist, double cdelt1)
02759 {
02760     check( uves_propertylist_update_double(plist, UVES_CDELT1, cdelt1),
02761        "Error writing keyword '%s'", UVES_CDELT1);
02762     
02763   cleanup:
02764     return cpl_error_get_code();
02765 }
02766 
02767 /*---------------------------------------------------------------------------*/
02774 /*---------------------------------------------------------------------------*/
02775 void 
02776 uves_flames_pfits_set_ccfposmax(uves_propertylist *plist, double ccfposmax)
02777 {
02778     check( uves_propertylist_update_double(plist, FLAMES_CCFPOSMAX, ccfposmax),
02779        "Error writing keyword '%s'", FLAMES_CCFPOSMAX);
02780 
02781   cleanup:
02782     return;
02783 }
02784 
02785 /*---------------------------------------------------------------------------*/
02792 /*---------------------------------------------------------------------------*/
02793 cpl_error_code 
02794 uves_pfits_set_cdelt2(uves_propertylist * plist, double cdelt2)
02795 {
02796     check( uves_propertylist_update_double(plist, UVES_CDELT2, cdelt2),
02797        "Error writing keyword '%s'", UVES_CDELT2);
02798     
02799   cleanup:
02800     return cpl_error_get_code();
02801 }
02802 
02803 /*---------------------------------------------------------------------------*/
02809 /*---------------------------------------------------------------------------*/
02810 void 
02811 uves_pfits_set_hs(uves_propertylist * plist, int hs)
02812 {
02813     check( uves_propertylist_update_int(plist, UVES_HS, hs),
02814        "Error writing keyword '%s'", UVES_HS);
02815     
02816   cleanup:
02817     return;
02818 }
02819 
02820 
02821 /*---------------------------------------------------------------------------*/
02829 /*---------------------------------------------------------------------------*/
02830 cpl_error_code 
02831 uves_pfits_set_wstart(uves_propertylist * plist, int order, double wstart)
02832 {
02833     char *wstart_string = NULL;
02834 
02835     assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT, 
02836         "Illegal order number: %d. Allowed range is 1 to 99", order);
02837     
02838     /* allocate room for two digits and '\0' */
02839     wstart_string = cpl_malloc( strlen(UVES_WSTART) + 2 + 1);  
02840     assure_mem( wstart_string );
02841 
02842     snprintf(wstart_string, strlen(UVES_WSTART)+2+1, UVES_WSTART "%d", order);
02843     
02844     check( uves_propertylist_update_double(plist, wstart_string, wstart ),
02845        "Error updating product header");
02846         
02847   cleanup:
02848     cpl_free(wstart_string);
02849     return cpl_error_get_code();
02850 }
02851 
02852 
02853 /*---------------------------------------------------------------------------*/
02860 /*---------------------------------------------------------------------------*/
02861 
02862 double 
02863 uves_pfits_get_wstart(const uves_propertylist * plist, int order)
02864 {
02865     double returnvalue;
02866     char *wstart = NULL;
02867 
02868     assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT, 
02869         "Illegal order number: %d. Allowed range is 1 to 99", order);
02870     
02871     /* allocate room for two digits and '\0' */
02872     wstart = cpl_malloc( strlen(UVES_WSTART) + 2 + 1);  
02873     assure_mem( wstart );
02874     
02875     snprintf(wstart, strlen(UVES_WSTART)+2+1, UVES_WSTART "%d", order);
02876     
02877     check( uves_get_property_value(plist, wstart, CPL_TYPE_DOUBLE, &returnvalue), 
02878        "Error reading keyword '%s'", wstart);
02879     
02880   cleanup:
02881     cpl_free(wstart);
02882     return returnvalue;
02883 }
02884 /*---------------------------------------------------------------------------*/
02892 /*---------------------------------------------------------------------------*/
02893 cpl_error_code 
02894 uves_pfits_set_wend(uves_propertylist * plist, int order, double wend)
02895 {
02896     char *wend_string = NULL;
02897 
02898     assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT, 
02899         "Illegal order number: %d. Allowed range is 1 to 99", order);
02900     
02901     /* allocate room for two digits and '\0' */
02902     wend_string = cpl_malloc( strlen(UVES_WEND) + 2 + 1);  
02903     assure_mem( wend_string );
02904 
02905     snprintf(wend_string, strlen(UVES_WEND)+2+1, UVES_WEND "%d", order);
02906     
02907     check( uves_propertylist_update_double(plist, wend_string, wend ),
02908        "Error updating product header");
02909         
02910   cleanup:
02911     cpl_free(wend_string);
02912     return cpl_error_get_code();
02913 }
02914 
02915 
02916 /*---------------------------------------------------------------------------*/
02923 /*---------------------------------------------------------------------------*/
02924 
02925 double 
02926 uves_pfits_get_wend(const uves_propertylist * plist, int order)
02927 {
02928     double returnvalue;
02929     char *wend = NULL;
02930 
02931     assure (1 <= order && order <= 99, CPL_ERROR_ILLEGAL_INPUT, 
02932         "Illegal order number: %d. Allowed range is 1 to 99", order);
02933     
02934     /* allocate room for two digits and '\0' */
02935     wend = cpl_malloc( strlen(UVES_WEND) + 2 + 1);  
02936     assure_mem( wend );
02937     
02938     snprintf(wend, strlen(UVES_WEND)+2+1, UVES_WEND "%d", order);
02939     
02940     check( uves_get_property_value(plist, wend, CPL_TYPE_DOUBLE, &returnvalue), 
02941        "Error reading keyword '%s'", wend);
02942     
02943   cleanup:
02944     cpl_free(wend);
02945     return returnvalue;
02946 }
02947 
02948 /*---------------------------------------------------------------------------*/
02954 /*---------------------------------------------------------------------------*/
02955 double 
02956 uves_pfits_get_pixelscale(const uves_propertylist *plist)
02957 {
02958     double pixelscale = 0;
02959     
02960     check( uves_get_property_value(plist, UVES_PIXELSCALE, CPL_TYPE_DOUBLE, &pixelscale),
02961            "Error reading keyword '%s'", UVES_PIXELSCALE);
02962     
02963   cleanup:
02964     return pixelscale;
02965 }
02966 
02967 /*---------------------------------------------------------------------------*/
02973 /*---------------------------------------------------------------------------*/
02974 const char* 
02975 uves_pfits_get_slit1_name(const uves_propertylist * plist)
02976 {
02977     const char* returnvalue = "";
02978     
02979     check( uves_get_property_value(plist, UVES_SLIT1NAME, CPL_TYPE_STRING, &returnvalue), 
02980        "Error reading keyword '%s'", UVES_SLIT1NAME);
02981     
02982   cleanup:
02983     return returnvalue;
02984 }
02985 
02986 
02987 /*---------------------------------------------------------------------------*/
02997 /*---------------------------------------------------------------------------*/
02998 
02999 double 
03000 uves_pfits_get_slitlength_pixels(const uves_propertylist * plist, 
03001                                  enum uves_chip chip)
03002 {
03003     double slitlength_pixels = 0;         /* Result */
03004     
03005     const char *slicer_name = "";
03006     double slitlength_arcsecs = 0;        /* Slit length in arc-seconds */
03007 
03008     check( slicer_name = uves_pfits_get_slit1_name(plist),
03009        "Could not read slicer id");
03010 
03011     if ( strncmp(slicer_name, "FREE", 4) != 0)
03012     {
03013         /* Slicer inserted */
03014         if      (strncmp(slicer_name, "SLIC#1", 6) == 0) slitlength_arcsecs = 8.0;
03015         else if (strncmp(slicer_name, "SLIC#2", 6) == 0) slitlength_arcsecs = 8.0;
03016         else if (strncmp(slicer_name, "SLIC#3", 6) == 0) slitlength_arcsecs = 10.0;
03017         else
03018         {
03019             assure( false, CPL_ERROR_ILLEGAL_INPUT, "Unrecognized slicer name: '%s'. "
03020                 "Recognized names are 'FREE', 'SLIC#1', 'SLIC#2', 'SLIC#3'.", 
03021                 slicer_name);
03022         }
03023     }
03024     else
03025     {
03026         /*  slicer_name = 'FREE', no slicer */
03027 
03028         check( uves_get_property_value(
03029                plist, UVES_SLITLENGTH(chip), CPL_TYPE_DOUBLE, &slitlength_arcsecs),
03030            "Error reading keyword '%s'", UVES_SLITLENGTH(chip));
03031     }
03032 
03033     /* Convert from arcseconds to pixels */
03034     {
03035     double pixelscale;         /* Arcseconds per pixel */
03036     int binx;                  /* The x-binning of the raw image 
03037                       is the y-binning of the extracted/rotated image */
03038     
03039     check_nomsg( pixelscale = uves_pfits_get_pixelscale(plist) );
03040 
03041     check( binx = uves_pfits_get_binx(plist),
03042            "Could not get x-binning");
03043 
03044     slitlength_pixels = slitlength_arcsecs / (pixelscale * binx);
03045     }
03046     
03047   cleanup:
03048     return slitlength_pixels;
03049 }
03050 
03051 
03052 /*---------------------------------------------------------------------------*/
03058 /*---------------------------------------------------------------------------*/
03059 int
03060 uves_flames_pfits_get_plateid(const uves_propertylist *raw_header)
03061 {
03062     int plate_no;
03063     
03064     if (uves_propertylist_contains(raw_header,
03065                   FLAMES_NEWPLATEID))
03066     {
03067         check( uves_get_property_value(raw_header, FLAMES_NEWPLATEID, 
03068                        CPL_TYPE_INT, &plate_no), 
03069            "Error reading keyword '%s'", FLAMES_NEWPLATEID);
03070     }
03071     else if(uves_propertylist_contains(raw_header, 
03072                       FLAMES_OBS_PLATE_ID))
03073     {
03074         check( uves_get_property_value(raw_header, FLAMES_OBS_PLATE_ID, 
03075                        CPL_TYPE_INT, &plate_no),
03076            "Error reading keyword '%s'", FLAMES_NEWPLATEID);
03077     }
03078     else if (uves_propertylist_contains(raw_header,
03079                        FLAMES_INS_SHUT09))
03080     {
03081         plate_no = 1;
03082     }
03083     else if (uves_propertylist_contains(raw_header,
03084                        FLAMES_INS_SHUT10))
03085     {
03086         plate_no = 2;
03087     }
03088     else
03089     {
03090         plate_no = 0;
03091         uves_msg_warning("Missing raw header keywords %s, %s, %s and %s, "
03092                  "setting plate number = %d",
03093                  FLAMES_NEWPLATEID, 
03094                  FLAMES_OBS_PLATE_ID,
03095                  FLAMES_INS_SHUT09,
03096                  FLAMES_INS_SHUT10,
03097                  plate_no);
03098     }
03099     
03100   cleanup:
03101     return plate_no;
03102 }
03103 
03104 
03105 /*---------------------------------------------------------------------------*/
03111 /*---------------------------------------------------------------------------*/
03112 double 
03113 uves_flames_pfits_get_dit(const uves_propertylist * plist)
03114 {
03115     double returnvalue = 0;
03116     
03117     check( uves_get_property_value(plist, FLAMES_DIT, CPL_TYPE_DOUBLE, &returnvalue), 
03118        "Error reading keyword '%s'", FLAMES_DIT);
03119     
03120   cleanup:
03121     return returnvalue;
03122 }
03123 
03124 /*---------------------------------------------------------------------------*/
03130 /*---------------------------------------------------------------------------*/
03131 void
03132 uves_flames_pfits_set_newplateid(uves_propertylist * plist, int plate_no)
03133 {
03134     check( uves_propertylist_update_int(plist, FLAMES_NEWPLATEID, plate_no),
03135        "Error writing keyword '%s'", FLAMES_NEWPLATEID);
03136   cleanup:
03137     return;
03138 }
03139 

Generated on Fri Apr 18 14:11:42 2008 for UVES Pipeline Reference Manual by  doxygen 1.5.1