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
00035
00036 #define visir_pfits_get_int(KEY) irplib_pfits_get_int(self, KEY)
00037 #define visir_pfits_get_string(KEY) irplib_pfits_get_string(self, KEY)
00038
00039
00040
00041
00042
00043
00044 #include <string.h>
00045 #include <assert.h>
00046 #include <math.h>
00047 #include <cpl.h>
00048
00049 #include "irplib_pfits.h"
00050
00051 #include "visir_utils.h"
00052 #include "visir_pfits.h"
00053
00054
00055
00056
00057
00058
00059 static const char * visir_pfits_get_slitname(const cpl_propertylist *);
00060 static double visir_pfits_get_slitwidth_raw(const cpl_propertylist *);
00061
00062
00067
00068
00071
00072
00073
00074
00075
00076 static inline double
00077 visir_pfits_get_double(const cpl_propertylist * self, const char *key) {
00078 if (cpl_propertylist_get_type(self, key) == CPL_TYPE_INT) {
00079 return irplib_pfits_get_int(self, key);
00080 }
00081 return irplib_pfits_get_double(self, key);
00082 }
00083
00084
00090
00091 double visir_pfits_get_airmass_start(const cpl_propertylist * self)
00092 {
00093 return visir_pfits_get_double(self, "ESO TEL AIRM START");
00094 }
00095
00096
00102
00103 double visir_pfits_get_airmass_end(const cpl_propertylist * self)
00104 {
00105 return visir_pfits_get_double(self, "ESO TEL AIRM END");
00106 }
00107
00108
00114
00115 double visir_pfits_get_alpha(const cpl_propertylist * self)
00116 {
00117 return visir_pfits_get_double(self, "ESO TEL TARG OFFSETALPHA");
00118 }
00119
00120
00126
00127 const char * visir_pfits_get_arcfile(const cpl_propertylist * self)
00128 {
00129 return visir_pfits_get_string("ARCFILE");
00130 }
00131
00132
00138
00139 const char * visir_pfits_get_chopnod_dir(const cpl_propertylist * self)
00140 {
00141 return visir_pfits_get_string(VISIR_PFITS_STRING_CHOPNOD_DIR);
00142 }
00143
00144
00145
00151
00152 double visir_pfits_get_chop_throw(const cpl_propertylist * self)
00153 {
00154 if (cpl_propertylist_has(self, VISIR_PFITS_DOUBLE_CHOP_THROW)) {
00155 return visir_pfits_get_double(self, VISIR_PFITS_DOUBLE_CHOP_THROW);
00156 }
00157 else {
00158 return visir_pfits_get_double(self, "ESO DET CHOP THROW");
00159 }
00160 }
00161
00162
00163
00169
00170 double visir_pfits_get_chop_freq(const cpl_propertylist * self)
00171 {
00172 if (cpl_propertylist_has(self, VISIR_PFITS_DOUBLE_CHOP_FREQ)) {
00173 return visir_pfits_get_double(self, VISIR_PFITS_DOUBLE_CHOP_FREQ);
00174 }
00175 else {
00176 return visir_pfits_get_double(self, "ESO DET CHOP FREQ");
00177 }
00178 }
00179
00180
00186
00187 double visir_pfits_get_chop_stat(const cpl_propertylist * self)
00188 {
00189 if (cpl_propertylist_has(self, VISIR_PFITS_BOOL_CHOP_STATUS)) {
00190 return cpl_propertylist_get_bool(self, VISIR_PFITS_BOOL_CHOP_STATUS);
00191 }
00192 else {
00193 return cpl_propertylist_get_bool(self, "ESO DET CHOP ST");
00194 }
00195 }
00196
00197
00198
00204
00205 double visir_pfits_get_chop_posang(const cpl_propertylist * self)
00206 {
00207 if (!cpl_propertylist_has(self, VISIR_PFITS_DOUBLE_CHOP_POSANG)) {
00208 return 0.;
00209 }
00210 return CPL_MATH_RAD_DEG *
00211 cpl_propertylist_get_double(self, VISIR_PFITS_DOUBLE_CHOP_POSANG);
00212 }
00213
00214
00215
00221
00222 double visir_pfits_get_chop_pthrow(const cpl_propertylist * self)
00223 {
00224 const double throw = visir_pfits_get_chop_throw(self);
00225 const double pscale = visir_pfits_get_pixscale(self);
00226 return pscale > 0.0 ? throw / pscale : 0.0;
00227 }
00228
00229
00230
00236
00237 int visir_pfits_get_chop_ncycles(const cpl_propertylist * self)
00238 {
00239 return visir_pfits_get_int("ESO DET CHOP NCYCLES");
00240 }
00241
00242
00248
00249 double visir_pfits_get_ada_posang(const cpl_propertylist * self)
00250 {
00251 if (!cpl_propertylist_has(self, VISIR_PFITS_DOUBLE_ADA_POSANG)) {
00252 return 0.;
00253 }
00254 return CPL_MATH_RAD_DEG *
00255 cpl_propertylist_get_double(self, VISIR_PFITS_DOUBLE_ADA_POSANG);
00256 }
00257
00258
00264
00265 double visir_pfits_get_cumoffsetx(const cpl_propertylist * self)
00266 {
00267 return visir_pfits_get_double(self, "ESO SEQ CUMOFFSETX");
00268 }
00269
00270
00276
00277 double visir_pfits_get_cumoffsety(const cpl_propertylist * self)
00278 {
00279 return visir_pfits_get_double(self, "ESO SEQ CUMOFFSETY");
00280 }
00281
00282
00288
00289 const char * visir_pfits_get_date_obs(const cpl_propertylist * self)
00290 {
00291 return visir_pfits_get_string("DATE-OBS");
00292 }
00293
00294
00300
00301 double visir_pfits_get_delta(const cpl_propertylist * self)
00302 {
00303 return visir_pfits_get_double(self, "ESO TEL TARG OFFSETDELTA");
00304 }
00305
00306
00312
00313 double visir_pfits_get_dec(const cpl_propertylist * self)
00314 {
00315 return visir_pfits_get_double(self, "DEC");
00316 }
00317
00318
00324
00325 double visir_pfits_get_dit(const cpl_propertylist * self)
00326 {
00327 if (cpl_propertylist_has(self, VISIR_PFITS_DOUBLE_SEQ1_DIT))
00328 return visir_pfits_get_double(self, VISIR_PFITS_DOUBLE_SEQ1_DIT);
00329 return visir_pfits_get_double(self, VISIR_PFITS_DOUBLE_DIT);
00330 }
00331
00332
00338
00339 int visir_pfits_get_navrg(const cpl_propertylist * self)
00340 {
00341 if (cpl_propertylist_has(self, VISIR_PFITS_INT_NAVRG))
00342 return visir_pfits_get_int(VISIR_PFITS_INT_NAVRG);
00343 return 1;
00344 }
00345
00346
00352
00353 int visir_pfits_get_expno(const cpl_propertylist * self)
00354 {
00355 return visir_pfits_get_int("ESO TPL EXPNO");
00356 }
00357
00358
00364
00365 const char * visir_pfits_get_filter(const cpl_propertylist * self)
00366 {
00367
00368
00369 const char * val = visir_pfits_get_insmode(self);
00370 static const char * spec[] = {
00371 "N_SW_spec",
00372 "H2S4_spec",
00373 "ARIII_spec",
00374 "NEII_2_spec",
00375 "H2S3_spec",
00376 "H2S1_spec",
00377 };
00378
00379
00380 if (val == NULL) return NULL ;
00381
00382
00383 if (!strcmp(val, "IMG" ))
00384 return visir_pfits_get_string("ESO INS FILT1 NAME");
00385
00386 if (!strcmp(val, "SPC" ))
00387 return visir_pfits_get_string("ESO INS FILT2 NAME");
00388
00389 if (!strcmp(val, "SPCIMG")) {
00390 const char * filt = visir_pfits_get_string("ESO INS FILT2 NAME");
00391 for (size_t i = 0; i < 6; i++) {
00392 if (strncmp(spec[i], filt, strlen(spec[i]) - 5) == 0) {
00393 return spec[i];
00394 }
00395 }
00396 return filt;
00397 }
00398
00399 cpl_ensure(0, CPL_ERROR_UNSUPPORTED_MODE, NULL);
00400
00401 }
00402
00403
00409
00410 double visir_pfits_get_focus(const cpl_propertylist * self)
00411 {
00412 return visir_pfits_get_double(self, "ESO TEL FOCU LEN");
00413 }
00414
00415
00421
00422 double visir_pfits_get_exptime(const cpl_propertylist * self)
00423 {
00424 return visir_pfits_get_double(self, "EXPTIME");
00425 }
00426
00427
00433
00434 const char * visir_pfits_get_frame_type(const cpl_propertylist * self)
00435 {
00436 return visir_pfits_get_string("ESO DET FRAM TYPE");
00437 }
00438
00439
00440
00446
00447 const char * visir_pfits_get_det_name(const cpl_propertylist * self)
00448 {
00449 if (cpl_propertylist_has(self, "ESO DET NAME")) {
00450 return visir_pfits_get_string("ESO DET NAME");
00451 }
00452 return NULL;
00453 }
00454
00455
00461
00462 const char * visir_pfits_get_grat1_name(const cpl_propertylist * self)
00463 {
00464 return visir_pfits_get_string("ESO INS GRAT1 NAME");
00465 }
00466
00467
00473
00474 const char * visir_pfits_get_insmode(const cpl_propertylist * self)
00475 {
00476 const char * mode = visir_pfits_get_string("ESO INS MODE");
00477 return mode ? mode : "(none)";
00478 }
00479
00480
00486
00487 const char * visir_pfits_get_instrument(const cpl_propertylist * self)
00488 {
00489 return visir_pfits_get_string("INSTRUME");
00490 }
00491
00492
00498
00499 double visir_pfits_get_mjdobs(const cpl_propertylist * self)
00500 {
00501 return visir_pfits_get_double(self, "MJD-OBS");
00502 }
00503
00504
00510
00511 const char * visir_pfits_get_mode(const cpl_propertylist * self)
00512 {
00513 return visir_pfits_get_string("ESO DET MODE NAME");
00514 }
00515
00516
00522
00523 double visir_pfits_get_monoc_pos(const cpl_propertylist * self)
00524 {
00525 return visir_pfits_get_double(self, "ESO INS MONOC1 POS");
00526 }
00527
00528
00534
00535 int visir_pfits_get_ndit(const cpl_propertylist * self)
00536 {
00537 return visir_pfits_get_int("ESO DET NDIT");
00538 }
00539
00545
00546 int visir_pfits_get_naxis1(const cpl_propertylist * self)
00547 {
00548 if (cpl_propertylist_has(self, "ZNAXIS1"))
00549 return visir_pfits_get_int("ZNAXIS1");
00550 else
00551 return visir_pfits_get_int("NAXIS1");
00552 }
00553
00554
00560
00561 int visir_pfits_get_naxis2(const cpl_propertylist * self)
00562 {
00563 if (cpl_propertylist_has(self, "ZNAXIS2"))
00564 return visir_pfits_get_int("ZNAXIS2");
00565 else
00566 return visir_pfits_get_int("NAXIS2");
00567 }
00568
00569
00575
00576 int visir_pfits_get_naxis3(const cpl_propertylist * self)
00577 {
00578 if (cpl_propertylist_has(self, "ZNAXIS3"))
00579 return visir_pfits_get_int("ZNAXIS3");
00580 else
00581 return visir_pfits_get_int("NAXIS3");
00582 }
00583
00584
00590
00591 int visir_pfits_get_win_nx(const cpl_propertylist * self)
00592 {
00593 if (cpl_propertylist_has(self, "ESO DET WIN NX")) {;
00594 return visir_pfits_get_int("ESO DET WIN NX");
00595 }
00596 else if (cpl_propertylist_has(self, "ESO DET1 WIN NX")) {;
00597 return visir_pfits_get_int("ESO DET1 WIN NX");
00598 }
00599 else if (cpl_propertylist_has(self, "ESO DET ACQ1 WIN NX")) {;
00600 return visir_pfits_get_int("ESO DET ACQ1 WIN NX");
00601 }
00602 return -1;
00603 }
00604
00605
00611
00612 int visir_pfits_get_win_ny(const cpl_propertylist * self)
00613 {
00614 if (cpl_propertylist_has(self, "ESO DET WIN NY")) {;
00615 return visir_pfits_get_int("ESO DET WIN NY");
00616 }
00617 else if (cpl_propertylist_has(self, "ESO DET1 WIN NY")) {;
00618 return visir_pfits_get_int("ESO DET1 WIN NY");
00619 }
00620 else if (cpl_propertylist_has(self, "ESO DET ACQ1 WIN NY")) {;
00621 return visir_pfits_get_int("ESO DET ACQ1 WIN NY");
00622 }
00623 return -1;
00624 }
00625
00626
00632
00633 int visir_pfits_get_start_x(const cpl_propertylist * self)
00634 {
00635 if (cpl_propertylist_has(self, "ESO DET WIN STRX")) {;
00636 return visir_pfits_get_int("ESO DET WIN STRX");
00637 }
00638 else if (cpl_propertylist_has(self, "ESO DET1 WIN STRX")) {;
00639 return visir_pfits_get_int("ESO DET1 WIN STRX");
00640 }
00641 else if (cpl_propertylist_has(self, "ESO DET ACQ1 WIN STRX")) {;
00642 return visir_pfits_get_int("ESO DET ACQ1 WIN STRX");
00643 }
00644 return -1;
00645 }
00646
00647
00653
00654 int visir_pfits_get_start_y(const cpl_propertylist * self)
00655 {
00656 if (cpl_propertylist_has(self, "ESO DET WIN STRY")) {;
00657 return visir_pfits_get_int("ESO DET WIN STRY");
00658 }
00659 else if (cpl_propertylist_has(self, "ESO DET1 WIN STRY")) {;
00660 return visir_pfits_get_int("ESO DET1 WIN STRY");
00661 }
00662 else if (cpl_propertylist_has(self, "ESO DET ACQ1 WIN STRY")) {;
00663 return visir_pfits_get_int("ESO DET ACQ1 WIN STRY");
00664 }
00665 return -1;
00666 }
00667
00668
00674
00675 int visir_pfits_get_numbexp(const cpl_propertylist * self)
00676 {
00677 return visir_pfits_get_int("ESO TPL NEXP");
00678 }
00679
00680
00686
00687 int visir_pfits_get_obs_id(const cpl_propertylist * self)
00688 {
00689 return visir_pfits_get_int("ESO OBS ID");
00690 }
00691
00692
00698
00699 const char * visir_pfits_get_nodpos(const cpl_propertylist * self)
00700 {
00701 return visir_pfits_get_string("ESO SEQ NODPOS");
00702 }
00703
00704
00710
00711 double visir_pfits_get_pixscale(const cpl_propertylist * self)
00712 {
00713 const char * sscale = visir_pfits_get_string(VISIR_PFITS_STRING_PIXSCALE);
00714 if (sscale && strlen(sscale) > 0)
00715 return atof(sscale);
00716 else
00717 return -1.;
00718 }
00719
00720
00726
00727 double visir_pfits_get_pixspace(const cpl_propertylist * self)
00728 {
00729 if (cpl_propertylist_has(self, "ESO DET CHIP1 PXSPACE")) {
00730 return visir_pfits_get_double(self, "ESO DET CHIP1 PXSPACE");
00731 }
00732 return visir_pfits_get_double(self, "ESO DET CHIP PXSPACE");
00733 }
00734
00735
00741
00742 double visir_pfits_get_ra(const cpl_propertylist * self)
00743 {
00744 return visir_pfits_get_double(self, "RA");
00745 }
00746
00747
00753
00754 double visir_pfits_get_slitwidth(const cpl_propertylist * self)
00755 {
00756 const char * slitname = visir_pfits_get_slitname(self);
00757 double slitwidth = visir_pfits_get_slitwidth_raw(self);
00758
00759
00760 if (!cpl_error_get_code()) {
00761
00762 static const char * slit_name[] = {"CU_0.12", "CU_0.14", "CU_0.16",
00763 "CU_0.20", "CU_0.25", "CU_0.30",
00764 "CU_0.40", "CU_0.50", "CU_0.60",
00765 "CU_0.70", "CU_0.80", "CU_1.00",
00766 "CU_1.20", "CU_1.60", "ST_0.14",
00767 "ST_0.16", "ST_0.20", "ST_0.30",
00768 "ST_0.40", "ST_0.50", "ST_0.60"};
00769
00770 static double slit_width[] = {0.12, 0.14, 0.16,
00771 0.20, 0.25, 0.30,
00772 0.40, 0.50, 0.60,
00773 0.70, 0.80, 1.00,
00774 1.20, 1.60, 0.14,
00775 0.16, 0.20, 0.30,
00776 0.40, 0.50, 0.60};
00777
00778 static const int slit_nums = (int)(sizeof(slit_width)/sizeof(double));
00779
00780 int i;
00781
00782 for (i=0; i < slit_nums; i++)
00783 if (strstr(slitname, slit_name[i])) break;
00784
00785 if (i < slit_nums && fabs(slit_width[i] - slitwidth) < 0.001) {
00786
00787
00788
00789
00790
00791 cpl_msg_warning(cpl_func,"The Width of slit %s is written in the "
00792 "FITS card in units mm. Converting to ArcSecs: "
00793 "%g => %g", slitname, slitwidth, slitwidth * 2.5);
00794 slitwidth *= 2.5;
00795 }
00796 }
00797
00798 return slitwidth;
00799 }
00800
00801
00807
00808 const char * visir_pfits_get_starname(const cpl_propertylist * self)
00809 {
00810 return visir_pfits_get_string("ESO OBS TARG NAME");
00811 }
00812
00813
00819
00820 const char * visir_pfits_get_resol(const cpl_propertylist * self)
00821 {
00822 if (cpl_propertylist_has(self, "ESO INS RESOL")) {
00823 return visir_pfits_get_string("ESO INS RESOL");
00824 }
00825 return NULL;
00826 }
00827
00828
00834
00835 double visir_pfits_get_temp(const cpl_propertylist * self)
00836 {
00837 return visir_pfits_get_double(self, "ESO TEL TH M1 TEMP");
00838 }
00839
00840
00846
00847 double visir_pfits_get_volt1dcta9(const cpl_propertylist * self)
00848 {
00849 return visir_pfits_get_double(self, "ESO DET VOLT1 DCTA9");
00850 }
00851
00852
00858
00859 double visir_pfits_get_volt1dctb9(const cpl_propertylist * self)
00860 {
00861 return visir_pfits_get_double(self, "ESO DET VOLT1 DCTB9");
00862 }
00863
00864
00870
00871 double visir_pfits_get_volt2dcta9(const cpl_propertylist * self)
00872 {
00873 return visir_pfits_get_double(self, "ESO DET VOLT2 DCTA9");
00874 }
00875
00876
00882
00883 double visir_pfits_get_volt2dctb9(const cpl_propertylist * self)
00884 {
00885 return visir_pfits_get_double(self, "ESO DET VOLT2 DCTB9");
00886 }
00887
00888
00894
00895 double visir_pfits_get_wlen(const cpl_propertylist * self)
00896 {
00897 if (cpl_propertylist_has(self, VISIR_PFITS_DOUBLE_PWLEN)) {
00898 return visir_pfits_get_double(self, VISIR_PFITS_DOUBLE_PWLEN);
00899 }
00900 return visir_pfits_get_double(self, VISIR_PFITS_DOUBLE_WLEN);
00901 }
00902
00903
00912
00913 double visir_pfits_get_img_weight(const cpl_propertylist * self)
00914 {
00915 double imgwgt = 1.;
00916 if (cpl_propertylist_has(self, "ESO DRS IMGWGT"))
00917 imgwgt = cpl_propertylist_get_float(self, "ESO DRS IMGWGT");
00918
00919 return imgwgt;
00920 }
00921
00922
00931
00932 int visir_pfits_get_nbeams(const cpl_propertylist * self)
00933 {
00934 const cpl_boolean chop_on =
00935 cpl_propertylist_get_bool(self, VISIR_PFITS_BOOL_CHOP_STATUS);
00936
00937
00938
00939 return chop_on ? 4 : 2;
00940 }
00941
00944
00951
00952 static double visir_pfits_get_slitwidth_raw(const cpl_propertylist * self)
00953 {
00954 return visir_pfits_get_double(self, "ESO INS SLIT1 WID");
00955 }
00956
00957
00963
00964 static const char * visir_pfits_get_slitname(const cpl_propertylist * self)
00965 {
00966 return visir_pfits_get_string("ESO INS SLIT1 NAME");
00967 }