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

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