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