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