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