sinfo_wavecal_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_wavecal_ini_by_cpl.c
00022    Author       :   Andrea Modigliani
00023    Created on   :   May 21, 2004
00024    Description  :   wavelength calibration cpl input handling for SPIFFI
00025 
00026  ---------------------------------------------------------------------------*/
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #  include <config.h>
00030 #endif
00031 
00032 
00033 /*---------------------------------------------------------------------------
00034                                 Includes
00035  ---------------------------------------------------------------------------*/
00036 
00037 #include "sinfo_wavecal_ini_by_cpl.h"
00038 #include "sinfo_raw_types.h"
00039 #include "sinfo_pro_types.h"
00040 #include "sinfo_ref_types.h"
00041 #include "sinfo_hidden.h"
00042 #include "sinfo_functions.h"
00043 
00044 /*---------------------------------------------------------------------------
00045                     Functions private to this module
00046  ---------------------------------------------------------------------------*/
00047 
00048 static void    
00049 parse_section_frames(wave_config *, cpl_frameset* sof, 
00050                      cpl_frameset** raw, int* status);
00051 
00052 static void     
00053 parse_section_findlines  (wave_config *, cpl_parameterlist* cpl_cfg);
00054 static void     
00055 parse_section_wavecalib  (wave_config *, cpl_parameterlist* cpl_cfg);
00056 static void     
00057 parse_section_wavemap    (wave_config *, cpl_parameterlist* cpl_cfg);
00058 static void     
00059 parse_section_qclog      (wave_config *, cpl_parameterlist* cpl_cfg);
00060 static void     
00061 parse_section_fitslits   (wave_config *, cpl_parameterlist* cpl_cfg);
00062 
00063 
00072 /*-------------------------------------------------------------------------*/
00090 /*--------------------------------------------------------------------------*/
00091 
00092 /* Removed  generateWave_ini_file */
00093 
00094 /*-------------------------------------------------------------------------*/
00105 /*--------------------------------------------------------------------------*/
00106 
00107 wave_config * 
00108 sinfo_parse_cpl_input_wave(cpl_parameterlist* cpl_cfg, 
00109                            cpl_frameset* sof, cpl_frameset** raw)
00110 {
00111 
00112         int  status=0;
00113         wave_config   * cfg= sinfo_wave_cfg_create();
00114         /*
00115          * Perform sanity checks, fill up the structure with what was
00116          * found in the ini file
00117          */
00118 
00119         parse_section_findlines (cfg, cpl_cfg);
00120         parse_section_wavecalib (cfg, cpl_cfg);
00121         parse_section_wavemap   (cfg, cpl_cfg); 
00122         parse_section_fitslits  (cfg, cpl_cfg); 
00123         parse_section_qclog     (cfg, cpl_cfg); 
00124         parse_section_frames    (cfg, sof, raw, &status);
00125 
00126         if (status > 0) {
00127                 sinfo_msg_error("parsing cpl input");
00128                 sinfo_wave_cfg_destroy(cfg);
00129                 cfg = NULL ;
00130                 return NULL ;
00131         }
00132         return cfg ;
00133 }
00134 
00135 
00136 /*---------------------------------------------------------------------------
00137    Functions:   parse_section_xxx()
00138    In           :       symbolic table read from ini file
00139    Out          :       void
00140    Job          :       update a wave_config structure from what can be
00141                             found in the ini file.
00142    Notice       :       all of these functions update a status integer to
00143                         indicate if an error occurred, or leave it as it is if
00144                         everything went Ok.
00145 
00146         parse_section_general()
00147         parse_section_findlines()
00148         parse_section_wavecalib()
00149         parse_section_wavemap()
00150         parse_section_fitslits()
00151 
00152  ---------------------------------------------------------------------------*/
00153 
00154 
00155 
00156 static void
00157 parse_section_frames(wave_config * cfg,cpl_frameset* sof, 
00158                      cpl_frameset** raw, int* status)
00159 {
00160    cpl_frame* frame   = NULL;
00161    char spat_res[FILE_NAME_SZ];
00162    char lamp_status[FILE_NAME_SZ];
00163    char band[FILE_NAME_SZ];
00164    int ins_set=0;
00165    int nraw=0;
00166    cpl_table* drs_tab=NULL;
00167    wcal* w=sinfo_wcal_new();
00168    int check=0;
00169 
00170    sinfo_extract_raw_frames_type(sof,raw,PRO_WAVE_LAMP_STACKED);
00171    nraw=cpl_frameset_get_size(*raw);
00172    if (nraw==0) {
00173       sinfo_extract_raw_frames_type(sof,raw,PRO_WAVE_NS_STACKED);
00174    }   
00175    nraw=cpl_frameset_get_size(*raw);
00176    if (nraw==0) {
00177       sinfo_extract_raw_frames_type(sof,raw,PRO_WAVE_SLITPOS_STACKED);
00178    }   
00179 
00180    nraw=cpl_frameset_get_size(*raw);
00181    if (nraw==0) {
00182        sinfo_msg("Frame %s or %s or %s not found!", 
00183          PRO_WAVE_LAMP_STACKED,PRO_WAVE_NS_STACKED,PRO_WAVE_SLITPOS_STACKED);
00184        (*status)++;
00185        return   ;
00186    }
00187  
00188    frame = cpl_frameset_get_frame(*raw,0);
00189    sinfo_get_spatial_res(frame,spat_res);
00190  
00191    switch(sinfo_frame_is_on(frame)) 
00192      {
00193    case 0: 
00194       strcpy(lamp_status,"on");
00195       break;
00196     case 1: 
00197       strcpy(lamp_status,"off");
00198       break;
00199     case -1:
00200       strcpy(lamp_status,"undefined");
00201       break;
00202     default: 
00203       strcpy(lamp_status,"undefined");
00204       break;
00205 
00206 
00207      }
00208 
00209    sinfo_get_band(frame,band);
00210    sinfo_msg("spatial resolution: %s lamp status: %s band: %s \n",
00211                      spat_res,              lamp_status,    band);
00212 
00213 
00214    sinfo_get_ins_set(band,&ins_set);
00215    if(NULL != cpl_frameset_find(sof,PRO_WAVE_LAMP_STACKED)) {
00216     frame = cpl_frameset_find(sof,PRO_WAVE_LAMP_STACKED);
00217         strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
00218    } else if(NULL != cpl_frameset_find(sof,PRO_WAVE_NS_STACKED)) {
00219     frame = cpl_frameset_find(sof,PRO_WAVE_NS_STACKED);
00220         strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
00221    } else if(NULL != cpl_frameset_find(sof,PRO_WAVE_SLITPOS_STACKED)) {
00222     frame = cpl_frameset_find(sof,PRO_WAVE_SLITPOS_STACKED);
00223         strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
00224    } else {
00225     sinfo_msg_error("Frame %s or %s not found! Exit!", 
00226                       PRO_WAVE_LAMP_STACKED,PRO_WAVE_NS_STACKED);
00227         (*status)++;
00228         return;
00229    }
00230  
00231 
00232    if(NULL != cpl_frameset_find(sof,DRS_SETUP_WAVE)) {
00233     frame = cpl_frameset_find(sof,DRS_SETUP_WAVE);
00234         strcpy(cfg -> drs_setup,cpl_frame_get_filename(frame));
00235         drs_tab = cpl_table_load(cfg->drs_setup,1,0);
00236         w->wstart=cpl_table_get_double(drs_tab,"W_START",ins_set,&check);
00237         w->wgdisp1=cpl_table_get_double(drs_tab,"W_DISP1",ins_set,&check);
00238         w->wgdisp2=cpl_table_get_double(drs_tab,"W_DISP2",ins_set,&check);
00239         w->hw=cpl_table_get_int(drs_tab,"W_HW",ins_set,&check);
00240         w->fwhm=cpl_table_get_double(drs_tab,"W_FWHM",ins_set,&check);
00241         w->min_amp=cpl_table_get_double(drs_tab,"W_MIN_AMP",ins_set,&check);
00242     /*
00243         w->min_dif=cpl_table_get_double(drs_tab,"W_MIN_DIF",ins_set,&check);
00244         w->na_coef=cpl_table_get_int(drs_tab,"W_NA_COEFF",ins_set,&check);
00245         w->nb_coef=cpl_table_get_int(drs_tab,"W_NB_COEFF",ins_set,&check);
00246         w->pixel_tol=cpl_table_get_double(drs_tab,"W_PIX_TOL",ins_set,&check); 
00247         w->y_box=cpl_table_get_double(drs_tab,"W_Y_BOX",ins_set,&check);
00248         */
00249         w->low_pos=cpl_table_get_int(drs_tab,"W_LOW_POS",ins_set,&check);
00250         w->hig_pos=cpl_table_get_int(drs_tab,"W_HI_POS",ins_set,&check);
00251 
00252     cfg -> guessBeginWavelength = w->wstart;
00253     cfg -> guessDispersion1 =  w->wgdisp1;
00254     cfg -> guessDispersion2 =  w->wgdisp2;
00255     cfg -> halfWidth =         w->hw;
00256     cfg -> fwhm =              w->fwhm;
00257     cfg -> minAmplitude =      w->min_amp;
00258     /*
00259     cfg -> mindiff =           w->min_dif;
00260     cfg -> nrDispCoefficients = w->na_coef;
00261     cfg -> nrCoefCoefficients = w->nb_coef;
00262     cfg -> pixel_tolerance =    w->pixel_tol;
00263     cfg -> yBox =               w->y_box;
00264     */
00265     cfg -> loPos =              w->low_pos;
00266     cfg -> hiPos =              w->hig_pos;
00267     /* cfg -> pixel_tolerance =    w->pixel_tol; */
00268         sinfo_msg("cfg->guessBeginWavelength %g",cfg -> guessBeginWavelength);
00269         sinfo_msg("cfg->guessDispersion1 %g",cfg -> guessDispersion1);
00270         sinfo_msg("cfg->guessDispersion2 %g",cfg -> guessDispersion2);
00271         sinfo_msg("cfg->mindiff %g",cfg -> mindiff);
00272         sinfo_msg("cfg->halfWidth %d",cfg ->  halfWidth);
00273         sinfo_msg("cfg->fwhm %g",cfg -> fwhm);
00274         sinfo_msg("cfg->minAmplitude %g",cfg -> minAmplitude);
00275         sinfo_msg("cfg->nrDispCoefficients %d",cfg -> nrDispCoefficients);
00276         sinfo_msg("cfg->nrCoefCoefficients %d",cfg -> nrCoefCoefficients);
00277         sinfo_msg("cfg->pixel_tolerance  %g",cfg -> pixel_tolerance);
00278         sinfo_msg("cfg->loPos %d",cfg -> loPos);
00279         sinfo_msg("cfg->hiPos %d",cfg -> hiPos);
00280         sinfo_msg("cfg->yBox  %f",cfg -> yBox);
00281 
00282 
00283     sinfo_wcal_delete(w);
00284         cpl_table_delete(drs_tab);
00285         if(-1 == sinfo_check_rec_status(0)) {
00286       (*status)++;
00287       return;
00288     }
00289 
00290    } else {
00291     sinfo_msg_error("Frame %s not found! Exit!", DRS_SETUP_WAVE);
00292         (*status)++;
00293         return;
00294    }
00295 
00296  
00297    if(NULL != cpl_frameset_find(sof,REF_LINE_ARC)) {
00298     frame = cpl_frameset_find(sof,REF_LINE_ARC);
00299         strcpy(cfg -> lineList,cpl_frame_get_filename(frame));
00300    } else {
00301     sinfo_msg_error("Frame %s not found! Exit!", REF_LINE_ARC);
00302         (*status)++;
00303         return;
00304    }
00305 
00306  
00307    if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS_GUESS)) {
00308     frame = cpl_frameset_find(sof,PRO_SLIT_POS_GUESS);
00309         strcpy(cfg -> slitposGuessName,cpl_frame_get_filename(frame));
00310    } else {
00311     sinfo_msg("Frame %s not found!", PRO_SLIT_POS_GUESS);
00312    }
00313  
00314    if(cfg -> writeParInd ==0) {
00315          if(NULL != cpl_frameset_find(sof,PRO_WAVE_PAR_LIST)) {
00316         frame = cpl_frameset_find(sof,PRO_WAVE_PAR_LIST);
00317             strcpy(cfg ->  paramsList,cpl_frame_get_filename(frame));
00318          } else {
00319         sinfo_msg("Frame %s not found!", PRO_WAVE_PAR_LIST);
00320            (*status)++;
00321             return   ;
00322          }
00323 
00324    } else {
00325 
00326          strcpy(cfg -> paramsList, WAVECAL_FIT_PARAMS_OUT_FILENAME);
00327          sinfo_msg("cfg -> paramsList %s not given\n",cfg -> paramsList);
00328 
00329    }
00330 
00331      
00332  
00333    if(cfg -> calibIndicator ==  0) {
00334          if(NULL != cpl_frameset_find(sof,PRO_WAVE_COEF_SLIT)) {
00335        frame = cpl_frameset_find(sof,PRO_WAVE_COEF_SLIT);
00336            strcpy(cfg -> coeffsName,cpl_frame_get_filename(frame));
00337          } else {
00338        sinfo_msg_error("Frame %s not found! Exit!", PRO_WAVE_COEF_SLIT);
00339            (*status)++;
00340            return;
00341          }
00342    } else {
00343 
00344          strcpy(cfg -> coeffsName, WAVECAL_COEFF_SLIT_OUT_FILENAME);
00345          sinfo_msg("cfg -> coeffsName %s not given\n",cfg -> coeffsName);
00346 
00347    }
00348 
00349    strcpy(cfg -> outName, WAVECAL_OUT_FILENAME);
00350    strcpy(cfg -> slitposName, WAVECAL_SLIT_POS_OUT_FILENAME);
00351 
00352    return;
00353 }
00354 
00355 
00356 static void     
00357 parse_section_findlines(wave_config * cfg,cpl_parameterlist* cpl_cfg)
00358 {
00359 
00360    cpl_parameter* p;
00361 
00362    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.calib_indicator");
00363    cfg -> calibIndicator = cpl_parameter_get_bool(p);
00364 
00365    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.min_diff");
00366    cfg -> mindiff =  cpl_parameter_get_double(p);
00367 
00368    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.half_width");
00369    cfg -> halfWidth = cpl_parameter_get_int(p);
00370 
00371    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.sigma");
00372    cfg -> sigma =  cpl_parameter_get_double(p);
00373 
00374    return ;
00375 }
00376 
00377 static void     
00378 parse_section_wavecalib(wave_config * cfg,cpl_parameterlist* cpl_cfg)
00379 {
00380    cpl_parameter* p;
00381 
00382    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.fwhm");
00383    cfg -> fwhm =  cpl_parameter_get_double(p);
00384 
00385    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.min_amplitude");
00386    cfg -> minAmplitude =  cpl_parameter_get_double(p);
00387 
00388    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.max_residual");
00389    cfg -> maxResidual =  cpl_parameter_get_double(p);
00390 
00391    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.n_a_coefficients");
00392    cfg -> nrDispCoefficients = cpl_parameter_get_int(p);
00393 
00394    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.n_b_coefficients");
00395    cfg -> nrCoefCoefficients = cpl_parameter_get_int(p);
00396 
00397    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.sigma_factor");
00398    cfg -> sigmaFactor =  cpl_parameter_get_double(p);
00399 
00400    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.write_coeffs_ind");
00401    cfg -> writeCoeffsInd = cpl_parameter_get_bool(p);
00402 
00403    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.write_par_ind");
00404    cfg -> writeParInd = cpl_parameter_get_bool(p);
00405 
00406    cfg -> nslitlets = NSLITLETS;
00407 
00408    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.pixel_dist");
00409    cfg -> pixeldist = cpl_parameter_get_int(p);
00410 
00411    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.pixel_tol");
00412    cfg -> pixel_tolerance = cpl_parameter_get_double(p);
00413 
00414 }
00415 
00416 static void     
00417 parse_section_wavemap(wave_config * cfg,cpl_parameterlist* cpl_cfg)
00418 {
00419    cpl_parameter* p;
00420 
00421    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.wave_map_ind");
00422    cfg -> wavemapInd = cpl_parameter_get_bool(p);
00423 
00424    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.mag_factor");
00425    cfg -> magFactor = cpl_parameter_get_int(p);
00426 
00427 
00428 }
00429 
00430 static void     
00431 parse_section_fitslits(wave_config * cfg,cpl_parameterlist* cpl_cfg)
00432 {
00433 
00434    cpl_parameter* p;
00435 
00436    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.slit_pos_indicator");
00437    cfg -> slitposIndicator = cpl_parameter_get_bool(p);
00438 
00439    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.fit_boltz_indicator");
00440    cfg -> fitBoltzIndicator = cpl_parameter_get_bool(p);
00441 
00442    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.fit_edge_indicator");
00443    cfg -> fitEdgeIndicator = cpl_parameter_get_bool(p);
00444 
00445    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.estimate_indicator");
00446    cfg -> estimateIndicator = cpl_parameter_get_bool(p);
00447 
00448    cfg -> loPos =  750;
00449    cfg -> hiPos =  1000;
00450 
00451    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.box_length");
00452    cfg -> boxLength = cpl_parameter_get_int(p);
00453 
00454    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.y_box");
00455    cfg -> yBox = cpl_parameter_get_double(p);
00456 
00457    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.diff_tol");
00458    cfg -> diffTol =  cpl_parameter_get_double(p);
00459 
00460    /* input CDB
00461    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.slit_pos_guess_name");
00462    strcpy(cfg -> slitposGuessName, cpl_parameter_get_default_string(p));
00463    */
00464 
00465 }
00466 
00467 static void     
00468 parse_section_qclog      (wave_config * cfg, cpl_parameterlist* cpl_cfg)
00469 {
00470    cpl_parameter* p;
00471 
00472    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.qc_thresh_min");
00473    cfg ->  qc_thresh_min = cpl_parameter_get_int(p);
00474 
00475 
00476    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.qc_thresh_max");
00477    cfg ->  qc_thresh_max = cpl_parameter_get_int(p);
00478 
00479 
00480 }
00481 
00482 void
00483 sinfo_wavecal_free(wave_config ** cfg)
00484 {  
00485   if(*cfg != NULL) {
00486     sinfo_wave_cfg_destroy(*cfg);
00487     *cfg=NULL;
00488   }
00489   return;
00490 
00491 }
00492 

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