00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "flat_ini_by_cpl.h"
00018
00019
00020
00021
00022 void flat_free_alloc(flat_config * cfg);
00023 static void parse_section_frames(flat_config *, cpl_frameset* sof, cpl_frameset** raw, int* status);
00024 static void parse_section_cleanmean(flat_config *, cpl_parameterlist* cpl_cfg);
00025 static void parse_section_badpixel(flat_config *, cpl_parameterlist* cpl_cfg);
00026 static void parse_section_badpix(flat_config *, cpl_parameterlist* cpl_cfg);
00027 static void parse_section_thresh(flat_config *, cpl_parameterlist* cpl_cfg);
00028 static void
00029 parse_section_qclog(flat_config * cfg, cpl_parameterlist * cpl_cfg);
00030
00031
00032
00033
00034
00045
00046
00047 flat_config * parse_cpl_input_flat(cpl_parameterlist* cpl_cfg,
00048 cpl_frameset* sof,
00049 cpl_frameset** raw)
00050 {
00051 const cxchar * _id = "parse_cpl_input_flat";
00052 flat_config * cfg = flat_cfg_create();
00053 int status=0;
00054
00055
00056
00057
00058 parse_section_badpixel (cfg, cpl_cfg);
00059 parse_section_cleanmean (cfg, cpl_cfg);
00060 parse_section_badpix (cfg, cpl_cfg);
00061 parse_section_thresh (cfg, cpl_cfg);
00062 parse_section_qclog (cfg,cpl_cfg);
00063
00064 parse_section_frames (cfg, sof, raw, &status);
00065 if (status > 0) {
00066 cpl_msg_error(_id,"parsing cpl input");
00067 flat_cfg_destroy(cfg);
00068 cfg = NULL ;
00069 return NULL ;
00070 }
00071 return cfg ;
00072 }
00073
00074
00075 static void
00076 parse_section_frames(flat_config * cfg,
00077 cpl_frameset * sof,
00078 cpl_frameset ** raw,
00079 int* status)
00080 {
00081 const cxchar * _id = "parse_section_frames";
00082 int i;
00083
00084 char * name ;
00085
00086 int nobj, noff ;
00087 int nditherobj, nditheroff ;
00088 int found_sky ;
00089 int found_dither ;
00090 int nframes=0;
00091 int nraw=0;
00092 char* tag;
00093 char spat_res[FILE_NAME_SZ];
00094 char lamp_status[FILE_NAME_SZ];
00095 char band[FILE_NAME_SZ];
00096 int ins_set=0;
00097
00098 cpl_frame* frame = NULL;
00099
00100 nframes = cpl_frameset_get_size(sof);
00101
00102 sinfoni_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
00103 nraw=cpl_frameset_get_size(*raw);
00104
00105 if (nraw==0) {
00106 sinfoni_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
00107 }
00108
00109
00110 nraw=cpl_frameset_get_size(*raw);
00111 if (nraw==0) {
00112 cpl_msg_info(_id,"Frame %s or %s not found!", RAW_FLAT_LAMP,RAW_FLAT_NS);
00113 (*status)++;
00114 return ;
00115 }
00116
00117 nraw = cpl_frameset_get_size(*raw);
00118 frame = cpl_frameset_get_frame(*raw,0);
00119
00120 sinfoni_get_spatial_res(frame,spat_res);
00121 switch(sinfoni_frame_is_on(frame))
00122 {
00123
00124 case 0:
00125 strcpy(lamp_status,"on");
00126 break;
00127 case 1:
00128 strcpy(lamp_status,"off");
00129 break;
00130 case -1:
00131 strcpy(lamp_status,"undefined");
00132 break;
00133 default:
00134 strcpy(lamp_status,"undefined");
00135 break;
00136
00137 }
00138
00139 sinfoni_get_band(frame,band);
00140 cpl_msg_info(_id,"spatial resolution: %s lamp status: %s band: %s \n",
00141 spat_res, lamp_status, band);
00142
00143
00144 sinfoni_get_ins_set(band,&ins_set);
00145
00146 if(nraw<1) {
00147 cpl_msg_error(_id,"no good raw frame in input, something wrong!");
00148 (*status)++;
00149 return;
00150 }
00151
00152 cfg->framelist = cpl_malloc(nraw * sizeof(char*));
00153 cfg->frametype = cpl_malloc(nraw * sizeof(int));
00154 cfg->frameposition = cpl_malloc(nraw * sizeof(int));
00155
00156 found_sky = 0 ;
00157 found_dither = 0 ;
00158 nobj = 0 ;
00159 noff = 0 ;
00160 nditheroff = 0 ;
00161 nditherobj = 0 ;
00162 for (i=0;i<nraw;i++) {
00163 cfg->framelist[i]=NULL;
00164 cfg->frametype[i]=-1;
00165 cfg->frameposition[i]=-1;
00166 }
00167
00168
00169 cfg->nframes = nraw ;
00170
00171 for (i=0 ; i<nraw ; i++) {
00172 frame = cpl_frameset_get_frame(*raw,i);
00173 name= (char*) cpl_frame_get_filename(frame);
00174 if(file_exists(name)==1) {
00175
00176 if(cpl_frame_get_tag(frame) != NULL) {
00177
00178 tag= (char*) cpl_frame_get_tag(frame);
00179
00180 if((sinfoni_frame_is_on(frame) == 0) ||
00181 (sinfoni_frame_is_sky(frame) == 1) )
00182 {
00183
00184 cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00185 cfg->frametype[i] = FRAME_OFF ;
00186 found_sky = 1;
00187 if (sinfoni_frame_is_dither(frame))
00188 {
00189 cfg->frameposition[i] = FRAME_POS2 ;
00190 found_dither = 1 ;
00191 nditheroff++ ;
00192
00193 }
00194 else
00195 {
00196 cfg->frameposition[i] = FRAME_POS1 ;
00197 noff++ ;
00198
00199 }
00200 }
00201 else if(sinfoni_frame_is_on(frame) == 1)
00202 {
00203 cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00204 cfg->frametype[i] = FRAME_ON ;
00205 if (sinfoni_frame_is_dither(frame))
00206 {
00207 cfg->frameposition[i] = FRAME_POS2 ;
00208 found_dither = 1 ;
00209 nditherobj++ ;
00210
00211 }
00212 else
00213 {
00214 cfg->frameposition[i] = FRAME_POS1 ;
00215 nobj++ ;
00216
00217 }
00218 }
00219
00220 }
00221
00222 else
00223 {
00224
00225
00226
00227
00228
00229
00230
00231
00232 }
00233 }
00234
00235
00236 }
00237
00238
00239
00240
00241
00242
00243
00244 if((nobj<1) && (nditherobj< 1)) {
00245 cpl_msg_error(_id,"no ON raw frame in input, something wrong!");
00246 flat_free_alloc(cfg);
00247 (*status)++;
00248 return;
00249 }
00250
00251
00252 cfg->nobj = nobj ;
00253 cfg->noff = noff ;
00254 cfg->nditherobj = nditherobj ;
00255 cfg->nditheroff = nditheroff ;
00256 cfg->contains_sky = found_sky ;
00257 cfg->contains_dither = found_dither ;
00258
00259 strcpy(cfg -> outName, LAMP_FLATS_OUT_FILENAME);
00260
00261 if(cfg->interpolInd != 0) {
00262
00263 if(NULL != cpl_frameset_find(sof,PRO_BP_MAP)) {
00264 frame = cpl_frameset_find(sof,PRO_BP_MAP);
00265 strcpy(cfg -> mask,cpl_frame_get_filename(frame));
00266 if(file_exists(cfg->mask)==1) {
00267
00268 } else {
00269 cpl_msg_error(_id,"Filename %s for Frame %s not found!",
00270 cfg->mask, PRO_BP_MAP);
00271 flat_free_alloc(cfg);
00272 (*status)++;
00273 return;
00274
00275 }
00276
00277 } else {
00278 cpl_msg_error(_id,"Frame %s not found!", PRO_BP_MAP);
00279 flat_free_alloc(cfg);
00280 (*status)++;
00281 return;
00282 }
00283 if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS)) {
00284 frame = cpl_frameset_find(sof,PRO_SLIT_POS);
00285 strcpy(cfg -> slitposList,cpl_frame_get_filename(frame));
00286 if(file_exists(cfg->mask) == 1) {
00287 } else {
00288 cpl_msg_error(_id,"Filename %s for Frame %s not found!",
00289 cfg->slitposList, PRO_SLIT_POS);
00290 flat_free_alloc(cfg);
00291 (*status)++;
00292 return;
00293 }
00294 } else {
00295 cpl_msg_error(_id,"Frame %s not found!", PRO_SLIT_POS);
00296 flat_free_alloc(cfg);
00297 (*status)++;
00298 return;
00299 }
00300
00301 }
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 }
00321
00322 static void
00323 parse_section_cleanmean(flat_config * cfg, cpl_parameterlist * cpl_cfg)
00324 {
00325 cpl_parameter *p;
00326
00327 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.low_rejection");
00328 cfg -> loReject = cpl_parameter_get_double(p);
00329
00330 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.high_rejection");
00331 cfg -> hiReject = cpl_parameter_get_double(p);
00332
00333 }
00334
00335 static void
00336 parse_section_badpixel(flat_config * cfg, cpl_parameterlist * cpl_cfg)
00337 {
00338 cpl_parameter *p;
00339
00340 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.interpol_index");
00341 cfg -> interpolInd = cpl_parameter_get_bool(p);
00342
00343 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.max_rad");
00344 cfg -> maxRad = cpl_parameter_get_int(p);
00345
00346 }
00347
00348 static void
00349 parse_section_badpix(flat_config * cfg, cpl_parameterlist * cpl_cfg)
00350 {
00351
00352 cpl_parameter* p;
00353
00354 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.bad_ind");
00355 cfg -> badInd = cpl_parameter_get_bool(p);
00356
00357 strcpy(cfg -> maskname, LAMP_FLATS_OUT_BPMAP);
00358
00359 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.sigma_factor");
00360 cfg -> sigmaFactor = cpl_parameter_get_double(p);
00361
00362 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.factor");
00363 cfg -> factor = cpl_parameter_get_double(p);
00364
00365 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.iterations");
00366 cfg -> iterations = cpl_parameter_get_int(p);
00367
00368 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.bad_low_rejection");
00369 cfg -> badLoReject = cpl_parameter_get_double(p);
00370
00371 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.bad_high_rejection");
00372 cfg -> badHiReject = cpl_parameter_get_double(p);
00373
00374 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.llx");
00375 cfg -> llx = cpl_parameter_get_int(p);
00376
00377 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.lly");
00378 cfg -> lly = cpl_parameter_get_int(p);
00379
00380 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.urx");
00381 cfg -> urx = cpl_parameter_get_int(p);
00382
00383 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.ury");
00384 cfg -> ury = cpl_parameter_get_int(p);
00385
00386 }
00387
00388 static void
00389 parse_section_thresh(flat_config * cfg,cpl_parameterlist* cpl_cfg)
00390 {
00391
00392 cpl_parameter* p;
00393 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.thresh_ind");
00394 cfg -> threshInd =cpl_parameter_get_bool(p);
00395
00396
00397 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.mean_factor");
00398 cfg -> meanfactor = cpl_parameter_get_double(p);
00399
00400
00401
00402 }
00403
00404
00405 static void
00406 parse_section_qclog(flat_config * cfg, cpl_parameterlist * cpl_cfg)
00407 {
00408 cpl_parameter *p;
00409
00410 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmin1");
00411 cfg -> qc_fpn_xmin1 = cpl_parameter_get_int(p);
00412
00413 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmax1");
00414 cfg -> qc_fpn_xmax1 = cpl_parameter_get_int(p);
00415
00416 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymin1");
00417 cfg -> qc_fpn_ymin1 = cpl_parameter_get_int(p);
00418
00419 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymax1");
00420 cfg -> qc_fpn_ymax1 = cpl_parameter_get_int(p);
00421
00422 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmin2");
00423 cfg -> qc_fpn_xmin2 = cpl_parameter_get_int(p);
00424
00425 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmax2");
00426 cfg -> qc_fpn_xmax2 = cpl_parameter_get_int(p);
00427
00428 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymin2");
00429 cfg -> qc_fpn_ymin2 = cpl_parameter_get_int(p);
00430
00431 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymax2");
00432 cfg -> qc_fpn_ymax2 = cpl_parameter_get_int(p);
00433
00434 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_thresh_min");
00435 cfg -> qc_thresh_min = cpl_parameter_get_int(p);
00436
00437 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_thresh_max");
00438 cfg -> qc_thresh_max = cpl_parameter_get_int(p);
00439
00440 }
00441
00442 void
00443 flat_free(flat_config * cfg)
00444 {
00445 flat_free_alloc(cfg);
00446 flat_cfg_destroy(cfg);
00447
00448 return;
00449
00450 }
00451
00452 void flat_free_alloc(flat_config * cfg)
00453 {
00454 if(cfg->frametype != NULL){
00455 cpl_free(cfg->frametype);
00456 }
00457 if(cfg->framelist != NULL) {
00458 cpl_free(cfg->framelist);
00459 }
00460 if(cfg->frameposition != NULL) {
00461 cpl_free(cfg->frameposition);
00462 }
00463 return ;
00464 }