sinfo_badsky_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    
00022    File name    :   sinfo_badsky_ini_by_cpl.c
00023    Author       :   Andrea Modigliani
00024    Created on   :   Jun 16, 2004
00025    Description  :   parse cpl input for the search of static bad pixels
00026 
00027  ---------------------------------------------------------------------------*/
00028 
00029 #ifdef HAVE_CONFIG_H
00030 #  include <config.h>
00031 #endif
00032 
00033 /*---------------------------------------------------------------------------
00034                                 Includes
00035  ---------------------------------------------------------------------------*/
00036 #include <string.h>
00037 #include "sinfo_badsky_ini_by_cpl.h"
00038 #include "sinfo_raw_types.h"
00039 #include "sinfo_pro_types.h"
00040 #include "sinfo_hidden.h"
00041 #include "sinfo_globals.h"
00042 #include "sinfo_functions.h"
00043 #include "sinfo_file_handling.h"
00044 /*---------------------------------------------------------------------------
00045                     Functions private to this module
00046  ---------------------------------------------------------------------------*/
00047 
00048 static void  
00049 parse_section_frames(badsky_config * cfg, cpl_parameterlist* cpl_cfg, 
00050 cpl_frameset* sof, cpl_frameset** raw, int* status);
00051 static void 
00052 parse_section_badpix(badsky_config * cfg, cpl_parameterlist* cpl_cfg);
00053 static void 
00054 parse_section_thresh(badsky_config * cfg, cpl_parameterlist* cpl_cfg);
00060 /*---------------------------------------------------------------------------
00061                               Function codes
00062  ---------------------------------------------------------------------------*/
00074 badsky_config * 
00075 sinfo_parse_cpl_input_badsky(cpl_parameterlist * cpl_cfg, 
00076                                      cpl_frameset* sof,
00077                                      cpl_frameset** raw) 
00078 {
00079   badsky_config    *       cfg ;
00080   int status = 0;
00081 
00082   cfg = sinfo_badsky_cfg_create();
00083   parse_section_badpix   (cfg, cpl_cfg);
00084   parse_section_thresh   (cfg, cpl_cfg);
00085   parse_section_frames   (cfg, cpl_cfg, sof, raw,&status);
00086   if(status>0) {
00087     sinfo_msg_error("parsing cpl input");
00088     sinfo_badsky_cfg_destroy(cfg);
00089     cfg = NULL ;
00090     return NULL ;
00091   }
00092   return cfg ;
00093 
00094 }
00095 
00107 static void     
00108 parse_section_frames(badsky_config   * cfg,
00109                      cpl_parameterlist  * cpl_cfg,
00110                      cpl_frameset * sof,          
00111                      cpl_frameset ** raw,
00112                      int* status)
00113 {
00114    int                i=0;
00115    int                nraw = 0;
00116    char *          tag=NULL;
00117 
00118    int  nraw_good = 0;
00119    cpl_frame* frame=NULL;
00120    cpl_parameter *p;     
00121    char spat_res[FILE_NAME_SZ];
00122    char lamp_status[FILE_NAME_SZ];
00123    char band[FILE_NAME_SZ];
00124    int ins_set=0;
00125 
00126    *raw=cpl_frameset_new();
00127 
00128 
00129    sinfo_contains_frames_type(sof,raw,RAW_SKY);
00130    nraw=cpl_frameset_get_size(*raw);
00131    if (nraw < 1) {
00132       sinfo_msg_error("Too few (%d) raw frames %s  present in"
00133              "frameset!Aborting...",nraw,RAW_SKY);
00134       (*status)++;
00135       return;
00136    }
00137         
00138    /* Removed: get "general:infile" read it, check input sinfo_matrix */
00139    /* Allocate structures to go into the blackboard */
00140    cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
00141 
00142    /* read input frames */
00143    for (i=0 ; i<nraw ; i++) {
00144       frame = cpl_frameset_get_frame(*raw,i);
00145       tag = (char*)cpl_frame_get_tag(frame) ;
00146       if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) 
00147     {
00148              /* Store file name into framelist */
00149              cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
00150              nraw_good++;
00151     }
00152    }
00153 
00154    if(nraw_good<1) {
00155      sinfo_msg_error("Error: no good raw frame in input, something wrong!");
00156      (*status)++;
00157      return;
00158    }
00159 
00160 
00161         if(NULL != cpl_frameset_find(sof,PRO_MASTER_DARK)) {
00162             frame = cpl_frameset_find(sof,PRO_MASTER_DARK);
00163             strcpy(cfg -> sinfo_dark, 
00164            cpl_strdup(cpl_frame_get_filename(frame)));
00165          } else {
00166             sinfo_msg_warning("Frame %s not found!", PRO_MASTER_DARK);
00167          }
00168 
00169    /* Copy relevant information into the blackboard */
00170    cfg->nframes         = nraw_good ;
00171 
00172    /* Output */
00173    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.out_filename");
00174    strcpy(cfg -> outName, cpl_parameter_get_string(p));
00175 
00176    frame = cpl_frameset_get_frame(*raw,0);
00177    sinfo_get_spatial_res(frame,spat_res);
00178  
00179 
00180    switch(sinfo_frame_is_on(frame)) 
00181      {
00182    case 0: 
00183       strcpy(lamp_status,"on");
00184       break;
00185     case 1: 
00186       strcpy(lamp_status,"off");
00187       break;
00188     case -1:
00189       strcpy(lamp_status,"undefined");
00190       break;
00191     default: 
00192       strcpy(lamp_status,"undefined");
00193       break;
00194      }
00195 
00196    sinfo_get_band(frame,band);
00197    sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
00198                      spat_res,              lamp_status,    band);
00199 
00200 
00201    sinfo_get_ins_set(band,&ins_set);
00202    return;
00203 
00204 }
00205 
00214 static void     
00215 parse_section_badpix(badsky_config    * cfg, cpl_parameterlist *   cpl_cfg)
00216 {
00217    cpl_parameter *p;     
00218 
00219    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.sigma_factor");
00220    cfg -> sigmaFactor = cpl_parameter_get_double(p);
00221 
00222    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.method_index");
00223    cfg -> methodInd = cpl_parameter_get_int(p);
00224 
00225    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.factor");
00226    cfg -> factor = cpl_parameter_get_double(p);
00227 
00228    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.iterations");
00229    cfg -> iterations = cpl_parameter_get_int(p);
00230 
00231    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.low_rejection");
00232    cfg -> loReject = cpl_parameter_get_double(p);
00233 
00234    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.high_rejection");
00235    cfg -> hiReject = cpl_parameter_get_double(p);
00236 
00237    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.llx");
00238    cfg -> llx = cpl_parameter_get_int(p);
00239 
00240    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.lly");
00241    cfg -> lly = cpl_parameter_get_int(p);
00242 
00243    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.urx");
00244    cfg -> urx = cpl_parameter_get_int(p);
00245 
00246    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.ury");
00247    cfg -> ury = cpl_parameter_get_int(p);
00248 
00249 }
00250 
00259 static void     
00260 parse_section_thresh(badsky_config    * cfg, cpl_parameterlist *   cpl_cfg)
00261 {
00262    cpl_parameter *p;     
00263 
00264    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.threshold_index");
00265    cfg -> threshInd  = cpl_parameter_get_bool(p);
00266 
00267    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.mean_factor");
00268    cfg -> meanfactor = cpl_parameter_get_double(p);
00269 
00270 
00271    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.min_cut");
00272    cfg -> mincut = cpl_parameter_get_double(p);
00273 
00274    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_sky.max_cut");
00275    cfg -> maxcut = cpl_parameter_get_double(p);
00276 
00277 }
00278 
00286 void
00287 sinfo_badsky_free(badsky_config * cfg)
00288 {  
00289   cpl_free(cfg->framelist);
00290   sinfo_badsky_cfg_destroy(cfg);
00291  
00292   return;
00293 
00294 }

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