37 #include "sinfo_stack_ini_by_cpl.h"
38 #include "sinfo_error.h"
39 #include "sinfo_pro_types.h"
40 #include "sinfo_raw_types.h"
41 #include "sinfo_ref_types.h"
42 #include "sinfo_functions.h"
44 #include "sinfo_file_handling.h"
49 static void sinfo_stack_free_alloc(stack_config_n * cfg);
53 parse_section_frames(stack_config_n *,
60 parse_section_cleanmean(stack_config_n *, cpl_parameterlist* cpl_cfg);
62 parse_section_flatfield(stack_config_n *, cpl_parameterlist* cpl_cfg);
64 parse_section_badpixel(stack_config_n *, cpl_parameterlist* cpl_cfg);
66 parse_section_interleaving(stack_config_n *);
68 parse_section_gaussconvolution(stack_config_n *, cpl_parameterlist* cpl_cfg);
70 parse_section_shiftframes(stack_config_n *);
72 parse_section_warpfix(stack_config_n *, cpl_parameterlist* cpl_cfg);
74 parse_section_qclog(stack_config_n *, cpl_parameterlist* cpl_cfg);
96 stack_config_n * sinfo_parse_cpl_input_stack(cpl_parameterlist* cpl_cfg,
101 stack_config_n * cfg =sinfo_stack_cfg_create_n();
111 parse_section_cleanmean (cfg, cpl_cfg);
112 parse_section_flatfield (cfg, cpl_cfg);
113 parse_section_badpixel (cfg, cpl_cfg);
114 parse_section_interleaving (cfg);
115 parse_section_gaussconvolution (cfg, cpl_cfg);
116 parse_section_shiftframes (cfg);
117 parse_section_warpfix (cfg, cpl_cfg);
118 parse_section_qclog (cfg, cpl_cfg);
119 parse_section_frames (cfg, sof, raw, &status, fk);
122 sinfo_stack_cfg_destroy_n(cfg);
138 parse_section_frames(stack_config_n * cfg,
139 cpl_frameset* sof, cpl_frameset** raw_set,
int* status,
145 char file[FILE_NAME_SZ];
146 int nobj, noff, ndark ;
147 int nditherobj, nditheroff ;
155 cpl_frame* frame = NULL;
157 char spat_res[FILE_NAME_SZ];
158 char lamp_status[FILE_NAME_SZ];
159 char band[FILE_NAME_SZ];
167 do_class=fk->pro_class;
169 if(strcmp(do_class,
"DEFAULT") == 0) {
170 sinfo_extract_raw_stack_frames(sof,raw_set);
171 }
else if (strcmp(do_class,PRO_FIBRE_NS_STACKED_DIST) == 0) {
172 sinfo_is_fibres_on_off(sof,*raw_set);
173 }
else if (strcmp(do_class,PRO_FIBRE_NS_STACKED) == 0) {
174 sinfo_contains_frames_kind(sof,*raw_set,(
char*)PRO_FIBRE_NS_STACKED);
175 }
else if (strcmp(do_class,RAW_STACKED_SLITPOS) == 0) {
176 sinfo_extract_raw_stack_frames(sof,raw_set);
178 sinfo_extract_raw_frames_type(sof,raw_set,do_class);
180 nraw = cpl_frameset_get_size(*raw_set);
189 cfg->framelist = cpl_malloc(nraw *
sizeof(
char*));
190 cfg->frametype = cpl_malloc(nraw *
sizeof(
int));
191 cfg->frameposition = cpl_malloc(nraw *
sizeof(
int));
193 for (i=0;i<nraw;i++) {
194 cfg->framelist[i]=NULL;
195 cfg->frametype[i]=-1;
196 cfg->frameposition[i]=-1;
213 for (i=0 ; i<nraw ; i++) {
214 frame = cpl_frameset_get_frame(*raw_set,i);
215 name=cpl_frame_get_filename(frame);
216 if(sinfo_file_exists((
char*)name)==1) {
218 if(cpl_frame_get_tag(frame) != NULL) {
220 tag= (
char*) cpl_frame_get_tag(frame);
221 if((sinfo_frame_is_on(frame) == 0) ||
222 (sinfo_frame_is_sky(frame) == 1))
224 cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
225 cfg->frametype[i] = FRAME_OFF ;
227 if (sinfo_frame_is_dither(frame))
229 cfg->frameposition[i] = FRAME_POS2 ;
234 cfg->frameposition[i] = FRAME_POS1 ;
238 else if(strstr(tag,RAW_REF) != NULL)
240 cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
241 cfg->frametype[i] = FRAME_REF ;
243 if (sinfo_frame_is_dither(frame))
245 cfg->frameposition[i] = FRAME_POS2 ;
249 cfg->frameposition[i] = FRAME_POS1 ;
252 else if(sinfo_is_dark(tag))
254 cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
255 cfg->frametype[i] = FRAME_DRK ;
256 cfg->frameposition[i] = FRAME_POS1 ;
259 sinfo_msg(
"Frame is sinfo_dark on\n");
264 cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
265 cfg->frametype[i] = FRAME_ON ;
267 if (sinfo_frame_is_dither(frame))
269 cfg->frameposition[i] = FRAME_POS2 ;
275 cfg->frameposition[i] = FRAME_POS1 ;
283 cfg->frametype[i] = FRAME_ON ;
285 cfg->frameposition[i] = FRAME_POS1 ;
294 sinfo_msg(
"Noff= %d Nobj= %d Nditheroff= %d Nditherobj= %d",
295 noff,nobj,nditheroff,nditherobj);
300 cfg->nframes = nraw ;
304 cfg->nditherobj = nditherobj ;
305 cfg->nditheroff = nditheroff ;
306 cfg->contains_sky = found_sky ;
307 cfg->contains_ref = found_ref ;
308 cfg->contains_dither = found_dither ;
309 cfg->contains_dark = found_dark ;
312 frame = cpl_frameset_get_frame(*raw_set,0);
314 ck0_nomsg(sinfo_get_spatial_res(frame,spat_res));
318 if(sinfo_frame_is_on(frame) == 1) {
319 strcpy(lamp_status,
"on");
321 strcpy(lamp_status,
"off");
323 switch(sinfo_frame_is_on(frame))
326 strcpy(lamp_status,
"on");
329 strcpy(lamp_status,
"off");
332 strcpy(lamp_status,
"undefined");
335 strcpy(lamp_status,
"undefined");
340 sinfo_get_band(frame,band);
343 sinfo_msg(
"Spatial resolution: %s lamp status: %s band: %s",
344 spat_res, lamp_status, band);
346 sinfo_get_ins_set(band,&ins_set);
347 frame = cpl_frameset_get_frame(*raw_set,0);
348 tag=(
char*)cpl_frame_get_tag(frame);
353 if(fk->frm_switch==1) {
359 cfg->maskInd = fk->mask_index;
360 cfg->indind = fk->ind_index;
361 cfg->flatInd = fk->flat_index;
362 cfg -> loReject = fk->low_rej;
363 cfg -> hiReject = fk->hig_rej;
364 cfg -> warpfixInd = fk->wfix_index;
380 if(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP)) {
381 frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP);
382 strcpy(file,cpl_frame_get_filename(frame));
383 strcpy(cfg -> flatfield1, file);
384 }
else if(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP1)) {
385 frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP1);
386 strcpy(file,cpl_frame_get_filename(frame));
387 strcpy(cfg -> flatfield1, file);
391 sinfo_stack_free_alloc(cfg);
397 if(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP2)) {
398 frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP2);
399 strcpy(file,cpl_frame_get_filename(frame));
400 strcpy(cfg -> flatfield2, file);
402 sinfo_msg(
"Frame %s not found!", PRO_MASTER_FLAT_LAMP2);
408 if(cfg->maskInd != 0) {
409 if(strstr(do_class,
"FIBRE_NS") != NULL) {
410 if(NULL != cpl_frameset_find(sof,PRO_BP_MAP_DI)) {
411 frame = cpl_frameset_find(sof,PRO_BP_MAP_DI);
412 strcpy(file,cpl_frame_get_filename(frame));
413 strcpy(cfg -> mask, file);
416 sinfo_stack_free_alloc(cfg);
423 if(NULL != cpl_frameset_find(sof,PRO_MASTER_BP_MAP)) {
424 frame = cpl_frameset_find(sof,PRO_MASTER_BP_MAP);
425 strcpy(file,cpl_frame_get_filename(frame));
426 strcpy(cfg -> mask, file);
429 sinfo_stack_free_alloc(cfg);
436 if (strcmp(do_class,RAW_STACKED_SLITPOS) == 0) {
440 if(cfg -> indind == 0) {
441 if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS)) {
442 frame = cpl_frameset_find(sof,PRO_SLIT_POS);
443 strcpy(file,cpl_frame_get_filename(frame));
444 strcpy(cfg -> slitposList, file);
445 sinfo_msg(
"Using %s to interpolate bad pixels",
448 }
else if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS_GUESS)) {
449 frame = cpl_frameset_find(sof,PRO_SLIT_POS_GUESS);
450 strcpy(file,cpl_frame_get_filename(frame));
451 strcpy(cfg -> slitposList, file);
452 sinfo_msg(
"Using %s to interpolated bad pixels",
457 PRO_SLIT_POS,PRO_SLIT_POS_GUESS);
458 sinfo_stack_free_alloc(cfg);
465 if(cfg -> maskInd == 2) {
466 if(NULL != cpl_frameset_find(sof,PRO_INDEX_LIST)) {
467 frame = cpl_frameset_find(sof,PRO_INDEX_LIST);
468 strcpy(file,cpl_frame_get_filename(frame));
469 strcpy(cfg ->indexlist, file);
472 sinfo_stack_free_alloc(cfg);
480 cfg -> warpfixInd = fk->wfix_index;
481 if(cfg->warpfixInd != 0) {
482 if(NULL != cpl_frameset_find(sof,PRO_DISTORTION)) {
483 frame = cpl_frameset_find(sof,PRO_DISTORTION);
484 strcpy(file,cpl_frame_get_filename(frame));
485 strcpy(cfg -> polyFile, file);
488 sinfo_stack_free_alloc(cfg);
494 if(NULL != cpl_frameset_find(sof,PRO_MASTER_DARK)) {
495 frame = cpl_frameset_find(sof,PRO_MASTER_DARK);
496 strcpy(file,cpl_frame_get_filename(frame));
497 strcpy(cfg -> mdark, file);
501 sinfo_msg(
"Frame %s not found", PRO_MASTER_DARK);
517 parse_section_cleanmean(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
521 p = cpl_parameterlist_find(cpl_cfg,
"sinfoni.stacked.low_rejection");
522 cfg -> loReject = cpl_parameter_get_double(p);
524 p = cpl_parameterlist_find(cpl_cfg,
"sinfoni.stacked.high_rejection");
525 cfg -> hiReject = cpl_parameter_get_double(p);
536 parse_section_flatfield(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
540 p = cpl_parameterlist_find(cpl_cfg,
"sinfoni.stacked.flat_index");
541 cfg -> flatInd = cpl_parameter_get_bool(p);
551 parse_section_badpixel(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
556 p = cpl_parameterlist_find(cpl_cfg,
"sinfoni.stacked.ind_index");
557 cfg -> indind = cpl_parameter_get_bool(p);
559 p = cpl_parameterlist_find(cpl_cfg,
"sinfoni.stacked.mask_index");
560 cfg -> maskInd = cpl_parameter_get_int(p);
562 p = cpl_parameterlist_find(cpl_cfg,
"sinfoni.stacked.mask_rad");
563 cfg -> maxRad = cpl_parameter_get_int(p);
567 cfg -> sigmaFactor = 3.;
576 parse_section_interleaving(stack_config_n * cfg)
589 parse_section_gaussconvolution(stack_config_n * cfg,cpl_parameterlist* cpl_cfg)
593 p = cpl_parameterlist_find(cpl_cfg,
"sinfoni.stacked.gauss_index");
594 cfg -> gaussInd = cpl_parameter_get_bool(p);
596 p = cpl_parameterlist_find(cpl_cfg,
"sinfoni.stacked.kernel_half_width");
597 cfg -> hw = cpl_parameter_get_int(p);
606 parse_section_shiftframes(stack_config_n * cfg)
632 parse_section_warpfix(stack_config_n * cfg,cpl_parameterlist * cpl_cfg)
637 p = cpl_parameterlist_find(cpl_cfg,
"sinfoni.stacked.warpfix_ind");
638 cfg -> warpfixInd = cpl_parameter_get_bool(p);
641 p = cpl_parameterlist_find(cpl_cfg,
"sinfoni.stacked.warpfix_kernel");
642 strcpy(cfg -> kernel, cpl_parameter_get_string(p));
654 parse_section_qclog(stack_config_n * cfg,cpl_parameterlist * cpl_cfg)
659 p = cpl_parameterlist_find(cpl_cfg,
"sinfoni.stacked.qc_thresh_min");
660 cfg -> qc_thresh_min = cpl_parameter_get_int(p);
662 p = cpl_parameterlist_find(cpl_cfg,
"sinfoni.stacked.qc_thresh_max");
663 cfg -> qc_thresh_max = cpl_parameter_get_int(p);
673 sinfo_stack_free(stack_config_n ** cfg)
676 sinfo_stack_free_alloc(*cfg);
677 sinfo_stack_cfg_destroy_n(*cfg);
690 sinfo_stack_free_alloc(stack_config_n * cfg)
693 for (i=0; i< cfg->nframes; i++) {
694 if(cfg->framelist[i] != NULL) {
695 cpl_free(cfg->framelist[i]);
696 cfg->framelist[i]=NULL;
699 if(cfg->frametype != NULL) {
700 cpl_free(cfg->frametype);
703 if(cfg->framelist != NULL) {
704 cpl_free(cfg->framelist);
707 if(cfg->frameposition != NULL) {
708 cpl_free(cfg->frameposition);
709 cfg->frameposition=NULL;
#define sinfo_msg_error(...)
Print an error message.