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

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