vircam_pfits.c

00001 /* $Id: vircam_pfits.c,v 1.26 2007/11/22 12:35:33 jim Exp $
00002  *
00003  * This file is part of the VIRCAM Pipeline
00004  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: jim $
00023  * $Date: 2007/11/22 12:35:33 $
00024  * $Revision: 1.26 $
00025  * $Name:  $
00026  */
00027 
00028 /* Includes */
00029 
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033 
00034 #include <cpl.h>
00035 #include <string.h>
00036 
00037 #include "vircam_utils.h"
00038 #include "vircam_pfits.h"
00039 
00040 static int vircam_pfits_get_float(const cpl_propertylist *plist, 
00041                                   const char *key, float *fval);
00042 static int vircam_pfits_get_double(const cpl_propertylist *plist, 
00043                                    const char *key, double *fval);
00044 
00058 /*---------------------------------------------------------------------------*/
00066 /*---------------------------------------------------------------------------*/
00067 
00068 extern int vircam_pfits_get_crval1(const cpl_propertylist *plist, 
00069                                    double *crval1) {
00070 
00071     return(vircam_pfits_get_double(plist,"CRVAL1",crval1));
00072 
00073 }
00074 
00075 /*---------------------------------------------------------------------------*/
00083 /*---------------------------------------------------------------------------*/
00084 
00085 extern int vircam_pfits_get_crpix1(const cpl_propertylist *plist, 
00086                                    double *crpix1) {
00087 
00088     return(vircam_pfits_get_double(plist,"CRPIX1",crpix1));
00089 
00090 }
00091 
00092 /*---------------------------------------------------------------------------*/
00099 /*---------------------------------------------------------------------------*/
00100 
00101 extern int vircam_pfits_get_crval2(const cpl_propertylist *plist, 
00102                                    double *crval2) {
00103 
00104     return(vircam_pfits_get_double(plist,"CRVAL2",crval2));
00105 
00106 }
00107 
00108 /*---------------------------------------------------------------------------*/
00115 /*---------------------------------------------------------------------------*/
00116 
00117 extern int vircam_pfits_get_crpix2(const cpl_propertylist *plist, 
00118                                    double *crpix2) {
00119 
00120     return(vircam_pfits_get_double(plist,"CRPIX2",crpix2));
00121 }
00122 
00123 /*---------------------------------------------------------------------------*/
00130 /*---------------------------------------------------------------------------*/
00131 
00132 extern int vircam_pfits_get_cd11(const cpl_propertylist *plist, double *cd11) {
00133 
00134     return(vircam_pfits_get_double(plist,"CD1_1",cd11));
00135 }
00136 
00137 /*---------------------------------------------------------------------------*/
00144 /*---------------------------------------------------------------------------*/
00145 
00146 extern int vircam_pfits_get_cd12(const cpl_propertylist *plist, double *cd12) {
00147 
00148     return(vircam_pfits_get_double(plist,"CD1_2",cd12));
00149 
00150 }
00151 
00152 /*---------------------------------------------------------------------------*/
00159 /*---------------------------------------------------------------------------*/
00160 
00161 extern int vircam_pfits_get_cd21(const cpl_propertylist *plist, double *cd21) {
00162 
00163     return(vircam_pfits_get_double(plist,"CD2_1",cd21));
00164 }
00165 
00166 /*---------------------------------------------------------------------------*/
00173 /*---------------------------------------------------------------------------*/
00174 
00175 extern int vircam_pfits_get_cd22(const cpl_propertylist *plist, double *cd22) {
00176 
00177     return(vircam_pfits_get_double(plist,"CD2_2",cd22));
00178 
00179 }
00180 
00181 /*---------------------------------------------------------------------------*/
00188 /*---------------------------------------------------------------------------*/
00189 
00190 extern int vircam_pfits_get_pv21(const cpl_propertylist *plist, double *pv21) {
00191 
00192     return(vircam_pfits_get_double(plist,"PV2_1",pv21));
00193 
00194 }
00195 
00196 /*---------------------------------------------------------------------------*/
00203 /*---------------------------------------------------------------------------*/
00204 
00205 extern int vircam_pfits_get_pv23(const cpl_propertylist *plist, double *pv23) {
00206 
00207     return(vircam_pfits_get_double(plist,"PV2_3",pv23));
00208 
00209 }
00210 
00211 /*---------------------------------------------------------------------------*/
00218 /*---------------------------------------------------------------------------*/
00219 
00220 extern int vircam_pfits_get_exptime(const cpl_propertylist *plist, 
00221                                     float *exptime) {
00222 
00223     return(vircam_pfits_get_float(plist,"EXPTIME",exptime));
00224 
00225 }
00226 
00227 /*---------------------------------------------------------------------------*/
00234 /*---------------------------------------------------------------------------*/
00235 
00236 extern int vircam_pfits_get_mindit(const cpl_propertylist *plist, 
00237                                    float *mindit) {
00238 
00239     return(vircam_pfits_get_float(plist,"ESO DET MINDIT",mindit));
00240 
00241 }
00242 
00243 /*---------------------------------------------------------------------------*/
00250 /*---------------------------------------------------------------------------*/
00251 
00252 extern int vircam_pfits_get_ditdelay(const cpl_propertylist *plist, 
00253                                      float *ditdelay) {
00254 
00255     return(vircam_pfits_get_float(plist,"ESO DET DITDELAY",ditdelay));
00256 
00257 }
00258 
00259 /*---------------------------------------------------------------------------*/
00266 /*---------------------------------------------------------------------------*/
00267 
00268 extern int vircam_pfits_get_naxis1(const cpl_propertylist *plist, 
00269                                    long *naxis1) {
00270     int val;
00271 
00272     val = cpl_propertylist_get_int(plist,"NAXIS1");
00273     if (cpl_error_get_code() == CPL_ERROR_NONE) {
00274         *naxis1 = (long)val;
00275         return(VIR_OK);
00276     } else {
00277         cpl_error_reset();
00278         *naxis1 = 0;
00279         return(VIR_FATAL);
00280     }
00281 }
00282 
00283 /*---------------------------------------------------------------------------*/
00290 /*---------------------------------------------------------------------------*/
00291 
00292 extern int vircam_pfits_get_naxis2(const cpl_propertylist *plist, 
00293                                    long *naxis2) {
00294     int val;
00295 
00296     val = cpl_propertylist_get_int(plist,"NAXIS2");
00297     if (cpl_error_get_code() == CPL_ERROR_NONE) {
00298         *naxis2 = (long)val;
00299         return(VIR_OK);
00300     } else {
00301         cpl_error_reset();
00302         *naxis2 = 0;
00303         return(VIR_FATAL);
00304     }
00305 }
00306 
00307 /*---------------------------------------------------------------------------*/
00314 /*---------------------------------------------------------------------------*/
00315 
00316 extern int vircam_pfits_get_chipno(const cpl_propertylist *plist, 
00317                                    int *chipno) {
00318     int val;
00319 
00320     val = cpl_propertylist_get_int(plist,"ESO DET CHIP NO");
00321     if (cpl_error_get_code() == CPL_ERROR_NONE) {
00322         *chipno = val;
00323         return(VIR_OK);
00324     } else {
00325         cpl_error_reset();
00326         *chipno = 0;
00327         return(VIR_FATAL);
00328     }
00329 }
00330 
00331 /*---------------------------------------------------------------------------*/
00338 /*---------------------------------------------------------------------------*/
00339 
00340 extern int vircam_pfits_get_jxoff(const cpl_propertylist *plist, 
00341                                   float *xoff) {
00342 
00343     return(vircam_pfits_get_float(plist,"ESO DRS XOFFDITHER",xoff));
00344 
00345 }
00346 
00347 /*---------------------------------------------------------------------------*/
00354 /*---------------------------------------------------------------------------*/
00355 
00356 extern int vircam_pfits_get_jyoff(const cpl_propertylist *plist, 
00357                                   float *yoff) {
00358 
00359     return(vircam_pfits_get_float(plist,"ESO DRS YOFFDITHER",yoff));
00360 
00361 }
00362 
00363 /*---------------------------------------------------------------------------*/
00370 /*---------------------------------------------------------------------------*/
00371 
00372 extern int vircam_pfits_get_airmass(const cpl_propertylist *plist, 
00373                                     float *airmass) {
00374 
00375     return(vircam_pfits_get_float(plist,"ESO TEL AIRM START",airmass));
00376 
00377 }
00378 
00379 /*---------------------------------------------------------------------------*/
00386 /*---------------------------------------------------------------------------*/
00387 
00388 extern int vircam_pfits_get_nusteps(const cpl_propertylist *plist, 
00389                                     int *nusteps) {
00390     int val;
00391 
00392     val = cpl_propertylist_get_int(plist,"NUSTEP");
00393     if (cpl_error_get_code() == CPL_ERROR_NONE) {
00394         *nusteps = val;
00395         return(VIR_OK);
00396     } else {
00397         cpl_error_reset();
00398         *nusteps = 0;
00399         return(VIR_FATAL);
00400     }
00401 
00402 }
00403 
00404 /*---------------------------------------------------------------------------*/
00412 /*---------------------------------------------------------------------------*/
00413 
00414 extern int vircam_pfits_get_ustepnum(const cpl_propertylist *plist, 
00415                                      int *ustepnum) {
00416     int val;
00417 
00418     val = cpl_propertylist_get_int(plist,"USTEPNUM");
00419     if (cpl_error_get_code() == CPL_ERROR_NONE) {
00420         *ustepnum = val;
00421         return(VIR_OK);
00422     } else {
00423         cpl_error_reset();
00424         *ustepnum = 0;
00425         return(VIR_FATAL);
00426     }
00427 
00428 }
00429 
00430 /*---------------------------------------------------------------------------*/
00438 /*---------------------------------------------------------------------------*/
00439 
00440 extern int vircam_pfits_get_jitternum(const cpl_propertylist *plist, 
00441                                       int *jitternum) {
00442     int val;
00443 
00444     val = cpl_propertylist_get_int(plist,"JITTRNUM");
00445     if (cpl_error_get_code() == CPL_ERROR_NONE) {
00446         *jitternum = val;
00447         return(VIR_OK);
00448     } else {
00449         cpl_error_reset();
00450         *jitternum = 0;
00451         return(VIR_FATAL);
00452     }
00453 
00454 }
00455 
00456 /*---------------------------------------------------------------------------*/
00463 /*---------------------------------------------------------------------------*/
00464 
00465 extern int vircam_pfits_get_ndit(const cpl_propertylist *plist, 
00466                                  int *ndit) {
00467     int val;
00468 
00469     val = cpl_propertylist_get_int(plist,"ESO DET NDIT");
00470     if (cpl_error_get_code() == CPL_ERROR_NONE) {
00471         *ndit = val;
00472         return(VIR_OK);
00473     } else {
00474         cpl_error_reset();
00475         *ndit = 1;
00476         return(VIR_FATAL);
00477     }
00478 }
00479 
00480 /*---------------------------------------------------------------------------*/
00487 /*---------------------------------------------------------------------------*/
00488 
00489 extern int vircam_pfits_get_detlive(const cpl_propertylist *plist, 
00490                                     int *detlive) {
00491     int val;
00492 
00493     val = cpl_propertylist_get_bool(plist,"ESO DET CHIP LIVE");
00494     if (cpl_error_get_code() == CPL_ERROR_NONE) {
00495         *detlive = val;
00496         return(VIR_OK);
00497     } else {
00498         cpl_error_reset();
00499         *detlive = 1;
00500         return(VIR_FATAL);
00501     }
00502 }
00503 
00504 /*---------------------------------------------------------------------------*/
00511 /*---------------------------------------------------------------------------*/
00512 
00513 extern int vircam_pfits_get_filter(const cpl_propertylist *plist, char *filt) {
00514 
00515     strcpy(filt,cpl_propertylist_get_string(plist,"ESO INS FILT1 NAME"));
00516     if (cpl_error_get_code() == CPL_ERROR_NONE) {
00517         return(VIR_OK);
00518     } else {
00519         cpl_error_reset();
00520         return(VIR_FATAL);
00521     }
00522 }
00523 
00524 /*---------------------------------------------------------------------------*/
00531 /*---------------------------------------------------------------------------*/
00532 
00533 extern int vircam_pfits_get_saturation(const cpl_propertylist *plist, 
00534                                        float *saturation) {
00535     int ival;
00536 
00537     ival = cpl_propertylist_get_int(plist,"ESO DET SATURATION");
00538     if (cpl_error_get_code() == CPL_ERROR_NONE) {
00539         *saturation = (float)ival;
00540         return(VIR_OK);
00541     } else {
00542         cpl_error_reset();
00543         *saturation = 65535.0;
00544         return(VIR_FATAL);
00545     }
00546 
00547 
00548 }
00549 
00550 /*---------------------------------------------------------------------------*/
00557 /*---------------------------------------------------------------------------*/
00558 
00559 extern int vircam_pfits_get_gain(const cpl_propertylist *plist, float *gain) {
00560 
00561     return(vircam_pfits_get_float(plist,"ESO DRS GAIN",gain));
00562 
00563 }
00564 
00565 /*---------------------------------------------------------------------------*/
00572 /*---------------------------------------------------------------------------*/
00573 
00574 extern int vircam_pfits_get_mjd(const cpl_propertylist *plist, double *mjd) {
00575 
00576     return(vircam_pfits_get_double(plist,"MJD-OBS",mjd));
00577 
00578 }
00579 
00580 /*---------------------------------------------------------------------------*/
00589 /*---------------------------------------------------------------------------*/
00590 
00591 static int vircam_pfits_get_float(const cpl_propertylist *plist, 
00592                                   const char *key, float *fval) {
00593     cpl_type type;
00594     const char *fctid = "vircam_pfits_get_float";
00595 
00596     /* Get the type of this keyword */
00597 
00598     type = cpl_propertylist_get_type(plist,key);
00599     if (cpl_error_get_code() != CPL_ERROR_NONE) {
00600         *fval = 0.0;
00601         cpl_error_reset();
00602         return(VIR_FATAL);
00603     }
00604 
00605     /* Switch of the property type */
00606 
00607     switch (type) {
00608     case CPL_TYPE_FLOAT:
00609         *fval = cpl_propertylist_get_float(plist,key);
00610         break;
00611     case CPL_TYPE_DOUBLE:
00612         *fval = (float)cpl_propertylist_get_double(plist,key);
00613         break;
00614     default:
00615         *fval = 0.0;
00616         cpl_msg_error(fctid,"Keyword %s is not floating point in header",key);
00617         return(VIR_FATAL);
00618     }
00619     return(VIR_OK);
00620 }
00621 
00622 /*---------------------------------------------------------------------------*/
00631 /*---------------------------------------------------------------------------*/
00632 
00633 static int vircam_pfits_get_double(const cpl_propertylist *plist, 
00634                                    const char *key, double *fval) {
00635     cpl_type type;
00636     const char *fctid = "vircam_pfits_get_float";
00637 
00638     /* Get the type of this keyword */
00639 
00640     type = cpl_propertylist_get_type(plist,key);
00641     if (cpl_error_get_code() != CPL_ERROR_NONE) {
00642         *fval = 0.0;
00643         cpl_error_reset();
00644         return(VIR_FATAL);
00645     }
00646 
00647     /* Switch of the property type */
00648 
00649     switch (type) {
00650     case CPL_TYPE_FLOAT:
00651         *fval = (double)cpl_propertylist_get_float(plist,key);
00652         break;
00653     case CPL_TYPE_DOUBLE:
00654         *fval = cpl_propertylist_get_double(plist,key);
00655         break;
00656     default:
00657         *fval = 0.0;
00658         cpl_msg_error(fctid,"Keyword %s is not floating point in header",key);
00659         return(VIR_FATAL);
00660     }
00661     return(VIR_OK);
00662 }
00663 
00666 /* 
00667 
00668 $Log: vircam_pfits.c,v $
00669 Revision 1.26  2007/11/22 12:35:33  jim
00670 Modified vircam_pfits_get_saturation so that the value of the
00671 saturation is read as an integer, but passed back as a float
00672 
00673 Revision 1.25  2007/11/20 09:39:39  jim
00674 added vircam_pfits_get_mjd
00675 
00676 Revision 1.24  2007/11/14 10:45:23  jim
00677 Added vircam_pfits_get_saturation
00678 
00679 Revision 1.23  2007/10/25 17:34:01  jim
00680 Modified to remove lint warnings
00681 
00682 Revision 1.22  2007/10/19 09:25:10  jim
00683 Fixed problems with missing includes
00684 
00685 Revision 1.21  2007/03/23 10:53:22  jim
00686 Fixed little documentation errors
00687 
00688 Revision 1.20  2007/03/01 12:42:42  jim
00689 Modified slightly after code checking
00690 
00691 Revision 1.19  2006/07/17 09:33:00  jim
00692 Changed keyword for detlive routine
00693 
00694 Revision 1.18  2006/07/11 14:52:13  jim
00695 Added vircam_pfits_get_detlive
00696 
00697 Revision 1.17  2006/06/20 19:00:06  jim
00698 Added vircam_pfits_get_ndit
00699 
00700 Revision 1.16  2006/06/13 14:08:12  jim
00701 Added vircam_pfits_get_gain
00702 
00703 Revision 1.15  2006/06/09 11:26:26  jim
00704 Small changes to keep lint happy
00705 
00706 Revision 1.14  2006/05/24 13:35:23  jim
00707 Added _get_nusteps, _get_ustepnum, _get_jitternum and _get_filter
00708 
00709 Revision 1.13  2006/05/17 12:05:48  jim
00710 Add vircam_pfits_get_airmass
00711 
00712 Revision 1.12  2006/05/15 13:15:11  jim
00713 Added vircam_pfits_j[x,y]off
00714 
00715 Revision 1.11  2006/04/21 15:17:48  jim
00716 Added vircam_pfits_get_float and vircam_pfits_get_double static routines
00717 
00718 Revision 1.10  2006/03/01 10:59:25  jim
00719 Added vircam_pfits_get_ditdelay
00720 
00721 Revision 1.9  2006/02/18 11:48:03  jim
00722 added routines to get mindit and chip number
00723 
00724 Revision 1.8  2006/01/23 10:30:49  jim
00725 Mainly documentation mods
00726 
00727 Revision 1.7  2005/12/14 22:17:33  jim
00728 Updated docs
00729 
00730 Revision 1.6  2005/11/25 15:33:22  jim
00731 Some code fixes to keep splint happy
00732 
00733 Revision 1.5  2005/11/25 09:56:15  jim
00734 Tidied up some more documentation
00735 
00736 Revision 1.4  2005/11/07 13:15:16  jim
00737 Fixed lots of bugs and added some error checking
00738 
00739 Revision 1.3  2005/11/07 11:23:41  jim
00740 fixed call to cpl_error_get_code
00741 
00742 Revision 1.2  2005/11/03 13:28:50  jim
00743 All sorts of changes to tighten up error handling
00744 
00745 Revision 1.1.1.1  2005/08/05 08:29:09  jim
00746 Initial import
00747 
00748 
00749 */

Generated on Wed Apr 10 04:01:56 2013 for VIRCAM Pipeline by  doxygen 1.5.1