sinfo_badnorm_ini_by_cpl.c

00001 /*
00002  * This file is part of the ESO SINFONI Pipeline
00003  * Copyright (C) 2004,2005 European Southern Observatory
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00018  */
00019 /*----------------------------------------------------------------------------
00020    
00021    File name    :   sinfo_badnorm_ini_by_cpl.c
00022    Author       :   Andrea Modigliani
00023    Created on   :   Jun 16, 2004
00024    Description  :   parse cpl input for the search of static bad pixels
00025 
00026  ---------------------------------------------------------------------------*/
00027 #ifdef HAVE_CONFIG_H
00028 #  include <config.h>
00029 #endif
00030 /*---------------------------------------------------------------------------
00031                                 Includes
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                     Functions private to this module
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         /* Removed check on ini_file */
00079         /* Removed load of ini file */
00080 
00081   cfg = sinfo_bad_cfg_create();
00082 
00083         /*
00084          * Perform sanity checks, fill up the structure with what was
00085          * found in the ini file
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    /* Removed: get "general:infile" read it, check input sinfo_matrix */
00171    /* Allocate structures to go into the blackboard */
00172    cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
00173 
00174    /* read input frames */
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              /* Store file name into framelist */
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    /* Copy relevant information into the blackboard */
00193    cfg->nframes         = nraw_good ;
00194 
00195    /* Output */
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 }

Generated on Wed Jan 17 08:33:42 2007 for SINFONI Pipeline Reference Manual by  doxygen 1.4.4