sinfo_baddist_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_baddist_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 #include <string.h>
00034 #include "sinfo_baddist_ini_by_cpl.h"
00035 #include "sinfo_hidden.h"
00036 #include "sinfo_pro_types.h"
00037 #include "sinfo_raw_types.h"
00038 #include "sinfo_globals.h"
00039 #include "sinfo_functions.h"
00040 #include "sinfo_file_handling.h"
00041 
00042 /*---------------------------------------------------------------------------
00043                     Functions private to this module
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 
00072 bad_config * 
00073 sinfo_parse_cpl_input_baddist(cpl_parameterlist * cpl_cfg, 
00074                                      cpl_frameset* sof,
00075                                      const char* procatg,
00076                                      cpl_frameset** raw) 
00077 {
00078   bad_config    *       cfg ;
00079   int status = 0;
00080         /* Removed check on ini_file */
00081         /* Removed load of ini file */
00082 
00083   cfg = sinfo_bad_cfg_create();
00084 
00085         /*
00086          * Perform sanity checks, fill up the structure with what was
00087          * found in the ini file
00088          */
00089 
00090   parse_section_badpix   (cfg, cpl_cfg);
00091   parse_section_thresh   (cfg, cpl_cfg);
00092   parse_section_frames   (cfg, sof, procatg, raw,&status);
00093   if(status>0) {
00094                sinfo_msg_error("parsing cpl input");
00095                 sinfo_bad_cfg_destroy(cfg);
00096                 cfg = NULL ;
00097                 return NULL ;
00098   }
00099   return cfg ;
00100 
00101 }
00102 
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 
00132 
00133      if(strcmp(procatg,PRO_BP_MAP_DI) == 0 ) {
00134 
00135       sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
00136       nraw=cpl_frameset_get_size(*raw);
00137 
00138    } else if(strcmp(procatg,PRO_BP_MAP_NO) == 0 ) {
00139       
00140       sinfo_extract_raw_frames_type(sof,raw,PRO_MASTER_FLAT_LAMP);
00141       nraw=cpl_frameset_get_size(*raw);
00142 
00143    } else {
00144       sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
00145       nraw=cpl_frameset_get_size(*raw);
00146 
00147       if (nraw==0) {
00148          sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
00149          nraw=cpl_frameset_get_size(*raw);
00150       }   
00151 
00152    }
00153     if (nraw==0) {
00154          sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
00155          nraw=cpl_frameset_get_size(*raw);
00156     }
00157 
00158     if (nraw==0) {
00159          sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
00160          nraw=cpl_frameset_get_size(*raw);
00161     }
00162 
00163 
00164 
00165    nraw=cpl_frameset_get_size(*raw);
00166    if (nraw < 1) {
00167       sinfo_msg_error("Too few (%d) raw frames (%s or %s) present in"
00168              "frameset!Aborting...",nraw,
00169                          RAW_FLAT_LAMP,RAW_FLAT_NS);
00170       (*status)++;
00171       return;
00172    }
00173         
00174    /* Removed: get "general:infile" read it, check input sinfo_matrix */
00175    /* Allocate structures to go into the blackboard */
00176    cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
00177 
00178    /* read input frames */
00179    for (i=0 ; i<nraw ; i++) {
00180       frame = cpl_frameset_get_frame(*raw,i);
00181       tag = (char*)cpl_frame_get_tag(frame) ;
00182       if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) 
00183     {
00184              /* Store file name into framelist */
00185              cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00186              nraw_good++;
00187     }
00188    }
00189    if(nraw_good<1) {
00190      sinfo_msg_error("Error: no good raw frame in input, something wrong!");
00191      (*status)++;
00192      return;
00193    }
00194 
00195    /* Copy relevant information into the blackboard */
00196    cfg->nframes         = nraw_good ;
00197 
00198    /* Output */
00199    strcpy(cfg -> outName, BP_DIST_OUT_FILENAME);
00200  
00201 
00202 
00203 
00204    frame = cpl_frameset_get_frame(*raw,0);
00205    sinfo_get_spatial_res(frame,spat_res);
00206  
00207     switch(sinfo_frame_is_on(frame)) 
00208      {
00209    case 0: 
00210       strcpy(lamp_status,"on");
00211       break;
00212     case 1: 
00213       strcpy(lamp_status,"off");
00214       break;
00215     case -1:
00216       strcpy(lamp_status,"undefined");
00217       break;
00218     default: 
00219       strcpy(lamp_status,"undefined");
00220       break;
00221      }
00222 
00223     sinfo_get_band(frame,band);
00224    sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
00225                      spat_res,    lamp_status,    band);
00226    sinfo_get_ins_set(band,&ins_set);
00227 
00228    return;
00229 
00230 }
00231 
00239 static void     
00240 parse_section_badpix(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
00241 {
00242    cpl_parameter *p;     
00243 
00244    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.sigma_factor");
00245    cfg -> sigmaFactor = cpl_parameter_get_double(p);
00246 
00247    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.method_index");
00248    cfg -> methodInd = cpl_parameter_get_int(p);
00249 
00250    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.factor");
00251    cfg -> factor = cpl_parameter_get_double(p);
00252 
00253    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.iterations");
00254    cfg -> iterations = cpl_parameter_get_int(p);
00255 
00256    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.low_rejection");
00257    cfg -> loReject = cpl_parameter_get_double(p);
00258 
00259    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.high_rejection");
00260    cfg -> hiReject = cpl_parameter_get_double(p);
00261 
00262    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.llx");
00263    cfg -> llx = cpl_parameter_get_int(p);
00264 
00265    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.lly");
00266    cfg -> lly = cpl_parameter_get_int(p);
00267 
00268    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.urx");
00269    cfg -> urx = cpl_parameter_get_int(p);
00270 
00271    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.ury");
00272    cfg -> ury = cpl_parameter_get_int(p);
00273 
00274 }
00275 
00283 static void     
00284 parse_section_thresh(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
00285 {
00286    cpl_parameter *p;     
00287 
00288    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.threshold_index");
00289    cfg -> threshInd  = cpl_parameter_get_bool(p);
00290 
00291    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.mean_factor");
00292    cfg -> meanfactor = cpl_parameter_get_double(p);
00293 
00294 
00295    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.min_cut");
00296    cfg -> mincut = cpl_parameter_get_double(p);
00297 
00298    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.max_cut");
00299    cfg -> maxcut = cpl_parameter_get_double(p);
00300 
00301 }

Generated on 8 Mar 2011 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1