00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 # include <config.h>
00030 #endif
00031
00032
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
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
00127 if (filename==NULL || key==NULL) return NULL ;
00128
00129
00130 if (sinfo_is_paf_file(filename)!=1) {
00131 sinfo_msg_error("not a PAF file: [%s]", filename);
00132 return NULL ;
00133 }
00134
00135
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
00147 sscanf(line, "%*[^ ] %[^;]", value);
00148 found ++ ;
00149 break ;
00150 }
00151 }
00152 if (!found) return NULL ;
00153
00154
00155 strcpy(val, sinfo_strcrop(value));
00156
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
00186 is_paf = 0 ;
00187
00188
00189 if ((fp = fopen(filename, "r"))==NULL) {
00190 sinfo_msg_error("cannot open file [%s]", filename) ;
00191 return -1 ;
00192 }
00193
00194
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
00241
00242
00243
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
00355
00356 double sinfo_pfits_get_targ_alpha(const cpl_propertylist * plist)
00357 {
00358 return cpl_propertylist_get_double(plist,"ESO INS TARG ALPHA");
00359 }
00360
00361
00362
00368
00369 double sinfo_pfits_get_targ_delta(const cpl_propertylist * plist)
00370 {
00371 return cpl_propertylist_get_double(plist,"ESO INS TARG DELTA");
00372 }
00373
00374
00380
00381 const char * sinfo_pfits_get_arcfile(const cpl_propertylist * plist)
00382 {
00383 return (const char*) cpl_propertylist_get_string(plist,KEY_NAME_ARCFILE);
00384 }
00385
00386
00392
00393 const char * sinfo_pfits_get_rec1raw1name(const cpl_propertylist * plist)
00394 {
00395 return (const char*) cpl_propertylist_get_string(plist,
00396 KEY_NAME_PRO_REC1_RAW1_NAME);
00397 }
00398
00399
00405
00406 const char * sinfo_pfits_get_ins_setup(const cpl_propertylist * plist)
00407 {
00408 if(cpl_propertylist_get_string(plist,"ESO INS SETUP ID")) {
00409 return (const char*) cpl_propertylist_get_string(plist,"ESO INS SETUP ID");
00410 } else {
00411 cpl_error_reset();
00412 return "Dark";
00413 }
00414
00415 }
00416
00417
00418
00419
00425
00426 double sinfo_pfits_get_wlen(const cpl_propertylist * plist)
00427 {
00428
00429 return cpl_propertylist_get_double(plist,"ESO INS GRAT1 WLEN");
00430 }
00431
00432
00438
00439 int sinfo_pfits_get_chop_ncycles(const cpl_propertylist * plist)
00440 {
00441
00442 return cpl_propertylist_get_int(plist,"ESO DET CHOP NCYCLES");
00443
00444 }
00445
00446
00452
00453 double sinfo_pfits_get_pixscale(const cpl_propertylist * plist)
00454 {
00455 const char* val=NULL;
00456 val=cpl_propertylist_get_string(plist,"ESO INS OPTI1 NAME");
00457 return atof(val);
00458 }
00459
00460
00466
00467 double sinfo_pfits_get_posangle(const cpl_propertylist * plist)
00468 {
00469 return cpl_propertylist_get_double(plist,"ESO ADA POSANG");
00470 }
00471
00472
00478
00479 double sinfo_pfits_get_DEC(const cpl_propertylist * plist)
00480 {
00481 return cpl_propertylist_get_double(plist,"DEC");
00482 }
00483
00484
00485
00491
00492 double sinfo_pfits_get_cumoffsetx(const cpl_propertylist * plist)
00493 {
00494 return cpl_propertylist_get_double(plist,"ESO SEQ CUMOFFSETX");
00495 }
00496
00497
00503
00504 double sinfo_pfits_get_cumoffsety(const cpl_propertylist * plist)
00505 {
00506 return cpl_propertylist_get_double(plist,"ESO SEQ CUMOFFSETY");
00507 }
00508
00509
00515
00516 const char * sinfo_pfits_get_date_obs(const cpl_propertylist * plist)
00517 {
00518
00519 return (const char*) cpl_propertylist_get_string(plist,"DATE-OBS");
00520
00521 }
00522
00523
00529
00530 double sinfo_pfits_get_delta(const cpl_propertylist * plist)
00531 {
00532
00533 return cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETDELTA");
00534
00535 }
00536
00537
00543
00544 double sinfo_pfits_get_dec(const cpl_propertylist * plist)
00545 {
00546 return cpl_propertylist_get_double(plist,"DEC");
00547 }
00548
00549
00556
00557 double sinfo_pfits_get_dit(const cpl_propertylist * plist)
00558 {
00559 return cpl_propertylist_get_double(plist,"ESO DET DIT");
00560 }
00561
00567
00568 float sinfo_pfits_get_pixelscale(const char * name)
00569 {
00570 cpl_propertylist* plist=NULL;
00571 float pixscale=0;
00572 const char* scale=NULL;
00573 plist=cpl_propertylist_load(name,0);
00574 scale= cpl_propertylist_get_string(plist,"ESO INS OPTI1 NAME");
00575 pixscale=atof(scale);
00576 sinfo_free_propertylist(&plist);
00577 return pixscale;
00578 }
00579
00580
00581
00588
00589 const char * sinfo_pfits_get_ncorrs_name(const cpl_propertylist * plist)
00590 {
00591 return cpl_propertylist_get_string(plist,"ESO DET NCORRS NAME");
00592 }
00593
00594
00595
00602
00603 const char * sinfo_pfits_get_band(const cpl_propertylist * plist)
00604 {
00605 return cpl_propertylist_get_string(plist,"ESO INS FILT1 NAME");
00606 }
00607
00608
00614
00615 const char * sinfo_pfits_get_dpr_catg(const cpl_propertylist * plist)
00616 {
00617 return cpl_propertylist_get_string(plist,"ESO DPR CATG");
00618 }
00619
00620
00626
00627 const char * sinfo_pfits_get_dpr_tech(const cpl_propertylist * plist)
00628 {
00629 return cpl_propertylist_get_string(plist,"ESO DPR TECH");
00630 }
00631
00632
00638
00639 const char * sinfo_pfits_get_dpr_type(const cpl_propertylist * plist)
00640 {
00641 return cpl_propertylist_get_string(plist,"ESO DPR TYPE");
00642 }
00643
00644
00645
00651
00652 const char * sinfo_pfits_get_filter_im(const cpl_propertylist * plist)
00653 {
00654 return cpl_propertylist_get_string(plist,"ESO INS FILT1 NAME");
00655 }
00656
00657
00663
00664 const char * sinfo_pfits_get_filter_spec(const cpl_propertylist * plist)
00665 {
00666 return cpl_propertylist_get_string(plist,"ESO INS FILT2 NAME");
00667 }
00668
00669
00675
00676 double sinfo_pfits_get_focus(const cpl_propertylist * plist)
00677 {
00678 return cpl_propertylist_get_double(plist,"ESO TEL FOCU LEN");
00679 }
00680
00681
00682
00688
00689 const char * sinfo_pfits_get_frame_type(const cpl_propertylist * plist)
00690 {
00691 return cpl_propertylist_get_string(plist,"ESO DET FRAM TYPE");
00692 }
00693
00694
00700
00701 const char * sinfo_pfits_get_instrument(const cpl_propertylist * plist)
00702 {
00703 return cpl_propertylist_get_string(plist,"INSTRUME");
00704 }
00705
00706
00712
00713 double sinfo_pfits_get_mjdobs(const cpl_propertylist * plist)
00714 {
00715 return cpl_propertylist_get_double(plist,"MJD-OBS");
00716 }
00717
00718
00719
00725
00726 double sinfo_pfits_get_monoc_pos(const cpl_propertylist * plist)
00727 {
00728 return cpl_propertylist_get_double(plist,"INS MONOC1 POS");
00729 }
00730
00731
00737
00738 int sinfo_pfits_get_ndit(const cpl_propertylist * plist)
00739 {
00740 return cpl_propertylist_get_int(plist,"ESO DET NDIT");
00741 }
00742
00743
00749
00750 int sinfo_pfits_get_naxis1(const cpl_propertylist * plist)
00751 {
00752 return cpl_propertylist_get_int(plist,"NAXIS1");
00753 }
00754
00755
00756
00762
00763 int sinfo_pfits_get_naxis2(const cpl_propertylist * plist)
00764 {
00765 return cpl_propertylist_get_int(plist,"NAXIS2");
00766 }
00767
00768
00769
00775
00776 int sinfo_pfits_get_naxis3(const cpl_propertylist * plist)
00777 {
00778 return cpl_propertylist_get_int(plist,"NAXIS3");
00779 }
00780
00781
00782
00783
00784
00790
00791 int sinfo_pfits_get_crpix1(const cpl_propertylist * plist)
00792 {
00793 return cpl_propertylist_get_int(plist,"CRPIX1");
00794 }
00795
00796
00797
00798
00804
00805 int sinfo_pfits_get_crpix2(const cpl_propertylist * plist)
00806 {
00807 return cpl_propertylist_get_int(plist,"CRPIX2");
00808 }
00809
00810
00811
00812
00818
00819 int sinfo_pfits_get_crpix3(const cpl_propertylist * plist)
00820 {
00821 return cpl_propertylist_get_int(plist,"CRPIX3");
00822 }
00823
00824
00825
00831
00832 double sinfo_pfits_get_cdelt1(const cpl_propertylist * plist)
00833 {
00834 return cpl_propertylist_get_double(plist,"CDELT1");
00835 }
00836
00837
00838
00839
00845
00846 double sinfo_pfits_get_cdelt2(const cpl_propertylist * plist)
00847 {
00848 return cpl_propertylist_get_double(plist,"CDELT2");
00849 }
00850
00851
00852
00853
00859
00860 double sinfo_pfits_get_cdelt3(const cpl_propertylist * plist)
00861 {
00862 return cpl_propertylist_get_double(plist,"CDELT3");
00863 }
00864
00865
00866
00867
00873
00874 double sinfo_pfits_get_crval1(const cpl_propertylist * plist)
00875 {
00876 return cpl_propertylist_get_double(plist,"CRVAL1");
00877 }
00878
00879
00885
00886 double sinfo_pfits_get_crval2(const cpl_propertylist * plist)
00887 {
00888 return cpl_propertylist_get_double(plist,"CRVAL2");
00889 }
00890
00891
00897
00898 double sinfo_pfits_get_crval3(const cpl_propertylist * plist)
00899 {
00900 return cpl_propertylist_get_double(plist,"CRVAL3");
00901 }
00902
00903
00909
00910 int sinfo_pfits_get_numbexp(const cpl_propertylist * plist)
00911 {
00912 return cpl_propertylist_get_int(plist,"ESO TPL NEXP");
00913 }
00914
00915
00921
00922 const char * sinfo_pfits_get_obs_id(const cpl_propertylist * plist)
00923 {
00924 return cpl_propertylist_get_string(plist,"ESO OBS ID");
00925 }
00926
00927
00933
00934 int sinfo_pfits_get_nodpos(const cpl_propertylist * plist)
00935 {
00936 return cpl_propertylist_get_int(plist,"ESO SEQ NODPOS");
00937 }
00938
00939
00940
00941
00947
00948 double sinfo_pfits_get_ra(const cpl_propertylist * plist)
00949 {
00950 return cpl_propertylist_get_double(plist,"RA");
00951 }
00952
00953
00959
00960 const char * sinfo_pfits_get_starname(const cpl_propertylist * plist)
00961 {
00962 return cpl_propertylist_get_string(plist,"ESO OBS TARG NAME");
00963 }
00964
00965
00971
00972 double sinfo_pfits_get_resol(const cpl_propertylist * plist)
00973 {
00974 return cpl_propertylist_get_double(plist,"ESO INS RESOL");
00975 }
00976
00977
00983
00984 const char * sinfo_pfits_get_templateid(const cpl_propertylist * plist)
00985 {
00986 return (const char*) cpl_propertylist_get_string(plist,"ESO TPL ID");
00987 }
00988