00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "objnod_ini_by_cpl.h"
00018
00019
00020
00021
00022
00023 static void parse_section_frames(object_config *,cpl_frameset* sof, cpl_frameset** stk, int* status);
00024 static void parse_section_jittering(object_config *, cpl_parameterlist * cpl_cfg);
00025 static void parse_section_resampling(object_config *, cpl_parameterlist * cpl_cfg);
00026 static void parse_section_calibration(object_config *);
00027 static void parse_section_cubecreation(object_config *, cpl_parameterlist * cpl_cfg);
00028 static void parse_section_finetuning(object_config *, cpl_parameterlist * cpl_cfg);
00029 static void parse_section_skyextraction(object_config *, cpl_parameterlist * cpl_cfg);
00030
00031
00032
00043
00044
00045 object_config *
00046 parse_cpl_input_objnod(cpl_parameterlist * cpl_cfg,cpl_frameset* sof,
00047 cpl_frameset** stk)
00048 {
00049 const char* _id = "parse_cpl_input_objnod";
00050 object_config * cfg = object_cfg_create();
00051 int status=0;
00052
00053
00054
00055
00056
00057
00058 parse_section_resampling (cfg, cpl_cfg);
00059 parse_section_calibration (cfg);
00060 parse_section_cubecreation (cfg, cpl_cfg);
00061 parse_section_finetuning (cfg, cpl_cfg);
00062 parse_section_skyextraction(cfg, cpl_cfg);
00063 parse_section_jittering (cfg, cpl_cfg);
00064 parse_section_frames (cfg, sof,stk,&status);
00065 if (status > 0) {
00066 cpl_msg_error(_id,"parsing cpl input");
00067 objnod_free(cfg);
00068 cfg = NULL ;
00069 return NULL ;
00070 }
00071
00072 return cfg ;
00073 }
00074
00075 static void
00076 parse_section_frames(object_config * cfg,
00077 cpl_frameset* sof,
00078 cpl_frameset** stk,
00079 int* status)
00080 {
00081 const char* _id = "parse_section_frames";
00082 cxint nraw_good =0;
00083
00084
00085
00086 int nframes=0;
00087 int nraw=0;
00088 cpl_frame* frame = NULL;
00089 int nstk=0;
00090 int i=0;
00091 char spat_res[FILE_NAME_SZ];
00092 char lamp_status[FILE_NAME_SZ];
00093 char band[FILE_NAME_SZ];
00094 int ins_set=0;
00095
00096
00097
00098 nframes = cpl_frameset_get_size(sof);
00099
00100 sinfoni_contains_frames_type(sof,stk,PRO_NODDING_STACKED);
00101 nstk = cpl_frameset_get_size(*stk);
00102
00103 if (nstk == 0) {
00104 sinfoni_contains_frames_type(sof,stk,PRO_PSF_CALIBRATOR_STACKED);
00105 nstk = cpl_frameset_get_size(*stk);
00106 }
00107 if (nstk == 0) {
00108 cpl_msg_error(_id, "Cannot find good frames") ;
00109 (*status)++;
00110 return ;
00111 }
00112
00113
00114
00115
00116 nraw = cpl_frameset_get_size(*stk);
00117
00118 if (nraw < 1) {
00119 cpl_msg_error(_id, "Cannot find input stacked frames in the input list") ;
00120 (*status)++;
00121 return ;
00122 }
00123
00124 nraw = cpl_frameset_get_size(*stk);
00125 if (nraw < 1) {
00126 cpl_msg_error(_id, "no raw frame in input, something wrong!");
00127 (*status)++;
00128 return ;
00129 }
00130
00131
00132 cfg->framelist = cpl_malloc(nraw * sizeof(char*));
00133
00134
00135 for (i=0 ; i<nraw ; i++) {
00136 frame = cpl_frameset_get_frame(*stk,i);
00137 if(file_exists((char*)cpl_frame_get_filename(frame))==1)
00138 {
00139 cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
00140 nraw_good++;
00141 }
00142
00143
00144 }
00145
00146
00147 if (nraw_good < 1) {
00148 cpl_msg_error(_id,"no good raw frame in input!");
00149 (*status)++;
00150 return;
00151 }
00152
00153 cfg->nframes = nraw ;
00154
00155 strcpy(cfg -> outName, OBJNOD_OUT_FILENAME);
00156 strcpy(cfg -> maskname, OBJNOD_OUT_BPMAP);
00157 strcpy(cfg -> med_cube_name, OBJNOD_OUT_MED_CUBE);
00158
00159
00160 frame = cpl_frameset_get_frame(*stk,0);
00161
00162 sinfoni_get_spatial_res(frame,spat_res);
00163 switch(sinfoni_frame_is_on(frame))
00164 {
00165
00166 case 0:
00167 strcpy(lamp_status,"on");
00168 break;
00169 case 1:
00170 strcpy(lamp_status,"off");
00171 break;
00172 case -1:
00173 strcpy(lamp_status,"undefined");
00174 break;
00175 default:
00176 strcpy(lamp_status,"undefined");
00177 break;
00178 }
00179 sinfoni_get_band(frame,band);
00180 cpl_msg_info(_id,"stat_res: %s lamp_status: %s band: %s",
00181 spat_res, lamp_status, band);
00182
00183
00184 sinfoni_get_ins_set(band,&ins_set);
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 if(NULL != cpl_frameset_find(sof,PRO_WAVE_MAP)) {
00204 frame = cpl_frameset_find(sof,PRO_WAVE_MAP);
00205 strcpy(cfg -> wavemap, cpl_frame_get_filename(frame));
00206 } else {
00207 cpl_msg_info(_id,"Frame %s not found!", PRO_WAVE_MAP);
00208 cpl_msg_error(_id,(char* ) cpl_error_get_message());
00209 (*status)++;
00210 return ;
00211 }
00212
00213 if(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP)) {
00214 frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP);
00215 strcpy(cfg -> mflat, cpl_frame_get_filename(frame));
00216 } else {
00217 cpl_msg_info(_id,"Frame %s not found!", PRO_MASTER_FLAT_LAMP);
00218 cpl_msg_error(_id,(char* ) cpl_error_get_message());
00219 (*status)++;
00220 return ;
00221 }
00222
00223 if(NULL != cpl_frameset_find(sof,PRO_STACK_SKY_DIST)) {
00224 frame = cpl_frameset_find(sof,PRO_STACK_SKY_DIST);
00225 strcpy(cfg -> sky_dist, cpl_frame_get_filename(frame));
00226 } else {
00227 cpl_msg_warning(_id,"Frame %s not found!", PRO_STACK_SKY_DIST);
00228 strcpy(cfg -> sky_dist,"no_sky");
00229 }
00230
00231 if(NULL != cpl_frameset_find(sof,PRO_STACK_MFLAT_DIST)) {
00232 frame = cpl_frameset_find(sof,PRO_STACK_MFLAT_DIST);
00233 strcpy(cfg -> mflat_dist, cpl_frame_get_filename(frame));
00234 } else {
00235 strcpy(cfg -> mflat_dist, "not_found");
00236 cpl_msg_info(_id,"Frame %s not found!", PRO_STACK_MFLAT_DIST);
00237 }
00238
00239
00240 if(NULL != cpl_frameset_find(sof,PRO_STACK_MFLAT_DITHER_DIST)) {
00241 frame = cpl_frameset_find(sof,PRO_STACK_MFLAT_DITHER_DIST);
00242 strcpy(cfg -> mflat_dither_dist, cpl_frame_get_filename(frame));
00243 } else {
00244 strcpy(cfg -> mflat_dither_dist, "not_found");
00245 cpl_msg_info(_id,"Frame %s not found!", PRO_STACK_MFLAT_DITHER_DIST);
00246 }
00247
00248
00249 if(cfg -> northsouthInd) {
00250
00251 if(NULL != cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE)) {
00252 frame = cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE);
00253 strcpy(cfg -> distlist, cpl_frame_get_filename(frame));
00254 } else {
00255 cpl_msg_info(_id,"Frame %s not found!", PRO_SLITLETS_DISTANCE);
00256 (*status)++;
00257 return ;
00258 }
00259
00260
00261
00262 if(NULL != cpl_frameset_find(sof,PRO_FIRST_COL)) {
00263 frame = cpl_frameset_find(sof,PRO_FIRST_COL);
00264 strcpy(cfg -> firstCol, cpl_frame_get_filename(frame));
00265 } else {
00266 cpl_msg_info(_id,"Frame %s not found!", PRO_FIRST_COL);
00267 (*status)++;
00268 return ;
00269 }
00270 } else {
00271
00272 if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS)) {
00273 frame = cpl_frameset_find(sof,PRO_SLIT_POS);
00274 strcpy(cfg -> poslist, cpl_frame_get_filename(frame));
00275 } else {
00276 cpl_msg_info(_id,"Frame %s not found!", PRO_SLIT_POS);
00277 (*status)++;
00278 return ;
00279 }
00280
00281 }
00282 if(cfg -> halocorrectInd) {
00283 if(NULL != cpl_frameset_find(sof,PRO_HALO_SPECT)) {
00284 frame = cpl_frameset_find(sof,PRO_HALO_SPECT);
00285 strcpy(cfg -> halospectrum, cpl_frame_get_filename(frame));
00286 } else {
00287 cpl_msg_info(_id,"Frame %s not found!", PRO_HALO_SPECT);
00288 (*status)++;
00289 return ;
00290 }
00291
00292 }
00293
00294
00295
00296
00297
00298
00299
00300 return;
00301 }
00302
00303
00304 static void
00305 parse_section_jittering(object_config * cfg,cpl_parameterlist * cpl_cfg)
00306 {
00307 cpl_parameter* p;
00308
00309 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.jitter_index");
00310 cfg -> jitterind = cpl_parameter_get_bool(p);
00311
00312 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.size_x");
00313 cfg -> size_x = cpl_parameter_get_int(p);
00314
00315 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.size_y");
00316 cfg -> size_y = cpl_parameter_get_int(p);
00317
00318 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.kernel_type");
00319 strcpy(cfg -> kernel_type, cpl_parameter_get_string(p));
00320
00321 }
00322
00323 static void
00324 parse_section_resampling(object_config * cfg,cpl_parameterlist* cpl_cfg)
00325 {
00326 cpl_parameter* p;
00327
00328 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.n_coeffs");
00329 cfg -> ncoeffs = cpl_parameter_get_int(p);
00330
00331 cfg -> nrows = 2560;
00332 return ;
00333 }
00334
00335 static void
00336 parse_section_calibration(object_config * cfg)
00337 {
00338 cfg -> halocorrectInd=0;
00339
00340
00341 }
00342
00343 static void
00344 parse_section_cubecreation(object_config * cfg,cpl_parameterlist* cpl_cfg)
00345 {
00346 cpl_parameter* p;
00347 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.nord_south_index");
00348 cfg -> northsouthInd = cpl_parameter_get_bool(p);
00349 cfg -> nslits = NSLITLETS;
00350
00351 return ;
00352 }
00353
00354 static void
00355 parse_section_finetuning(object_config * cfg,cpl_parameterlist* cpl_cfg)
00356 {
00357 cpl_parameter* p;
00358
00359 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.fine_tuning_method");
00360 strcpy(cfg -> method, cpl_parameter_get_string(p));
00361
00362 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.order");
00363 cfg -> order = cpl_parameter_get_int(p);
00364
00365 }
00366
00367 static void
00368 parse_section_skyextraction(object_config * cfg,cpl_parameterlist* cpl_cfg)
00369 {
00370
00371 cpl_parameter* p;
00372 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.low_rejection");
00373 cfg -> loReject = cpl_parameter_get_double(p);
00374
00375 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.high_rejection");
00376 cfg -> hiReject = cpl_parameter_get_double(p);
00377
00378 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.tolerance");
00379 cfg -> tolerance = cpl_parameter_get_int(p);
00380
00381 }
00382
00383
00384 void
00385 objnod_free(object_config * cfg) {
00386 int i=0;
00387
00388 for(i=0;i<cfg->nframes;i++) {
00389 cpl_free(cfg->framelist[i]);
00390 }
00391 cpl_free(cfg->framelist);
00392
00393 object_cfg_destroy (cfg);
00394 return;
00395 }