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 #ifdef HAVE_CONFIG_H
00028 # include <config.h>
00029 #endif
00030
00031
00032
00033
00034 #include <string.h>
00035 #include "sinfo_badnorm_ini_by_cpl.h"
00036 #include "sinfo_raw_types.h"
00037 #include "sinfo_pro_types.h"
00038 #include "sinfo_hidden.h"
00039 #include "sinfo_globals.h"
00040 #include "sinfo_functions.h"
00041 #include "sinfo_file_handling.h"
00042
00043
00044
00045
00046 static void parse_section_frames(bad_config * cfg,
00047 cpl_frameset* sof, const char* procatg, cpl_frameset** raw, int* status);
00048 static void parse_section_badpix(bad_config * cfg, cpl_parameterlist* cpl_cfg);
00049 static void parse_section_thresh(bad_config * cfg, cpl_parameterlist* cpl_cfg);
00050
00071 bad_config *
00072 sinfo_parse_cpl_input_badnorm(cpl_parameterlist * cpl_cfg,
00073 cpl_frameset* sof,
00074 const char* procatg,
00075 cpl_frameset** raw)
00076 {
00077 bad_config * cfg ;
00078 int status = 0;
00079
00080
00081
00082 cfg = sinfo_bad_cfg_create();
00083
00084
00085
00086
00087
00088
00089 parse_section_badpix (cfg, cpl_cfg);
00090 parse_section_thresh (cfg, cpl_cfg);
00091 parse_section_frames (cfg, sof, procatg, raw,&status);
00092 if(status>0) {
00093 sinfo_msg_error("parsing cpl input");
00094 sinfo_bad_cfg_destroy(cfg);
00095 cfg = NULL ;
00096 return NULL ;
00097 }
00098 return cfg ;
00099
00100 }
00101
00102
00115 static void
00116 parse_section_frames(bad_config * cfg,
00117 cpl_frameset * sof,
00118 const char * procatg,
00119 cpl_frameset ** raw,
00120 int* status)
00121 {
00122 int i=0;
00123 int nraw = 0;
00124 char * tag=NULL;
00125
00126 int nraw_good = 0;
00127 cpl_frame* frame=NULL;
00128 char spat_res[FILE_NAME_SZ];
00129 char lamp_status[FILE_NAME_SZ];
00130 char band[FILE_NAME_SZ];
00131 int ins_set=0;
00132 if(strcmp(procatg,PRO_BP_MAP_DI) == 0 ) {
00133
00134 sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
00135 nraw=cpl_frameset_get_size(*raw);
00136
00137 } else if(strcmp(procatg,PRO_BP_MAP_NO) == 0 ) {
00138
00139 sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
00140 nraw=cpl_frameset_get_size(*raw);
00141
00142 } else {
00143 sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
00144 nraw=cpl_frameset_get_size(*raw);
00145
00146 if (nraw==0) {
00147 sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
00148 nraw=cpl_frameset_get_size(*raw);
00149 }
00150
00151 }
00152 if (nraw==0) {
00153 sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
00154 nraw=cpl_frameset_get_size(*raw);
00155 }
00156
00157 if (nraw==0) {
00158 sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
00159 nraw=cpl_frameset_get_size(*raw);
00160 }
00161
00162
00163 if (nraw < 1) {
00164 sinfo_msg_error("Too few (%d) raw frames (%s or %s or %s) present in"
00165 "frameset!Aborting...",nraw,
00166 PRO_MASTER_FLAT_LAMP,RAW_FLAT_LAMP,RAW_FLAT_NS);
00167 (*status)++;
00168 return;
00169 }
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(*raw,i);
00178 tag = (char*)cpl_frame_get_tag(frame) ;
00179 if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1)
00180 {
00181
00182 cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00183 nraw_good++;
00184 }
00185 }
00186
00187 if(nraw_good<1) {
00188 sinfo_msg_error("Error: no good raw frame in input, something wrong!");
00189 (*status)++;
00190 return;
00191 }
00192
00193
00194 cfg->nframes = nraw_good ;
00195
00196
00197 if (strcmp(procatg,PRO_BP_MAP_NO) == 0) {
00198 strcpy(cfg -> outName, BP_NORM_OUT_FILENAME);
00199 } else if (strcmp(procatg,PRO_BP_MAP_DI) == 0) {
00200 strcpy(cfg -> outName, BP_DIST_OUT_FILENAME);
00201 } else if (strcmp(procatg,PRO_DEFAULT) == 0) {
00202 strcpy(cfg -> outName, BP_NORM_OUT_FILENAME);
00203 } else {
00204 sinfo_msg_error("Error: PRO.CATG %s, not supported!",procatg);
00205 (*status)++;
00206 return;
00207 }
00208
00209
00210
00211 frame = cpl_frameset_get_frame(*raw,0);
00212 sinfo_get_spatial_res(frame,spat_res);
00213
00214
00215 switch(sinfo_frame_is_on(frame))
00216 {
00217 case 0:
00218 strcpy(lamp_status,"on");
00219 break;
00220 case 1:
00221 strcpy(lamp_status,"off");
00222 break;
00223 case -1:
00224 strcpy(lamp_status,"undefined");
00225 break;
00226 default:
00227 strcpy(lamp_status,"undefined");
00228 break;
00229 }
00230
00231 sinfo_get_band(frame,band);
00232 sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
00233 spat_res, lamp_status, band);
00234
00235
00236 sinfo_get_ins_set(band,&ins_set);
00237
00238 return;
00239
00240 }
00241
00251 static void
00252 parse_section_badpix(bad_config * cfg, cpl_parameterlist * cpl_cfg)
00253 {
00254 cpl_parameter *p;
00255
00256 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.sigma_factor");
00257 cfg -> sigmaFactor = cpl_parameter_get_double(p);
00258
00259 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.method_index");
00260 cfg -> methodInd = cpl_parameter_get_int(p);
00261
00262 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.factor");
00263 cfg -> factor = cpl_parameter_get_double(p);
00264
00265 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.iterations");
00266 cfg -> iterations = cpl_parameter_get_int(p);
00267
00268 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.low_rejection");
00269 cfg -> loReject = cpl_parameter_get_double(p);
00270
00271 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.high_rejection");
00272 cfg -> hiReject = cpl_parameter_get_double(p);
00273
00274 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.llx");
00275 cfg -> llx = cpl_parameter_get_int(p);
00276
00277 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.lly");
00278 cfg -> lly = cpl_parameter_get_int(p);
00279
00280 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.urx");
00281 cfg -> urx = cpl_parameter_get_int(p);
00282
00283 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.ury");
00284 cfg -> ury = cpl_parameter_get_int(p);
00285
00286 }
00287
00297 static void
00298 parse_section_thresh(bad_config * cfg, cpl_parameterlist * cpl_cfg)
00299 {
00300 cpl_parameter *p;
00301
00302 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.threshold_index");
00303 cfg -> threshInd = cpl_parameter_get_bool(p);
00304
00305 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.mean_factor");
00306 cfg -> meanfactor = cpl_parameter_get_double(p);
00307
00308
00309 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.min_cut");
00310 cfg -> mincut = cpl_parameter_get_double(p);
00311
00312 p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.max_cut");
00313 cfg -> maxcut = cpl_parameter_get_double(p);
00314
00315 }
00323 void
00324 sinfo_badnorm_free(bad_config ** cfg)
00325 {
00326 if((*cfg) != NULL) {
00327 if((*cfg)->framelist != NULL) {
00328 cpl_free((*cfg)->framelist);
00329 (*cfg)->framelist=NULL;
00330 }
00331 sinfo_bad_cfg_destroy((*cfg));
00332 *cfg =NULL;
00333 }
00334 return;
00335
00336 }