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

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