00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "new_stack_ini_by_cpl.h"
00017
00018
00019
00020
00021
00022 void stack_free_alloc(stack_config_n * cfg);
00023
00024
00025 static void parse_section_frames(stack_config_n *,
00026 cpl_frameset* sof, cpl_frameset** raw,int* status,
00027 fake* fk);
00028
00029 static void parse_section_cleanmean(stack_config_n *, cpl_parameterlist* cpl_cfg);
00030 static void parse_section_flatfield(stack_config_n *, cpl_parameterlist* cpl_cfg);
00031 static void parse_section_badpixel(stack_config_n *, cpl_parameterlist* cpl_cfg);
00032 static void parse_section_interleaving(stack_config_n *);
00033 static void parse_section_gaussconvolution(stack_config_n *, cpl_parameterlist* cpl_cfg);
00034 static void parse_section_shiftframes(stack_config_n *);
00035 static void parse_section_warpfix(stack_config_n *, cpl_parameterlist* cpl_cfg);
00036 static void parse_section_qclog(stack_config_n *, cpl_parameterlist* cpl_cfg);
00037
00038
00039
00050
00051
00052 stack_config_n * parse_cpl_input_stack(cpl_parameterlist* cpl_cfg,
00053 cpl_frameset* sof,
00054 cpl_frameset** raw,
00055 fake* fk)
00056 {
00057 const cxchar * _id = "parse_cpl_input_stack";
00058 stack_config_n * cfg =stack_cfg_create_n();
00059 int status=0;
00060
00061
00062
00063
00064
00065
00066
00067
00068 parse_section_cleanmean (cfg, cpl_cfg);
00069 parse_section_flatfield (cfg, cpl_cfg);
00070 parse_section_badpixel (cfg, cpl_cfg);
00071 parse_section_interleaving (cfg);
00072 parse_section_gaussconvolution (cfg, cpl_cfg);
00073 parse_section_shiftframes (cfg);
00074 parse_section_warpfix (cfg, cpl_cfg);
00075 parse_section_qclog (cfg, cpl_cfg);
00076 parse_section_frames (cfg, sof, raw, &status, fk);
00077 if (status > 0) {
00078 cpl_msg_error(_id,"parsing cpl input");
00079 stack_cfg_destroy_n(cfg);
00080 cfg = NULL ;
00081 return NULL ;
00082 }
00083 return cfg ;
00084 }
00085
00086 static void
00087 parse_section_frames(stack_config_n * cfg,
00088 cpl_frameset* sof, cpl_frameset** raw_set,int* status,
00089 fake* fk)
00090 {
00091 const cxchar * _id = "parse_section_frames";
00092
00093 int i;
00094 const char * name;
00095 char file[FILE_NAME_SZ];
00096 int nobj, noff, ndark ;
00097 int nditherobj, nditheroff ;
00098 int found_sky ;
00099 int found_ref ;
00100 int found_dither ;
00101 int found_dark ;
00102 int nraw=0;
00103 int nsof=0;
00104
00105 cpl_frame* frame = NULL;
00106
00107 char spat_res[FILE_NAME_SZ];
00108 char lamp_status[FILE_NAME_SZ];
00109 char band[FILE_NAME_SZ];
00110 int ins_set=0;
00111 char* tag=NULL;
00112 char* do_class=NULL;
00113 nsof = cpl_frameset_get_size(sof);
00114 cpl_msg_info(_id,"cfg->warpfixInd=%d",cfg->warpfixInd);
00115
00116
00117 do_class=fk->pro_class;
00118
00119 if(strcmp(do_class,"DEFAULT") == 0) {
00120 sinfoni_extract_raw_stack_frames(sof,raw_set);
00121 } else if (strcmp(do_class,PRO_FIBRE_NS_STACKED_DIST) == 0) {
00122 sinfoni_is_fibres_on_off(sof,*raw_set);
00123 } else if (strcmp(do_class,PRO_FIBRE_NS_STACKED) == 0) {
00124 sinfoni_contains_frames_kind(sof,*raw_set,(char*)PRO_STACKED);
00125 } else if (strcmp(do_class,RAW_STACKED_SLITPOS) == 0) {
00126 sinfoni_extract_raw_stack_frames(sof,raw_set);
00127 } else {
00128 sinfoni_extract_raw_frames_type(sof,raw_set,do_class);
00129 }
00130 nraw = cpl_frameset_get_size(*raw_set);
00131 if (nraw < 1) {
00132 cpl_msg_error(_id,"Too few raw frames present in frameset!");
00133 (*status)++;
00134 return;
00135 }
00136
00137
00138
00139 cfg->framelist = cpl_malloc(nraw * sizeof(char*));
00140 cfg->frametype = cpl_malloc(nraw * sizeof(int));
00141 cfg->frameposition = cpl_malloc(nraw * sizeof(int));
00142
00143 for (i=0;i<nraw;i++) {
00144 cfg->framelist[i]=NULL;
00145 cfg->frametype[i]=-1;
00146 cfg->frameposition[i]=-1;
00147 }
00148
00149 found_sky = 0 ;
00150 found_ref = 0 ;
00151 found_dither = 0 ;
00152 found_dark = 0 ;
00153 nobj = 0 ;
00154 noff = 0 ;
00155 ndark = 0 ;
00156 nditherobj = 0 ;
00157 nditheroff = 0 ;
00158
00159
00160
00161
00162
00163 for (i=0 ; i<nraw ; i++) {
00164 frame = cpl_frameset_get_frame(*raw_set,i);
00165 name=cpl_frame_get_filename(frame);
00166 if(file_exists((char*)name)==1) {
00167
00168 if(cpl_frame_get_tag(frame) != NULL) {
00169
00170 tag= (char*) cpl_frame_get_tag(frame);
00171
00172 if((sinfoni_frame_is_on(frame) == 0) ||
00173 (sinfoni_frame_is_sky(frame) == 1))
00174 {
00175 cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
00176 cfg->frametype[i] = FRAME_OFF ;
00177 found_sky = 1;
00178 if (sinfoni_frame_is_dither(frame))
00179 {
00180 cfg->frameposition[i] = FRAME_POS2 ;
00181 nditheroff++ ;
00182
00183 }
00184 else
00185 {
00186 cfg->frameposition[i] = FRAME_POS1 ;
00187 noff++ ;
00188
00189 }
00190 }
00191 else if(strstr(tag,RAW_REF) != NULL)
00192 {
00193 cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
00194 cfg->frametype[i] = FRAME_REF ;
00195 found_ref=1;
00196 if (sinfoni_frame_is_dither(frame))
00197 {
00198 cfg->frameposition[i] = FRAME_POS2 ;
00199
00200 }
00201 else
00202 {
00203 cfg->frameposition[i] = FRAME_POS1 ;
00204
00205 }
00206 }
00207 else if(sinfoni_is_dark(tag))
00208 {
00209 cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
00210 cfg->frametype[i] = FRAME_DRK ;
00211 cfg->frameposition[i] = FRAME_POS1 ;
00212 found_dark=1;
00213 ndark++;
00214 cpl_msg_info(_id,"Frame is dark on\n");
00215 }
00216 else
00217 {
00218
00219 cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
00220 cfg->frametype[i] = FRAME_ON ;
00221 found_ref=1;
00222 if (sinfoni_frame_is_dither(frame))
00223 {
00224 cfg->frameposition[i] = FRAME_POS2 ;
00225 found_dither=1;
00226 nditherobj++;
00227
00228 }
00229 else
00230 {
00231 cfg->frameposition[i] = FRAME_POS1 ;
00232 nobj++;
00233
00234 }
00235 }
00236 }
00237 else
00238 {
00239
00240 cfg->frametype[i] = FRAME_ON ;
00241
00242 cfg->frameposition[i] = FRAME_POS1 ;
00243
00244 nobj ++ ;
00245
00246 }
00247 }
00248
00249
00250
00251 }
00252
00253 cpl_msg_info(_id,"Noff= %d Nobj= %d Nditheroff= %d Nditherobj= %d",
00254 noff,nobj,nditheroff,nditherobj);
00255
00256
00257
00258
00259 cfg->nframes = nraw ;
00260 cfg->nobj = nobj ;
00261 cfg->noff = noff ;
00262 cfg->ndark = ndark ;
00263 cfg->nditherobj = nditherobj ;
00264 cfg->nditheroff = nditheroff ;
00265 cfg->contains_sky = found_sky ;
00266 cfg->contains_ref = found_ref ;
00267 cfg->contains_dither = found_dither ;
00268 cfg->contains_dark = found_dark ;
00269
00270
00271 frame = cpl_frameset_get_frame(*raw_set,0);
00272
00273 sinfoni_get_spatial_res(frame,spat_res);
00274
00275
00276
00277 if(sinfoni_frame_is_on(frame) == 1) {
00278 strcpy(lamp_status,"on");
00279 } else {
00280 strcpy(lamp_status,"off");
00281 }
00282 switch(sinfoni_frame_is_on(frame))
00283 {
00284 case 0:
00285 strcpy(lamp_status,"on");
00286 break;
00287 case 1:
00288 strcpy(lamp_status,"off");
00289 break;
00290 case -1:
00291 strcpy(lamp_status,"undefined");
00292 break;
00293 default:
00294 strcpy(lamp_status,"undefined");
00295 break;
00296
00297
00298 }
00299 sinfoni_get_band(frame,band);
00300
00301
00302 cpl_msg_info(_id,"spatial resolution: %s lamp status: %s band: %s",
00303 spat_res, lamp_status, band);
00304
00305 sinfoni_get_ins_set(band,&ins_set);
00306 frame = cpl_frameset_get_frame(*raw_set,0);
00307 tag=(char*)cpl_frame_get_tag(frame);
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375 if(fk->frm_switch==1) {
00376
00377
00378
00379
00380
00381 cfg->maskInd = fk->mask_index;
00382 cfg->indind = fk->ind_index;
00383 cfg->flatInd = fk->flat_index;
00384 cfg -> loReject = fk->low_rej;
00385 cfg -> hiReject = fk->hig_rej;
00386 cfg -> warpfixInd = fk->wfix_index;
00387
00388
00389
00390
00391
00392
00393
00394
00395 }
00396
00397
00398
00399
00400
00401 if(cfg -> flatInd) {
00402 if(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP)) {
00403 frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP);
00404 strcpy(file,cpl_frame_get_filename(frame));
00405 strcpy(cfg -> flatfield1, file);
00406 } else if(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP1)) {
00407 frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP1);
00408 strcpy(file,cpl_frame_get_filename(frame));
00409 strcpy(cfg -> flatfield1, file);
00410 } else {
00411 cpl_msg_error(_id,"Frame %s not found!", PRO_MASTER_FLAT_LAMP);
00412 cpl_msg_error(_id,"Frame %s not found!", PRO_MASTER_FLAT_LAMP1);
00413 stack_free_alloc(cfg);
00414 (*status)++;
00415 return;
00416 }
00417
00418 if(found_dither) {
00419 if(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP2)) {
00420 frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP2);
00421 strcpy(file,cpl_frame_get_filename(frame));
00422 strcpy(cfg -> flatfield2, file);
00423 } else {
00424 cpl_msg_info(_id,"Frame %s not found!", PRO_MASTER_FLAT_LAMP2);
00425 }
00426 }
00427 }
00428
00429
00430 if(cfg->maskInd != 0) {
00431 if(strstr(do_class,"FIBRE_NS") != NULL) {
00432 if(NULL != cpl_frameset_find(sof,PRO_BP_MAP_DI)) {
00433 frame = cpl_frameset_find(sof,PRO_BP_MAP_DI);
00434 strcpy(file,cpl_frame_get_filename(frame));
00435 strcpy(cfg -> mask, file);
00436 } else {
00437 cpl_msg_error(_id,"Frame %s not found!", PRO_BP_MAP_DI);
00438 stack_free_alloc(cfg);
00439 (*status)++;
00440 return;
00441 }
00442
00443 } else {
00444
00445 if(NULL != cpl_frameset_find(sof,PRO_MASTER_BP_MAP)) {
00446 frame = cpl_frameset_find(sof,PRO_MASTER_BP_MAP);
00447 strcpy(file,cpl_frame_get_filename(frame));
00448 strcpy(cfg -> mask, file);
00449 } else {
00450 cpl_msg_error(_id,"Frame %s not found!", PRO_MASTER_BP_MAP);
00451 stack_free_alloc(cfg);
00452 (*status)++;
00453 return;
00454 }
00455
00456 }
00457
00458 if (strcmp(do_class,RAW_STACKED_SLITPOS) == 0) {
00459 cfg -> indind = 1;
00460 }
00461
00462 if(cfg -> indind == 0) {
00463 if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS)) {
00464 frame = cpl_frameset_find(sof,PRO_SLIT_POS);
00465 strcpy(file,cpl_frame_get_filename(frame));
00466 strcpy(cfg -> slitposList, file);
00467 cpl_msg_info(_id,"Using %s to interpolated bad pixels",
00468 PRO_SLIT_POS);
00469 cpl_error_reset();
00470 } else if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS_GUESS)) {
00471 frame = cpl_frameset_find(sof,PRO_SLIT_POS_GUESS);
00472 strcpy(file,cpl_frame_get_filename(frame));
00473 strcpy(cfg -> slitposList, file);
00474 cpl_msg_info(_id,"Using %s to interpolated bad pixels",
00475 PRO_SLIT_POS_GUESS);
00476 cpl_error_reset();
00477 } else {
00478 cpl_msg_error(_id,"Frame %s nor %s found!",
00479 PRO_SLIT_POS,PRO_SLIT_POS_GUESS);
00480 stack_free_alloc(cfg);
00481 (*status)++;
00482 return;
00483 }
00484
00485
00486 }
00487 if(cfg -> maskInd == 2) {
00488 if(NULL != cpl_frameset_find(sof,PRO_INDEX_LIST)) {
00489 frame = cpl_frameset_find(sof,PRO_INDEX_LIST);
00490 strcpy(file,cpl_frame_get_filename(frame));
00491 strcpy(cfg ->indexlist, file);
00492 } else {
00493 cpl_msg_error(_id,"Frame %s not found!", PRO_INDEX_LIST);
00494 stack_free_alloc(cfg);
00495 (*status)++;
00496 return;
00497 }
00498
00499 }
00500 }
00501
00502 cfg -> warpfixInd = fk->wfix_index;
00503 if(cfg->warpfixInd != 0) {
00504 if(NULL != cpl_frameset_find(sof,PRO_DISTORTION)) {
00505 frame = cpl_frameset_find(sof,PRO_DISTORTION);
00506 strcpy(file,cpl_frame_get_filename(frame));
00507 strcpy(cfg -> polyFile, file);
00508 } else {
00509 cpl_msg_error(_id,"Frame %s not found!", PRO_DISTORTION);
00510 stack_free_alloc(cfg);
00511 (*status)++;
00512 return;
00513 }
00514 }
00515
00516
00517 return ;
00518 }
00519
00520 static void
00521 parse_section_cleanmean(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
00522 {
00523
00524 cpl_parameter* p;
00525 p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.low_rejection");
00526 cfg -> loReject = cpl_parameter_get_double(p);
00527
00528 p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.high_rejection");
00529 cfg -> hiReject = cpl_parameter_get_double(p);
00530
00531 return ;
00532 }
00533
00534 static void
00535 parse_section_flatfield(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
00536 {
00537
00538 cpl_parameter* p;
00539 p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.flat_index");
00540 cfg -> flatInd = cpl_parameter_get_bool(p);
00541
00542 }
00543
00544 static void
00545 parse_section_badpixel(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
00546 {
00547 cpl_parameter* p;
00548
00549
00550 p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.ind_index");
00551 cfg -> indind = cpl_parameter_get_bool(p);
00552
00553 p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.mask_index");
00554 cfg -> maskInd = cpl_parameter_get_int(p);
00555
00556 p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.mask_rad");
00557 cfg -> maxRad = cpl_parameter_get_int(p);
00558
00559
00560
00561 cfg -> sigmaFactor = 3.;
00562
00563 }
00564
00565 static void
00566 parse_section_interleaving(stack_config_n * cfg)
00567 {
00568 cfg -> interInd = 0;
00569 cfg -> noRows = 400;
00570
00571 }
00572 static void
00573 parse_section_gaussconvolution(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
00574 {
00575
00576 cpl_parameter* p;
00577 p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.gauss_index");
00578 cfg -> gaussInd = cpl_parameter_get_bool(p);
00579
00580 p = cpl_parameterlist_find(cpl_cfg,"sinfoni.stacked.kernel_half_width");
00581 cfg -> hw = cpl_parameter_get_int(p);
00582
00583 }
00584 static void
00585 parse_section_shiftframes(stack_config_n * cfg)
00586 {
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599 cfg -> sfInd = 0;
00600 cfg -> sfType = 1;
00601 cfg -> sfOrder = 2;
00602
00603 }
00604
00605 static void
00606 parse_section_warpfix(stack_config_n * cfg,cpl_parameterlist * cpl_cfg)
00607 {
00608
00609 cpl_parameter* p;
00610
00611 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.stacked.warpfix_ind");
00612 cfg -> warpfixInd = cpl_parameter_get_bool(p);
00613
00614
00615 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.stacked.warpfix_kernel");
00616 strcpy(cfg -> kernel, cpl_parameter_get_string(p));
00617
00618 return ;
00619 }
00620
00621
00622 static void
00623 parse_section_qclog(stack_config_n * cfg,cpl_parameterlist * cpl_cfg)
00624 {
00625
00626 cpl_parameter* p;
00627
00628 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.stacked.qc_thresh_min");
00629 cfg -> qc_thresh_min = cpl_parameter_get_int(p);
00630
00631 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.stacked.qc_thresh_max");
00632 cfg -> qc_thresh_max = cpl_parameter_get_int(p);
00633
00634 return ;
00635 }
00636
00637 void
00638 stack_free(stack_config_n * cfg)
00639 {
00640 stack_free_alloc(cfg);
00641 stack_cfg_destroy_n(cfg);
00642 return;
00643
00644 }
00645
00646
00647 void
00648 stack_free_alloc(stack_config_n * cfg)
00649 {
00650 int i=0;
00651 for (i=0; i< cfg->nframes; i++) {
00652 if(cfg->framelist[i] != NULL) {
00653 cpl_free(cfg->framelist[i]);
00654 cfg->framelist[i]=NULL;
00655 }
00656 }
00657 if(cfg->frametype != NULL) cpl_free(cfg->frametype);
00658 if(cfg->framelist != NULL) cpl_free(cfg->framelist);
00659 if(cfg->frameposition != NULL) cpl_free(cfg->frameposition);
00660 }