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