badnorm_ini_by_cpl.c

00001 
00002 /*----------------------------------------------------------------------------
00003    
00004    File name    :   badnorm_ini_by_cpl.c
00005    Author       :   Andrea Modigliani
00006    Created on   :   Jun 16, 2004
00007    Description  :   parse cpl input for the search of static bad pixels
00008 
00009  ---------------------------------------------------------------------------*/
00010 
00011 
00012 /*---------------------------------------------------------------------------
00013                                 Includes
00014  ---------------------------------------------------------------------------*/
00015 
00016 #include "badnorm_ini_by_cpl.h"
00017 /*---------------------------------------------------------------------------
00018                     Functions private to this module
00019  ---------------------------------------------------------------------------*/
00020 
00021 static void  parse_section_frames(bad_config * cfg, 
00022 cpl_frameset* sof, const char* procatg, cpl_frameset** raw, int* status);
00023 static void parse_section_badpix(bad_config * cfg, cpl_parameterlist* cpl_cfg);
00024 static void parse_section_thresh(bad_config * cfg, cpl_parameterlist* cpl_cfg);
00025 
00026 
00027 /* Removed generatebadnorm_ini_file */
00028 
00029 
00030 /*-------------------------------------------------------------------------*/
00041 /*--------------------------------------------------------------------------*/
00042 
00043 bad_config * parse_cpl_input_badnorm(cpl_parameterlist * cpl_cfg, 
00044                                      cpl_frameset* sof,
00045                                      const char* procatg,
00046                                      cpl_frameset** raw) 
00047 {
00048   const char* _id = "parse_cpl_input_badnorm";
00049   bad_config    *       cfg ;
00050   int status = 0;
00051         /* Removed check on ini_file */
00052         /* Removed load of ini file */
00053 
00054   cfg = bad_cfg_create();
00055 
00056         /*
00057          * Perform sanity checks, fill up the structure with what was
00058          * found in the ini file
00059          */
00060 
00061   parse_section_badpix   (cfg, cpl_cfg);
00062   parse_section_thresh   (cfg, cpl_cfg);
00063   parse_section_frames   (cfg, sof, procatg, raw,&status);
00064   if(status>0) {
00065                cpl_msg_error(_id,"parsing cpl input");
00066                 bad_cfg_destroy(cfg);
00067                 cfg = NULL ;
00068                 return NULL ;
00069   }
00070   return cfg ;
00071 
00072 }
00073 
00074 static void     
00075 parse_section_frames(bad_config   * cfg,
00076                      cpl_frameset * sof,
00077                      const char         * procatg,          
00078                      cpl_frameset ** raw,
00079                      int* status)
00080 {
00081    const char * _id = "badnorm_ini_by_cpl";
00082    int                i=0;
00083    int                nraw = 0;
00084    char *          tag=NULL;
00085 
00086    int  nraw_good = 0;
00087    cpl_frame* frame=NULL;
00088    char spat_res[FILE_NAME_SZ];
00089    char lamp_status[FILE_NAME_SZ];
00090    char band[FILE_NAME_SZ];
00091    int ins_set=0;
00092      if(strcmp(procatg,PRO_BP_MAP_DI) == 0 ) {
00093 
00094       sinfoni_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
00095       nraw=cpl_frameset_get_size(*raw);
00096 
00097    } else if(strcmp(procatg,PRO_BP_MAP_NO) == 0 ) {
00098       
00099       sinfoni_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
00100       nraw=cpl_frameset_get_size(*raw);
00101 
00102    } else {
00103       sinfoni_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
00104       nraw=cpl_frameset_get_size(*raw);
00105 
00106       if (nraw==0) {
00107          sinfoni_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
00108          nraw=cpl_frameset_get_size(*raw);
00109       }   
00110 
00111    }
00112     if (nraw==0) {
00113          sinfoni_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
00114          nraw=cpl_frameset_get_size(*raw);
00115     }
00116 
00117     if (nraw==0) {
00118          sinfoni_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
00119          nraw=cpl_frameset_get_size(*raw);
00120     }
00121 
00122 
00123    if (nraw < 1) {
00124       cpl_msg_error(_id, "Too few (%d) raw frames (%s or %s or %s) present in"
00125              "frameset!Aborting...",nraw,
00126                          PRO_MASTER_FLAT_LAMP,RAW_FLAT_LAMP,RAW_FLAT_NS);
00127       (*status)++;
00128       return;
00129    }
00130         
00131    /* Removed: get "general:infile" read it, check input matrix */
00132    /* Allocate structures to go into the blackboard */
00133    cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
00134 
00135    /* read input frames */
00136    for (i=0 ; i<nraw ; i++) {
00137       frame = cpl_frameset_get_frame(*raw,i);
00138       tag = (char*)cpl_frame_get_tag(frame) ;
00139       if(file_exists((char*) cpl_frame_get_filename(frame))==1) 
00140     {
00141              /* Store file name into framelist */
00142              cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00143              nraw_good++;
00144     }
00145    }
00146 
00147    if(nraw_good<1) {
00148      cpl_msg_error(_id,"Error: no good raw frame in input, something wrong!");
00149      (*status)++;
00150      return;
00151    }
00152 
00153    /* Copy relevant information into the blackboard */
00154    cfg->nframes         = nraw_good ;
00155 
00156    /* Output */
00157           if (strcmp(procatg,PRO_BP_MAP_NO) == 0) {
00158       strcpy(cfg -> outName, BP_NORM_OUT_FILENAME);
00159    } else if (strcmp(procatg,PRO_BP_MAP_DI) == 0) {
00160       strcpy(cfg -> outName, BP_DIST_OUT_FILENAME);
00161    } else if (strcmp(procatg,PRO_DEFAULT) == 0) {
00162       strcpy(cfg -> outName, BP_NORM_OUT_FILENAME);
00163    } else {
00164       cpl_msg_error(_id,"Error: PRO.CATG %s, not supported!",procatg);
00165       (*status)++;
00166       return;
00167    }
00168 
00169 
00170 
00171    frame = cpl_frameset_get_frame(*raw,0);
00172    sinfoni_get_spatial_res(frame,spat_res);
00173  
00174  
00175    switch(sinfoni_frame_is_on(frame)) 
00176      {
00177    case 0: 
00178       strcpy(lamp_status,"on");
00179       break;
00180     case 1: 
00181       strcpy(lamp_status,"off");
00182       break;
00183     case -1:
00184       strcpy(lamp_status,"undefined");
00185       break;
00186     default: 
00187       strcpy(lamp_status,"undefined");
00188       break;
00189      }
00190 
00191    sinfoni_get_band(frame,band);
00192    cpl_msg_info(_id,"spatial resolution: %s lamp status: %s band: %s \n",
00193                      spat_res,              lamp_status,    band);
00194 
00195 
00196    sinfoni_get_ins_set(band,&ins_set);
00197    /*
00198    printf("cfg -> sigmaFactor =%f\n", cfg -> sigmaFactor);
00199    printf("cfg -> methodInd   =%d\n", cfg -> methodInd);
00200    printf("cfg -> factor      =%f\n", cfg -> factor);
00201    printf("cfg -> iterations  =%d\n", cfg -> iterations);
00202    printf("cfg -> loReject    =%f\n", cfg -> loReject);
00203    printf("cfg -> hiReject    =%f\n", cfg -> hiReject);
00204    printf("cfg -> llx         =%d\n", cfg -> llx);
00205    printf("cfg -> lly         =%d\n", cfg -> lly);
00206    printf("cfg -> urx         =%d\n", cfg -> urx);
00207    printf("cfg -> ury         =%d\n", cfg -> ury);
00208 
00209    printf("cfg -> threshInd   =%d\n", cfg -> threshInd);
00210    printf("cfg -> meanfactor  =%f\n", cfg -> meanfactor);
00211    printf("cfg -> mincut      =%f\n", cfg -> mincut);
00212    printf("cfg -> maxcut      =%f\n", cfg -> maxcut);
00213    */
00214 
00215    return;
00216 
00217 }
00218 
00219 static void     
00220 parse_section_badpix(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
00221 {
00222    cpl_parameter *p;     
00223 
00224    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.sigma_factor");
00225    cfg -> sigmaFactor = cpl_parameter_get_double(p);
00226 
00227    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.method_index");
00228    cfg -> methodInd = cpl_parameter_get_int(p);
00229 
00230    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.factor");
00231    cfg -> factor = cpl_parameter_get_double(p);
00232 
00233    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.iterations");
00234    cfg -> iterations = cpl_parameter_get_int(p);
00235 
00236    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.low_rejection");
00237    cfg -> loReject = cpl_parameter_get_double(p);
00238 
00239    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.high_rejection");
00240    cfg -> hiReject = cpl_parameter_get_double(p);
00241 
00242    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.llx");
00243    cfg -> llx = cpl_parameter_get_int(p);
00244 
00245    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.lly");
00246    cfg -> lly = cpl_parameter_get_int(p);
00247 
00248    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.urx");
00249    cfg -> urx = cpl_parameter_get_int(p);
00250 
00251    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.ury");
00252    cfg -> ury = cpl_parameter_get_int(p);
00253 
00254 }
00255 
00256 static void     
00257 parse_section_thresh(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
00258 {
00259    cpl_parameter *p;     
00260 
00261    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.threshold_index");
00262    cfg -> threshInd  = cpl_parameter_get_bool(p);
00263 
00264    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.mean_factor");
00265    cfg -> meanfactor = cpl_parameter_get_double(p);
00266 
00267 
00268    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.min_cut");
00269    cfg -> mincut = cpl_parameter_get_double(p);
00270 
00271    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_norm.max_cut");
00272    cfg -> maxcut = cpl_parameter_get_double(p);
00273 
00274 }
00275 
00276 void
00277 bad_free(bad_config * cfg)
00278 {  
00279   cpl_free(cfg->framelist);
00280   bad_cfg_destroy(cfg);
00281  
00282   return;
00283 
00284 }

Generated on Wed Oct 26 13:08:51 2005 for SINFONI Pipeline Reference Manual by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001