sinfo_pfits.c

00001 /* $Id: sinfo_pfits.c,v 1.6 2006/12/28 14:43:11 amodigli Exp $
00002  *
00003  * This file is part of the SINFONI Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
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: amodigli $
00023  * $Date: 2006/12/28 14:43:11 $
00024  * $Revision: 1.6 $
00025  * $Name:  $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #  include <config.h>
00030 #endif
00031 /*----------------------------------------------------------------------------
00032                                 Includes
00033  ----------------------------------------------------------------------------*/
00034 #include <ctype.h>
00035 #include <cpl.h>
00036 #include "sinfo_pfits.h"
00037 #include "sinfo_key_names.h"
00038 #include "sinfo_utils_wrappers.h"
00039 #include "sinfo_msg.h"
00040 #include <string.h>
00041 
00042 /*---------------------------------------------------------------------------*/
00043 #define ASCIILINESZ                         1024
00044 #define PAF_MAGIC_SZ               13
00045 #define PAF_MAGIC       "PAF.HDR.START"
00046 
00047 /*-----------------------------------------------------------------------------
00048                             Function codes
00049  ----------------------------------------------------------------------------*/
00050 char * sinfo_paf_query(
00051         char    *   filename,
00052         char    *   key) ;
00053 
00054 static int sinfo_is_paf_file(char * filename) ;
00055 
00056 static char * sinfo_strcrop(char * s);
00057 
00058 
00067 /*---------------------------------------------------------------------------*/
00080 /*---------------------------------------------------------------------------*/
00081 static char * sinfo_strcrop(char * s)
00082 {
00083     static char l[ASCIILINESZ+1];
00084     char * last ;
00085 
00086     if (s==NULL) return NULL ;
00087     memset(l, 0, ASCIILINESZ+1);
00088     strcpy(l, s);
00089     last = l + strlen(l);
00090     while (last > l) {
00091         if (!isspace((int)*(last-1)))
00092             break ;
00093         last -- ;
00094     }
00095     *last = (char)0;
00096     return l ;
00097 }
00098 
00099 
00100 /*---------------------------------------------------------------------------*/
00113 /*---------------------------------------------------------------------------*/
00114 char * sinfo_paf_query(
00115         char    *   filename, 
00116         char    *   key)
00117 {
00118     static char value[ASCIILINESZ];
00119     FILE    *   paf ;
00120     char        line[ASCIILINESZ+1];
00121     char        val[ASCIILINESZ+1];
00122     char        head[ASCIILINESZ+1];
00123     int         found ;
00124     int         len ;
00125 
00126     /* Check inputs */
00127     if (filename==NULL || key==NULL) return NULL ;
00128 
00129     /* Check PAF validity */
00130     if (sinfo_is_paf_file(filename)!=1) {
00131         sinfo_msg_error("not a PAF file: [%s]", filename);
00132         return NULL ;
00133     }
00134 
00135     /* Open file and read it */
00136     paf = fopen(filename, "r");
00137     if (paf==NULL) {
00138         sinfo_msg_error("opening [%s]", filename);
00139         return NULL ;
00140     }
00141     
00142     found = 0 ;
00143     while (fgets(line, ASCIILINESZ, paf)!=NULL) {
00144         sscanf(line, "%[^ ]", head);
00145         if (!strcmp(head, key)) {
00146             /* Get value */
00147             sscanf(line, "%*[^ ] %[^;]", value);
00148             found ++ ;
00149             break ;
00150         }
00151     }
00152     if (!found) return NULL ;
00153     
00154     /* Remove trailing blanks */
00155     strcpy(val, sinfo_strcrop(value));
00156     /* Get rid of possible quotes */
00157     len = strlen(val);
00158     if (val[0]=='\"' && val[len-1]=='\"') {
00159         strncpy(value, val+1, len-2);
00160         value[len-2]=(char)0;
00161     } else {
00162         strcpy(value, val);
00163     }
00164     return value ;
00165 }
00166 
00167 /*---------------------------------------------------------------------------*/
00176 /*---------------------------------------------------------------------------*/
00177 static int sinfo_is_paf_file(char * filename)
00178 {
00179     FILE    *   fp ;
00180     int         is_paf ;
00181     char        line[ASCIILINESZ] ;
00182     
00183     if (filename==NULL) return -1 ;
00184 
00185     /* Initialize is_paf */
00186     is_paf = 0 ;
00187 
00188     /* Open file */
00189     if ((fp = fopen(filename, "r"))==NULL) {
00190         sinfo_msg_error("cannot open file [%s]", filename) ;
00191         return -1 ;
00192     }
00193 
00194     /* Parse file */
00195     while (fgets(line, ASCIILINESZ, fp) != NULL) {
00196         if (line[0] != '#') {
00197            if (!strncmp(line, PAF_MAGIC, PAF_MAGIC_SZ)) is_paf = 1 ;
00198              (void)fclose(fp) ;
00199             return is_paf ;
00200         }
00201     }
00202 
00203     (void)fclose(fp) ;
00204     return is_paf ;
00205 }
00206 
00207 /*---------------------------------------------------------------------------*/
00213 /*---------------------------------------------------------------------------*/
00214 char * sinfo_pfits_get_mode(const cpl_propertylist * plist)
00215 {
00216 
00217    return (char*) cpl_propertylist_get_string(plist,"ESO DET MODE NAME");
00218   
00219 }
00220 
00221 /*---------------------------------------------------------------------------*/
00227 /*---------------------------------------------------------------------------*/
00228 double sinfo_pfits_get_exp_time(const cpl_propertylist* plist)
00229 {
00230   
00231     return cpl_propertylist_get_double(plist,"EXPTIME");
00232 
00233 }
00234 
00235 
00236 
00237 
00238 
00239 /*----------------------------------------------------------------------------
00240    Function     :       sinfo_pfits_get_ditndit()
00241    In           :       fits file name
00242    Out          :       total integration time in sec
00243    Job          :       reads the product dit*ndit from the FITS-header 
00244  ---------------------------------------------------------------------------*/
00245 double sinfo_pfits_get_ditndit(const char* name)
00246 {
00247   double dit;
00248   int ndit=0;
00249   cpl_propertylist* plist=NULL;
00250   plist=cpl_propertylist_load(name,0);
00251 
00252   dit = cpl_propertylist_get_double(plist,"ESO DET DIT");
00253   ndit = cpl_propertylist_get_int(plist,"ESO DET NDIT");
00254   sinfo_free_propertylist(&plist);
00255   return dit*ndit ;
00256 
00257 }
00258 
00259 
00260 /*---------------------------------------------------------------------------*/
00266 /*---------------------------------------------------------------------------*/
00267 double sinfo_pfits_get_exptime(const char * filename)
00268 {
00269     double exptime ;
00270     cpl_propertylist* plist=NULL;
00271     plist=cpl_propertylist_load(filename,0);
00272     exptime = cpl_propertylist_get_double(plist,"EXPTIME");
00273     sinfo_free_propertylist(&plist);
00274     
00275     return exptime;
00276 }
00277 
00278 
00279 
00280 
00281 /*---------------------------------------------------------------------------*/
00287 /*---------------------------------------------------------------------------*/
00288 int sinfo_pfits_get_rom(const cpl_propertylist * plist)
00289 {
00290 
00291     return  cpl_propertylist_get_int(plist,"ESO DET NCORRS");
00292 
00293 }
00294 
00295 /*---------------------------------------------------------------------------*/
00301 /*---------------------------------------------------------------------------*/
00302 int sinfo_pfits_get_expno(const cpl_propertylist * plist)
00303 {
00304     
00305    return cpl_propertylist_get_int(plist,"ESO TPL EXPNO");
00306 
00307 }
00308 
00309 
00310 /*---------------------------------------------------------------------------*/
00316 /*---------------------------------------------------------------------------*/
00317 double sinfo_pfits_get_airmass_start(const cpl_propertylist * plist)
00318 {
00319 
00320     return cpl_propertylist_get_double(plist,"ESO TEL AIRM START");
00321 
00322 }
00323 
00324 /*---------------------------------------------------------------------------*/
00330 /*---------------------------------------------------------------------------*/
00331 double sinfo_pfits_get_airmass_end(const cpl_propertylist * plist)
00332 {
00333     return cpl_propertylist_get_double(plist,"ESO TEL AIRM END");
00334 
00335 }
00336 
00337 /*---------------------------------------------------------------------------*/
00343 /*---------------------------------------------------------------------------*/
00344 double sinfo_pfits_get_alpha(const cpl_propertylist * plist)
00345 {
00346   return cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETALPHA");
00347 }
00348 
00349 
00350 /*---------------------------------------------------------------------------*/
00356 /*---------------------------------------------------------------------------*/
00357 const char * sinfo_pfits_get_arcfile(const cpl_propertylist * plist)
00358 {
00359     return (const char*) cpl_propertylist_get_string(plist,KEY_NAME_ARCFILE);
00360 }
00361 
00362 /*---------------------------------------------------------------------------*/
00368 /*---------------------------------------------------------------------------*/
00369 const char * sinfo_pfits_get_rec1raw1name(const cpl_propertylist * plist)
00370 {
00371     return (const char*) cpl_propertylist_get_string(plist,
00372                                                   KEY_NAME_PRO_REC1_RAW1_NAME);
00373 }
00374 
00375 /*---------------------------------------------------------------------------*/
00381 /*---------------------------------------------------------------------------*/
00382 const char * sinfo_pfits_get_ins_setup(const cpl_propertylist * plist)
00383 {
00384   if(cpl_propertylist_get_string(plist,"ESO INS SETUP ID")) {
00385     return (const char*) cpl_propertylist_get_string(plist,"ESO INS SETUP ID");
00386   } else {
00387     cpl_error_reset();
00388     return "Dark";
00389   }
00390 
00391 }
00392 
00393 
00394 
00395 /*---------------------------------------------------------------------------*/
00401 /*---------------------------------------------------------------------------*/
00402 double sinfo_pfits_get_wlen(const cpl_propertylist * plist)
00403 {
00404 
00405     return cpl_propertylist_get_double(plist,"ESO INS GRAT1 WLEN");
00406 }
00407 
00408 /*---------------------------------------------------------------------------*/
00414 /*---------------------------------------------------------------------------*/
00415 int sinfo_pfits_get_chop_ncycles(const cpl_propertylist * plist)
00416 {
00417 
00418     return cpl_propertylist_get_int(plist,"ESO DET CHOP NCYCLES");
00419 
00420 }
00421 
00422 /*---------------------------------------------------------------------------*/
00428 /*---------------------------------------------------------------------------*/
00429 double sinfo_pfits_get_pixscale(const cpl_propertylist * plist)
00430 {
00431   const char* val=NULL;
00432   val=cpl_propertylist_get_string(plist,"ESO INS OPTI1 NAME");
00433   return atof(val);
00434 }
00435 
00436 /*---------------------------------------------------------------------------*/
00442 /*---------------------------------------------------------------------------*/
00443 double sinfo_pfits_get_posangle(const cpl_propertylist * plist)
00444 {
00445     return cpl_propertylist_get_double(plist,"ESO ADA POSANG");
00446 }
00447 
00448 /*---------------------------------------------------------------------------*/
00454 /*---------------------------------------------------------------------------*/
00455 double sinfo_pfits_get_DEC(const cpl_propertylist * plist)
00456 {
00457     return cpl_propertylist_get_double(plist,"DEC");
00458 }
00459 
00460 
00461 /*---------------------------------------------------------------------------*/
00467 /*---------------------------------------------------------------------------*/
00468 double sinfo_pfits_get_cumoffsetx(const cpl_propertylist * plist)
00469 {
00470     return cpl_propertylist_get_double(plist,"ESO SEQ CUMOFFSETX");
00471 }
00472 
00473 /*---------------------------------------------------------------------------*/
00479 /*---------------------------------------------------------------------------*/
00480 double sinfo_pfits_get_cumoffsety(const cpl_propertylist * plist)
00481 {
00482     return cpl_propertylist_get_double(plist,"ESO SEQ CUMOFFSETY");
00483 }
00484 
00485 /*---------------------------------------------------------------------------*/
00491 /*---------------------------------------------------------------------------*/
00492 const char * sinfo_pfits_get_date_obs(const cpl_propertylist * plist)
00493 {
00494 
00495     return (const char*) cpl_propertylist_get_string(plist,"DATE-OBS");
00496 
00497 }
00498         
00499 /*---------------------------------------------------------------------------*/
00505 /*---------------------------------------------------------------------------*/
00506 double  sinfo_pfits_get_delta(const cpl_propertylist * plist)
00507 {
00508 
00509     return cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETDELTA");
00510 
00511 }
00512 
00513 /*---------------------------------------------------------------------------*/
00519 /*---------------------------------------------------------------------------*/
00520 double  sinfo_pfits_get_dec(const cpl_propertylist * plist)
00521 {
00522     return cpl_propertylist_get_double(plist,"DEC");
00523 }
00524 
00525 /*---------------------------------------------------------------------------*/
00532 /*---------------------------------------------------------------------------*/
00533 double sinfo_pfits_get_dit(const cpl_propertylist * plist)
00534 {
00535     return cpl_propertylist_get_double(plist,"ESO DET DIT");
00536 }
00537 /*---------------------------------------------------------------------------*/
00543 /*---------------------------------------------------------------------------*/
00544 float sinfo_pfits_get_pixelscale(const char * name)
00545 {
00546   cpl_propertylist* plist=NULL;
00547   float pixscale=0;
00548   const char* scale=NULL;
00549   plist=cpl_propertylist_load(name,0);
00550   scale= cpl_propertylist_get_string(plist,"ESO INS OPTI1 NAME");
00551   pixscale=atof(scale);
00552   sinfo_free_propertylist(&plist);
00553   return pixscale;
00554 }
00555 
00556 
00557 /*---------------------------------------------------------------------------*/
00564 /*---------------------------------------------------------------------------*/
00565 const char * sinfo_pfits_get_ncorrs_name(const cpl_propertylist * plist)
00566 {
00567     return cpl_propertylist_get_string(plist,"ESO DET NCORRS NAME");
00568 }
00569 
00570 
00571 /*---------------------------------------------------------------------------*/
00578 /*---------------------------------------------------------------------------*/
00579 const char * sinfo_pfits_get_band(const cpl_propertylist * plist)
00580 {
00581     return cpl_propertylist_get_string(plist,"ESO INS FILT1 NAME");
00582 }
00583 
00584 /*---------------------------------------------------------------------------*/
00590 /*---------------------------------------------------------------------------*/
00591 const char * sinfo_pfits_get_dpr_catg(const cpl_propertylist * plist)
00592 {
00593     return cpl_propertylist_get_string(plist,"ESO DPR CATG");
00594 }
00595 
00596 /*---------------------------------------------------------------------------*/
00602 /*---------------------------------------------------------------------------*/
00603 const char * sinfo_pfits_get_dpr_tech(const cpl_propertylist * plist)
00604 {
00605     return cpl_propertylist_get_string(plist,"ESO DPR TECH");
00606 }
00607 
00608 /*---------------------------------------------------------------------------*/
00614 /*---------------------------------------------------------------------------*/
00615 const char * sinfo_pfits_get_dpr_type(const cpl_propertylist * plist)
00616 {
00617     return cpl_propertylist_get_string(plist,"ESO DPR TYPE");
00618 }
00619 
00620 
00621 /*---------------------------------------------------------------------------*/
00627 /*---------------------------------------------------------------------------*/
00628 const char * sinfo_pfits_get_filter_im(const cpl_propertylist * plist)
00629 {
00630   return cpl_propertylist_get_string(plist,"ESO INS FILT1 NAME");
00631 }
00632 
00633 /*---------------------------------------------------------------------------*/
00639 /*---------------------------------------------------------------------------*/
00640 const char * sinfo_pfits_get_filter_spec(const cpl_propertylist * plist)
00641 {
00642     return cpl_propertylist_get_string(plist,"ESO INS FILT2 NAME");
00643 }
00644 
00645 /*---------------------------------------------------------------------------*/
00651 /*---------------------------------------------------------------------------*/
00652 double sinfo_pfits_get_focus(const cpl_propertylist * plist)
00653 {
00654     return cpl_propertylist_get_double(plist,"ESO TEL FOCU LEN");
00655 }
00656 
00657 
00658 /*---------------------------------------------------------------------------*/
00664 /*---------------------------------------------------------------------------*/
00665 const char * sinfo_pfits_get_frame_type(const cpl_propertylist * plist)
00666 {
00667     return cpl_propertylist_get_string(plist,"ESO DET FRAM TYPE");
00668 }
00669 
00670 /*---------------------------------------------------------------------------*/
00676 /*---------------------------------------------------------------------------*/
00677 const char * sinfo_pfits_get_instrument(const cpl_propertylist * plist)
00678 {
00679     return cpl_propertylist_get_string(plist,"INSTRUME");
00680 }
00681 
00682 /*---------------------------------------------------------------------------*/
00688 /*---------------------------------------------------------------------------*/
00689 double sinfo_pfits_get_mjdobs(const cpl_propertylist * plist)
00690 {
00691     return cpl_propertylist_get_double(plist,"MJD-OBS");
00692 }
00693 
00694 
00695 /*---------------------------------------------------------------------------*/
00701 /*---------------------------------------------------------------------------*/
00702 double sinfo_pfits_get_monoc_pos(const cpl_propertylist * plist)
00703 {
00704     return cpl_propertylist_get_double(plist,"INS MONOC1 POS");
00705 }
00706 
00707 /*---------------------------------------------------------------------------*/
00713 /*---------------------------------------------------------------------------*/
00714 int sinfo_pfits_get_ndit(const cpl_propertylist * plist)
00715 {
00716     return cpl_propertylist_get_int(plist,"ESO DET NDIT");
00717 }
00718 
00719 /*---------------------------------------------------------------------------*/
00725 /*---------------------------------------------------------------------------*/
00726 int sinfo_pfits_get_naxis1(const cpl_propertylist * plist)
00727 {
00728     return cpl_propertylist_get_int(plist,"NAXIS1");
00729 }
00730 
00731 
00732 /*---------------------------------------------------------------------------*/
00738 /*---------------------------------------------------------------------------*/
00739 int sinfo_pfits_get_naxis2(const cpl_propertylist * plist)
00740 {
00741     return cpl_propertylist_get_int(plist,"NAXIS2");
00742 }
00743 
00744 
00745 /*---------------------------------------------------------------------------*/
00751 /*---------------------------------------------------------------------------*/
00752 int sinfo_pfits_get_naxis3(const cpl_propertylist * plist)
00753 {
00754     return cpl_propertylist_get_int(plist,"NAXIS3");
00755 }
00756 
00757 
00758 
00759 
00760 /*---------------------------------------------------------------------------*/
00766 /*---------------------------------------------------------------------------*/
00767 int sinfo_pfits_get_crpix1(const cpl_propertylist * plist)
00768 {
00769     return cpl_propertylist_get_int(plist,"CRPIX1");
00770 }
00771 
00772 
00773 
00774 /*---------------------------------------------------------------------------*/
00780 /*---------------------------------------------------------------------------*/
00781 int sinfo_pfits_get_crpix2(const cpl_propertylist * plist)
00782 {
00783     return cpl_propertylist_get_int(plist,"CRPIX2");
00784 }
00785 
00786 
00787 
00788 /*---------------------------------------------------------------------------*/
00794 /*---------------------------------------------------------------------------*/
00795 int sinfo_pfits_get_crpix3(const cpl_propertylist * plist)
00796 {
00797     return cpl_propertylist_get_int(plist,"CRPIX3");
00798 }
00799 
00800 
00801 /*---------------------------------------------------------------------------*/
00807 /*---------------------------------------------------------------------------*/
00808 double sinfo_pfits_get_cdelt1(const cpl_propertylist * plist)
00809 {
00810     return cpl_propertylist_get_double(plist,"CDELT1");
00811 }
00812 
00813 
00814 
00815 /*---------------------------------------------------------------------------*/
00821 /*---------------------------------------------------------------------------*/
00822 double sinfo_pfits_get_cdelt2(const cpl_propertylist * plist)
00823 {
00824     return cpl_propertylist_get_double(plist,"CDELT2");
00825 }
00826 
00827 
00828 
00829 /*---------------------------------------------------------------------------*/
00835 /*---------------------------------------------------------------------------*/
00836 double sinfo_pfits_get_cdelt3(const cpl_propertylist * plist)
00837 {
00838     return cpl_propertylist_get_double(plist,"CDELT3");
00839 }
00840 
00841 
00842 
00843 /*---------------------------------------------------------------------------*/
00849 /*---------------------------------------------------------------------------*/
00850 double sinfo_pfits_get_crval1(const cpl_propertylist * plist)
00851 {
00852     return cpl_propertylist_get_double(plist,"CRVAL1");
00853 }
00854 
00855 /*---------------------------------------------------------------------------*/
00861 /*---------------------------------------------------------------------------*/
00862 double sinfo_pfits_get_crval2(const cpl_propertylist * plist)
00863 {
00864     return cpl_propertylist_get_double(plist,"CRVAL2");
00865 }
00866 
00867 /*---------------------------------------------------------------------------*/
00873 /*---------------------------------------------------------------------------*/
00874 double sinfo_pfits_get_crval3(const cpl_propertylist * plist)
00875 {
00876     return cpl_propertylist_get_double(plist,"CRVAL3");
00877 }
00878 
00879 /*---------------------------------------------------------------------------*/
00885 /*---------------------------------------------------------------------------*/
00886 int sinfo_pfits_get_numbexp(const cpl_propertylist * plist)
00887 {
00888     return cpl_propertylist_get_int(plist,"ESO TPL NEXP");
00889 }
00890 
00891 /*---------------------------------------------------------------------------*/
00897 /*---------------------------------------------------------------------------*/
00898 const char * sinfo_pfits_get_obs_id(const cpl_propertylist * plist)
00899 {
00900     return cpl_propertylist_get_string(plist,"ESO OBS ID");
00901 }
00902 
00903 /*---------------------------------------------------------------------------*/
00909 /*---------------------------------------------------------------------------*/
00910 int sinfo_pfits_get_nodpos(const cpl_propertylist * plist)
00911 {
00912     return cpl_propertylist_get_int(plist,"ESO SEQ NODPOS");
00913 }
00914 
00915 
00916 
00917 /*---------------------------------------------------------------------------*/
00923 /*---------------------------------------------------------------------------*/
00924 double sinfo_pfits_get_ra(const cpl_propertylist * plist)
00925 {
00926     return cpl_propertylist_get_double(plist,"RA");
00927 }
00928 
00929 /*---------------------------------------------------------------------------*/
00935 /*---------------------------------------------------------------------------*/
00936 const char * sinfo_pfits_get_starname(const cpl_propertylist * plist)
00937 {
00938     return cpl_propertylist_get_string(plist,"ESO OBS TARG NAME");
00939 }
00940 
00941 /*---------------------------------------------------------------------------*/
00947 /*---------------------------------------------------------------------------*/
00948 double sinfo_pfits_get_resol(const cpl_propertylist * plist)
00949 {
00950     return cpl_propertylist_get_double(plist,"ESO INS RESOL");
00951 }
00952 
00953 /*---------------------------------------------------------------------------*/
00959 /*---------------------------------------------------------------------------*/
00960 const char * sinfo_pfits_get_templateid(const cpl_propertylist * plist)
00961 {
00962     return (const char*) cpl_propertylist_get_string(plist,"ESO TPL ID"); 
00963 }
00964 

Generated on Wed Jan 17 08:33:43 2007 for SINFONI Pipeline Reference Manual by  doxygen 1.4.4