sinfo_detlin_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_detlin_ini_by_cpl.c
00022    Author       :   Andrea Modigliani
00023    Created on   :    May 17, 2004
00024    Description  :    produce and read an .ini file for the search of static
00025                         bad pixels
00026  ---------------------------------------------------------------------------*/
00027 #ifdef HAVE_CONFIG_H
00028 #  include <config.h>
00029 #endif
00030 /*---------------------------------------------------------------------------
00031                                 Includes
00032  ---------------------------------------------------------------------------*/
00033 #include <string.h>
00034 #include "sinfo_detlin_ini_by_cpl.h"
00035 #include "sinfo_error.h"
00036 #include "sinfo_hidden.h"
00037 #include "sinfo_raw_types.h"
00038 #include "sinfo_functions.h"
00039 #include "sinfo_file_handling.h"
00040 /*---------------------------------------------------------------------------
00041                     Functions private to this module
00042  ---------------------------------------------------------------------------*/
00043 static void     
00044 parse_section_frames(detlin_config *, 
00045                 cpl_frameset* sof, cpl_frameset** raw,int* status);
00046 static void     
00047 parse_section_response(detlin_config *, cpl_parameterlist* cpl_cfg);
00048 
00068 detlin_config * 
00069 sinfo_parse_cpl_input_detlin(cpl_parameterlist * cpl_cfg, cpl_frameset* sof, 
00070  cpl_frameset** raw)
00071 {
00072 
00073         detlin_config    *    cfg ;
00074         int                   status ;
00075 
00076         /* check on input ini file removed */
00077         /* loading input ini file removed */
00078 
00079 
00080         cfg = sinfo_detlin_cfg_create();
00081 
00082         /*
00083          * Perform sanity checks, fill up the structure with what was
00084          * found in the ini file
00085          */
00086 
00087         status = 0 ;
00088         parse_section_response(cfg, cpl_cfg);
00089         parse_section_frames(cfg, sof, raw,  &status);
00090         if (status > 0) {
00091                 sinfo_msg_error("parsing cpl input");
00092                 sinfo_detlin_free(&cfg);
00093                 cfg = NULL ;
00094                 return NULL ;
00095         }
00096         return cfg ;
00097 }
00098 
00110 static void   
00111 parse_section_frames(detlin_config * cfg,
00112              cpl_frameset * sof,
00113                      cpl_frameset** raw,
00114                      int* status)
00115 {
00116 
00117    int                     i=0;
00118    char* tag=NULL;
00119    int  nraw = 0;
00120    int  nraw_good = 0;
00121    cpl_frame* frame=NULL;
00122    char spat_res[FILE_NAME_SZ];
00123    char lamp_status[FILE_NAME_SZ];
00124    char band[FILE_NAME_SZ];
00125    int ins_set=0;
00126   
00127    sinfo_extract_raw_frames_type(sof,raw,RAW_LINEARITY_LAMP);
00128 
00129    nraw=cpl_frameset_get_size(*raw);
00130  
00131    if (nraw < 1) {
00132       sinfo_msg_error( "Too few (%d) raw frames (%s)  present in"
00133              "frameset!Aborting...",nraw, RAW_LINEARITY_LAMP);
00134       (*status)++;
00135       return;
00136    }
00137 
00138 
00139 
00140    /* get "general:infile" read it, check input sinfo_matrix */
00141    /* Allocate structures to go into the blackboard */
00142    cfg->framelist = cpl_malloc(nraw * sizeof(char*)); 
00143    
00144   /* read input frames */
00145    for (i=0 ; i<nraw ; i++) {
00146      /* cfg->framelist[i] = cpl_malloc(FILE_NAME_SZ * sizeof(char));  */
00147       frame = cpl_frameset_get_frame(*raw,i);
00148      if(sinfo_file_exists((char*)cpl_frame_get_filename(frame))==1) 
00149     {
00150           tag = (char*)cpl_frame_get_tag(frame) ;
00151       if(sinfo_is_flat_lindet(tag) || sinfo_is_dark(tag)) {
00152           /* Store file name into framelist */
00153              cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
00154              nraw_good++;
00155       }
00156     }
00157    }
00158 
00159    /* Copy relevant information into the blackboard */
00160    cfg->nframes         = nraw_good ;
00161 
00162 
00163    if (nraw_good < (cfg->order+1)) {
00164       sinfo_msg_error( "Too few (%d) raw frames (%s)  present in"
00165              "frameset as we do a %d order polymnomial fit" 
00166                          "!Aborting...",nraw_good, 
00167                          RAW_LINEARITY_LAMP,cfg->order);
00168 
00169       (*status)++;
00170       return;
00171    }
00172 
00173 
00174    strcpy(cfg -> outName, BP_LIN_OUT_FILENAME);
00175 
00176    check_nomsg(frame = cpl_frameset_get_frame(*raw,0));
00177    sinfo_get_spatial_res(frame,spat_res);
00178  
00179    switch(sinfo_frame_is_on(frame)) 
00180      {
00181    case 0: 
00182       strcpy(lamp_status,"on");
00183       break;
00184     case 1: 
00185       strcpy(lamp_status,"off");
00186       break;
00187     case -1:
00188       strcpy(lamp_status,"undefined");
00189       break;
00190     default: 
00191       strcpy(lamp_status,"undefined");
00192       break;
00193 
00194 
00195      }
00196 
00197    sinfo_get_band(frame,band);
00198    sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
00199                      spat_res,              lamp_status,    band);
00200 
00201 
00202    sinfo_get_ins_set(band,&ins_set);
00203 
00204   
00205   cleanup:
00206 
00207    return;
00208 }
00217 static void     
00218 parse_section_response(detlin_config * cfg,cpl_parameterlist *   cpl_cfg)
00219 {
00220    cpl_parameter *p;     
00221 
00222    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.order");
00223    cfg -> order = cpl_parameter_get_int(p);
00224  
00225    p = cpl_parameterlist_find(cpl_cfg,"sinfoni.bp_lin.thresh_sigma_factor");
00226    cfg->threshSigmaFactor = (float) cpl_parameter_get_double(p);
00227 
00228    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.low_rejection");
00229    cfg -> loReject = (float) cpl_parameter_get_double(p);
00230 
00231    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.high_rejection");
00232    cfg -> hiReject = (float) cpl_parameter_get_double(p);
00233 
00234    p = cpl_parameterlist_find(cpl_cfg,"sinfoni.bp_lin.nlin_threshold");
00235    cfg->nonlinearThresh = (float) cpl_parameter_get_double(p);
00236 
00237    /* name of the data cube storing the found polynomial coefficients */
00238    strcpy(cfg->coeffsCubeName, BP_LIN_COEFFS_CUBE_OUT_FILENAME);
00239 
00240    return ;
00241 }
00248 void
00249 sinfo_detlin_free(detlin_config ** cfg)
00250 {  
00251   int i=0;
00252   if(*cfg!=NULL) {
00253     for(i=0;i<(*cfg)->nframes; i++) {
00254       if((*cfg)->framelist[i] != NULL) cpl_free((*cfg)->framelist[i]);
00255     }
00256     cpl_free((*cfg)->framelist);
00257     sinfo_detlin_cfg_destroy((*cfg));
00258     *cfg = NULL;
00259   }
00260   return;
00261 
00262 }

Generated on 3 Mar 2013 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1