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 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030
00031
00032 #include <string.h>
00033 #include "sinfo_flat_ini_by_cpl.h"
00034 #include "sinfo_error.h"
00035 #include "sinfo_hidden.h"
00036 #include "sinfo_pro_types.h"
00037 #include "sinfo_raw_types.h"
00038 #include "sinfo_functions.h"
00039 #include "sinfo_file_handling.h"
00040
00041
00042
00043 void sinfo_flat_free_alloc(flat_config * cfg);
00044 static void
00045 parse_section_frames(flat_config *, cpl_frameset* sof,
00046 cpl_frameset** raw, int* status);
00047 static void parse_section_cleanmean(flat_config *, cpl_parameterlist* cpl_cfg);
00048 static void parse_section_badpixel(flat_config *, cpl_parameterlist* cpl_cfg);
00049 static void parse_section_badpix(flat_config *, cpl_parameterlist* cpl_cfg);
00050 static void parse_section_thresh(flat_config *, cpl_parameterlist* cpl_cfg);
00051 static void
00052 parse_section_qclog(flat_config * cfg, cpl_parameterlist * cpl_cfg);
00074 flat_config *
00075 sinfo_parse_cpl_input_flat(cpl_parameterlist* cpl_cfg,
00076 cpl_frameset* sof,
00077 cpl_frameset** raw)
00078 {
00079 flat_config * cfg = sinfo_flat_cfg_create();
00080 int status=0;
00081
00082
00083
00084
00085 parse_section_badpixel (cfg, cpl_cfg);
00086 parse_section_cleanmean (cfg, cpl_cfg);
00087 parse_section_badpix (cfg, cpl_cfg);
00088 parse_section_thresh (cfg, cpl_cfg);
00089 parse_section_qclog (cfg,cpl_cfg);
00090
00091 parse_section_frames (cfg, sof, raw, &status);
00092 if (status > 0) {
00093 sinfo_msg_error("parsing cpl input");
00094 sinfo_flat_cfg_destroy(cfg);
00095 cfg = NULL ;
00096 return NULL ;
00097 }
00098 return cfg ;
00099 }
00100
00110 static void
00111 parse_section_frames(flat_config * cfg,
00112 cpl_frameset * sof,
00113 cpl_frameset ** raw,
00114 int* status)
00115 {
00116 int i;
00117
00118 char * name ;
00119
00120 int nobj, noff ;
00121 int nditherobj, nditheroff ;
00122 int found_sky ;
00123 int found_dither ;
00124 int nframes=0;
00125 int nraw=0;
00126 char* tag;
00127 char spat_res[FILE_NAME_SZ];
00128 char lamp_status[FILE_NAME_SZ];
00129 char band[FILE_NAME_SZ];
00130 int ins_set=0;
00131
00132 cpl_frame* frame = NULL;
00133
00134
00135 nframes = cpl_frameset_get_size(sof);
00136
00137 sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
00138 nraw=cpl_frameset_get_size(*raw);
00139
00140 if (nraw==0) {
00141 sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
00142 }
00143
00144
00145 nraw=cpl_frameset_get_size(*raw);
00146 if (nraw==0) {
00147 sinfo_msg("Frame %s or %s not found!", RAW_FLAT_LAMP,RAW_FLAT_NS);
00148 (*status)++;
00149 return ;
00150 }
00151
00152 nraw = cpl_frameset_get_size(*raw);
00153
00154 sinfo_msg("nraw=%d",nraw);
00155 if(nraw<1) {
00156 sinfo_msg_error("no good raw frame in input, something wrong!");
00157 (*status)++;
00158 return;
00159 }
00160
00161 cknull_nomsg(frame = cpl_frameset_get_frame(*raw,0));
00162
00163 ck0_nomsg(sinfo_get_spatial_res(frame,spat_res));
00164 switch(sinfo_frame_is_on(frame))
00165 {
00166
00167 case 0:
00168 strcpy(lamp_status,"on");
00169 break;
00170 case 1:
00171 strcpy(lamp_status,"off");
00172 break;
00173 case -1:
00174 strcpy(lamp_status,"undefined");
00175 break;
00176 default:
00177 strcpy(lamp_status,"undefined");
00178 break;
00179
00180 }
00181
00182 sinfo_get_band(frame,band);
00183 sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
00184 spat_res, lamp_status, band);
00185
00186
00187 sinfo_get_ins_set(band,&ins_set);
00188
00189
00190
00191 cfg->framelist = cpl_malloc(nraw * sizeof(char*));
00192 cfg->frametype = cpl_malloc(nraw * sizeof(int));
00193 cfg->frameposition = cpl_malloc(nraw * sizeof(int));
00194
00195 found_sky = 0 ;
00196 found_dither = 0 ;
00197 nobj = 0 ;
00198 noff = 0 ;
00199 nditheroff = 0 ;
00200 nditherobj = 0 ;
00201 for (i=0;i<nraw;i++) {
00202 cfg->framelist[i]=NULL;
00203 cfg->frametype[i]=-1;
00204 cfg->frameposition[i]=-1;
00205 }
00206
00207
00208 cfg->nframes = nraw ;
00209
00210 for (i=0 ; i<nraw ; i++) {
00211 frame = cpl_frameset_get_frame(*raw,i);
00212 name= (char*) cpl_frame_get_filename(frame);
00213 if(sinfo_file_exists(name)==1) {
00214
00215 if(cpl_frame_get_tag(frame) != NULL) {
00216
00217 tag= (char*) cpl_frame_get_tag(frame);
00218
00219 if((sinfo_frame_is_on(frame) == 0) ||
00220 (sinfo_frame_is_sky(frame) == 1) )
00221 {
00222
00223 cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00224 cfg->frametype[i] = FRAME_OFF ;
00225 found_sky = 1;
00226 if (sinfo_frame_is_dither(frame))
00227 {
00228 cfg->frameposition[i] = FRAME_POS2 ;
00229 found_dither = 1 ;
00230 nditheroff++ ;
00231 }
00232 else
00233 {
00234 cfg->frameposition[i] = FRAME_POS1 ;
00235 noff++ ;
00236 }
00237 }
00238 else if(sinfo_frame_is_on(frame) == 1)
00239 {
00240 cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00241 cfg->frametype[i] = FRAME_ON ;
00242 if (sinfo_frame_is_dither(frame))
00243 {
00244 cfg->frameposition[i] = FRAME_POS2 ;
00245 found_dither = 1 ;
00246 nditherobj++ ;
00247 }
00248 else
00249 {
00250 cfg->frameposition[i] = FRAME_POS1 ;
00251 nobj++ ;
00252 }
00253 }
00254
00255 }
00256
00257 else
00258 {
00259
00260
00261
00262
00263
00264
00265
00266 }
00267 }
00268
00269
00270 }
00271
00272
00273
00274
00275
00276
00277
00278 if((nobj<1) && (nditherobj< 1)) {
00279 sinfo_msg_error("no ON raw frame in input, something wrong!");
00280 sinfo_flat_free_alloc(cfg);
00281 (*status)++;
00282 return;
00283 }
00284
00285
00286 cfg->nobj = nobj ;
00287 cfg->noff = noff ;
00288 cfg->nditherobj = nditherobj ;
00289 cfg->nditheroff = nditheroff ;
00290 cfg->contains_sky = found_sky ;
00291 cfg->contains_dither = found_dither ;
00292
00293 strcpy(cfg -> outName, LAMP_FLATS_OUT_FILENAME);
00294
00295 if(cfg->interpolInd != 0) {
00296
00297 if(NULL != cpl_frameset_find(sof,PRO_BP_MAP)) {
00298 frame = cpl_frameset_find(sof,PRO_BP_MAP);
00299 strcpy(cfg -> mask,cpl_frame_get_filename(frame));
00300 if(sinfo_file_exists(cfg->mask)==1) {
00301 } else {
00302 sinfo_msg_error("Filename %s for Frame %s not found!",
00303 cfg->mask, PRO_BP_MAP);
00304 sinfo_flat_free_alloc(cfg);
00305 (*status)++;
00306 return;
00307
00308 }
00309
00310 } else {
00311 sinfo_msg_error("Frame %s not found!", PRO_BP_MAP);
00312 sinfo_flat_free_alloc(cfg);
00313 (*status)++;
00314 return;
00315 }
00316 if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS)) {
00317 frame = cpl_frameset_find(sof,PRO_SLIT_POS);
00318 strcpy(cfg -> slitposList,cpl_frame_get_filename(frame));
00319 if(sinfo_file_exists(cfg->mask) == 1) {
00320 } else {
00321 sinfo_msg_error("Filename %s for Frame %s not found!",
00322 cfg->slitposList, PRO_SLIT_POS);
00323 sinfo_flat_free_alloc(cfg);
00324 (*status)++;
00325 return;
00326 }
00327 } else {
00328 sinfo_msg_error("Frame %s not found!", PRO_SLIT_POS);
00329 sinfo_flat_free_alloc(cfg);
00330 (*status)++;
00331 return;
00332 }
00333
00334 }
00335
00336 cleanup:
00337
00338 return;
00339 }
00340
00348 static void
00349 parse_section_cleanmean(flat_config * cfg, cpl_parameterlist * cpl_cfg)
00350 {
00351 cpl_parameter *p;
00352
00353 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.low_rejection");
00354 cfg -> loReject = cpl_parameter_get_double(p);
00355
00356 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.high_rejection");
00357 cfg -> hiReject = cpl_parameter_get_double(p);
00358
00359 }
00360
00368 static void
00369 parse_section_badpixel(flat_config * cfg, cpl_parameterlist * cpl_cfg)
00370 {
00371 cpl_parameter *p;
00372
00373 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.interpol_index");
00374 cfg -> interpolInd = cpl_parameter_get_bool(p);
00375
00376 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.max_rad");
00377 cfg -> maxRad = cpl_parameter_get_int(p);
00378
00379 }
00380
00388 static void
00389 parse_section_badpix(flat_config * cfg, cpl_parameterlist * cpl_cfg)
00390 {
00391
00392 cpl_parameter* p;
00393
00394 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.bad_ind");
00395 cfg -> badInd = cpl_parameter_get_bool(p);
00396
00397 strcpy(cfg -> maskname, LAMP_FLATS_OUT_BPMAP);
00398
00399 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.sigma_factor");
00400 cfg -> sigmaFactor = cpl_parameter_get_double(p);
00401
00402 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.factor");
00403 cfg -> factor = cpl_parameter_get_double(p);
00404
00405 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.iterations");
00406 cfg -> iterations = cpl_parameter_get_int(p);
00407
00408 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.bad_low_rejection");
00409 cfg -> badLoReject = cpl_parameter_get_double(p);
00410
00411 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.bad_high_rejection");
00412 cfg -> badHiReject = cpl_parameter_get_double(p);
00413
00414 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.llx");
00415 cfg -> llx = cpl_parameter_get_int(p);
00416
00417 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.lly");
00418 cfg -> lly = cpl_parameter_get_int(p);
00419
00420 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.urx");
00421 cfg -> urx = cpl_parameter_get_int(p);
00422
00423 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.ury");
00424 cfg -> ury = cpl_parameter_get_int(p);
00425
00426 }
00427
00435 static void
00436 parse_section_thresh(flat_config * cfg,cpl_parameterlist* cpl_cfg)
00437 {
00438
00439 cpl_parameter* p;
00440 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.thresh_ind");
00441 cfg -> threshInd =cpl_parameter_get_bool(p);
00442
00443 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.mean_factor");
00444 cfg -> meanfactor = cpl_parameter_get_double(p);
00445
00446
00447 }
00448
00449
00457 static void
00458 parse_section_qclog(flat_config * cfg, cpl_parameterlist * cpl_cfg)
00459 {
00460 cpl_parameter *p;
00461
00462 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmin1");
00463 cfg -> qc_fpn_xmin1 = cpl_parameter_get_int(p);
00464
00465 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmax1");
00466 cfg -> qc_fpn_xmax1 = cpl_parameter_get_int(p);
00467
00468 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymin1");
00469 cfg -> qc_fpn_ymin1 = cpl_parameter_get_int(p);
00470
00471 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymax1");
00472 cfg -> qc_fpn_ymax1 = cpl_parameter_get_int(p);
00473
00474 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmin2");
00475 cfg -> qc_fpn_xmin2 = cpl_parameter_get_int(p);
00476
00477 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmax2");
00478 cfg -> qc_fpn_xmax2 = cpl_parameter_get_int(p);
00479
00480 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymin2");
00481 cfg -> qc_fpn_ymin2 = cpl_parameter_get_int(p);
00482
00483 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymax2");
00484 cfg -> qc_fpn_ymax2 = cpl_parameter_get_int(p);
00485
00486 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_thresh_min");
00487 cfg -> qc_thresh_min = cpl_parameter_get_int(p);
00488
00489 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_thresh_max");
00490 cfg -> qc_thresh_max = cpl_parameter_get_int(p);
00491
00492 }
00500 void
00501 sinfo_flat_free(flat_config ** cfg)
00502 {
00503 if ((*cfg) != NULL) {
00504 sinfo_flat_free_alloc(*cfg);
00505 sinfo_flat_cfg_destroy(*cfg);
00506 *cfg=NULL;
00507 }
00508 return;
00509
00510 }
00518 void
00519 sinfo_flat_free_alloc(flat_config * cfg)
00520 {
00521 if(cfg->frametype != NULL){
00522 cpl_free(cfg->frametype);
00523 }
00524 if(cfg->framelist != NULL) {
00525 cpl_free(cfg->framelist);
00526 }
00527 if(cfg->frameposition != NULL) {
00528 cpl_free(cfg->frameposition);
00529 }
00530 return ;
00531 }