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 #include <string.h>
00033
00034 #include "omega_pfits.h"
00035 #include "omega_stats.h"
00036 #include "omega_utils.h"
00037
00038 static int omega_get_quadrant(const char * extname, int filtno);
00039
00055
00056 static void omega_property_dump(cpl_property *property)
00057 {
00058
00059 const char *name = cpl_property_get_name(property);
00060 const char *comment = cpl_property_get_comment(property);
00061
00062 char c;
00063
00064 long size = cpl_property_get_size(property);
00065
00066 cpl_type type = cpl_property_get_type(property);
00067
00068
00069 cpl_msg_info(cpl_func, "Property at address %p", property);
00070 cpl_msg_info(cpl_func, "\tname : %p '%s'", name, name);
00071 cpl_msg_info(cpl_func, "\tcomment: %p '%s'", comment, comment);
00072 cpl_msg_info(cpl_func, "\ttype : %#09x", type);
00073 cpl_msg_info(cpl_func, "\tsize : %ld", size);
00074 cpl_msg_info(cpl_func, "\tvalue : ");
00075
00076
00077 switch (type) {
00078 case CPL_TYPE_CHAR:
00079 c = cpl_property_get_char(property);
00080 if (!c)
00081 fprintf(stderr, "''");
00082 else
00083 fprintf(stderr, "'%c'", c);
00084 break;
00085
00086 case CPL_TYPE_BOOL:
00087 fprintf(stderr, "%d", cpl_property_get_bool(property));
00088 break;
00089
00090 case CPL_TYPE_INT:
00091 fprintf(stderr, "%d", cpl_property_get_int(property));
00092 break;
00093
00094 case CPL_TYPE_LONG:
00095 fprintf(stderr, "%ld", cpl_property_get_long(property));
00096 break;
00097
00098 case CPL_TYPE_FLOAT:
00099 fprintf(stderr, "%.7g", cpl_property_get_float(property));
00100 break;
00101
00102 case CPL_TYPE_DOUBLE:
00103 fprintf(stderr, "%.15g", cpl_property_get_double(property));
00104 break;
00105
00106 case CPL_TYPE_STRING:
00107 fprintf(stderr, "'%s'", cpl_property_get_string(property));
00108 break;
00109
00110 default:
00111 fprintf(stderr, "unknown.");
00112 break;
00113
00114 }
00115
00116 fprintf(stderr, "\n");
00117
00118 return;
00119
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129 const char * omega_pfits_get_date_obs(const cpl_propertylist * plist)
00130 {
00131 return (const char *) cpl_propertylist_get_string(plist, "DATE-OBS") ;
00132 }
00133
00134
00141
00142 const char * omega_pfits_get_arcfile(const cpl_propertylist * plist)
00143 {
00144 return (const char *) cpl_propertylist_get_string(plist, "ARCFILE");
00145 }
00146
00147
00153
00154 double omega_pfits_get_dit(const cpl_propertylist * plist)
00155 {
00156 if (cpl_propertylist_has(plist, "ESO DET DIT") == 1)
00157 return cpl_propertylist_get_double(plist, "ESO DET DIT");
00158 else
00159 return 0.0;
00160 }
00161
00162
00168
00169 const char * omega_pfits_get_templateid(const cpl_propertylist * plist)
00170 {
00171 return (const char *) cpl_propertylist_get_string(plist, "ESO TPL ID") ;
00172 }
00173
00174
00180
00181 double omega_pfits_get_mjdobs(const cpl_propertylist * plist)
00182 {
00183 return cpl_propertylist_get_double(plist, "MJD-OBS") ;
00184 }
00185
00186
00192
00193 double omega_pfits_get_exptime(const cpl_propertylist * plist)
00194 {
00195
00196 if(cpl_propertylist_has(plist, "EXPTIME")){
00197 return cpl_propertylist_get_double(plist, "EXPTIME") ;
00198 }
00199 else{
00200 return 0.0;
00201 }
00202 }
00203
00204
00205
00212
00213
00214 extern int omega_pfits_get_detlive(const cpl_propertylist *plist,
00215 int *detlive)
00216 {
00217 int val;
00218
00219 if(cpl_propertylist_has(plist, "ESO DET CHIP LIVE") == 0){
00220 cpl_error_reset();
00221 *detlive = 1;
00222 return 0;
00223 }
00224
00225 val = cpl_propertylist_get_bool(plist,"ESO DET CHIP LIVE");
00226 if (cpl_error_get_code() == CPL_ERROR_NONE) {
00227 *detlive = val;
00228 return 0;
00229 } else {
00230 cpl_error_reset();
00231 *detlive = 1;
00232 return -1;
00233 }
00234 }
00235
00236
00244
00245 int omega_pfits_get_orientation(const char *chip)
00246 {
00247
00248 int orient = 0;
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 if(strcmp(chip, "ESO_CCD_#65" )==0 ||
00262 strcmp(chip, "ESO_CCD_#66" )==0 ||
00263 strcmp(chip, "ESO_CCD_#67" )==0 ||
00264 strcmp(chip, "ESO_CCD_#68" )==0 ||
00265 strcmp(chip, "ESO_CCD_#69" )==0 ||
00266 strcmp(chip, "ESO_CCD_#70" )==0 ||
00267 strcmp(chip, "ESO_CCD_#71" )==0 ||
00268 strcmp(chip, "ESO_CCD_#72" )==0 ||
00269 strcmp(chip, "ESO_CCD_#73" )==0 ||
00270 strcmp(chip, "ESO_CCD_#74" )==0 ||
00271 strcmp(chip, "ESO_CCD_#75" )==0 ||
00272 strcmp(chip, "ESO_CCD_#76" )==0 ||
00273 strcmp(chip, "ESO_CCD_#77" )==0 ||
00274 strcmp(chip, "ESO_CCD_#78" )==0 ||
00275 strcmp(chip, "ESO_CCD_#79" )==0 ||
00276 strcmp(chip, "ESO_CCD_#80" )==0){
00277
00278 orient = 1;
00279 }
00280 else if (strcmp(chip, "ESO_CCD_#81" )==0 ||
00281 strcmp(chip, "ESO_CCD_#82" )==0 ||
00282 strcmp(chip, "ESO_CCD_#83" )==0 ||
00283 strcmp(chip, "ESO_CCD_#84" )==0 ||
00284 strcmp(chip, "ESO_CCD_#85" )==0 ||
00285 strcmp(chip, "ESO_CCD_#86" )==0 ||
00286 strcmp(chip, "ESO_CCD_#87" )==0 ||
00287 strcmp(chip, "ESO_CCD_#88" )==0 ||
00288 strcmp(chip, "ESO_CCD_#89" )==0 ||
00289 strcmp(chip, "ESO_CCD_#90" )==0 ||
00290 strcmp(chip, "ESO_CCD_#91" )==0 ||
00291 strcmp(chip, "ESO_CCD_#92" )==0 ||
00292 strcmp(chip, "ESO_CCD_#93" )==0 ||
00293 strcmp(chip, "ESO_CCD_#94" )==0 ||
00294 strcmp(chip, "ESO_CCD_#95" )==0 ||
00295 strcmp(chip, "ESO_CCD_#96" )==0){
00296
00297 orient = 2;
00298 }
00299 else {
00300 orient = 0;
00301 }
00302
00303
00304 return orient;
00305 }
00306
00307
00317
00318
00319 void omega_pfits_get_xysize(const char *chip, int *xs, int *ys)
00320 {
00321
00322 int orientation = 0;
00323 int prscx = 48;
00324 int prscy = 0;
00325 int ovscx = 48;
00326 int ovscy = 30;
00327 int naxis1 = 2142;
00328 int naxis2 = 4128;
00329 int x0 = 1;
00330 int x1 = 1;
00331 int y0 = 1;
00332 int y1 = 1;
00333
00334 orientation = omega_pfits_get_orientation(chip);
00335
00336
00337 switch (orientation) {
00338 case 1:
00339 x0 = prscx + 1;
00340 y0 = prscy + 1;
00341 x1 = naxis1 - ovscx;
00342 y1 = naxis2 - ovscy;
00343 break;
00344 case 2:
00345 x0 = prscx + 1;
00346 y0 = ovscy + 1;
00347 x1 = naxis1 - ovscx;
00348 y1 = naxis2 - prscy;
00349 break;
00350 case 3:
00351 x0 = ovscx + 1;
00352 y0 = prscy+ 1;
00353 x1 = naxis1 - prscx;
00354 y1 = naxis2 - ovscy;
00355 break;
00356 case 4:
00357 x0 = ovscx + 1;
00358 y0 = ovscy + 1;
00359 x1 = naxis1 - prscx;
00360 y1 = naxis2 - prscy;
00361 break;
00362 default:
00363 x0 = prscx + 1;
00364 y0 = prscy + 1;
00365 x1 = naxis1 - ovscx;
00366 y1 = naxis2 - ovscy;
00367 break;
00368 }
00369
00370 *xs = x1 - x0+1;
00371 *ys = y1 - y0+1;
00372
00373 }
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00695
00696
00697 void omega_pfits_get_mean_airmass(const cpl_propertylist *plist, double *airm)
00698 {
00699
00700 double airm0 = 1.0;
00701 double airm1 = 1.0;
00702
00703
00704 if( (cpl_propertylist_has(plist, "ESO TEL AIRM START") == 1) &&
00705 (cpl_propertylist_has(plist, "ESO TEL AIRM END") == 1 ) ) {
00706 airm0 = cpl_propertylist_get_double(plist, "ESO TEL AIRM START");
00707 airm1 = cpl_propertylist_get_double(plist, "ESO TEL AIRM END");
00708
00709 *airm = (airm0 + airm1)/2;
00710 }
00711 else if ( (cpl_propertylist_has(plist, "AIRMSTRT") == 1) &&
00712 (cpl_propertylist_has(plist, "AIRMEND")) == 1 ){
00713 airm0 = cpl_propertylist_get_double(plist, "AIRMSTRT");
00714 airm1 = cpl_propertylist_get_double(plist, "AIRMEND");
00715
00716 *airm = (airm0 + airm1)/2;
00717 }
00718 else if (cpl_propertylist_has(plist, "AIRMASS") == 1){
00719 *airm = cpl_propertylist_get_double(plist, "AIRMASS");
00720 }
00721 else {
00722 *airm = 1.0;
00723 }
00724
00725 if (*airm == 0.0){
00726 *airm = 1.0;
00727 }
00728
00729 return;
00730
00731 }
00732
00733
00744
00745 void omega_pfits_get_airmass(const cpl_propertylist *plist1, double *start, double *end)
00746 {
00747
00748
00749
00750
00751 if (plist1 == NULL) {
00752 cpl_msg_error(cpl_func,"Main header is empty");
00753 }
00754
00755 if( (cpl_propertylist_has(plist1, "ESO TEL AIRM START") == 1) &&
00756 (cpl_propertylist_has(plist1, "ESO TEL AIRM END") == 1 ) ){
00757 *start = cpl_propertylist_get_double(plist1, "ESO TEL AIRM START");
00758 *end = cpl_propertylist_get_double(plist1, "ESO TEL AIRM END");
00759 }
00760 else if ( (cpl_propertylist_has(plist1, "AIRMSTRT") == 1) &&
00761 (cpl_propertylist_has(plist1, "AIRMEND")) == 1 ){
00762 *start = cpl_propertylist_get_double(plist1, "AIRMSTRT");
00763 *end = cpl_propertylist_get_double(plist1, "AIRMEND");
00764 }
00765 else if (cpl_propertylist_has(plist1, "AIRMASS") == 1) {
00766 *start = cpl_propertylist_get_double(plist1, "AIRMASS");
00767 *end = *start;
00768 }
00769 else {
00770 *start = 1.0;
00771 *end = 1.0;
00772 }
00773
00774
00775 }
00776
00777
00778
00779
00785 int omega_pfits_check_instrume(const cpl_frame *fr)
00786 {
00787
00788 const char *INSTRUMENT = NULL;
00789 cpl_propertylist *plist;
00790
00791
00792 if (fr == NULL) {
00793 cpl_msg_error(cpl_func,"NULL frame");
00794 return -1;
00795 }
00796
00797 plist = cpl_propertylist_load_regexp(cpl_frame_get_filename(fr), 0,
00798 "INSTRUME", 0);
00799 if (plist == NULL) {
00800 cpl_msg_error (cpl_func,"Cannot load main header for %s",cpl_frame_get_filename(fr));
00801 return -1;
00802 }
00803
00804 INSTRUMENT = cpl_propertylist_get_string(plist, "INSTRUME");
00805 if(!INSTRUMENT) {
00806 cpl_msg_error(cpl_func,"Cannot find INSTRUME keyword in header");
00807 cpl_propertylist_delete(plist);
00808 return -1;
00809 }
00810
00811 if(strcmp("OMEGA", INSTRUMENT)==0){
00812 cpl_propertylist_delete(plist);
00813 return 0;
00814 }
00815 else if(strcmp("WFI", INSTRUMENT)==0){
00816 cpl_propertylist_delete(plist);
00817 return 1;
00818 }
00819 else{
00820 cpl_propertylist_delete(plist);
00821 return -1;
00822 }
00823
00824 return 0;
00825 }
00826
00834 int omega_pfits_get_instrume(const cpl_propertylist *plist)
00835 {
00836
00837 const char *INSTRUMENT = NULL;
00838
00839
00840 if (plist == NULL) {
00841 cpl_msg_error(cpl_func,"NULL property list");
00842 return -1;
00843 }
00844
00845
00846 INSTRUMENT = cpl_propertylist_get_string(plist, "INSTRUME");
00847 if(!INSTRUMENT) {
00848 cpl_msg_warning(cpl_func,"Cannot find INSTRUME keyword in header");
00849 return 0;
00850 }
00851
00852 if(strcmp("OMEGA", INSTRUMENT)==0){
00853 return 0;
00854 }
00855 else if(strcmp("WFI", INSTRUMENT)==0){
00856 return 1;
00857 }
00858
00859 return 0;
00860 }
00861
00869
00870 void omega_pfits_get_readnoise(cpl_propertylist *plist, double *rn)
00871 {
00872
00873 int i = 0;
00874
00875 const char *ronstring = "ESO DET OUT1 RON";
00876
00877
00878
00879
00880 if (plist == NULL) {
00881 cpl_msg_error(cpl_func,"Extension header is empty");
00882 }
00883
00884 if (cpl_propertylist_has(plist, ronstring) == 1) {
00885 *rn = cpl_propertylist_get_double(plist, ronstring);
00886 }
00887 else if (cpl_propertylist_has(plist, "RON") == 1) {
00888 *rn = cpl_propertylist_get_double(plist, "RON");
00889 }
00890 else{
00891
00892 for(i=1; i<= 32; i++) {
00893 char name[80] = "";
00894 sprintf(name,"ESO DET OUT%d RON", i);
00895
00896 if (cpl_propertylist_has(plist, name) == 1) {
00897 *rn = cpl_propertylist_get_double(plist, name);
00898 break;
00899 }
00900 }
00901 }
00902
00903 }
00904
00912 int omega_pfits_get_overscan(const cpl_frame *frame, int xn)
00913 {
00914 int value;
00915 cpl_propertylist *plist;
00916
00917 if(frame == NULL){
00918 cpl_msg_warning(cpl_func,"Frame is NULL");
00919 return -1;
00920 }
00921
00922 plist = cpl_propertylist_load_regexp(cpl_frame_get_filename(frame), xn,
00923 "ESO DRS", 0);
00924
00925 if(plist == NULL){
00926 cpl_msg_warning(cpl_func,"Cannot load property list");
00927 return -1;
00928 }
00929
00930 if( cpl_propertylist_has(plist, "ESO DRS OVERSCAN METHOD") == 1 ){
00931 value = cpl_propertylist_get_int(plist, "ESO DRS OVERSCAN METHOD");
00932 }
00933 else {
00934 cpl_msg_warning(cpl_func,"Cannot find overscan method in header");
00935 value = -1;
00936 }
00937
00938 freeplist(plist);
00939
00940 return value;
00941 }
00942
00943
00951
00952 void omega_pfits_get_gain(cpl_propertylist *plist, double *gain)
00953 {
00954
00955 int i = 0;
00956 char name[80] = "";
00957
00958 *gain = 0.0;
00959
00960 if(plist == NULL)
00961 return;
00962
00963
00964 if (plist == NULL) {
00965 cpl_msg_warning(cpl_func,"Header is NULL");
00966 }
00967 else if (cpl_propertylist_has(plist, "ESO DET OUT GAIN") == 1) {
00968 *gain = cpl_propertylist_get_double(plist, "ESO DET OUT GAIN");
00969 }
00970 else if (cpl_propertylist_has(plist, "GAIN") == 1) {
00971 *gain = cpl_propertylist_get_double(plist, "GAIN");
00972 }
00973 else {
00974
00975 for(i=1; i<= 32; i++){
00976
00977 sprintf(name,"ESO DET OUT%d GAIN", i);
00978
00979 if (cpl_propertylist_has(plist, name) == 1) {
00980 *gain = cpl_propertylist_get_double(plist, name);
00981 break;
00982 }
00983 }
00984 }
00985
00986 return;
00987 }
00988
00995 void omega_pfits_get_conad(cpl_propertylist *plist, double *conad)
00996 {
00997
00998 int i = 0;
00999 char name[80] = "";
01000
01001 *conad = 0.0;
01002
01003 if(plist == NULL)
01004 return;
01005
01006
01007 if (plist == NULL) {
01008 cpl_msg_error(cpl_func,"Header is empty");
01009 }
01010 else if (cpl_propertylist_has(plist, "ESO DET OUT CONAD") == 1) {
01011 *conad = cpl_propertylist_get_double(plist, "ESO DET OUT CONAD");
01012 }
01013 else if (cpl_propertylist_has(plist, "CONAD") == 1) {
01014 *conad = cpl_propertylist_get_double(plist, "CONAD");
01015 }
01016 else {
01017
01018 for(i=1; i<= 32; i++){
01019
01020 sprintf(name,"ESO DET OUT%d CONAD", i);
01021
01022 if (cpl_propertylist_has(plist, name) == 1) {
01023 *conad = cpl_propertylist_get_double(plist, name);
01024 break;
01025 }
01026 }
01027 }
01028
01029 return;
01030 }
01031
01038
01044 const char *omega_pfits_get_chipid(const cpl_propertylist *plist)
01045 {
01046 int i = 0;
01047 int nextensions = 32;
01048 const char *chipid = NULL;
01049 char name[80] = "";
01050
01051 if (plist == NULL) {
01052 cpl_msg_error(cpl_func,"NULL input property list");
01053 return NULL;
01054 }
01055
01056
01057
01058
01059
01060 for(i=1; i<= nextensions; i++) {
01061
01062 if (cpl_propertylist_has(plist, "ESO DET CHIP ID") == 1) {
01063 chipid = cpl_propertylist_get_string(plist, "ESO DET CHIP ID");
01064 break;
01065 }
01066 else {
01067 sprintf(name,"ESO DET CHIP%d ID", i);
01068
01069 if (cpl_propertylist_has(plist, name) == 1) {
01070 chipid = cpl_propertylist_get_string(plist, name);
01071 break;
01072 }
01073 }
01074 }
01075
01076 return chipid;
01077 }
01078
01085
01086
01087 const char * omega_pfits_get_extname(const cpl_propertylist *plist)
01088 {
01089
01090 if (cpl_propertylist_has(plist, "EXTNAME") == 0){
01091 return NULL;
01092 }
01093
01094 return cpl_propertylist_get_string(plist, "EXTNAME");
01095
01096 }
01097
01107
01108
01109 int omega_compare_extname(cpl_propertylist *plist1, cpl_propertylist *plist2)
01110 {
01111 const char *extn1 = NULL;
01112 const char *extn2 = NULL;
01113
01114 if(plist1 == NULL || plist2 == NULL){
01115 cpl_msg_error(cpl_func,"NULL input property list(s)");
01116 return -1;
01117 }
01118
01119 if((cpl_propertylist_has(plist1, "EXTNAME") == 1)
01120 && (cpl_propertylist_has(plist2, "EXTNAME") == 1)) {
01121
01122 extn1 = cpl_propertylist_get_string(plist1, "EXTNAME");
01123 extn2 = cpl_propertylist_get_string(plist2, "EXTNAME");
01124 return strcmp(extn1, extn2);
01125 }
01126 else{
01127 return -1;
01128 }
01129
01130 }
01131
01132
01153
01154 cpl_propertylist * omega_pfits_get_filter_info(const cpl_propertylist *main)
01155 {
01156
01157 int has_fringes = 0;
01158 int i = 0;
01159 int n = 4;
01160 int check =0 ;
01161 int check1 = 0;
01162 int filtno = 0;
01163
01164 double wave_central = 0.0f;
01165
01166 const char *filtid = "none";
01167 const char *filtname = "none";
01168 const char *reffiltname = "none";
01169 const char *referr = "none";
01170 const char *extname = "none";
01171
01172
01173 cpl_propertylist *list;
01174
01175 if (main == NULL) {
01176 cpl_msg_error(cpl_func,"Main header is empty");
01177 return NULL;
01178 }
01179
01180 list = cpl_propertylist_new();
01181
01182 if (cpl_propertylist_has(main,"ESO INS FILT ID") == 1) {
01183 filtid = cpl_propertylist_get_string(main, "ESO INS FILT ID");
01184 filtname = cpl_propertylist_get_string(main, "ESO INS FILT NAME");
01185 }
01186 else if (cpl_propertylist_has(main,"ESO INS FILT1 ID") == 1) {
01187 filtid = cpl_propertylist_get_string(main, "ESO INS FILT1 ID");
01188 filtname = cpl_propertylist_get_string(main, "ESO INS FILT1 NAME");
01189 }
01190 else if (cpl_propertylist_has(main,"FILT_ID") == 1) {
01191 filtid = cpl_propertylist_get_string(main, "FILT_ID");
01192 filtname = cpl_propertylist_get_string(main, "FILT_NAME");
01193 }
01194 else {
01195 filtid = "";
01196 filtname = "";
01197 cpl_msg_warning(cpl_func,"Cannot find filter information in header");
01198
01199 }
01200
01201 if (cpl_propertylist_has(main,"EXTNAME") == 1) {
01202 extname= cpl_propertylist_get_string(main, "EXTNAME");
01203 }
01204 else {
01205 extname = "";
01206 cpl_msg_debug(cpl_func,"Cannot find extension name in header");
01207 }
01208
01209 if (cpl_propertylist_has(main,"ESO INS FILT1 NO") == 1) {
01210 filtno= cpl_propertylist_get_int(main, "ESO INS FILT1 NO");
01211 }
01212 else {
01213 filtno=0;
01214 }
01215
01216
01217
01218 cpl_propertylist_append_string(list,"FILT_ID", filtid);
01219
01220
01221
01222 for(i=0; i<n; i++) {
01223
01224
01225
01226
01227
01228 check = strcmp("PS7", filtid);
01229 check1 = strcmp("u_SDSS", filtname);
01230 if(check == 0 || check1 == 0) {
01231 reffiltname = "SloanU";
01232 referr = "SloanU_err";
01233 wave_central = 3540.;
01234 has_fringes = 0;
01235 break;
01236 }
01237
01238 check = strcmp("PS2", filtid);
01239 check1 = strcmp("g_SDSS", filtname);
01240 if(check == 0 || check1 == 0) {
01241 reffiltname = "SloanG";
01242 referr = "SloanG_err";
01243 wave_central = 4750.;
01244 has_fringes = 0;
01245 break;
01246 }
01247
01248 check = strcmp("PS4", filtid);
01249 check1 = strcmp("r_SDSS", filtname);
01250 if(check == 0 || check1 == 0) {
01251 reffiltname = "SloanR";
01252 referr = "SloanR_err";
01253 wave_central = 6250.;
01254 has_fringes = 0;
01255 break;
01256 }
01257
01258 check = strcmp("PS3", filtid);
01259 check1 = strcmp("i_SDSS", filtname);
01260 if(check == 0 || check1 == 0) {
01261 reffiltname = "SloanI";
01262 referr = "SloanI_err";
01263 wave_central = 7560.;
01264 has_fringes = 1;
01265 break;
01266 }
01267
01268 check = strcmp("PS1", filtid);
01269 check1 = strcmp("z_SDSS", filtname);
01270 if(check == 0 || check1 == 0) {
01271 reffiltname = "SloanZ";
01272 referr = "SloanZ_err";
01273 wave_central = 8800.;
01274 has_fringes = 1;
01275 break;
01276 }
01277
01278 check = strcmp("PS9", filtid);
01279 check1 = strcmp("B_JOHN", filtname);
01280 if(check == 0 || check1 == 0) {
01281 reffiltname = "JohnsonB";
01282 referr = "JohnsonB_err";
01283 wave_central = 4390;
01284 has_fringes = 0;
01285 break;
01286 }
01287
01288 check = strcmp("PS10", filtid);
01289 check1 = strcmp("V_JOHN", filtname);
01290 if(check == 0 || check1 == 0) {
01291 reffiltname = "JohnsonV";
01292 referr = "JohnsonV_err";
01293 wave_central = 5510;
01294 has_fringes = 0;
01295 break;
01296 }
01297
01298 check = strcmp("PS5", filtid);
01299 check1 = strcmp("v_STRM", filtname);
01300 if(check == 0 || check1 == 0) {
01301 wave_central = 4120.;
01302 has_fringes = 0;
01303 break;
01304 }
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319 check = strcmp("PS6", filtid);
01320 check1 = strcmp("NB_852_861_869_878", filtname);
01321 if(check == 0 || check1 == 0) {
01322 wave_central = 0.;
01323 has_fringes = 0;
01324 break;
01325 }
01326
01327 check = strcmp("PS14", filtid);
01328 check1 = strcmp("NB_454_494_533_575", filtname);
01329 if(check == 0 || check1 == 0) {
01330 wave_central = 0.;
01331 has_fringes = 0;
01332 break;
01333 }
01334
01335 check = strcmp("PS22", filtid);
01336 check1 = strcmp("NB_617_710_755_817", filtname);
01337 if(check == 0 || check1 == 0) {
01338 wave_central = 0.;
01339 has_fringes = 0;
01340 break;
01341 }
01342
01343 check = strcmp("PS59", filtid);
01344 check1 = strcmp("Dummy_2", filtname);
01345 if(check == 0 || check1 == 0) {
01346 wave_central = 0.;
01347 has_fringes = 0;
01348 break;
01349 }
01350
01351 check = strcmp("PS60", filtid);
01352 check1 = strcmp("Dummy_1", filtname);
01353 if(check == 0 || check1 == 0) {
01354 wave_central = 0.;
01355 has_fringes = 0;
01356 break;
01357 }
01358
01359 check = strcmp("opaque", filtid);
01360 check1 = strcmp("opaque", filtname);
01361 if(check == 0 || check1 == 0) {
01362 wave_central = 0.;
01363 has_fringes = 0;
01364 break;
01365 }
01366
01367
01368 check = strcmp("calib", filtid);
01369 check1 = strcmp("u_g_r_i_SDSS", filtname);
01370 if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 1) {
01371 reffiltname = "SloanU";
01372 referr = "SloanU_err";
01373 wave_central = 3540.;
01374 has_fringes = 0;
01375 break;
01376 }
01377
01378
01379 check = strcmp("calib", filtid);
01380 check1 = strcmp("u_g_r_i_SDSS", filtname);
01381 if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 4) {
01382 reffiltname = "SloanG";
01383 referr = "SloanG_err";
01384 wave_central = 4750.;
01385 has_fringes = 0;
01386 break;
01387 }
01388
01389
01390 check = strcmp("calib", filtid);
01391 check1 = strcmp("u_g_r_i_SDSS", filtname);
01392 if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 3) {
01393 reffiltname = "SloanR";
01394 referr = "SloanR_err";
01395 wave_central = 6250.;
01396 has_fringes = 0;
01397 break;
01398 }
01399
01400 check = strcmp("calib", filtid);
01401 check1 = strcmp("u_g_r_i_SDSS", filtname);
01402 if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 2) {
01403 reffiltname = "SloanI";
01404 referr = "SloanI_err";
01405 wave_central = 7560.;
01406 has_fringes = 0;
01407 break;
01408 }
01409
01410
01411
01412
01413 check = strcmp("PS11", filtid);
01414 check1 = strcmp("H_ALPHA", filtname);
01415 if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 1) {
01416 reffiltname = "H_ALPHA";
01417 referr = "H_ALPHA_err";
01418 wave_central = 6791.;
01419 has_fringes = 0;
01420 break;
01421 }
01422
01423
01424 check = strcmp("PS11", filtid);
01425 check1 = strcmp("H_ALPHA", filtname);
01426 if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 4) {
01427 reffiltname = "H_ALPHA";
01428 referr = "H_ALPHA_err";
01429 wave_central = 6590.;
01430 has_fringes = 0;
01431 break;
01432 }
01433
01434
01435 check = strcmp("PS11", filtid);
01436 check1 = strcmp("H_ALPHA", filtname);
01437 if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 3) {
01438 reffiltname = "H_ALPHA";
01439 referr = "H_ALPHA_err";
01440 wave_central = 6660.;
01441 has_fringes = 0;
01442 break;
01443 }
01444
01445 check = strcmp("PS11", filtid);
01446 check1 = strcmp("H_ALPHA", filtname);
01447 if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 2) {
01448 reffiltname = "H_ALPHA";
01449 referr = "H_ALPHA_err";
01450 wave_central = 6726.;
01451 has_fringes = 0;
01452 break;
01453 }
01454
01455
01456
01457 check = strcmp("PS30", filtid);
01458 check1 = strcmp("NB_659", filtname);
01459 if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 1) {
01460 reffiltname = "NB_659";
01461 referr = "NB_659_err";
01462 wave_central = 6586.;
01463 has_fringes = 0;
01464 break;
01465 }
01466
01467
01468 check = strcmp("PS30", filtid);
01469 check1 = strcmp("NB_659", filtname);
01470 if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 4) {
01471 reffiltname = "NB_659";
01472 referr = "NB_659_err";
01473 wave_central = 6593.;
01474 has_fringes = 0;
01475 break;
01476 }
01477
01478
01479 check = strcmp("PS30", filtid);
01480 check1 = strcmp("NB_659", filtname);
01481 if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 3) {
01482 reffiltname = "NB_659";
01483 referr = "NB_659_err";
01484 wave_central = 6586.;
01485 has_fringes = 0;
01486 break;
01487 }
01488
01489 check = strcmp("PS30", filtid);
01490 check1 = strcmp("NB_659", filtname);
01491 if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 2) {
01492 reffiltname = "NB_659";
01493 referr = "NB_659_err";
01494 wave_central = 6586.;
01495 has_fringes = 0;
01496 break;
01497 }
01498
01499 }
01500
01501 cpl_propertylist_append_string(list,"FILT_NAME", filtname);
01502 cpl_propertylist_append_string(list,"REF_MAG_ID", reffiltname);
01503 cpl_propertylist_append_string(list,"REF_MAG_ID_ERR", referr);
01504 cpl_propertylist_append_double(list,"CWL", wave_central);
01505 cpl_propertylist_append_int(list,"HAS_FRINGES", has_fringes);
01506
01507
01508
01509 return list;
01510 }
01511
01512
01521
01522 int omega_pfits_update_header(cpl_propertylist *to, const cpl_propertylist *from)
01523 {
01524
01525 int i = 0;
01526 int n = 0;
01527
01528 if(from == NULL)
01529 return -1;
01530
01531 if(to == NULL) {
01532 to = cpl_propertylist_new();
01533 cpl_propertylist_append(to, from);
01534 return 0;
01535 }
01536
01537 n = cpl_propertylist_get_size(from);
01538 for (i=0; i < n; i++){
01539 const cpl_property *pro = cpl_propertylist_get_const(from, i);
01540 const char *name = cpl_property_get_name(pro);
01541 if(cpl_propertylist_has(to, name) == 1)
01542 cpl_propertylist_erase(to, name);
01543
01544 cpl_propertylist_copy_property(to, from, name);
01545 }
01546
01547
01548
01549 return 0;
01550 }
01551
01552
01563
01564 cpl_vector * omega_pfits_get_preovscan(const cpl_propertylist *plist)
01565 {
01566 int i = 0;
01567 int index = 0;
01568 int next = 32;
01569 int prscx = 48;
01570 int prscy = 0;
01571 int ovscx = 48;
01572 int ovscy = 100;
01573 char name[80] = "";
01574 const char *readkeys = "|ESO DET OUT[0-9]|ESO DET OUT|";
01575 cpl_vector *sregion;
01576
01577 if(plist == NULL)
01578 return NULL;
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589 for(i=1; i<= next; i++) {
01590 sprintf(name,"ESO DET OUT%d INDEX", i);
01591 if(cpl_propertylist_has(plist, name) == 1) {
01592 index = cpl_propertylist_get_int (plist, name);
01593 break;
01594 }
01595 }
01596
01597 if(index == 0){
01598 cpl_msg_warning(cpl_func,"Cannot find HIERARCH ESO DET OUT# INDEX");
01599
01600 index = 1;
01601 }
01602
01603
01604 sprintf(name, "ESO DET OUT%d PRSCX", index);
01605 if(cpl_propertylist_has(plist, name) == 1){
01606 prscx = cpl_propertylist_get_int (plist, name);
01607 sprintf(name,"ESO DET OUT%d PRSCY", index);
01608 prscy = cpl_propertylist_get_int (plist, name);
01609 sprintf(name,"ESO DET OUT%d OVSCX", index);
01610 ovscx = cpl_propertylist_get_int (plist, name);
01611 sprintf(name,"ESO DET OUT%d OVSCY", index);
01612 ovscy = cpl_propertylist_get_int (plist, name);
01613 }
01614 else {
01615 return NULL;
01616 }
01617
01618 sregion = cpl_vector_new(4);
01619 cpl_vector_set(sregion, 0, prscx);
01620 cpl_vector_set(sregion, 1, prscy);
01621 cpl_vector_set(sregion, 2, ovscx);
01622 cpl_vector_set(sregion, 3, ovscy);
01623
01624
01625 return sregion;
01626
01627 }
01628
01637 double omega_pfits_get_jitter_offset(cpl_propertylist *plist)
01638 {
01639
01640 double offset = 0.0;
01641
01642 if(cpl_propertylist_has(plist,"ESO TEL TARG OFFSETSIZE") == 0)
01643 return 0;
01644
01645 offset = cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETSIZE");
01646
01647 return offset;
01648 }
01649
01658 double omega_pfits_get_dither_offsetx(cpl_propertylist *plist)
01659 {
01660
01661 double offset = 0.0;
01662
01663 if(cpl_propertylist_has(plist,"ESO TEL TARG OFFSETSIZEX") == 0)
01664 return 0;
01665
01666 offset = cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETSIZEX");
01667
01668 return offset;
01669 }
01670
01679 double omega_pfits_get_dither_offsety(cpl_propertylist *plist)
01680 {
01681
01682 double offset = 0.0;
01683
01684 if(cpl_propertylist_has(plist,"ESO TEL TARG OFFSETSIZEY") == 0)
01685 return 0;
01686
01687 offset = cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETSIZEY");
01688
01689 return offset;
01690 }
01691
01700 double omega_pfits_get_offset_alpha(cpl_propertylist *plist)
01701 {
01702
01703 double offset = 0.0;
01704
01705 if(cpl_propertylist_has(plist,"ESO TEL TARG OFFSETALPHA") == 0)
01706 return 0;
01707
01708 offset = cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETALPHA");
01709
01710 return offset;
01711 }
01712
01721 double omega_pfits_get_offset_delta(cpl_propertylist *plist)
01722 {
01723
01724 double offset = 0.0;
01725
01726 if(cpl_propertylist_has(plist,"ESO TEL TARG OFFSETDELTA") == 0)
01727 return 0;
01728
01729 offset = cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETDELTA");
01730
01731 return offset;
01732 }
01733
01734
01741
01742
01743 double omega_pfits_get_cd11(const cpl_propertylist *plist)
01744 {
01745
01746 if(cpl_propertylist_has(plist, "CD1_1") == 0)
01747 return 0;
01748
01749 return(cpl_propertylist_get_double(plist,"CD1_1"));
01750 }
01751
01752
01759
01760
01761 double omega_pfits_get_cd12(const cpl_propertylist *plist)
01762 {
01763
01764 if(cpl_propertylist_has(plist, "CD1_2") == 0)
01765 return 0;
01766
01767 return(cpl_propertylist_get_double(plist,"CD1_2"));
01768
01769 }
01770
01771
01778
01779
01780 double omega_pfits_get_cd21(const cpl_propertylist *plist)
01781 {
01782
01783 if(cpl_propertylist_has(plist, "CD2_1") == 0)
01784 return 0;
01785
01786 return(cpl_propertylist_get_double(plist,"CD2_1"));
01787
01788 }
01789
01790
01797
01798
01799 double omega_pfits_get_cd22(const cpl_propertylist *plist)
01800 {
01801
01802 if(cpl_propertylist_has(plist, "CD2_2") == 0)
01803 return 0;
01804
01805 return(cpl_propertylist_get_double(plist,"CD2_2"));
01806
01807 }
01808
01809
01816
01817
01818 double omega_pfits_get_cdelt2(const cpl_propertylist *plist)
01819 {
01820
01821 if(cpl_propertylist_has(plist, "CDELT2") == 0)
01822 return 0;
01823
01824 return(cpl_propertylist_get_double(plist,"CDELT2"));
01825
01826 }
01827
01838 void omega_pfits_get_chip_size(const cpl_propertylist *plist,int *xs, int *ys)
01839 {
01840 int prscx = 48;
01841 int prscy = 0;
01842 int ovscx = 48;
01843 int ovscy = 100;
01844 int naxis1 = 2144;
01845 int naxis2 = 4200;
01846 int x0 = 1;
01847 int x1 = 1;
01848 int y0 = 1;
01849 int y1 = 1;
01850 cpl_vector *vec;
01851
01852 if(plist == NULL){
01853
01854 cpl_msg_info(cpl_func,"Using default chip sizes");
01855 x0 = prscx + 1;
01856 y0 = prscy + 1;
01857 x1 = naxis1 - ovscx;
01858 y1 = naxis2 - ovscy;
01859
01860 *xs = x1 - x0+1;
01861 *ys = y1 - y0+1;
01862 return;
01863 }
01864
01865
01866 naxis1 = cpl_propertylist_get_int(plist, "NAXIS1");
01867 naxis2 = cpl_propertylist_get_int(plist, "NAXIS2");
01868
01869
01870 vec = omega_pfits_get_preovscan(plist);
01871 prscx = cpl_vector_get(vec,0);
01872 prscy = cpl_vector_get(vec,1);
01873 ovscx = cpl_vector_get(vec,2);
01874 ovscy = cpl_vector_get(vec,3);
01875
01876 x0 = prscx + 1;
01877 y0 = prscy + 1;
01878 x1 = naxis1 - ovscx;
01879 y1 = naxis2 - ovscy;
01880
01881 *xs = x1 - x0+1;
01882 *ys = y1 - y0+1;
01883
01884 freevector(vec);
01885
01886 return;
01887 }
01888
01898 static int omega_get_quadrant(const char * extname, int filtno)
01899 {
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913 if (extname == NULL){
01914 return 0;
01915 }
01916 else if((strcmp("ESO_CCD_#96", extname)== 0) ||
01917 (strcmp("ESO_CCD_#95", extname)== 0) ||
01918 (strcmp("ESO_CCD_#94", extname)== 0) ||
01919 (strcmp("ESO_CCD_#93", extname)== 0) ||
01920 (strcmp("ESO_CCD_#88", extname)== 0) ||
01921 (strcmp("ESO_CCD_#87", extname)== 0) ||
01922 (strcmp("ESO_CCD_#86", extname)== 0) ||
01923 (strcmp("ESO_CCD_#85", extname)== 0)) {
01924 if(filtno>=1 && filtno<=6){
01925 return 1;
01926 }
01927 else if (filtno>=7 && filtno<=12){
01928 return 3;
01929 }
01930 }
01931 else if((strcmp("ESO_CCD_#92", extname)== 0) ||
01932 (strcmp("ESO_CCD_#91", extname)== 0) ||
01933 (strcmp("ESO_CCD_#90", extname)== 0) ||
01934 (strcmp("ESO_CCD_#89", extname)== 0) ||
01935 (strcmp("ESO_CCD_#84", extname)== 0) ||
01936 (strcmp("ESO_CCD_#83", extname)== 0) ||
01937 (strcmp("ESO_CCD_#82", extname)== 0) ||
01938 (strcmp("ESO_CCD_#81", extname)== 0)) {
01939 if(filtno>=1 && filtno<=6){
01940 return 2;
01941 }
01942 else if (filtno>=7 && filtno<=12){
01943 return 4;
01944 }
01945 }
01946 else if((strcmp("ESO_CCD_#76", extname)== 0) ||
01947 (strcmp("ESO_CCD_#75", extname)== 0) ||
01948 (strcmp("ESO_CCD_#74", extname)== 0) ||
01949 (strcmp("ESO_CCD_#73", extname)== 0) ||
01950 (strcmp("ESO_CCD_#68", extname)== 0) ||
01951 (strcmp("ESO_CCD_#67", extname)== 0) ||
01952 (strcmp("ESO_CCD_#66", extname)== 0) ||
01953 (strcmp("ESO_CCD_#65", extname)== 0)) {
01954 if(filtno>=1 && filtno<=6){
01955 return 3;
01956 }
01957 else if (filtno>=7 && filtno<=12){
01958 return 1;
01959 }
01960 }
01961 else if((strcmp("ESO_CCD_#80", extname)== 0) ||
01962 (strcmp("ESO_CCD_#79", extname)== 0) ||
01963 (strcmp("ESO_CCD_#78", extname)== 0) ||
01964 (strcmp("ESO_CCD_#77", extname)== 0) ||
01965 (strcmp("ESO_CCD_#72", extname)== 0) ||
01966 (strcmp("ESO_CCD_#71", extname)== 0) ||
01967 (strcmp("ESO_CCD_#70", extname)== 0) ||
01968 (strcmp("ESO_CCD_#69", extname)== 0)){
01969 if(filtno>=1 && filtno<=6){
01970 return 4;
01971 }
01972 else if (filtno>=7 && filtno<=12){
01973 return 2;
01974 }
01975 }
01976
01977 else {
01978 return 0;
01979 }
01980
01981
01982 }
01983