sinfo_ns_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_ns_ini_by_cpl.c
00023    Author       :   Andrea Modigliani
00024    Created on   :   May 19, 2003
00025    Description  :   cpl input handling for the north-south test
00026 
00027  ---------------------------------------------------------------------------*/
00028 
00029 #ifdef HAVE_CONFIG_H
00030 #  include <config.h>
00031 #endif
00032 
00033 
00034 /*---------------------------------------------------------------------------
00035                                 Includes
00036  ---------------------------------------------------------------------------*/
00037 
00038 #include <string.h>
00039 #include "sinfo_ns_ini_by_cpl.h"
00040 #include "sinfo_pro_types.h"
00041 #include "sinfo_hidden.h"
00042 #include "sinfo_functions.h"
00043 #include "sinfo_file_handling.h"
00044 
00045 /*---------------------------------------------------------------------------
00046                     Functions private to this module
00047  ---------------------------------------------------------------------------*/
00048 void sinfo_ns_free_alloc(ns_config * cfg);
00049 static void     
00050 parse_section_frames (ns_config *,cpl_parameterlist* cpl_cfg,cpl_frameset* sof,
00051                      cpl_frameset** raw, int* status);
00052 static void     
00053 parse_section_cleanmean (ns_config *,cpl_parameterlist* cpl_cfg);
00054 static void     
00055 parse_section_gaussconvolution (ns_config *,cpl_parameterlist* cpl_cfg);
00056 static void     
00057 parse_section_northsouthtest(ns_config *,cpl_parameterlist* cpl_cfg);
00058 
00059 
00069 /* removed generateNS_ini_file */
00070 
00071 /*-------------------------------------------------------------------------*/
00082 /*--------------------------------------------------------------------------*/
00083 
00084 ns_config * 
00085 sinfo_parse_cpl_input_ns(cpl_parameterlist * cpl_cfg, cpl_frameset* sof, 
00086                    cpl_frameset** raw)
00087 {
00088         ns_config   *         cfg = sinfo_ns_cfg_create();
00089         int status=0;
00090         /*
00091          * Perform sanity checks, fill up the structure with what was
00092          * found in the ini file
00093          */
00094 
00095         parse_section_cleanmean        (cfg,cpl_cfg);
00096         parse_section_gaussconvolution (cfg,cpl_cfg);
00097         parse_section_northsouthtest   (cfg,cpl_cfg);
00098         parse_section_frames           (cfg,cpl_cfg,sof,raw,&status);
00099 
00100         if (status > 0) {
00101                 sinfo_msg_error("parsing cpl input");
00102                 sinfo_ns_cfg_destroy(cfg);
00103                 cfg = NULL ;
00104                 return NULL ;
00105         }
00106         return cfg ;
00107 }
00108 
00109 
00110 
00111 
00112 static void     
00113 parse_section_frames(ns_config * cfg,
00114              cpl_parameterlist * cpl_cfg,
00115              cpl_frameset * sof,
00116              cpl_frameset ** raw,
00117                      int* status)
00118 {
00119    int                     i;
00120    int                     nobj ;
00121    int                     noff ;
00122     int nraw=0;
00123    char* tag;
00124    cpl_frame* frame   = NULL;
00125    cpl_parameter *p;   
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    nstpar* nstp=sinfo_nstpar_new();
00131   
00132    sinfo_extract_raw_frames_type(sof,raw,PRO_FIBRE_NS_STACKED_DIST);
00133   
00134    nraw    = cpl_frameset_get_size(*raw);
00135 
00136     if(nraw == 0) {
00137      sinfo_msg_error("No input raw frames");
00138      sinfo_nstpar_delete(nstp);
00139      (*status)++;
00140      return;
00141    }
00142 
00143    /* Allocate structures to go into the blackboard */
00144    cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
00145    cfg->frametype     = cpl_malloc(nraw * sizeof(int));
00146 
00147 
00148     
00149    /* Browse through the charmatrix to get names and file types */
00150    i=0 ;
00151    nobj = 0 ;
00152    noff = 0 ;
00153    
00154    for (i=0 ; i<nraw ; i++) {
00155       frame = cpl_frameset_get_frame(*raw,i);
00156       if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1) 
00157     {
00158       /* to go on the file must exist */
00159        tag=(char*) cpl_frame_get_tag(frame);
00160       if(cpl_frame_get_tag(frame) != NULL) {
00161         /* If the frame has a tag we process it. Else it is an object */ 
00162             if((sinfo_frame_is_on(frame)  == 0)) 
00163           {
00164             cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00165             cfg->frametype[i] = FRAME_OFF ;
00166             noff++;
00167           }
00168             else if(sinfo_is_sky_flat(tag))
00169           {
00170             cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00171             cfg->frametype[i] = FRAME_OFF ;
00172             noff++;
00173           }
00174             else if((sinfo_frame_is_on(frame)  == 1)) 
00175           {
00176             cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00177             cfg->frametype[i] = FRAME_ON ;
00178             nobj++;
00179           }
00180             else  
00181               {
00182           /* without label the frame is assumed on */
00183           cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00184           cfg->frametype[i] = FRAME_ON ;
00185           nobj++;
00186         }
00187       }
00188         else 
00189       {
00190         /* without label the frame is assumed on */
00191           cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00192           cfg->frametype[i] = FRAME_ON ;
00193           nobj++;
00194       }
00195        /* Store file name into framelist */
00196     }
00197       else {
00198       sinfo_msg_warning("file %s does not exist",
00199           cpl_frame_get_filename(frame));
00200     }
00201         
00202     }
00203 
00204 
00205    if((noff == 0) && (nobj == 0)) {
00206      sinfo_msg_error("Wrong input frames");
00207      sinfo_nstpar_delete(nstp);
00208      sinfo_ns_free_alloc(cfg);
00209      (*status)++;
00210      return;
00211    }
00212    /* Copy relevant information into the blackboard */
00213    cfg->nframes         = nraw ;
00214    cfg->nobj            = nobj ;
00215    cfg->noff            = noff ;
00216 
00217    strcpy(cfg -> outName, NS_TEST_DISTANCES_OUT_FILENAME);
00218 
00219 
00220    frame = cpl_frameset_get_frame(*raw,0);
00221    sinfo_get_spatial_res(frame,spat_res);
00222  
00223    switch(sinfo_frame_is_on(frame)) 
00224      {
00225    case 0: 
00226       strcpy(lamp_status,"on");
00227       break;
00228     case 1: 
00229       strcpy(lamp_status,"off");
00230       break;
00231     case -1:
00232       strcpy(lamp_status,"undefined");
00233       break;
00234     default: 
00235       strcpy(lamp_status,"undefined");
00236       break;
00237 
00238 
00239      }
00240 
00241    sinfo_get_band(frame,band);
00242    sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
00243                      spat_res,    lamp_status,    band);
00244 
00245 
00246    sinfo_get_ins_set(band,&ins_set);
00247 
00248 
00249    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.fwhm");
00250    if(cpl_parameter_get_double(p) != cpl_parameter_get_default_double(p)) {
00251      cfg -> fwhm = cpl_parameter_get_double(p);
00252    } else {
00253      cfg -> fwhm = nstp->fwhm[ins_set];
00254    }
00255 
00256    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.min_diff");
00257    if(cpl_parameter_get_double(p) != cpl_parameter_get_default_double(p)) {
00258      cfg -> minDiff = cpl_parameter_get_double(p);
00259    } else {
00260      cfg -> minDiff = nstp->min_dif[ins_set];
00261    }
00262     sinfo_nstpar_delete(nstp);
00263 
00264 
00265    if(cfg -> maskInd) {
00266       if(NULL != cpl_frameset_find(sof,PRO_BP_MAP_DI)) {
00267          frame = cpl_frameset_find(sof,PRO_BP_MAP_DI);
00268          strcpy(cfg -> mask,cpl_frame_get_filename(frame));
00269       } else {
00270          sinfo_msg_error("Frame %s not found! Exit!", PRO_BP_MAP_DI);
00271          sinfo_ns_free_alloc(cfg);
00272          (*status)++;
00273          return;
00274       }
00275    }
00276 
00277  
00278      return ;
00279 }
00280 
00281 static void     
00282 parse_section_cleanmean(ns_config * cfg,cpl_parameterlist * cpl_cfg)
00283 {
00284 
00285    cpl_parameter *p;                  
00286    p = cpl_parameterlist_find(cpl_cfg, 
00287                              "sinfoni.north_south_test.low_rejection");
00288    cfg -> loReject = cpl_parameter_get_double(p);
00289 
00290    p = cpl_parameterlist_find(cpl_cfg, 
00291                               "sinfoni.north_south_test.high_rejection");
00292    cfg -> hiReject = cpl_parameter_get_double(p);
00293 
00294    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.mask_ind");
00295    cfg -> maskInd = cpl_parameter_get_bool(p);
00296 
00297    return ;
00298 }
00299 
00300 static void     
00301 parse_section_gaussconvolution(ns_config * cfg,cpl_parameterlist * cpl_cfg)
00302 {
00303    cpl_parameter *p;     
00304    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.gauss_ind");
00305    cfg -> gaussInd = cpl_parameter_get_bool(p);
00306 
00307    p = cpl_parameterlist_find(cpl_cfg, 
00308                               "sinfoni.north_south_test.kernel_half_width");
00309    cfg -> hw = cpl_parameter_get_int(p);
00310 
00311 }
00312 
00313 static void     
00314 parse_section_northsouthtest(ns_config  * cfg,cpl_parameterlist * cpl_cfg)
00315 {
00316 
00317    cpl_parameter *p;     
00318    strcat(cfg -> fitsname, NS_TEST_OUT_FILENAME);
00319    cfg -> nslits = NSLITLETS;
00320 
00321    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.half_width");
00322    cfg -> halfWidth = cpl_parameter_get_int(p);
00323 
00324    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.fwhm");
00325    cfg -> fwhm = cpl_parameter_get_double(p);
00326 
00327    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.min_diff");
00328    cfg -> minDiff = cpl_parameter_get_double(p);
00329 
00330    cfg -> estimated_dist = ESTIMATED_SLITLETS_DISTANCE;
00331 
00332    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.dev_tol");
00333    cfg -> devtol = cpl_parameter_get_double(p);
00334 
00335    return ;
00336 }
00337 
00338 void
00339 sinfo_ns_free(ns_config ** cfg)
00340 {  
00341   if(*cfg!=NULL) { 
00342     sinfo_ns_free_alloc(*cfg);
00343     sinfo_ns_cfg_destroy(*cfg);
00344     *cfg=NULL;
00345   } 
00346   return;
00347 
00348 }
00349 void
00350 sinfo_ns_free_alloc(ns_config * cfg)
00351 {
00352     if(cfg->framelist != NULL) {
00353       cpl_free(cfg->framelist);
00354       cfg->framelist=NULL;
00355     }
00356     if(cfg->frametype != NULL) {
00357       cpl_free(cfg->frametype);
00358       cfg->frametype=NULL;
00359     }
00360   
00361   return;
00362 
00363 }

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