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 "sinfo_baddist_ini_by_cpl.h"
00034 #include "sinfo_hidden.h"
00035 #include "sinfo_pro_types.h"
00036 #include "sinfo_raw_types.h"
00037 #include "sinfo_globals.h"
00038 #include "sinfo_functions.h"
00039 #include "sinfo_file_handling.h"
00040 
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 
00071 bad_config * 
00072 sinfo_parse_cpl_input_baddist(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         /* Removed check on ini_file */
00080         /* Removed load of ini file */
00081 
00082   cfg = sinfo_bad_cfg_create();
00083 
00084         /*
00085          * Perform sanity checks, fill up the structure with what was
00086          * found in the ini file
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 
00113 static void     
00114 parse_section_frames(bad_config   * cfg,
00115                      cpl_frameset * sof,
00116                      const char    * procatg,          
00117                      cpl_frameset ** raw,
00118                      int* status)
00119 {
00120    int                i=0;
00121    int                nraw = 0;
00122    char *          tag=NULL;
00123 
00124    int  nraw_good = 0;
00125    cpl_frame* frame=NULL;
00126    char spat_res[FILE_NAME_SZ];
00127    char lamp_status[FILE_NAME_SZ];
00128    char band[FILE_NAME_SZ];
00129    int ins_set=0;
00130 
00131 
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 
00164    nraw=cpl_frameset_get_size(*raw);
00165    if (nraw < 1) {
00166       sinfo_msg_error("Too few (%d) raw frames (%s or %s) present in"
00167              "frameset!Aborting...",nraw,
00168                          RAW_FLAT_LAMP,RAW_FLAT_NS);
00169       (*status)++;
00170       return;
00171    }
00172         
00173    /* Removed: get "general:infile" read it, check input sinfo_matrix */
00174    /* Allocate structures to go into the blackboard */
00175    cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
00176 
00177    /* read input frames */
00178    for (i=0 ; i<nraw ; i++) {
00179       frame = cpl_frameset_get_frame(*raw,i);
00180       tag = (char*)cpl_frame_get_tag(frame) ;
00181       if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) 
00182     {
00183              /* Store file name into framelist */
00184              cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00185              nraw_good++;
00186     }
00187    }
00188    if(nraw_good<1) {
00189      sinfo_msg_error("Error: no good raw frame in input, something wrong!");
00190      (*status)++;
00191      return;
00192    }
00193 
00194    /* Copy relevant information into the blackboard */
00195    cfg->nframes         = nraw_good ;
00196 
00197    /* Output */
00198    strcpy(cfg -> outName, BP_DIST_OUT_FILENAME);
00199  
00200 
00201 
00202 
00203    frame = cpl_frameset_get_frame(*raw,0);
00204    sinfo_get_spatial_res(frame,spat_res);
00205  
00206     switch(sinfo_frame_is_on(frame)) 
00207      {
00208    case 0: 
00209       strcpy(lamp_status,"on");
00210       break;
00211     case 1: 
00212       strcpy(lamp_status,"off");
00213       break;
00214     case -1:
00215       strcpy(lamp_status,"undefined");
00216       break;
00217     default: 
00218       strcpy(lamp_status,"undefined");
00219       break;
00220      }
00221 
00222     sinfo_get_band(frame,band);
00223    sinfo_msg("stat_res: %s lamp_status: %s band: %s \n",
00224                      spat_res,    lamp_status,    band);
00225    sinfo_get_ins_set(band,&ins_set);
00226 
00227    return;
00228 
00229 }
00230 
00238 static void     
00239 parse_section_badpix(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
00240 {
00241    cpl_parameter *p;     
00242 
00243    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.sigma_factor");
00244    cfg -> sigmaFactor = cpl_parameter_get_double(p);
00245 
00246    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.method_index");
00247    cfg -> methodInd = cpl_parameter_get_int(p);
00248 
00249    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.factor");
00250    cfg -> factor = cpl_parameter_get_double(p);
00251 
00252    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.iterations");
00253    cfg -> iterations = cpl_parameter_get_int(p);
00254 
00255    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.low_rejection");
00256    cfg -> loReject = cpl_parameter_get_double(p);
00257 
00258    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.high_rejection");
00259    cfg -> hiReject = cpl_parameter_get_double(p);
00260 
00261    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.llx");
00262    cfg -> llx = cpl_parameter_get_int(p);
00263 
00264    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.lly");
00265    cfg -> lly = cpl_parameter_get_int(p);
00266 
00267    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.urx");
00268    cfg -> urx = cpl_parameter_get_int(p);
00269 
00270    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.ury");
00271    cfg -> ury = cpl_parameter_get_int(p);
00272 
00273 }
00274 
00282 static void     
00283 parse_section_thresh(bad_config    * cfg, cpl_parameterlist *   cpl_cfg)
00284 {
00285    cpl_parameter *p;     
00286 
00287    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.threshold_index");
00288    cfg -> threshInd  = cpl_parameter_get_bool(p);
00289 
00290    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.mean_factor");
00291    cfg -> meanfactor = cpl_parameter_get_double(p);
00292 
00293 
00294    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.min_cut");
00295    cfg -> mincut = cpl_parameter_get_double(p);
00296 
00297    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_dist.max_cut");
00298    cfg -> maxcut = cpl_parameter_get_double(p);
00299 
00300 }

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