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
00029
00030
00031
00032
00033 #include "sinfoni_dfs.h"
00034 #include <qfits.h>
00035 #include <cpl.h>
00036 #include <math.h>
00037
00038
00044
00045
00048 int sinfoni_get_clean_mean_window(cpl_image* img,
00049 int llx, int lly, int urx, int ury,
00050 const int kappa, const int nclip,
00051 double* clean_mean, double* clean_stdev)
00052 {
00053
00054 double mean=0;
00055 double stdev=0;
00056 double threshold=0;
00057 double lo_cut=0;
00058 double hi_cut=0;
00059 cpl_mask* mask=NULL;
00060 cpl_image* tmp=NULL;
00061 int i=0;
00062
00063 tmp=cpl_image_duplicate(img);
00064 cpl_image_accept_all(img);
00065 for(i=0;i<nclip;i++) {
00066
00067 mean=cpl_image_get_mean_window(tmp,llx,lly,urx,ury);
00068 stdev=cpl_image_get_stdev_window(tmp,llx,lly,urx,ury);
00069
00070
00071 threshold=kappa*stdev;
00072 lo_cut=mean-threshold;
00073 hi_cut=mean+threshold;
00074
00075 cpl_image_accept_all(img);
00076 mask=cpl_mask_threshold_image_create(tmp,lo_cut,hi_cut);
00077
00078 cpl_mask_not(mask);
00079 cpl_image_reject_from_mask(tmp,mask);
00080 cpl_mask_delete(mask);
00081
00082
00083 }
00084 *clean_mean=mean;
00085 *clean_stdev=stdev;
00086 cpl_image_delete(tmp);
00087
00088 return 0;
00089
00090
00091 }
00092 int check_rec_status(const char* _id, const int val) {
00093 if(cpl_error_get_code() != CPL_ERROR_NONE) {
00094 cpl_msg_error(_id,"error before %d",val);
00095 cpl_msg_error(_id,(char* ) cpl_error_get_message());
00096 cpl_msg_error(_id,(char* ) cpl_error_get_where());
00097 return -1;
00098 }
00099 return 0;
00100 }
00101
00102
00103 int
00104 sinfoni_clean_nan(cpl_image** im)
00105 {
00106 int i=0;
00107 int j=0;
00108 int nx=0;
00109 int ny=0;
00110 float* data=NULL;
00111
00112 nx=cpl_image_get_size_x(*im);
00113 ny=cpl_image_get_size_y(*im);
00114 data=cpl_image_get_data_float(*im);
00115
00116 for(j=0;j<ny;j++) {
00117 for(i=0;i<nx;i++) {
00118 if(qfits_isnan(data[j*nx+i]) != 0) {
00119 data[j*nx+i] = 0;
00120 }
00121 }
00122 }
00123 return 0;
00124 }
00125
00126
00127 void
00128 add_pro_fits_key(cpl_propertylist * plist, char* pro_catg, char* file_name, char* out_name)
00129 {
00130
00131 char* date=NULL;
00132 date = get_datetime_iso8601() ;
00133
00134 cpl_propertylist_insert_after_string(plist, "EXPTIME", KEY_NAME_PIPEFILE, out_name) ;
00135 cpl_propertylist_set_comment(plist, KEY_NAME_PIPEFILE,KEY_HELP_PIPEFILE) ;
00136
00137 cpl_propertylist_insert_after_string(plist, "EXPTIME", KEY_NAME_HPRO_DID, KEY_VALUE_HPRO_DID) ;
00138 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DID,KEY_HELP_HPRO_DID) ;
00139
00140 cpl_propertylist_insert_after_string(plist, "EXPTIME", KEY_NAME_HPRO_TYPE, "REDUCED") ;
00141 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_TYPE, KEY_HELP_HPRO_TYPE ) ;
00142
00143 cpl_propertylist_insert_after_string(plist, "EXPTIME", KEY_NAME_HPRO_CATG, pro_catg) ;
00144 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_CATG, KEY_HELP_HPRO_CATG ) ;
00145
00146 cpl_propertylist_insert_after_string(plist, "EXPTIME", KEY_NAME_HPRO_STATUS, "OK") ;
00147 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_STATUS, KEY_HELP_HPRO_CATG ) ;
00148
00149 cpl_propertylist_insert_after_string(plist, "EXPTIME", KEY_NAME_HPRO_DATE, date) ;
00150 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DATE, KEY_HELP_HPRO_DATE ) ;
00151
00152 cpl_propertylist_insert_after_string(plist, "EXPTIME", KEY_NAME_HPRO_RECID, file_name) ;
00153 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_RECID, KEY_HELP_HPRO_RECID ) ;
00154
00155 cpl_propertylist_insert_after_string(plist, "EXPTIME", KEY_NAME_HPRO_DRSID, PACKAGE_VERSION) ;
00156 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DRSID, KEY_HELP_HPRO_DRSID ) ;
00157
00158
00159 }
00160
00161
00162
00163
00164
00165
00172
00173 int sinfoni_compare_tags(
00174 cpl_frame * frame1,
00175 cpl_frame * frame2)
00176 {
00177 char * v1 ;
00178 char * v2 ;
00179
00180
00181 if (frame1==NULL || frame2==NULL) return -1 ;
00182
00183
00184 if ((v1 = (char*)cpl_frame_get_tag(frame1)) == NULL) return -1 ;
00185 if ((v2 = (char*)cpl_frame_get_tag(frame2)) == NULL) return -1 ;
00186
00187
00188 if (strcmp(v1, v2)) return 0 ;
00189 else return 1 ;
00190 }
00191
00192 int sinfoni_extract_raw_pinhole_frames(cpl_frameset * sof, cpl_frameset** raw)
00193 {
00194 char* tag=NULL;
00195 char* name=NULL;
00196 cpl_frame* frame = NULL;
00197 int nsof=0;
00198 int i=0;
00199 nsof = cpl_frameset_get_size(sof);
00200 for (i=0 ; i<nsof ; i++) {
00201 frame = cpl_frameset_get_frame(sof,i);
00202 name= (char*) cpl_frame_get_filename(frame);
00203 if(is_fits_file(name) == 1) {
00204
00205 if(cpl_frame_get_tag(frame) != NULL) {
00206
00207 tag= (char*) cpl_frame_get_tag(frame);
00208 if(sinfoni_frame_is_pinhole_lamp(tag) == 1) {
00209 cpl_frameset_insert(*raw,frame);
00210 }
00211 }
00212 }
00213 }
00214 return 0;
00215 }
00216
00217
00218 int sinfoni_get_ins_set(char* band,int* ins_set){
00219
00220 if (strcmp(band,"H") == 0) {
00221 *ins_set = 0;
00222 }
00223 else if (strcmp(band,"H+K") == 0) {
00224 *ins_set = 1;
00225 }
00226 else if (strcmp(band,"K") == 0) {
00227 *ins_set = 2;
00228 }
00229 else if (strcmp(band,"J") == 0) {
00230 *ins_set = 3;
00231 }
00232 return 0;
00233
00234
00235 }
00236 int sinfoni_extract_raw_frames(cpl_frameset * sof, cpl_frameset** raw)
00237 {
00238 char* tag=NULL;
00239 char* name=NULL;
00240 cpl_frame* frame = NULL;
00241 int nsof=0;
00242 int i=0;
00243 nsof = cpl_frameset_get_size(sof);
00244 for (i=0 ; i<nsof ; i++) {
00245 frame = cpl_frameset_get_frame(sof,i);
00246 name= (char*) cpl_frame_get_filename(frame);
00247 if(is_fits_file(name) == 1) {
00248
00249 if(cpl_frame_get_tag(frame) != NULL) {
00250
00251 tag= (char*) cpl_frame_get_tag(frame);
00252 if(sinfoni_frame_is_raw(tag) == 1) {
00253 cpl_frameset_insert(*raw,frame);
00254 }
00255 }
00256 }
00257 }
00258 return 0;
00259 }
00260
00261 int sinfoni_remove_qc_frames(cpl_frameset* sof,cpl_frameset** raw)
00262 {
00263 char* tag=NULL;
00264 char* name=NULL;
00265 cpl_frame* frame = NULL;
00266 int nsof=0;
00267 int i=0;
00268
00269 nsof = cpl_frameset_get_size(sof);
00270 for (i=0 ; i<nsof ; i++) {
00271 frame = cpl_frameset_get_frame(sof,i);
00272 name= (char*) cpl_frame_get_filename(frame);
00273
00274 if(is_fits_file(name) == 1) {
00275
00276
00277 if(cpl_frame_get_tag(frame) != NULL) {
00278
00279 tag= (char*) cpl_frame_get_tag(frame);
00280
00281 if(strstr(tag,"QC") != NULL) {
00282
00283 cpl_frameset_erase(*raw,tag);
00284 }
00285 }
00286 } else {
00287
00288 cpl_frameset_erase_frame(*raw,frame);
00289 }
00290 }
00291 return 0;
00292
00293 }
00294
00295
00296 int sinfoni_contains_frames_kind(cpl_frameset * sof,
00297 cpl_frameset* raw,
00298 const char* type)
00299 {
00300 char* tag=NULL;
00301 char* name=NULL;
00302 cpl_frame* frame = NULL;
00303 cpl_frame* frame_dup = NULL;
00304
00305 int nsof=0;
00306 int i=0;
00307 nsof = cpl_frameset_get_size(sof);
00308 for (i=0 ; i<nsof ; i++) {
00309 frame = cpl_frameset_get_frame(sof,i);
00310 name= (char*) cpl_frame_get_filename(frame);
00311 if(is_fits_file(name) == 1) {
00312
00313 if(cpl_frame_get_tag(frame) != NULL) {
00314
00315 tag= (char*) cpl_frame_get_tag(frame);
00316
00317 if(strstr(tag,type) != NULL) {
00318
00319 frame_dup = cpl_frame_duplicate(frame);
00320 cpl_frameset_insert(raw,frame_dup);
00321
00322 }
00323 }
00324 }
00325 }
00326 return 0;
00327 }
00328
00329
00330
00331
00332 int sinfoni_is_fibres_on_off(cpl_frameset * sof,
00333 cpl_frameset* raw)
00334 {
00335 char* tag=NULL;
00336 char* name=NULL;
00337 cpl_frame* frame = NULL;
00338 cpl_frame* frame_dup = NULL;
00339
00340 int nsof=0;
00341 int i=0;
00342 nsof = cpl_frameset_get_size(sof);
00343 for (i=0 ; i<nsof ; i++) {
00344 frame = cpl_frameset_get_frame(sof,i);
00345 name= (char*) cpl_frame_get_filename(frame);
00346 if(is_fits_file(name) == 1) {
00347
00348 if(cpl_frame_get_tag(frame) != NULL) {
00349
00350 tag= (char*) cpl_frame_get_tag(frame);
00351
00352 if( strcmp(tag,PRO_FIBRE_NS_STACKED ) == 0) {
00353
00354 frame_dup = cpl_frame_duplicate(frame);
00355 cpl_frameset_insert(raw,frame_dup);
00356
00357 }
00358 }
00359 }
00360 }
00361 return 0;
00362 }
00363
00364
00365 int sinfoni_contains_frames_type(cpl_frameset * sof,
00366 cpl_frameset** raw,
00367 const char* type)
00368 {
00369 char* tag=NULL;
00370 char* name=NULL;
00371 cpl_frame* frame = NULL;
00372 cpl_frame* frame_dup = NULL;
00373 int nsof=0;
00374 int i=0;
00375 nsof = cpl_frameset_get_size(sof);
00376 for (i=0 ; i<nsof ; i++) {
00377 frame = cpl_frameset_get_frame(sof,i);
00378 name= (char*) cpl_frame_get_filename(frame);
00379 if(is_fits_file(name) == 1) {
00380
00381 if(cpl_frame_get_tag(frame) != NULL) {
00382
00383 tag= (char*) cpl_frame_get_tag(frame);
00384 if(strstr(tag,type) != NULL) {
00385
00386 frame_dup=cpl_frame_duplicate(frame);
00387 cpl_frameset_insert(*raw,frame_dup);
00388 }
00389 }
00390 }
00391 }
00392 return 0;
00393 }
00394
00395 int sinfoni_extract_raw_frames_type2(cpl_frameset * sof,
00396 cpl_frameset** raw,
00397 const char* type)
00398 {
00399
00400 cpl_frame* frame=NULL;
00401 cpl_frame* frame_dup = NULL;
00402 frame = cpl_frameset_find(sof,type);
00403 while(frame) {
00404 frame_dup=cpl_frame_duplicate(frame);
00405 cpl_frameset_insert(*raw,frame_dup);
00406 frame = cpl_frameset_find(sof,NULL);
00407 }
00408 return 0;
00409
00410 }
00411
00412
00413 int sinfoni_extract_raw_frames_type1(cpl_frameset * sof,
00414 cpl_frameset* raw,
00415 const char* type)
00416 {
00417
00418 cpl_frame* frame=NULL;
00419 cpl_frame* frame_dup = NULL;
00420 frame = cpl_frameset_find(sof,type);
00421 while(frame) {
00422 frame_dup=cpl_frame_duplicate(frame);
00423 cpl_frameset_insert(raw,frame_dup);
00424 frame = cpl_frameset_find(sof,NULL);
00425 }
00426 return 0;
00427
00428 }
00429
00430 int sinfoni_extract_raw_frames_type(cpl_frameset * sof,
00431 cpl_frameset** raw,
00432 const char* type)
00433 {
00434 char tag[FILE_NAME_SZ];
00435 char name[FILE_NAME_SZ];
00436 cpl_frame* frame = NULL;
00437 cpl_frame* frame_dup = NULL;
00438 int nsof=0;
00439 int i=0;
00440 nsof = cpl_frameset_get_size(sof);
00441 for (i=0 ; i<nsof ; i++) {
00442 frame = cpl_frameset_get_frame(sof,i);
00443 strcpy(name, cpl_frame_get_filename(frame));
00444 if(is_fits_file(name) == 1) {
00445
00446 if(cpl_frame_get_tag(frame) != NULL) {
00447
00448 strcpy(tag,cpl_frame_get_tag(frame));
00449 if(strcmp(tag,type) == 0) {
00450
00451 frame_dup=cpl_frame_duplicate(frame);
00452
00453 cpl_frameset_insert(*raw,frame_dup);
00454 }
00455 }
00456 }
00457 }
00458 return 0;
00459 }
00460
00461 int sinfoni_extract_frames_type(cpl_frameset * sof,
00462 cpl_frameset * raw,
00463 const char* type)
00464 {
00465 char* tag=NULL;
00466 char* name=NULL;
00467 cpl_frame* frame = NULL;
00468 cpl_frame* frame_dup = NULL;
00469 int nsof=0;
00470 int i=0;
00471 nsof = cpl_frameset_get_size(sof);
00472 for (i=0 ; i<nsof ; i++) {
00473 frame = cpl_frameset_get_frame(sof,i);
00474 name= (char*) cpl_frame_get_filename(frame);
00475 if(is_fits_file(name) == 1) {
00476
00477 if(cpl_frame_get_tag(frame) != NULL) {
00478
00479 tag= (char*) cpl_frame_get_tag(frame);
00480 if(strcmp(tag,type) == 0) {
00481
00482 frame_dup=cpl_frame_duplicate(frame);
00483 cpl_frameset_insert(raw,frame_dup);
00484 }
00485 }
00486 }
00487 }
00488 return 0;
00489 }
00490
00491
00492 int sinfoni_extract_obj_frames(cpl_frameset * sof, cpl_frameset* obj)
00493 {
00494 char* tag=NULL;
00495 char* name=NULL;
00496 cpl_frame* frame = NULL;
00497 cpl_frame* frame_dup = NULL;
00498
00499 int nsof=0;
00500 int i=0;
00501 nsof = cpl_frameset_get_size(sof);
00502 for (i=0 ; i<nsof ; i++) {
00503 frame = cpl_frameset_get_frame(sof,i);
00504 name= (char*) cpl_frame_get_filename(frame);
00505 if(is_fits_file(name) ==1) {
00506
00507 if(cpl_frame_get_tag(frame) != NULL) {
00508
00509 tag= (char*) cpl_frame_get_tag(frame);
00510 if(sinfoni_tag_is_obj(tag) == 1) {
00511 frame_dup=cpl_frame_duplicate(frame);
00512 cpl_frameset_insert(obj,frame_dup);
00513 }
00514 }
00515 }
00516 }
00517
00518 return 0;
00519 }
00520
00521
00522
00523 int sinfoni_extract_sky_frames(cpl_frameset * sof, cpl_frameset* sky)
00524 {
00525 char* tag=NULL;
00526 char* name=NULL;
00527 cpl_frame* frame = NULL;
00528 cpl_frame* frame_dup = NULL;
00529 int nsof=0;
00530 int i=0;
00531 nsof = cpl_frameset_get_size(sof);
00532 for (i=0 ; i<nsof ; i++) {
00533 frame = cpl_frameset_get_frame(sof,i);
00534 name= (char*) cpl_frame_get_filename(frame);
00535 if(is_fits_file(name) ==1) {
00536
00537 if(cpl_frame_get_tag(frame) != NULL) {
00538
00539 tag= (char*) cpl_frame_get_tag(frame);
00540 if(sinfoni_tag_is_sky(tag) == 1) {
00541 frame_dup=cpl_frame_duplicate(frame);
00542 cpl_frameset_insert(sky,frame_dup);
00543 }
00544 }
00545 }
00546 }
00547
00548 return 0;
00549 }
00550
00551 int sinfoni_extract_mst_frames(cpl_frameset * sof, cpl_frameset* cdb)
00552 {
00553 char* tag=NULL;
00554 char* name=NULL;
00555 cpl_frame* frame = NULL;
00556 cpl_frame* frame_dup = NULL;
00557 int nsof=0;
00558 int i=0;
00559 nsof = cpl_frameset_get_size(sof);
00560 for (i=0 ; i<nsof ; i++) {
00561 frame = cpl_frameset_get_frame(sof,i);
00562 name= (char*) cpl_frame_get_filename(frame);
00563 if(is_fits_file(name) ==1) {
00564
00565 if(cpl_frame_get_tag(frame) != NULL) {
00566
00567 tag= (char*) cpl_frame_get_tag(frame);
00568 if(sinfoni_frame_is_cdb(tag) == 1) {
00569 frame_dup=cpl_frame_duplicate(frame);
00570 cpl_frameset_insert(cdb,frame_dup);
00571 }
00572 }
00573 }
00574 }
00575
00576 return 0;
00577 }
00578
00579 int sinfoni_extract_cdb_frames(cpl_frameset * sof, cpl_frameset** cdb)
00580 {
00581 char* tag=NULL;
00582 char* name=NULL;
00583 cpl_frame* frame = NULL;
00584 cpl_frame* frame_dup = NULL;
00585 int nsof=0;
00586 int i=0;
00587
00588 nsof = cpl_frameset_get_size(sof);
00589 for (i=0 ; i<nsof ; i++) {
00590 frame = cpl_frameset_get_frame(sof,i);
00591 name= (char*) cpl_frame_get_filename(frame);
00592 if(is_fits_file(name) ==1) {
00593
00594 if(cpl_frame_get_tag(frame) != NULL) {
00595
00596 tag= (char*) cpl_frame_get_tag(frame);
00597 if(sinfoni_frame_is_cdb(tag) == 1) {
00598 frame_dup=cpl_frame_duplicate(frame);
00599 cpl_frameset_insert(*cdb,frame_dup);
00600 }
00601 }
00602 }
00603 }
00604
00605 return 0;
00606 }
00607
00608 int sinfoni_extract_raw_stack_frames(cpl_frameset * sof, cpl_frameset** pro)
00609 {
00610 char* tag=NULL;
00611 char* name=NULL;
00612 cpl_frame* frame = NULL;
00613 cpl_frame* frame_dup = NULL;
00614
00615 int nsof=0;
00616 int i=0;
00617 nsof = cpl_frameset_get_size(sof);
00618
00619 for (i=0 ; i<nsof ; i++) {
00620 frame = cpl_frameset_get_frame(sof,i);
00621 name= (char*) cpl_frame_get_filename(frame);
00622 if(is_fits_file(name) ==1) {
00623
00624 if(cpl_frame_get_tag(frame) != NULL) {
00625
00626 tag= (char*) cpl_frame_get_tag(frame);
00627
00628 if(sinfoni_frame_is_raw_stack(tag) == 1) {
00629 frame_dup = cpl_frame_duplicate(frame);
00630 cpl_frameset_insert(*pro,frame_dup);
00631 }
00632 }
00633 }
00634 }
00635
00636 return 0;
00637 }
00638
00639
00640 int sinfoni_extract_raw_slit_frames(cpl_frameset * sof, cpl_frameset** pro)
00641 {
00642 char* tag=NULL;
00643 char* name=NULL;
00644 cpl_frame* frame = NULL;
00645 int nsof=0;
00646 int i=0;
00647 nsof = cpl_frameset_get_size(sof);
00648 for (i=0 ; i<nsof ; i++) {
00649 frame = cpl_frameset_get_frame(sof,i);
00650 name= (char*) cpl_frame_get_filename(frame);
00651 if(is_fits_file(name) ==1) {
00652
00653 if(cpl_frame_get_tag(frame) != NULL) {
00654
00655 tag= (char*) cpl_frame_get_tag(frame);
00656 if(sinfoni_frame_is_slit_lamp(tag) == 1) {
00657 cpl_frameset_insert(*pro,frame);
00658 }
00659 }
00660 }
00661 }
00662
00663 return 0;
00664 }
00665
00666
00672
00673 int sinfoni_frame_is_raw(char * tag)
00674 {
00675
00676 if (tag == NULL) return -1 ;
00677
00678 if (!strcmp(tag, RAW_LINEARITY_LAMP)) return 1 ;
00679 if (!strcmp(tag, RAW_DARK)) return 1 ;
00680 if (!strcmp(tag, RAW_PINHOLE_LAMP)) return 1 ;
00681 if (!strcmp(tag, RAW_SLIT_LAMP)) return 1 ;
00682 if (!strcmp(tag, RAW_WAVE_LAMP)) return 1 ;
00683 if (!strcmp(tag, RAW_FLAT_LAMP)) return 1 ;
00684 if (!strcmp(tag, RAW_WAVE_NS)) return 1 ;
00685 if (!strcmp(tag, RAW_FLAT_NS)) return 1 ;
00686 if (!strcmp(tag, RAW_FIBRE_LAMP)) return 1 ;
00687 if (!strcmp(tag, RAW_FIBRE_EW)) return 1 ;
00688 if (!strcmp(tag, RAW_FIBRE_NS)) return 1 ;
00689 if (!strcmp(tag, RAW_FLAT_SKY)) return 1 ;
00690 if (!strcmp(tag, RAW_FLUX_LAMP)) return 1 ;
00691 if (!strcmp(tag, RAW_PSF_CALIBRATOR)) return 1 ;
00692 if (!strcmp(tag, RAW_FOCUS)) return 1 ;
00693
00694 if (!strcmp(tag, RAW_STD)) return 1 ;
00695 if (!strcmp(tag, RAW_STD_STAR)) return 1 ;
00696 if (!strcmp(tag, RAW_STD_STAR_DITHER)) return 1 ;
00697 if (!strcmp(tag, RAW_SKY_STD)) return 1 ;
00698 if (!strcmp(tag, RAW_SKY_OH)) return 1 ;
00699 if (!strcmp(tag, RAW_SKY_PSF_CALIBRATOR)) return 1 ;
00700
00701 if (!strcmp(tag, RAW_OBJECT_NODDING)) return 1 ;
00702 if (!strcmp(tag, RAW_OBJECT_SKYSPIDER)) return 1 ;
00703 if (!strcmp(tag, RAW_SKY_NODDING)) return 1 ;
00704
00705 if (!strcmp(tag, RAW_FLAT_LAMP_DITHER)) return 1 ;
00706 if (!strcmp(tag, RAW_WAVE_LAMP_DITHER)) return 1 ;
00707 if (!strcmp(tag, RAW_STD_STAR_DITHER)) return 1 ;
00708 if (!strcmp(tag, RAW_OBJECT_NODDING_DITHER)) return 1 ;
00709 if (!strcmp(tag, RAW_OBJECT_SKYSPIDER_DITHER)) return 1 ;
00710 if (!strcmp(tag, RAW_SKY_NODDING_DITHER)) return 1 ;
00711
00712
00713 return 0 ;
00714 }
00715
00716
00722
00723 int sinfoni_frame_is_raw_stack(char * tag)
00724 {
00725
00726 if (tag == NULL) return -1 ;
00727
00728
00729 if (!strcmp(tag, PRO_SKY_DUMMY)) return 1 ;
00730 if (!strcmp(tag, RAW_WAVE_LAMP)) return 1 ;
00731 if (!strcmp(tag, RAW_WAVE_LAMP_DITHER)) return 1 ;
00732 if (!strcmp(tag, RAW_WAVE_NS)) return 1 ;
00733 if (!strcmp(tag, RAW_WAVE_NS_DITHER)) return 1 ;
00734
00735 if (!strcmp(tag, RAW_FLUX_LAMP)) return 1 ;
00736 if (!strcmp(tag, RAW_FIBRE_NS)) return 1 ;
00737 if (!strcmp(tag, RAW_FIBRE_EW)) return 1 ;
00738
00739 if (!strcmp(tag, RAW_PSF_CALIBRATOR)) return 1 ;
00740
00741 if (!strcmp(tag, RAW_FOCUS)) return 1 ;
00742
00743 if (!strcmp(tag, RAW_OBJECT_NODDING)) return 1 ;
00744 if (!strcmp(tag, RAW_OBJECT_SKYSPIDER)) return 1 ;
00745 if (!strcmp(tag, RAW_SKY_NODDING)) return 1 ;
00746
00747 if (!strcmp(tag, RAW_OBJECT_NODDING_DITHER)) return 1 ;
00748 if (!strcmp(tag, RAW_OBJECT_SKYSPIDER_DITHER)) return 1 ;
00749 if (!strcmp(tag, RAW_SKY_NODDING_DITHER)) return 1 ;
00750
00751
00752 if (!strcmp(tag, RAW_STD)) return 1 ;
00753 if (!strcmp(tag, RAW_SKY_STD)) return 1 ;
00754 if (!strcmp(tag, RAW_SKY_OH)) return 1 ;
00755 if (!strcmp(tag, RAW_SKY_PSF_CALIBRATOR)) return 1 ;
00756 if (!strcmp(tag, RAW_STD_STAR)) return 1 ;
00757 if (!strcmp(tag, RAW_SKY)) return 1 ;
00758
00759 return 0 ;
00760 }
00761
00762
00763
00769
00770 int sinfoni_frame_is_raw_dark(char * tag)
00771 {
00772
00773 if (tag == NULL) return -1 ;
00774
00775 if (!strcmp(tag, RAW_DARK)) return 1 ;
00776
00777 return 0 ;
00778 }
00779
00780
00786
00787 int sinfoni_frame_is_slit_lamp(char * tag)
00788 {
00789
00790 if (tag == NULL) return -1 ;
00791
00792 if (!strcmp(tag, RAW_SLIT_LAMP)) return 1 ;
00793
00794 return 0 ;
00795 }
00796
00797
00798
00804
00805 int sinfoni_frame_is_pinhole_lamp(char * tag)
00806 {
00807
00808 if (tag == NULL) return -1 ;
00809
00810 if (!strcmp(tag, RAW_PINHOLE_LAMP)) return 1 ;
00811
00812 return 0 ;
00813 }
00814
00815
00816 int sinfoni_frame_is_cdb(char * tag)
00817 {
00818
00819 if (tag == NULL) return -1 ;
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849 if (!strcmp(tag, REF_LINE_ARC)) return 1 ;
00850 if (!strcmp(tag, PRO_BP_MAP)) return 1 ;
00851 if (!strcmp(tag, PRO_BP_MAP_HP)) return 1 ;
00852 if (!strcmp(tag, PRO_BP_MAP_DI)) return 1 ;
00853 if (!strcmp(tag, PRO_BP_MAP_NO)) return 1 ;
00854 if (!strcmp(tag, PRO_BP_MAP_NL)) return 1 ;
00855 if (!strcmp(tag, PRO_MASTER_BP_MAP)) return 1 ;
00856 if (!strcmp(tag, PRO_MASTER_DARK)) return 1 ;
00857 if (!strcmp(tag, PRO_SLOPE)) return 1 ;
00858 if (!strcmp(tag, PRO_DISTORTION)) return 1 ;
00859 if (!strcmp(tag, PRO_SLITLETS_DISTANCE)) return 1 ;
00860 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP)) return 1 ;
00861 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP1)) return 1 ;
00862 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP2)) return 1 ;
00863 if (!strcmp(tag, PRO_SLIT_POS)) return 1 ;
00864 if (!strcmp(tag, PRO_SLIT_POS_GUESS)) return 1 ;
00865 if (!strcmp(tag, PRO_WAVE_PAR_LIST)) return 1 ;
00866 if (!strcmp(tag, PRO_WAVE_COEF_SLIT)) return 1 ;
00867 if (!strcmp(tag, PRO_MASTER_LAMP_SPEC)) return 1 ;
00868 if (!strcmp(tag, PRO_MASTER_TWIFLAT)) return 1 ;
00869 if (!strcmp(tag, PRO_COEFF_LIST)) return 1 ;
00870 if (!strcmp(tag, PRO_INDEX_LIST)) return 1 ;
00871 if (!strcmp(tag, PRO_HALO_SPECT)) return 1 ;
00872 if (!strcmp(tag, PRO_FIRST_COL)) return 1 ;
00873 if (!strcmp(tag, PRO_FOCUS)) return 1 ;
00874 if (!strcmp(tag, PRO_WAVE_MAP)) return 1 ;
00875
00876 return 0;
00877
00878 }
00879
00880
00881 int get_gain(cpl_frameset* set)
00882 {
00883
00884 cpl_frameset* son=NULL;
00885 cpl_frameset* sof=NULL;
00886 cpl_frameset* sff=NULL;
00887
00888 cpl_frame* frm=NULL;
00889 cpl_frame* dup=NULL;
00890 int non=0;
00891 int nof=0;
00892 int nff=0;
00893 int nfr=0;
00894 double med_on=0;
00895 double avg_on=0;
00896 double* sig_on=0;
00897 double* sig_of=0;
00898 char* name=NULL;
00899 cpl_image* img=NULL;
00900 int i=0;
00901 double gain=0;
00902 son=cpl_frameset_new();
00903 sof=cpl_frameset_new();
00904 sff=set;
00905
00906 nff=cpl_frameset_get_size(sff);
00907
00908
00909 for(i=0;i<nff;i++) {
00910 frm=cpl_frameset_get_frame(sff,i);
00911 dup=cpl_frame_duplicate(frm);
00912 if(sinfoni_frame_is_on(frm)) {
00913 cpl_frameset_insert(son,dup);
00914 } else {
00915 cpl_frameset_insert(sof,dup);
00916 }
00917 }
00918
00919 non = cpl_frameset_get_size(son);
00920 nof = cpl_frameset_get_size(sof);
00921 nfr = (non <= nof) ? non : nof;
00922 sig_on=cpl_calloc(nfr,sizeof(double));
00923 sig_of=cpl_calloc(nfr,sizeof(double));
00924
00925
00926 for(i=0;i<nfr;i++) {
00927 frm=cpl_frameset_get_frame(son,i);
00928 name=(char*)cpl_frame_get_filename(frm);
00929 img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
00930 med_on=cpl_image_get_median(img);
00931 avg_on=cpl_image_get_mean(img);
00932 cpl_image_delete(img);
00933 sinfoni_get_ron(son,1,2047,1,2047,4,100,&sig_on);
00934 sinfoni_get_ron(sof,1,2047,1,2047,4,100,&sig_of);
00935 gain=2*med_on/(sig_on-sig_of);
00936 gain=2*avg_on/(sig_on-sig_of);
00937 }
00938 cpl_frameset_delete(son);
00939 cpl_frameset_delete(sof);
00940 cpl_free(sig_on);
00941 cpl_free(sig_of);
00942
00943 return 0;
00944
00945 }
00946
00947
00948
00949
00950
00951 int get_gain2(cpl_frameset* sff)
00952 {
00953
00954 cpl_frameset* son=NULL;
00955 cpl_frameset* sof=NULL;
00956
00957 cpl_frame* frm=NULL;
00958 cpl_frame* dup=NULL;
00959
00960 cpl_image* img_on1=NULL;
00961 cpl_image* img_on2=NULL;
00962 cpl_image* img_on_dif=NULL;
00963
00964
00965 cpl_image* img_of1=NULL;
00966 cpl_image* img_of2=NULL;
00967 cpl_image* img_of_dif=NULL;
00968
00969 int non=0;
00970 int nof=0;
00971 int nff=0;
00972 int nfr=0;
00973 double avg_on1=0;
00974 double avg_on2=0;
00975 double avg_of1=0;
00976 double avg_of2=0;
00977
00978 double sig_on_dif=0;
00979 double sig_of_dif=0;
00980 char* name=NULL;
00981 int i=0;
00982 int m=0;
00983 int llx=270;
00984 int lly=1000;
00985 int urx=320;
00986 int ury=1050;
00987
00988 double gain=0;
00989 double dit_ref=0;
00990 double dit_tmp=0;
00991 double exptime_ref=0;
00992 double exptime_tmp=0;
00993
00994 cpl_vector* dit_on=NULL;
00995 cpl_vector* dit_of=NULL;
00996 cpl_vector* exptime_on=NULL;
00997 cpl_vector* exptime_of=NULL;
00998
00999 nff=cpl_frameset_get_size(sff);
01000 son=cpl_frameset_new();
01001 sof=cpl_frameset_new();
01002
01003
01004
01005
01006
01007 for(i=0;i<nff;i++) {
01008 frm=cpl_frameset_get_frame(sff,i);
01009 dup=cpl_frame_duplicate(frm);
01010 if(sinfoni_frame_is_on(frm)) {
01011 cpl_frameset_insert(son,dup);
01012 } else {
01013 cpl_frameset_insert(sof,dup);
01014 }
01015 }
01016
01017 non = cpl_frameset_get_size(son);
01018 nof = cpl_frameset_get_size(sof);
01019 nfr = (non <= nof) ? non : nof;
01020
01021 dit_on=cpl_vector_new(nfr);
01022 dit_of=cpl_vector_new(nfr);
01023 exptime_on=cpl_vector_new(nfr);
01024 exptime_of=cpl_vector_new(nfr);
01025
01026 for(i=0;i<nfr;i++) {
01027
01028 frm=cpl_frameset_get_frame(son,i);
01029 name=(char*)cpl_frame_get_filename(frm);
01030 dit_ref=spiffi_get_dit(name);
01031 exptime_ref=spiffi_get_exptime(name);
01032 cpl_vector_set(dit_on,i,dit_ref);
01033 cpl_vector_set(exptime_on,i,exptime_ref);
01034
01035 frm=cpl_frameset_get_frame(sof,i);
01036 name=(char*)cpl_frame_get_filename(frm);
01037 dit_ref=spiffi_get_dit(name);
01038 exptime_ref=spiffi_get_exptime(name);
01039 cpl_vector_set(dit_of,i,dit_ref);
01040 cpl_vector_set(exptime_of,i,exptime_ref);
01041
01042 }
01043
01044 for(i=0;i<nfr;i++) {
01045 frm=cpl_frameset_get_frame(son,i);
01046 name=(char*)cpl_frame_get_filename(frm);
01047 printf("frm on1=%s\n",name);
01048 img_on1=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
01049
01050 frm=cpl_frameset_get_frame(sof,i);
01051 name=(char*)cpl_frame_get_filename(frm);
01052 printf("frm of1=%s\n",name);
01053 img_of1=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
01054
01055
01056 dit_ref=cpl_vector_get(dit_on,i);
01057 exptime_ref=cpl_vector_get(exptime_on,i);
01058
01059 for(m=0;m<nfr; m++) {
01060 if(m != i) {
01061 frm=cpl_frameset_get_frame(son,m);
01062 name=(char*)cpl_frame_get_filename(frm);
01063 dit_tmp=cpl_vector_get(dit_on,m);
01064 exptime_tmp=cpl_vector_get(exptime_on,m);
01065 if(dit_tmp == dit_ref && exptime_tmp == exptime_ref) {
01066 printf("m=%d i=%d\n",m,i);
01067 printf("frm on2=%s\n",name);
01068 img_on2=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
01069 frm=cpl_frameset_get_frame(sof,m);
01070 name=(char*)cpl_frame_get_filename(frm);
01071 printf("frm of2=%s\n",name);
01072 img_of2=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
01073
01074 img_on_dif=cpl_image_subtract_create(img_on1,img_on2);
01075 img_of_dif=cpl_image_subtract_create(img_of1,img_of2);
01076
01077 avg_on1=cpl_image_get_mean_window(img_on1,llx,lly,urx,ury);
01078 avg_on2=cpl_image_get_mean_window(img_on2,llx,lly,urx,ury);
01079 avg_of1=cpl_image_get_mean_window(img_of1,llx,lly,urx,ury);
01080 avg_of2=cpl_image_get_mean_window(img_of2,llx,lly,urx,ury);
01081
01082 sig_on_dif=cpl_image_get_stdev_window(img_on_dif,llx,lly,urx,ury);
01083 sig_of_dif=cpl_image_get_stdev_window(img_of_dif,llx,lly,urx,ury);
01084
01085 gain=((avg_on1+avg_on2)-(avg_of1+avg_of2))/
01086 ((sig_on_dif*sig_on_dif)-(sig_of_dif*sig_of_dif));
01087
01088 printf("gain=%f\n",gain);
01089
01090 }
01091 }
01092 }
01093
01094
01095
01096
01097 }
01098 cpl_vector_delete(dit_on);
01099 cpl_vector_delete(dit_of);
01100 cpl_vector_delete(exptime_on);
01101 cpl_vector_delete(exptime_of);
01102
01103 cpl_frameset_delete(son);
01104 cpl_frameset_delete(sof);
01105
01106
01107
01108
01109 return 0;
01110
01111 }
01112
01113
01114
01115
01116
01117
01118
01119
01120 cpl_table* get_gain3(cpl_frameset* sff)
01121 {
01122
01123 cpl_frameset* son=NULL;
01124 cpl_frameset* sof=NULL;
01125
01126 cpl_frame* frm=NULL;
01127 cpl_frame* dup=NULL;
01128
01129 cpl_image* img_on1=NULL;
01130 cpl_image* img_on2=NULL;
01131 cpl_image* img_on_dif=NULL;
01132
01133
01134 cpl_image* img_of1=NULL;
01135 cpl_image* img_of2=NULL;
01136 cpl_image* img_of_dif=NULL;
01137
01138 int non=0;
01139 int nof=0;
01140 int nff=0;
01141 int nfr=0;
01142 double avg_on1=0;
01143 double avg_on2=0;
01144 double avg_of1=0;
01145 double avg_of2=0;
01146 double std=0;
01147
01148 double sig_on_dif=0;
01149 double sig_of_dif=0;
01150 char* name=NULL;
01151 int i=0;
01152 int m=0;
01153
01154 int llx=270;
01155 int lly=1000;
01156 int urx=320;
01157 int ury=1050;
01158 int zone[4];
01159 double gain=0;
01160 double dit_ref=0;
01161 double dit_tmp=0;
01162 double exptime_ref=0;
01163 double exptime_tmp=0;
01164 cpl_table* res_tbl=NULL;
01165 int kappa=3;
01166 int nclip=5;
01167 cpl_vector* dit_on=NULL;
01168 cpl_vector* dit_of=NULL;
01169 cpl_vector* exptime_on=NULL;
01170 cpl_vector* exptime_of=NULL;
01171
01172 nff=cpl_frameset_get_size(sff);
01173 son=cpl_frameset_new();
01174 sof=cpl_frameset_new();
01175
01176
01177
01178 for(i=0;i<nff;i++) {
01179 frm=cpl_frameset_get_frame(sff,i);
01180 dup=cpl_frame_duplicate(frm);
01181 if(sinfoni_frame_is_on(frm)) {
01182 cpl_frameset_insert(son,dup);
01183 } else {
01184 cpl_frameset_insert(sof,dup);
01185 }
01186 }
01187
01188 non = cpl_frameset_get_size(son);
01189 nof = cpl_frameset_get_size(sof);
01190 nfr = (non <= nof) ? non : nof;
01191
01192 dit_on=cpl_vector_new(nfr);
01193 dit_of=cpl_vector_new(nfr);
01194 exptime_on=cpl_vector_new(nfr);
01195 exptime_of=cpl_vector_new(nfr);
01196
01197 for(i=0;i<nfr;i++) {
01198
01199 frm=cpl_frameset_get_frame(son,i);
01200 name=(char*)cpl_frame_get_filename(frm);
01201 dit_ref=spiffi_get_dit(name);
01202 exptime_ref=spiffi_get_exptime(name);
01203 cpl_vector_set(dit_on,i,dit_ref);
01204 cpl_vector_set(exptime_on,i,exptime_ref);
01205
01206 frm=cpl_frameset_get_frame(sof,i);
01207 name=(char*)cpl_frame_get_filename(frm);
01208 dit_ref=spiffi_get_dit(name);
01209 exptime_ref=spiffi_get_exptime(name);
01210 cpl_vector_set(dit_of,i,dit_ref);
01211 cpl_vector_set(exptime_of,i,exptime_ref);
01212
01213 }
01214 zone[0]=270;
01215 zone[1]=1030;
01216 zone[2]=310;
01217 zone[3]=1060;
01218
01219
01220 res_tbl=cpl_table_new(nfr);
01221 cpl_table_new_column(res_tbl,"adu", CPL_TYPE_DOUBLE);
01222 cpl_table_new_column(res_tbl,"gain", CPL_TYPE_DOUBLE);
01223
01224 for(i=0;i<nfr;i++) {
01225 frm=cpl_frameset_get_frame(son,i);
01226 name=(char*)cpl_frame_get_filename(frm);
01227 img_on1=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
01228
01229 frm=cpl_frameset_get_frame(sof,i);
01230 name=(char*)cpl_frame_get_filename(frm);
01231 img_of1=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
01232
01233
01234 dit_ref=cpl_vector_get(dit_on,i);
01235 exptime_ref=cpl_vector_get(exptime_on,i);
01236
01237
01238 for(m=0;m<nfr; m++) {
01239 if(m != i) {
01240 frm=cpl_frameset_get_frame(son,m);
01241 name=(char*)cpl_frame_get_filename(frm);
01242 dit_tmp=cpl_vector_get(dit_on,m);
01243 exptime_tmp=cpl_vector_get(exptime_on,m);
01244 if(dit_tmp == dit_ref && exptime_tmp == exptime_ref) {
01245
01246 img_on2=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
01247 frm=cpl_frameset_get_frame(sof,m);
01248 name=(char*)cpl_frame_get_filename(frm);
01249 img_of2=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
01250
01251 img_on_dif=cpl_image_subtract_create(img_on1,img_on2);
01252 img_of_dif=cpl_image_subtract_create(img_of1,img_of2);
01253
01254 sinfoni_get_clean_mean_window(img_on1,llx,lly,urx,ury,kappa,nclip,&avg_on1,&std);
01255 sinfoni_get_clean_mean_window(img_on2,llx,lly,urx,ury,kappa,nclip,&avg_on2,&std);
01256 sinfoni_get_clean_mean_window(img_of1,llx,lly,urx,ury,kappa,nclip,&avg_of1,&std);
01257 sinfoni_get_clean_mean_window(img_of2,llx,lly,urx,ury,kappa,nclip,&avg_of2,&std);
01258
01259 cpl_flux_get_noise_window(img_on_dif, zone,2,100, &sig_on_dif, NULL);
01260 cpl_flux_get_noise_window(img_of_dif, zone,2,100, &sig_of_dif, NULL);
01261
01262 cpl_image_delete(img_on2);
01263 cpl_image_delete(img_of2);
01264 cpl_image_delete(img_on_dif);
01265 cpl_image_delete(img_of_dif);
01266
01267 gain=((avg_on1+avg_on2)-(avg_of1+avg_of2))/
01268 ((sig_on_dif*sig_on_dif)-(sig_of_dif*sig_of_dif));
01269
01270 cpl_table_set_double(res_tbl,"gain",m,gain);
01271 cpl_table_set_double(res_tbl,"adu",m,((avg_on1+avg_on2)/2-(avg_of1+avg_of2)/2));
01272
01273
01274 }
01275 }
01276 }
01277 cpl_image_delete(img_on1);
01278 cpl_image_delete(img_of1);
01279 }
01280
01281
01282
01283
01284
01285
01286 cpl_vector_delete(dit_on);
01287 cpl_vector_delete(dit_of);
01288 cpl_vector_delete(exptime_on);
01289 cpl_vector_delete(exptime_of);
01290
01291 cpl_frameset_delete(son);
01292 cpl_frameset_delete(sof);
01293
01294
01295
01296
01297 return res_tbl;
01298
01299 }
01300
01301
01302
01303
01304 cpl_table* get_linearity(cpl_frameset* set)
01305 {
01306
01307 cpl_frameset* son=NULL;
01308 cpl_frameset* sof=NULL;
01309 cpl_frameset* sff=NULL;
01310
01311 cpl_frame* frm=NULL;
01312 cpl_frame* dup=NULL;
01313
01314 int* status=0;
01315 int non=0;
01316 int nof=0;
01317 int nff=0;
01318 int nfr=0;
01319 int i=0;
01320 double med_on=0;
01321 double avg_on=0;
01322 double med_of=0;
01323 double avg_of=0;
01324 double med_dit=0;
01325 double avg_dit=0;
01326
01327 double med=0;
01328 double avg=0;
01329
01330 char* name=NULL;
01331 cpl_image* img=NULL;
01332 cpl_vector* vec_adl=NULL;
01333 cpl_vector* vec_dit=NULL;
01334 cpl_vector* vec_avg=NULL;
01335 cpl_vector* vec_med=NULL;
01336 cpl_vector* vec_avg_dit=NULL;
01337 cpl_vector* vec_med_dit=NULL;
01338
01339 double dit=0;
01340 cpl_table* lin_tbl=NULL;
01341
01342 son=cpl_frameset_new();
01343 sof=cpl_frameset_new();
01344 sff=set;
01345
01346 nff=cpl_frameset_get_size(sff);
01347
01348
01349 for(i=0;i<nff;i++) {
01350 frm=cpl_frameset_get_frame(sff,i);
01351 dup=cpl_frame_duplicate(frm);
01352 if(sinfoni_frame_is_on(frm)) {
01353 cpl_frameset_insert(son,dup);
01354 } else {
01355 cpl_frameset_insert(sof,dup);
01356 }
01357 }
01358
01359 non = cpl_frameset_get_size(son);
01360 nof = cpl_frameset_get_size(sof);
01361 nfr = (non <= nof) ? non : nof;
01362
01363 lin_tbl=cpl_table_new(nfr);
01364 cpl_table_new_column(lin_tbl,"med", CPL_TYPE_DOUBLE);
01365 cpl_table_new_column(lin_tbl,"avg", CPL_TYPE_DOUBLE);
01366 cpl_table_new_column(lin_tbl,"med_dit", CPL_TYPE_DOUBLE);
01367 cpl_table_new_column(lin_tbl,"avg_dit", CPL_TYPE_DOUBLE);
01368 cpl_table_new_column(lin_tbl,"dit", CPL_TYPE_DOUBLE);
01369 vec_med=cpl_vector_new(nfr);
01370 vec_avg=cpl_vector_new(nfr);
01371 vec_med_dit=cpl_vector_new(nfr);
01372 vec_avg_dit=cpl_vector_new(nfr);
01373 vec_dit=cpl_vector_new(nfr);
01374 vec_adl=cpl_vector_new(nfr);
01375 for(i=0;i<nfr;i++) {
01376 frm=cpl_frameset_get_frame(son,i);
01377 name=(char*)cpl_frame_get_filename(frm);
01378 img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
01379 med_on=cpl_image_get_median(img);
01380 avg_on=cpl_image_get_mean(img);
01381 cpl_image_delete(img);
01382
01383 frm=cpl_frameset_get_frame(sof,i);
01384 name=(char*)cpl_frame_get_filename(frm);
01385 img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
01386 med_of=cpl_image_get_median(img);
01387 avg_of=cpl_image_get_mean(img);
01388 cpl_image_delete(img);
01389 med=med_on-med_of;
01390 avg=avg_on-avg_of;
01391
01392 dit=(double)spiffi_get_dit(name);
01393 avg_dit=avg/dit;
01394 med_dit=med/dit;
01395
01396 cpl_vector_set(vec_dit,i,dit);
01397 cpl_vector_set(vec_avg,i,avg);
01398 cpl_vector_set(vec_med,i,med);
01399 cpl_vector_set(vec_avg_dit,i,avg_dit);
01400 cpl_vector_set(vec_med_dit,i,med_dit);
01401
01402
01403 cpl_table_set_double(lin_tbl,"dit",i,dit);
01404 cpl_table_set_double(lin_tbl,"med",i,med);
01405 cpl_table_set_double(lin_tbl,"avg",i,avg);
01406 cpl_table_set_double(lin_tbl,"med_dit",i,med_dit);
01407 cpl_table_set_double(lin_tbl,"avg_dit",i,avg_dit);
01408
01409 }
01410 cpl_table_new_column(lin_tbl,"adl", CPL_TYPE_DOUBLE);
01411 med_dit=cpl_vector_get_mean(vec_med_dit);
01412 avg_dit=cpl_vector_get_mean(vec_avg_dit);
01413
01414 for(i=0;i<nfr;i++) {
01415 dit = cpl_table_get_double(lin_tbl,"dit",i,status);
01416 cpl_vector_set(vec_adl,i,dit*med_dit);
01417 cpl_table_set_double(lin_tbl,"adl",i,dit*med_dit);
01418 }
01419
01420 cpl_frameset_delete(son);
01421 cpl_frameset_delete(sof);
01422
01423
01424 cpl_vector_delete(vec_dit);
01425 cpl_vector_delete(vec_adl);
01426 cpl_vector_delete(vec_avg);
01427 cpl_vector_delete(vec_med);
01428 cpl_vector_delete(vec_avg_dit);
01429 cpl_vector_delete(vec_med_dit);
01430
01431
01432 return lin_tbl;
01433
01434 }
01435
01436
01437
01444
01445 int sinfoni_get_ron(cpl_frameset * framelist,
01446 const int ron_xmin,
01447 const int ron_xmax,
01448 const int ron_ymin,
01449 const int ron_ymax,
01450 const int ron_hsize,
01451 const int ron_nsamp,
01452 double** ron)
01453 {
01454 const char * fctid = "sinfoni_get_ron" ;
01455 cpl_imagelist * iset =NULL;
01456 cpl_image * tmp_im =NULL;
01457 int zone[4] ;
01458 double rms =0;
01459 char * sval =NULL;
01460 double ndit =0;
01461 cpl_frame * cur_frame =NULL;
01462 int i;
01463
01464
01465 if (framelist == NULL) return -1 ;
01466
01467
01468 if ((iset = sinfoni_frameset_to_iset(framelist)) == NULL) {
01469 cpl_msg_error(fctid, "Cannot load the data") ;
01470 return -1 ;
01471 }
01472
01473
01474 zone[0]=ron_xmin;
01475 zone[1]=ron_xmax;
01476 zone[2]=ron_ymin;
01477 zone[3]=ron_ymax;
01478
01479
01480 for (i=0 ; i<cpl_imagelist_get_size(iset)-1 ; i++) {
01481
01482
01483 if ((tmp_im = cpl_image_subtract_create(cpl_imagelist_get(iset, i),
01484 cpl_imagelist_get(iset, i+1))) == NULL) {
01485 cpl_msg_error(fctid, "Cannot subtract the images") ;
01486 cpl_imagelist_delete(iset) ;
01487 return -1 ;
01488 }
01489
01490
01491 if (cpl_flux_get_noise_window(tmp_im, zone, ron_hsize,
01492 ron_nsamp, &rms, NULL) != CPL_ERROR_NONE) {
01493 cpl_msg_error(fctid, "Cannot compute the RON") ;
01494 cpl_image_delete(tmp_im) ;
01495 cpl_imagelist_delete(iset) ;
01496 return -1 ;
01497 }
01498
01499 cpl_image_delete(tmp_im) ;
01500
01501 cur_frame = cpl_frameset_get_frame(framelist, i) ;
01502 if ((sval = sinfoni_pfits_get_ndit(
01503 (char*)cpl_frame_get_filename(cur_frame))) == NULL) {
01504 cpl_msg_error(fctid, "Cannot get NDIT") ;
01505 cpl_imagelist_delete(iset) ;
01506 return -1 ;
01507 }
01508
01509 ndit = (double)atof(sval) ;
01510
01511 (*ron)[i] = rms * sqrt(ndit/2.0) ;
01512
01513 }
01514
01515
01516 cpl_imagelist_delete(iset) ;
01517 return 0 ;
01518 }
01519
01520
01521
01522
01528
01529 int sinfoni_stack_get_pro_tag(char * tag_in, char* tag_out)
01530 {
01531
01532 if (tag_in == NULL) return -1 ;
01533
01534 if (strcmp(tag_in,RAW_WAVE_LAMP_DITHER) == 0 ) {
01535 strcpy(tag_out,PRO_WAVE_LAMP_STACKED);
01536 return 0 ;
01537 }
01538
01539
01540 if (strcmp(tag_in,RAW_WAVE_LAMP) == 0 ) {
01541 strcpy(tag_out,PRO_WAVE_LAMP_STACKED);
01542 return 0 ;
01543 }
01544
01545 if (strcmp(tag_in,RAW_WAVE_NS_DITHER) == 0 ) {
01546 strcpy(tag_out,PRO_WAVE_NS_STACKED);
01547 return 0 ;
01548 }
01549
01550
01551 if (strcmp(tag_in,RAW_WAVE_NS) == 0 ) {
01552 strcpy(tag_out,PRO_WAVE_NS_STACKED);
01553 return 0 ;
01554 }
01555
01556
01557 if (strcmp(tag_in,RAW_FIBRE_LAMP) == 0 ) {
01558 strcpy(tag_out,PRO_FIBRE_LAMP_STACKED);
01559 return 0 ;
01560 }
01561
01562 if (strcmp(tag_in,RAW_FIBRE_EW) == 0 ) {
01563 strcpy(tag_out,PRO_FIBRE_EW_STACKED);
01564 return 0 ;
01565 }
01566
01567 if (strcmp(tag_in,RAW_FIBRE_NS) == 0 ) {
01568 strcpy(tag_out,PRO_FIBRE_NS_STACKED);
01569 return 0 ;
01570 }
01571
01572
01573 if (strcmp(tag_in,PRO_FIBRE_NS_STACKED_ON) == 0 ) {
01574 strcpy(tag_out,PRO_FIBRE_NS_STACKED);
01575 return 0 ;
01576 }
01577
01578 if (strcmp(tag_in,PRO_FIBRE_NS_STACKED) == 0 ) {
01579 strcpy(tag_out,PRO_FIBRE_NS_STACKED_DIST);
01580 return 0 ;
01581 }
01582
01583
01584 if (strcmp(tag_in,RAW_SLIT_LAMP) == 0 ) {
01585 strcpy(tag_out,PRO_SLIT_LAMP_STACKED);
01586 return 0 ;
01587 }
01588
01589
01590 if (strstr(tag_in, "FLUX") != NULL ) {
01591 strcpy(tag_out,PRO_FLUX_LAMP_STACKED);
01592 return 0 ;
01593 }
01594
01595 if (strstr(tag_in, "PSF") != NULL ) {
01596 strcpy(tag_out,PRO_PSF_CALIBRATOR_STACKED);
01597 return 0 ;
01598 }
01599
01600
01601 if (strstr(tag_in, "FOCUS") != NULL ) {
01602 strcpy(tag_out,PRO_FOCUS_STACKED);
01603 return 0 ;
01604 }
01605
01606 if (strstr(tag_in, "OBJECT_NODDING") != NULL ) {
01607 strcpy(tag_out,PRO_OBJECT_NODDING_STACKED);
01608 return 0 ;
01609 }
01610
01611 if (strstr(tag_in, "SKY_NODDING") != NULL ) {
01612 strcpy(tag_out,PRO_SKY_NODDING_STACKED);
01613 return 0 ;
01614 }
01615
01616 if (strstr(tag_in, "STD_NODDING") != NULL ) {
01617 strcpy(tag_out,PRO_STD_NODDING_STACKED);
01618 return 0 ;
01619 }
01620
01621 if (strstr(tag_in, "OBJECT_SKYSPIDER") != NULL ) {
01622 strcpy(tag_out,PRO_OBJECT_SKYSPIDER_STACKED);
01623 return 0 ;
01624 }
01625
01626
01627 if (strstr(tag_in, RAW_STD) != NULL ) {
01628 strcpy(tag_out,PRO_STD_STACKED);
01629 return 0 ;
01630 }
01631
01632
01633 if (strstr(tag_in, RAW_SKY_STD) != NULL ) {
01634 strcpy(tag_out,PRO_SKY_STD_STACKED);
01635 return 0 ;
01636 }
01637
01638 if (strstr(tag_in, RAW_SKY_OH) != NULL ) {
01639 strcpy(tag_out,PRO_SKY_OH_STACKED);
01640 return 0 ;
01641 }
01642
01643 if (strstr(tag_in, RAW_SKY_PSF_CALIBRATOR) != NULL ) {
01644 strcpy(tag_out,PRO_SKY_PSF_CALIBRATOR_STACKED);
01645 return 0 ;
01646 }
01647
01648 if (strstr(tag_in, RAW_STD_STAR) != NULL ) {
01649 strcpy(tag_out,PRO_STD_STAR_STACKED);
01650 return 0 ;
01651 }
01652
01653 if (strstr(tag_in, RAW_STD_STAR) != NULL ) {
01654 strcpy(tag_out,PRO_STD_STAR_DITHER_STACKED);
01655 return 0 ;
01656 }
01657
01658 if (strstr(tag_in, RAW_SKY) != NULL ) {
01659 strcpy(tag_out,PRO_SKY_STACKED);
01660 return 0 ;
01661 }
01662
01663
01664 return 1 ;
01665 }
01666
01667
01673
01674 int sinfoni_util_inputs_is_raw(char * tag)
01675 {
01676
01677 if (tag == NULL) return -1 ;
01678
01679 if (!strcmp(tag, "IM_OBS")) return 1 ;
01680 if (!strcmp(tag, "SPC_OBS")) return 1 ;
01681 return 0 ;
01682 }
01683
01684 int sinfoni_is_dark(char * tag)
01685 {
01686
01687 if (tag == NULL) return -1 ;
01688
01689 if (!strcmp(tag, RAW_DARK)) return 1 ;
01690 return 0 ;
01691 }
01692
01693 int sinfoni_is_flat_bp(char * tag)
01694 {
01695
01696 if (tag == NULL) return -1 ;
01697
01698 if (!strcmp(tag, RAW_LINEARITY_LAMP)) return 1 ;
01699 return 0 ;
01700 }
01701
01702 int sinfoni_is_flat_lindet(char * tag)
01703 {
01704
01705 if (tag == NULL) return -1 ;
01706
01707 if (!strcmp(tag, RAW_LINEARITY_LAMP)) return 1 ;
01708 return 0 ;
01709 }
01710
01711
01712 int sinfoni_blank2dot(const char * in, char* ou)
01713 {
01714 int len=0;
01715 int i=0;
01716
01717 strcpy(ou,in);
01718 len = strlen(in);
01719 for (i=0;i<len;i++)
01720 {
01721 if (in[i] == ' ') {
01722 ou[i] = '.';
01723 }
01724 }
01725 return 0;
01726 }
01727
01728
01729 int sinfoni_is_sky_flat(char * tag)
01730 {
01731
01732 if (tag == NULL) return -1 ;
01733 if (!strcmp(tag, RAW_FLAT_SKY)) return 1 ;
01734 return 0 ;
01735 }
01736
01737
01738
01739 int sinfoni_is_master_flat(char * tag)
01740 {
01741
01742 if (tag == NULL) return -1 ;
01743
01744 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP)) return 1 ;
01745 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP1)) return 1 ;
01746 return 0 ;
01747 }
01748
01749 int sinfoni_is_master_flat_dither(char * tag)
01750 {
01751
01752 if (tag == NULL) return -1 ;
01753
01754 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP2)) return 1 ;
01755 return 0 ;
01756 }
01757
01758
01764
01765 int sinfoni_is_stack(char * tag)
01766 {
01767
01768 if (tag == NULL) return -1 ;
01769
01770 if (strstr(tag, PRO_STACKED) != NULL) return 1 ;
01771 return 0 ;
01772 }
01773
01774 int sinfoni_is_mflat(char * tag)
01775 {
01776
01777 if (tag == NULL) return -1 ;
01778
01779 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP)) return 1 ;
01780 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP1)) return 1 ;
01781 if (!strcmp(tag, PRO_MASTER_FLAT_LAMP2)) return 1 ;
01782 return 0 ;
01783 }
01784
01785
01786
01792
01793 int sinfoni_is_psf_calibrator_stacked(char * tag)
01794 {
01795
01796 if (tag == NULL) return -1 ;
01797
01798 if (!strcmp(tag, PRO_PSF_CALIBRATOR_STACKED)) return 1 ;
01799 return 0 ;
01800 }
01801
01807
01808 int sinfoni_is_focus_stacked(char * tag)
01809 {
01810
01811 if (tag == NULL) return -1 ;
01812
01813 if (!strcmp(tag, PRO_FOCUS_STACKED)) return 1 ;
01814 return 0 ;
01815 }
01816
01817
01823
01824 int sinfoni_is_lamp_wave_stacked(char * tag)
01825 {
01826
01827 if (tag == NULL) return -1 ;
01828
01829 if (!strcmp(tag, PRO_WAVE_LAMP_STACKED)) return 1 ;
01830 return 0 ;
01831 }
01832
01833
01839
01840 int sinfoni_is_lamp_flux_stacked(char * tag)
01841 {
01842
01843 if (tag == NULL) return -1 ;
01844
01845 if (!strcmp(tag, PRO_FLUX_LAMP_STACKED)) return 1 ;
01846 return 0 ;
01847 }
01848
01849
01855
01856 int sinfoni_is_object_nodding_stacked(char * tag)
01857 {
01858
01859 if (tag == NULL) return -1 ;
01860
01861 if (!strcmp(tag, PRO_OBJECT_NODDING_STACKED)) return 1 ;
01862 return 0 ;
01863 }
01864
01865
01871
01872 int sinfoni_is_object_skyspider_stacked(char * tag)
01873 {
01874
01875 if (tag == NULL) return -1 ;
01876
01877 if (!strcmp(tag, PRO_OBJECT_SKYSPIDER_STACKED)) return 1 ;
01878 return 0 ;
01879 }
01880
01881
01882
01888
01889 int sinfoni_is_sky_nodding_stacked(char * tag)
01890 {
01891
01892 if (tag == NULL) return -1 ;
01893
01894 if (!strcmp(tag, PRO_SKY_NODDING_STACKED)) return 1 ;
01895 return 0 ;
01896 }
01897
01898
01904
01905 int sinfoni_is_wavemap(char * tag)
01906 {
01907
01908 if (tag == NULL) return -1 ;
01909
01910 if (!strcmp(tag, PRO_WAVE_MAP)) return 1 ;
01911 return 0 ;
01912 }
01913
01914
01920
01921 int sinfoni_is_halosp(char * tag)
01922 {
01923
01924 if (tag == NULL) return -1 ;
01925
01926 if (!strcmp(tag, PRO_HALO_SPECT)) return 1 ;
01927 return 0 ;
01928 }
01929
01930
01936
01937 int sinfoni_is_distlist(char * tag)
01938 {
01939
01940 if (tag == NULL) return -1 ;
01941
01942 if (!strcmp(tag, PRO_SLITLETS_DISTANCE)) return 1 ;
01943 return 0 ;
01944 }
01945
01946
01952
01953 int sinfoni_is_slitpos(char * tag)
01954 {
01955
01956 if (tag == NULL) return -1 ;
01957
01958 if (!strcmp(tag, PRO_SLIT_POS)) return 1 ;
01959 return 0 ;
01960 }
01961
01962
01968
01969 int sinfoni_is_firstcol(char * tag)
01970 {
01971
01972 if (tag == NULL) return -1 ;
01973
01974 if (!strcmp(tag, PRO_FIRST_COL)) return 1 ;
01975 return 0 ;
01976 }
01977
01978
01984
01985 int sinfoni_is_bpmap(char * tag)
01986 {
01987
01988 if (tag == NULL) return -1 ;
01989
01990 if (!strcmp(tag, PRO_BP_MAP)) return 1 ;
01991 return 0 ;
01992 }
01993
01994
01995
02004
02005
02006 int sinfoni_get_band(cpl_frame * ref_frame,char * band)
02007 {
02008
02009 const char* _id="sinfoni_get_ins_setting";
02010 char* ref_file=NULL;
02011 cpl_propertylist* plist=NULL;
02012
02013 ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
02014 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
02015 cpl_msg_error(_id, "getting header from reference frame %s",ref_file);
02016 cpl_propertylist_delete(plist) ;
02017 return -1 ;
02018 }
02019
02020 if (cpl_propertylist_contains(plist, KEY_NAME_FILT_NAME)) {
02021 strcpy(band, cpl_propertylist_get_string(plist, KEY_NAME_FILT_NAME));
02022
02023
02024 } else {
02025 cpl_msg_warning(_id,"keyword %s does not exist",KEY_NAME_FILT_NAME);
02026 return -1;
02027 }
02028
02029 cpl_free(ref_file);
02030 cpl_propertylist_delete(plist);
02031 return 0;
02032 }
02033
02034
02035
02036 double sinfoni_get_mjd_obs(cpl_frame * frame)
02037 {
02038 const char* _id = "get_mjd_obs";
02039 cpl_propertylist* plist=NULL;
02040 char* file=NULL;
02041
02042 double mjd_obs=0.;
02043 file = cpl_strdup( cpl_frame_get_filename(frame)) ;
02044
02045 if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
02046 cpl_msg_error(_id, "getting header from reference frame %s",file);
02047 cpl_propertylist_delete(plist) ;
02048 cpl_free(file);
02049 return -1 ;
02050 }
02051
02052 if (cpl_propertylist_contains(plist, KEY_NAME_MJD_OBS)) {
02053 mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
02054 } else {
02055 cpl_msg_error(_id,"keyword %s does not exist",KEY_NAME_MJD_OBS);
02056 cpl_propertylist_delete(plist) ;
02057 return -1;
02058 }
02059 cpl_propertylist_delete(plist) ;
02060 cpl_free(file);
02061
02062 return mjd_obs;
02063
02064 }
02065
02066 int sinfoni_frame_is_dither(cpl_frame * frame)
02067 {
02068
02069 const char* _id="sinfoni_get_ins_setting";
02070 char* file=NULL;
02071 char band[FILE_NAME_SZ];
02072
02073
02074 cpl_propertylist* plist=NULL;
02075 int grat_encoder=0;
02076 int dith_status=1;
02077
02078
02079 file = cpl_strdup(cpl_frame_get_filename(frame)) ;
02080 if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
02081 cpl_msg_error(_id, "getting header from reference frame %s",file);
02082 cpl_propertylist_delete(plist) ;
02083 cpl_free(file);
02084 return -1 ;
02085 }
02086
02087 if (cpl_propertylist_contains(plist, KEY_NAME_FILT_NAME)) {
02088 strcpy(band,cpl_propertylist_get_string(plist, KEY_NAME_FILT_NAME));
02089 } else {
02090 cpl_msg_error(_id,"keyword %s does not exist",KEY_NAME_FILT_NAME);
02091 cpl_free(file);
02092 return -1;
02093 }
02094
02095 if (cpl_propertylist_contains(plist, KEY_NAME_GRAT_ENC)) {
02096 grat_encoder = cpl_propertylist_get_int(plist, KEY_NAME_GRAT_ENC);
02097 } else {
02098 cpl_msg_error(_id,"keyword %s does not exist",KEY_NAME_GRAT_ENC);
02099 cpl_free(file);
02100 return -1;
02101 }
02102
02103 cpl_propertylist_delete(plist);
02104
02105 if (strcmp(band,"H") == 0) {
02106 if( abs(grat_encoder - GRAT_VAL2_H) <= GRAT_VAL_TOL ) {
02107 dith_status = 0;
02108 } else {
02109 dith_status = 0;
02110 }
02111 }
02112 else if (strcmp(band,"H+K") == 0) {
02113 if( abs(grat_encoder - GRAT_VAL2_HK) <= GRAT_VAL_TOL ) {
02114 dith_status = 0;
02115 } else {
02116 dith_status = 0;
02117 }
02118 }
02119 else if (strcmp(band,"K") == 0) {
02120 if( abs(grat_encoder - GRAT_VAL2_K) <= GRAT_VAL_TOL ) {
02121 dith_status = 0;
02122 } else {
02123 dith_status = 0;
02124 }
02125 }
02126 else if (strcmp(band,"J") == 0) {
02127 if( abs(grat_encoder - GRAT_VAL2_J) <= GRAT_VAL_TOL ) {
02128 dith_status = 0;
02129 } else {
02130 dith_status = 0;
02131 }
02132 }
02133 cpl_free(file);
02134 return dith_status;
02135 }
02136
02137
02146
02147
02148 int sinfoni_get_spatial_res(cpl_frame * ref_frame, char * spat_res)
02149 {
02150
02151 const char* _id="sinfoni_get_ins_setting";
02152 char* ref_file;
02153 cpl_propertylist* plist=NULL;
02154
02155 ref_file=(char*)cpl_frame_get_filename(ref_frame) ;
02156 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
02157 cpl_msg_error(_id, "getting header from reference frame %s",ref_file);
02158 cpl_propertylist_delete(plist) ;
02159 return -1 ;
02160
02161 }
02162
02163 if (cpl_propertylist_contains(plist, KEY_NAME_PREOPTICS)) {
02164 strcpy(spat_res,cpl_propertylist_get_string(plist, KEY_NAME_PREOPTICS));
02165
02166 } else {
02167 cpl_msg_warning(_id,"keyword %s does not exist",KEY_NAME_PREOPTICS);
02168 cpl_free(ref_file);
02169 return -1;
02170 }
02171 cpl_propertylist_delete(plist);
02172 return 0;
02173
02174 }
02175
02176
02177
02178
02179
02180
02188
02189
02190 int sinfoni_frame_is_sky(cpl_frame * ref_frame)
02191 {
02192
02193 const char* _id="sinfoni_frame_is_sky";
02194 char dpr_type[FILE_NAME_SZ];
02195 char* ref_file=NULL;
02196 const char* sval=NULL;
02197
02198 int result=0;
02199 cpl_propertylist* plist=NULL;
02200
02201 sval = cpl_frame_get_filename(ref_frame) ;
02202 ref_file = cpl_strdup(sval) ;
02203
02204 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
02205 cpl_msg_error(_id, "getting header from reference frame %s",ref_file);
02206 cpl_propertylist_delete(plist) ;
02207 cpl_free(ref_file);
02208 return -1 ;
02209 }
02210
02211 if (cpl_propertylist_contains(plist, KEY_NAME_DPR_TYPE)) {
02212 strcpy(dpr_type,cpl_propertylist_get_string(plist, KEY_NAME_DPR_TYPE));
02213
02214 } else {
02215 cpl_msg_warning(_id,"keyword %s does not exist",KEY_NAME_DPR_TYPE);
02216 cpl_propertylist_delete(plist) ;
02217 cpl_free(ref_file);
02218 return -1;
02219 }
02220 cpl_propertylist_delete(plist);
02221 if(strstr(dpr_type,RAW_SKY) != NULL) {
02222 result=1;
02223 }
02224 cpl_free(ref_file);
02225
02226 return result;
02227
02228 }
02229
02230
02231
02239
02240
02241 int sinfoni_tag_is_sky(char * tag)
02242 {
02243
02244 int result=0;
02245
02246 if(
02247 (strcmp(tag,RAW_SKY) == 0) ||
02248 (strcmp(tag,RAW_SKY_NODDING) == 0) ||
02249 (strcmp(tag,RAW_SKY_STD) == 0) ||
02250 (strcmp(tag,RAW_SKY_OH) == 0) ||
02251 (strcmp(tag,RAW_SKY_PSF_CALIBRATOR) == 0)
02252 ) {
02253 result=1;
02254 }
02255
02256 return result;
02257
02258 }
02259
02260
02261
02269
02270
02271 int sinfoni_tag_is_obj(char * tag)
02272 {
02273
02274 int result=0;
02275
02276 if(
02277 (strcmp(tag,RAW_OBJECT) == 0) ||
02278 (strcmp(tag,RAW_OBJECT_NODDING) == 0) ||
02279 (strcmp(tag,RAW_PSF_CALIBRATOR) == 0) ||
02280 (strcmp(tag,RAW_STD) == 0) ||
02281 (strcmp(tag,RAW_STD_STAR) == 0)
02282
02283 ) {
02284 result=1;
02285 }
02286
02287 return result;
02288
02289 }
02290
02291
02292
02293
02294
02302
02303
02304 int sinfoni_frame_is_on(cpl_frame * ref_frame)
02305 {
02306
02307 const char* _id="sinfoni_frame_is_on";
02308 char* ref_file=NULL;
02309 char dpr_type[FILE_NAME_SZ];
02310 int lamp_Xe=0;
02311 int lamp_Kr=0;
02312 int lamp_Ne=0;
02313 int lamp_Ar=0;
02314 int lamp_Halo=0;
02315
02316 int result=0;
02317 cpl_propertylist* plist=NULL;
02318
02319 ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
02320 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file,0)) == NULL)) {
02321 cpl_msg_error(_id, "getting header from reference frame %s",ref_file);
02322 cpl_propertylist_delete(plist) ;
02323 cpl_free(ref_file);
02324 return -1 ;
02325 }
02326
02327
02328
02329
02330
02331
02332
02333 if (cpl_propertylist_contains(plist, KEY_NAME_DPR_TYPE)) {
02334 strcpy(dpr_type,cpl_propertylist_get_string(plist, KEY_NAME_DPR_TYPE));
02335
02336 } else {
02337 cpl_msg_warning(_id,"keyword %s does not exist",KEY_NAME_DPR_TYPE);
02338 cpl_propertylist_delete(plist);
02339 cpl_free(ref_file);
02340 return -1;
02341 }
02342
02343
02344
02345
02346
02347
02348
02349 if(strstr(dpr_type,"STD") != NULL) {
02350 result = 1;
02351 cpl_propertylist_delete(plist);
02352 cpl_free(ref_file);
02353 return result;
02354 }
02355
02356 if(strstr(dpr_type,"PSF") != NULL) {
02357 result = 1;
02358 cpl_propertylist_delete(plist);
02359 cpl_free(ref_file);
02360 return result;
02361 }
02362
02363 if(strstr(dpr_type,"SKY") != NULL) {
02364 result = 0;
02365 cpl_propertylist_delete(plist);
02366 cpl_free(ref_file);
02367 return result;
02368 }
02369
02370
02371 if(strstr(dpr_type,"OBJECT") != NULL) {
02372 result = 1;
02373 cpl_propertylist_delete(plist);
02374 cpl_free(ref_file);
02375 return result;
02376 }
02377
02378 if (cpl_propertylist_contains(plist, KEY_NAME_LAMP_XE)) {
02379 lamp_Xe=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_XE);
02380
02381 } else {
02382 cpl_msg_warning(_id,"keyword %s does not exist",KEY_NAME_LAMP_XE);
02383 cpl_propertylist_delete(plist);
02384 cpl_free(ref_file);
02385 return -1;
02386 }
02387
02388 if (cpl_propertylist_contains(plist, KEY_NAME_LAMP_KR)) {
02389 lamp_Kr=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_KR);
02390
02391 } else {
02392 cpl_msg_warning(_id,"keyword %s does not exist",KEY_NAME_LAMP_KR);
02393 cpl_propertylist_delete(plist);
02394 cpl_free(ref_file);
02395 return -1;
02396 }
02397
02398 if (cpl_propertylist_contains(plist, KEY_NAME_LAMP_NE)) {
02399 lamp_Ne=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_NE);
02400
02401 } else {
02402 cpl_msg_warning(_id,"keyword %s does not exist",KEY_NAME_LAMP_NE);
02403 cpl_propertylist_delete(plist);
02404 cpl_free(ref_file);
02405 return -1;
02406 }
02407
02408 if (cpl_propertylist_contains(plist, KEY_NAME_LAMP_AR)) {
02409 lamp_Ar=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_AR);
02410
02411 } else {
02412 cpl_msg_warning(_id,"keyword %s does not exist",KEY_NAME_LAMP_AR);
02413 cpl_propertylist_delete(plist);
02414 cpl_free(ref_file);
02415 return -1;
02416 }
02417
02418 if (cpl_propertylist_contains(plist, KEY_NAME_LAMP_HALO)) {
02419 lamp_Halo=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_HALO);
02420
02421 } else {
02422 cpl_msg_warning(_id,"keyword %s does not exist",KEY_NAME_LAMP_HALO);
02423 cpl_propertylist_delete(plist);
02424 cpl_free(ref_file);
02425 return -1;
02426 }
02427
02428
02429
02430
02431 if(lamp_Xe) {
02432 result=1;
02433 }
02434
02435 if(lamp_Kr) {
02436 result=1;
02437 }
02438
02439 if(lamp_Ne) {
02440 result=1;
02441 }
02442
02443 if(lamp_Ar) {
02444 result=1;
02445 }
02446
02447
02448 if(lamp_Halo) {
02449 result=1;
02450 }
02451
02452 cpl_propertylist_delete(plist);
02453 cpl_free(ref_file);
02454 return result;
02455
02456
02457 }
02458
02459
02460
02461
02477
02478 int sinfoni_pfits_add_pro(
02479 cpl_propertylist * plist,
02480 char * pipefile,
02481 char * pro_type,
02482 char * pro_redlevel,
02483 char * pro_catg,
02484 char * pro_status,
02485 const char * pro_rec_id,
02486 cpl_frameset * raw,
02487 cpl_frameset * cal)
02488 {
02489 char cval[80] ;
02490 char ** files ;
02491 char ** tags ;
02492 char * filename=NULL;
02493 int nfiles ;
02494 int i ;
02495
02496 if (plist == NULL) return -1 ;
02497
02498 if (cpl_propertylist_contains(plist, KEY_NAME_HPRO_RBSID)) {
02499 cpl_propertylist_set_string(plist, KEY_NAME_HPRO_RBSID, KEY_VALUE_HPRO_RBSID);
02500 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_RBSID, KEY_HELP_HPRO_RBSID);
02501 } else {
02502 cpl_propertylist_append_string(plist, KEY_NAME_HPRO_RBSID,KEY_VALUE_HPRO_RBSID) ;
02503 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_RBSID,KEY_HELP_HPRO_RBSID) ;
02504 }
02505
02506
02507 if (cpl_propertylist_contains(plist, KEY_NAME_HPRO_DOID)) {
02508 cpl_propertylist_set_string(plist, KEY_NAME_HPRO_DOID, KEY_VALUE_HPRO_DOID);
02509 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DOID, KEY_HELP_HPRO_DOID);
02510 } else {
02511 cpl_propertylist_append_string(plist, KEY_NAME_HPRO_DOID,KEY_VALUE_HPRO_DOID) ;
02512 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DOID,KEY_HELP_HPRO_DOID) ;
02513 }
02514
02515 if (cpl_propertylist_contains(plist, KEY_NAME_HPRO_DID)) {
02516 cpl_propertylist_set_string(plist, KEY_NAME_HPRO_DID, KEY_VALUE_HPRO_DID);
02517 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DID, KEY_HELP_HPRO_DID);
02518 } else {
02519 cpl_propertylist_append_string(plist, KEY_NAME_HPRO_DID,KEY_VALUE_HPRO_DID) ;
02520 cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DID,KEY_HELP_HPRO_DID) ;
02521 }
02522
02523
02524 if (cpl_propertylist_contains(plist, KEY_NAME_PIPE_ID)) {
02525 cpl_propertylist_set_string(plist, KEY_NAME_PIPE_ID, VERSION);
02526 cpl_propertylist_set_comment(plist, KEY_NAME_PIPE_ID, KEY_HELP_PIPE_ID);
02527 } else {
02528 cpl_propertylist_append_string(plist, KEY_NAME_PIPE_ID,VERSION) ;
02529 cpl_propertylist_set_comment(plist, KEY_NAME_PIPE_ID,KEY_HELP_PIPE_ID) ;
02530 }
02531
02532
02533 if (pipefile != NULL) {
02534 if (cpl_propertylist_contains(plist, KEY_NAME_PIPEFILE)) {
02535 cpl_propertylist_set_string(plist, KEY_NAME_PIPEFILE,
02536 qfits_get_base_name(pipefile)) ;
02537 } else {
02538 cpl_propertylist_append_string(plist, KEY_NAME_PIPEFILE,
02539 qfits_get_base_name(pipefile)) ;
02540 }
02541 }
02542
02543
02544
02545 if (pro_type != NULL) {
02546 if (cpl_propertylist_contains(plist, KEY_NAME_PRO_TYPE)) {
02547 cpl_propertylist_set_string(plist, KEY_NAME_PRO_TYPE, pro_type) ;
02548 } else {
02549 cpl_propertylist_append_string(plist, KEY_NAME_PRO_TYPE, pro_type) ;
02550 }
02551 }
02552
02553
02554
02555 if (pro_redlevel != NULL) {
02556 if (cpl_propertylist_contains(plist, KEY_NAME_PRO_REDLEVEL)) {
02557 cpl_propertylist_set_string(plist, KEY_NAME_PRO_REDLEVEL,pro_redlevel) ;
02558 } else {
02559 cpl_propertylist_append_string(plist, KEY_NAME_PRO_REDLEVEL,pro_redlevel);
02560 }
02561 }
02562
02563
02564 if (cpl_propertylist_contains(plist, KEY_NAME_PRO_CATG)) {
02565 cpl_propertylist_set_string(plist, KEY_NAME_PRO_CATG, pro_catg) ;
02566 } else {
02567 cpl_propertylist_append_string(plist, KEY_NAME_PRO_CATG, pro_catg) ;
02568 }
02569
02570
02571
02572 if (pro_status != NULL) {
02573 if (cpl_propertylist_contains(plist, KEY_NAME_PRO_STATUS)) {
02574 cpl_propertylist_set_string(plist, KEY_NAME_PRO_STATUS, pro_status) ;
02575 } else {
02576 cpl_propertylist_append_string(plist,KEY_NAME_PRO_STATUS,pro_status);
02577 }
02578 }
02579
02580
02581 if (cpl_propertylist_contains(plist, KEY_NAME_PRO_DATE)) {
02582 cpl_propertylist_set_string(plist,KEY_NAME_PRO_DATE,
02583 qfits_get_date_iso8601()) ;
02584 } else {
02585 cpl_propertylist_append_string(plist,KEY_NAME_PRO_DATE,
02586 qfits_get_date_iso8601()) ;
02587 }
02588
02589
02590 nfiles = cpl_frameset_get_size(raw) ;
02591 if (nfiles > 0) {
02592 if (cpl_propertylist_contains(plist,KEY_NAME_PRO_DATANCOM)) {
02593 cpl_propertylist_set_int(plist,KEY_NAME_PRO_DATANCOM, nfiles) ;
02594 } else {
02595 cpl_propertylist_append_int(plist,KEY_NAME_PRO_DATANCOM, nfiles) ;
02596 }
02597 }
02598
02599
02600 if (pro_rec_id != NULL) {
02601 if (cpl_propertylist_contains(plist, KEY_NAME_PRO_RECID)) {
02602 cpl_propertylist_set_string(plist,KEY_NAME_PRO_RECID , pro_rec_id);
02603 } else {
02604 cpl_propertylist_append_string(plist, KEY_NAME_PRO_RECID,
02605 pro_rec_id) ;
02606 }
02607 }
02608
02609
02610
02611 sprintf(cval, "CPL") ;
02612 if (cpl_propertylist_contains(plist,KEY_NAME_PRO_DRSID)) {
02613 cpl_propertylist_set_string(plist,KEY_NAME_PRO_DRSID , cval) ;
02614 } else {
02615 cpl_propertylist_append_string(plist,KEY_NAME_PRO_DRSID, cval) ;
02616 }
02617
02618
02619 if (raw != NULL) {
02620 files = my_frameset_to_filenames(raw, &nfiles) ;
02621 tags = my_frameset_to_tags(raw, &nfiles) ;
02622 for (i=0 ; i<nfiles ; i++) {
02623 sprintf(cval, "ESO PRO REC1 RAW%d NAME", i+1) ;
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633 if ((files[i]) != NULL) {
02634 filename = get_basename(files[i]);
02635 if (cpl_propertylist_contains(plist, cval)) {
02636 cpl_propertylist_set_string(plist, cval, filename) ;
02637 } else {
02638 cpl_propertylist_append_string(plist, cval, filename) ;
02639 }
02640 }
02641 sprintf(cval, "ESO PRO REC1 RAW%d CATG", i+1) ;
02642 if (tags != NULL) {
02643 if (tags[i] != NULL) {
02644 if (cpl_propertylist_contains(plist, cval)) {
02645 cpl_propertylist_set_string(plist, cval, tags[i]) ;
02646 } else {
02647 cpl_propertylist_append_string(plist, cval, tags[i]) ;
02648 }
02649 }
02650 }
02651 }
02652 if (files) cpl_free(files) ;
02653 if (tags) cpl_free(tags) ;
02654 }
02655
02656
02657 if (cal != NULL) {
02658 files = my_frameset_to_filenames(cal, &nfiles) ;
02659 tags = my_frameset_to_tags(cal, &nfiles) ;
02660 for (i=0 ; i<nfiles ; i++) {
02661 sprintf(cval, "ESO PRO REC1 CAL%d NAME", i+1) ;
02662 filename = get_basename(files[i]);
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672 if ((files[i]) != NULL) {
02673 if (cpl_propertylist_contains(plist, cval)) {
02674 cpl_propertylist_set_string(plist, cval, filename) ;
02675 } else {
02676 cpl_propertylist_append_string(plist, cval, filename) ;
02677 }
02678 }
02679 sprintf(cval, "ESO PRO REC1 CAL%d CATG", i+1) ;
02680 if (tags != NULL) {
02681 if (tags[i] != NULL) {
02682 if (cpl_propertylist_contains(plist, cval)) {
02683 cpl_propertylist_set_string(plist, cval, tags[i]) ;
02684 } else {
02685 cpl_propertylist_append_string(plist, cval, tags[i]) ;
02686 }
02687 }
02688 }
02689
02690 }
02691 if (files) cpl_free(files) ;
02692 if (tags) cpl_free(tags) ;
02693 }
02694 return 0 ;
02695 }
02696
02697
02698
02699 int sinfoni_pfits_add_qc(
02700 cpl_propertylist * plist,
02701 qc_log * qclog)
02702 {
02703 char key_name[80] ;
02704 char key_value[80] ;
02705
02706 int i =0;
02707
02708
02709 if (plist == NULL) return -1 ;
02710
02711
02712
02713 for(i=0;i<qclog[0].n;i++) {
02714 strcpy(key_name,"ESO ");
02715 strcat(key_name,qclog[i].name);
02716 if(strcmp(qclog[i].type,"string") == 0) {
02717 sprintf(key_value,"%s",qclog[i].s_val);
02718 cpl_propertylist_append_string(plist, key_name,key_value) ;
02719 cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
02720
02721 } else if(strcmp(qclog[i].type,"bool") == 0) {
02722 sprintf(key_value,"%i",(int)qclog[i].n_val);
02723 cpl_propertylist_append_bool(plist, key_name,(int)qclog[i].n_val) ;
02724 cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
02725 } else if(strcmp(qclog[i].type,"int") == 0) {
02726 sprintf(key_value,"%i",(int)qclog[i].n_val);
02727 cpl_propertylist_append_int(plist, key_name,(int)qclog[i].n_val) ;
02728 cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
02729 } else if(strcmp(qclog[i].type,"float") == 0) {
02730 sprintf(key_value,"%f",(float)qclog[i].n_val);
02731 cpl_propertylist_append_float(plist, key_name,(float)qclog[i].n_val) ;
02732 cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
02733 } else if(strcmp(qclog[i].type,"double") == 0) {
02734 sprintf(key_value,"%f",qclog[i].n_val);
02735 cpl_propertylist_append_double(plist, key_name,qclog[i].n_val) ;
02736 cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
02737 }
02738
02739 }
02740
02741 return 0 ;
02742 }
02743
02744 int sinfoni_pfits_put_qc(
02745 cpl_propertylist * plist,
02746 cpl_table * qclog)
02747 {
02748 char key_name[FILE_NAME_SZ];
02749 char key_value[FILE_NAME_SZ];
02750 char key_type[FILE_NAME_SZ];
02751 char key_help[FILE_NAME_SZ] ;
02752
02753 int i =0;
02754 int n =0;
02755
02756 if (plist == NULL) {
02757 printf("plist=NULL, something strange\n");
02758 return -1 ;
02759 }
02760
02761
02762 n=cpl_table_get_nrow(qclog);
02763 for(i=0;i<n;i++) {
02764 strcpy(key_name,"ESO ");
02765
02766 strcat(key_name,cpl_table_get_string(qclog,"key_name",i));
02767 strcpy(key_type,cpl_table_get_string(qclog,"key_type",i));
02768 strcpy(key_value,cpl_table_get_string(qclog,"key_value",i));
02769 strcpy(key_help,cpl_table_get_string(qclog,"key_help",i));
02770
02771
02772 if(strcmp(key_type,"CPL_TYPE_STRING") == 0) {
02773 cpl_propertylist_append_string(plist, key_name,key_value) ;
02774 cpl_propertylist_set_comment(plist, key_name,key_help) ;
02775 } else if(strcmp(key_type,"CPL_TYPE_BOOL") == 0) {
02776 cpl_propertylist_append_bool(plist, key_name,atoi(key_value)) ;
02777 cpl_propertylist_set_comment(plist, key_name,key_help) ;
02778 } else if(strcmp(key_type,"CPL_TYPE_INT") == 0) {
02779 cpl_propertylist_append_int(plist,key_name,atoi(key_value)) ;
02780 cpl_propertylist_set_comment(plist, key_name,key_help) ;
02781 } else if(strcmp(key_type,"CPL_TYPE_FLOAT") == 0) {
02782 cpl_propertylist_append_float(plist, key_name,(float)atof(key_value)) ;
02783 cpl_propertylist_set_comment(plist, key_name,key_help) ;
02784 } else if(strcmp(key_type,"CPL_TYPE_DOUBLE") == 0) {
02785 cpl_propertylist_append_double(plist, key_name,atof(key_value)) ;
02786 cpl_propertylist_set_comment(plist, key_name,key_help) ;
02787 }
02788
02789 }
02790
02791 return 0 ;
02792 }
02793
02794 cpl_table *
02795 sinfoni_qclog_init(const int sz)
02796 {
02797
02798 cpl_table *table;
02799
02800
02801 if (sz < 0) {
02802 return NULL;
02803 }
02804
02805 table = cpl_table_new(sz);
02806 cpl_table_new_column(table,"key_name", CPL_TYPE_STRING);
02807 cpl_table_new_column(table,"key_type", CPL_TYPE_STRING);
02808 cpl_table_new_column(table,"key_value", CPL_TYPE_STRING);
02809 cpl_table_new_column(table,"key_help", CPL_TYPE_STRING);
02810
02811 return table;
02812 }
02813
02814 int
02815 sinfoni_qclog_add(cpl_table* table, int raw,
02816 const char* key_name,
02817 const char* key_type,
02818 char* key_value,
02819 const char* key_help)
02820 {
02821
02822 cpl_table_set_string(table,"key_name" ,raw,key_name);
02823 cpl_table_set_string(table,"key_type" ,raw,key_type);
02824 cpl_table_set_string(table,"key_value",raw,key_value);
02825 cpl_table_set_string(table,"key_help" ,raw,key_help);
02826
02827 return 0;
02828
02829 }
02830
02831 int
02832 sinfoni_qclog_delete(cpl_table* table)
02833 {
02834 cpl_table_delete(table);
02835 return 0;
02836 }