sinfo_focus_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_focus_ini_by_cpl.c
00022    Author       :   Andrea Modigliani
00023    Created on   :   May 20, 2004
00024    Description  :   cpl input handling for SPIFFI
00025  ---------------------------------------------------------------------------*/
00026 #ifdef HAVE_CONFIG_H
00027 #  include <config.h>
00028 #endif
00029 /*---------------------------------------------------------------------------
00030                                 Includes
00031  ---------------------------------------------------------------------------*/
00032 #include "sinfo_focus_ini_by_cpl.h"
00033 #include "sinfo_pro_types.h"
00034 #include "sinfo_functions.h"
00035 #include "sinfo_file_handling.h"
00036 /*---------------------------------------------------------------------------
00037                     Functions private to this module
00038  ---------------------------------------------------------------------------*/
00039 static void 
00040 parse_section_frames(focus_config *, cpl_parameterlist* cpl_cfg, 
00041                    cpl_frameset* sof,cpl_frameset** stk, int* status);
00042 static void 
00043 parse_section_reconstruction(focus_config *, cpl_parameterlist* cpl_cfg);
00044 static void 
00045 parse_section_gauss2dfit(focus_config *, cpl_parameterlist* cpl_cfg);
00046 
00069 focus_config * 
00070 sinfo_parse_cpl_input_focus(cpl_parameterlist * cpl_cfg, cpl_frameset* sof,
00071                      cpl_frameset** stk)
00072 {
00073         focus_config  *       cfg = sinfo_focus_cfg_create();
00074   int status=0;
00075         /*
00076          * Perform sanity checks, fill up the structure with what was
00077          * found in the ini file
00078          */
00079 
00080         parse_section_reconstruction   (cfg, cpl_cfg);
00081         parse_section_gauss2dfit       (cfg, cpl_cfg);
00082         parse_section_frames           (cfg, cpl_cfg,sof,stk,&status);
00083         if (status > 0) {
00084                 sinfo_msg_error("parsing cpl input");
00085                 sinfo_focus_cfg_destroy(cfg);
00086                 cfg = NULL ;
00087                 return NULL ;
00088         }
00089         return cfg ;
00090 }
00091 
00102 static void   
00103 parse_section_frames(focus_config * cfg,
00104                      cpl_parameterlist* cpl_cfg,
00105                      cpl_frameset* sof,
00106                      cpl_frameset** raw, 
00107                      int* status)
00108 {
00109 
00110 
00111    char            *       name ;
00112     int nframes=0;
00113    int nraw=0;
00114    cpl_frame* frame   = NULL;
00115    cpl_parameter *p; 
00116 
00117 
00118    char spat_res[FILE_NAME_SZ];
00119    char lamp_status[FILE_NAME_SZ];
00120    char band[FILE_NAME_SZ];
00121    int ins_set=0;
00122 
00123 
00124    char * tag;
00125    int i=0;
00126    nframes = cpl_frameset_get_size(sof);
00127     /* Get the raw and the calibration files */
00128     /* Labelise the input frames according to their tags */
00129 
00130   *raw=cpl_frameset_new();
00131    sinfo_extract_raw_frames_type(sof,raw,PRO_FOCUS_STACKED);
00132 
00133 
00134    nraw=cpl_frameset_get_size(*raw);
00135    if (nraw < 1) {
00136       sinfo_msg_error("Too few (%d) raw frames (%s) present in"
00137             "frameset!Aborting...",nraw,PRO_FOCUS_STACKED);
00138           (*status)++;
00139           return;
00140    }
00141    /* Allocate structures to go into the blackboard */
00142    cfg->inFrameList     = cpl_malloc(nraw * sizeof(char*));
00143  
00144    /* Browse through the charmatrix to get names and file types */
00145    for (i=0 ; i<nraw ; i++) {
00146       frame = cpl_frameset_get_frame(*raw,i);
00147       name= (char*) cpl_frame_get_filename(frame);
00148       if(sinfo_file_exists(name)==1) {
00149     /* to go on the file must exist */
00150     if(cpl_frame_get_tag(frame) != NULL) {
00151       /* If the frame has a tag we process it. Else it is an object */ 
00152       tag= (char*) cpl_frame_get_tag(frame);
00153           if(sinfo_is_stack(tag)) 
00154         {
00155              cfg->inFrameList[i]=cpl_strdup(cpl_frame_get_filename(frame));
00156         }
00157           else {
00158             sinfo_msg_error("No good frame tag %s in input frame set",tag);
00159         (*status)++;
00160             return;
00161       }
00162     }
00163       }
00164       /* Store file name into inFrameList */
00165    }
00166 
00167    /* Copy relevant information into the blackboard */
00168    cfg->nframes = nraw ;
00169 
00170 
00171    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.output_filename");
00172    strcpy(cfg -> outName, cpl_parameter_get_string(p));
00173 
00174    if(NULL != cpl_frameset_find(sof,PRO_FIRST_COL)) {
00175       frame = cpl_frameset_find(sof,PRO_FIRST_COL);
00176       strcpy(cfg -> firstCol,cpl_strdup(cpl_frame_get_filename(frame)));
00177    } else {
00178       sinfo_msg_error("Frame %s not found! Exit!", PRO_FIRST_COL);
00179         (*status)++;
00180       return;
00181    }
00182 
00183    if(NULL != cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE)) {
00184       frame = cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE);
00185       strcpy(cfg -> poslist,cpl_strdup(cpl_frame_get_filename(frame)));
00186    } else {
00187       sinfo_msg_error("Frame %s not found! Exit!", PRO_SLITLETS_DISTANCE);
00188         (*status)++;
00189       return;
00190    }
00191 
00192 
00193 
00194    frame = cpl_frameset_get_frame(*raw,0);
00195    sinfo_get_spatial_res(frame,spat_res);
00196  
00197    switch(sinfo_frame_is_on(frame)) 
00198      {
00199    case 0: 
00200       strcpy(lamp_status,"on");
00201       break;
00202     case 1: 
00203       strcpy(lamp_status,"off");
00204       break;
00205     case -1:
00206       strcpy(lamp_status,"undefined");
00207       break;
00208     default: 
00209       strcpy(lamp_status,"undefined");
00210       break;
00211      }
00212 
00213    sinfo_get_band(frame,band);
00214    sinfo_msg("stat_res: %s lamp_status: %s band: %s \n",
00215                      spat_res,    lamp_status,    band);
00216 
00217 
00218    sinfo_get_ins_set(band,&ins_set);
00219    return;
00220 }
00221 
00229 static void     
00230 parse_section_reconstruction(focus_config * cfg,cpl_parameterlist * cpl_cfg)
00231 {
00232 
00233 
00234   cpl_parameter* p;
00235 
00236    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.lower_rejection");
00237    cfg -> lo_reject = cpl_parameter_get_double(p);
00238 
00239    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.higher_rejection");
00240    cfg -> hi_reject =  cpl_parameter_get_double(p);
00241 
00242    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.north_south_index");
00243    cfg -> northsouthInd = cpl_parameter_get_bool(p);
00244 
00245    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.nslits");
00246    cfg -> nslits = cpl_parameter_get_int(p);
00247  
00248    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.method");
00249    strcpy(cfg->method, cpl_parameter_get_string(p));
00250 
00251    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.order");
00252    cfg -> order= cpl_parameter_get_int(p);
00253 
00254 }
00255 
00263 static void     
00264 parse_section_gauss2dfit(focus_config * cfg,cpl_parameterlist * cpl_cfg)
00265 {
00266  cpl_parameter* p;
00267    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.llx");
00268    cfg -> llx = cpl_parameter_get_int(p);
00269 
00270    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.lly");
00271    cfg -> lly = cpl_parameter_get_int(p);
00272 
00273    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.halfbox_x");
00274    cfg -> halfbox_x =  cpl_parameter_get_int(p);
00275 
00276    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.halfbox_y");
00277    cfg -> halfbox_y = cpl_parameter_get_int(p);
00278 
00279    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar0");
00280    cfg -> mpar0 = cpl_parameter_get_int(p);
00281 
00282    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar1");
00283    cfg -> mpar1 = cpl_parameter_get_int(p);
00284 
00285    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar2");
00286    cfg -> mpar2 = cpl_parameter_get_int(p);
00287 
00288    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar3");
00289    cfg -> mpar3 = cpl_parameter_get_int(p);
00290 
00291    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar4");
00292    cfg -> mpar4 = cpl_parameter_get_int(p);
00293 
00294    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar5");
00295    cfg -> mpar5 = cpl_parameter_get_int(p);
00296 
00297    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar6");
00298    cfg -> mpar6 = cpl_parameter_get_int(p);
00299 
00300    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.fit_list");
00301    strcpy(cfg -> fitlist, cpl_parameter_get_string(p));
00302 
00303    /* int or string ?*/
00304    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.plot_gauss_ind");
00305    cfg -> plotGaussInd = cpl_parameter_get_bool(p);
00306 
00307    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.gauss_plot_name");
00308    strcpy( cfg -> gaussplotName, cpl_parameter_get_string(p));
00309 
00310    return ;
00311 }
00318 void
00319 sinfo_free_focus(focus_config * cfg) {
00320    cpl_free(cfg->inFrameList);
00321    sinfo_focus_cfg_destroy (cfg);
00322   
00323    return;
00324 }

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