sinfo_finddist_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_finddist_ini_by_cpl.c
00022    Author       :   Andrea Modigliani
00023    Created on   :   Aug 12, 2004
00024    Description  :   distortion, slitlet distances, first column CPL input 
00025                     handling for SINFONI
00026  ---------------------------------------------------------------------------*/
00027 #ifdef HAVE_CONFIG_H
00028 #  include <config.h>
00029 #endif
00030 /*---------------------------------------------------------------------------
00031                                 Includes
00032  ---------------------------------------------------------------------------*/
00033 #include <string.h>
00034 #include "sinfo_finddist_ini_by_cpl.h"
00035 #include "sinfo_pro_types.h"
00036 #include "sinfo_hidden.h"
00037 #include "sinfo_raw_types.h"
00038 #include "sinfo_ref_types.h"
00039 /*---------------------------------------------------------------------------
00040                     Functions private to this module
00041  ---------------------------------------------------------------------------*/
00042 static void     
00043 parse_section_frames(finddist_config *, cpl_parameterlist* cpl_cfg, 
00044                      cpl_frameset* sof, cpl_frameset** raw, int* status);
00045 static void     
00046 parse_section_findlines(finddist_config *, cpl_parameterlist* cpl_cfg);
00047 static void     
00048 parse_section_wavecalib(finddist_config *, cpl_parameterlist* cpl_cfg);
00049 static void     
00050 parse_section_wavemap(finddist_config *, cpl_parameterlist* cpl_cfg);
00051 static void     
00052 parse_section_fitslits(finddist_config *, cpl_parameterlist* cpl_cfg);
00053 static void     
00054 parse_section_northsouthtest(finddist_config *, cpl_parameterlist* cpl_cfg);
00055 static void     
00056 parse_section_qclog      (finddist_config * cfg, cpl_parameterlist* cpl_cfg);
00057 
00077 finddist_config * 
00078 sinfo_parse_cpl_input_finddist(cpl_parameterlist * cpl_cfg, 
00079                                cpl_frameset* sof, 
00080                                cpl_frameset** raw)
00081 {
00082         finddist_config   *       cfg ;
00083         int                   status =0;
00084 
00085         cfg = sinfo_finddist_cfg_create();
00086 
00087         parse_section_findlines (cfg, cpl_cfg);
00088         parse_section_wavecalib (cfg, cpl_cfg);
00089         parse_section_wavemap   (cfg, cpl_cfg); 
00090         parse_section_fitslits  (cfg, cpl_cfg); 
00091         parse_section_northsouthtest (cfg, cpl_cfg);
00092         parse_section_qclog(cfg,cpl_cfg);
00093         parse_section_frames   (cfg, cpl_cfg, sof, raw, &status);
00094 
00095         if (status > 0) {
00096                 sinfo_msg_error("parsing cpl input");
00097                 sinfo_finddist_cfg_destroy(cfg);
00098                 cfg = NULL ;
00099                 return NULL ;
00100         }
00101         return cfg ;
00102 }
00103 
00104 
00116 static void     
00117 parse_section_frames(finddist_config * cfg,
00118              cpl_parameterlist * cpl_cfg,
00119              cpl_frameset * sof,
00120                      cpl_frameset** raw,
00121                      int* status)
00122 {
00123 
00124 
00125 
00126    int nframes=0;
00127    int nraw=0;
00128    cpl_frame* frame   = NULL;
00129    cpl_parameter *p; 
00130 
00131 
00132    char spat_res[FILE_NAME_SZ];
00133    char lamp_status[FILE_NAME_SZ];
00134    char band[FILE_NAME_SZ];
00135    int ins_set=0;
00136    cpl_table* drs_tab=NULL;
00137    wcal* w=NULL;
00138    int check=0;
00139    nstpar* nstp=NULL;
00140    distpar* d=NULL;
00141 
00142    d=sinfo_distpar_new();
00143    w=sinfo_wcal_new();
00144 
00145    nframes = cpl_frameset_get_size(sof);
00146 
00147     /* Get the raw and the calibration files */
00148 
00149 
00150    sinfo_extract_raw_frames_type(sof,raw,PRO_FIBRE_NS_STACKED);
00151    
00152 
00153    nraw=cpl_frameset_get_size(*raw);
00154    if (nraw < 1) {
00155       sinfo_msg_error("Too few (%d) raw frames (%s) present "
00156                       "in frameset!Aborting...",nraw,PRO_FIBRE_NS_STACKED);
00157         sinfo_distpar_delete(d);
00158     sinfo_wcal_delete(w);
00159           (*status)++;
00160           return;
00161    }
00162 
00163 
00164    if(NULL != cpl_frameset_find(sof,PRO_WAVE_LAMP_STACKED)) {
00165       frame = cpl_frameset_find(sof,PRO_WAVE_LAMP_STACKED);
00166       strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
00167    } else {
00168       sinfo_msg_error("Frame %s not found! Exit!", PRO_WAVE_LAMP_STACKED);
00169         sinfo_distpar_delete(d);
00170     sinfo_wcal_delete(w);
00171         (*status)++;
00172       return;
00173    }
00174 
00175    strcpy(cfg -> outName, DISTORTION_OUT_FILENAME);
00176 
00177 
00178    if(NULL != cpl_frameset_find(sof,REF_LINE_ARC)) {
00179       frame = cpl_frameset_find(sof,REF_LINE_ARC);
00180       strcpy(cfg -> lineList,cpl_frame_get_filename(frame));
00181    } else {
00182       sinfo_msg_error("Frame %s not found! Exit!", REF_LINE_ARC);
00183         sinfo_distpar_delete(d);
00184     sinfo_wcal_delete(w);
00185         (*status)++;
00186       return;
00187    }
00188 
00189    if(NULL != cpl_frameset_find(sof,PRO_FIBRE_NS_STACKED)) {
00190       frame = cpl_frameset_find(sof,PRO_FIBRE_NS_STACKED);
00191       strcpy(cfg -> nsFrame,cpl_frame_get_filename(frame));
00192    } else {
00193       sinfo_msg_error("Frame %s not found! Exit!", PRO_FIBRE_NS_STACKED);
00194         sinfo_distpar_delete(d);
00195     sinfo_wcal_delete(w);
00196         (*status)++;
00197       return;
00198    }
00199 
00200 
00201    if(NULL != cpl_frameset_find(sof,PRO_BP_MAP_DI)) {
00202       frame = cpl_frameset_find(sof,PRO_BP_MAP_DI);
00203       strcpy(cfg -> mask,cpl_frame_get_filename(frame));
00204    } else {
00205       sinfo_msg_error("Frame %s not found! Exit!", PRO_BP_MAP_DI);
00206         sinfo_distpar_delete(d);
00207     sinfo_wcal_delete(w);
00208         (*status)++;
00209       return;
00210    }
00211 
00212 
00213   
00214    frame = cpl_frameset_get_frame(*raw,0);
00215    sinfo_get_spatial_res(frame,spat_res);
00216  
00217    switch(sinfo_frame_is_on(frame)) 
00218      {
00219    case 0: 
00220       strcpy(lamp_status,"on");
00221       break;
00222     case 1: 
00223       strcpy(lamp_status,"off");
00224       break;
00225     case -1:
00226       strcpy(lamp_status,"undefined");
00227       break;
00228     default: 
00229       strcpy(lamp_status,"undefined");
00230       break;
00231      }
00232 
00233    sinfo_get_band(frame,band);
00234    sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
00235                      spat_res,    lamp_status,    band);
00236 
00237 
00238    sinfo_get_ins_set(band,&ins_set);
00239     if(NULL != cpl_frameset_find(sof,DRS_SETUP_WAVE)) {
00240      frame = cpl_frameset_find(sof,DRS_SETUP_WAVE);
00241         strcpy(cfg -> drs_setup,cpl_frame_get_filename(frame));
00242         drs_tab = cpl_table_load(cfg->drs_setup,1,0);
00243         w->wstart=cpl_table_get_double(drs_tab,"W_START",ins_set,&check);
00244         w->wgdisp1=cpl_table_get_double(drs_tab,"W_DISP1",ins_set,&check);
00245         w->wgdisp2=cpl_table_get_double(drs_tab,"W_DISP2",ins_set,&check);
00246         w->hw=cpl_table_get_int(drs_tab,"W_HW",ins_set,&check);
00247         w->fwhm=cpl_table_get_double(drs_tab,"W_FWHM",ins_set,&check);
00248         w->min_amp=cpl_table_get_double(drs_tab,"W_MIN_AMP",ins_set,&check);
00249     /*
00250         w->min_dif=cpl_table_get_double(drs_tab,"W_MIN_DIF",ins_set,&check);
00251         w->na_coef=cpl_table_get_int(drs_tab,"W_NA_COEFF",ins_set,&check);
00252         w->nb_coef=cpl_table_get_int(drs_tab,"W_NB_COEFF",ins_set,&check);
00253         w->pixel_tol=cpl_table_get_double(drs_tab,"W_PIX_TOL",ins_set,&check);
00254         w->y_box=cpl_table_get_double(drs_tab,"W_Y_BOX",ins_set,&check);
00255     */
00256         w->low_pos=cpl_table_get_int(drs_tab,"W_LOW_POS",ins_set,&check);
00257         w->hig_pos=cpl_table_get_int(drs_tab,"W_HI_POS",ins_set,&check);
00258 
00259     cfg -> guessBeginWavelength = w->wstart;
00260     cfg -> guessDispersion1 =  w->wgdisp1;
00261     cfg -> guessDispersion2 =  w->wgdisp2;
00262     cfg -> halfWidth =         w->hw;
00263     cfg -> fwhm =              w->fwhm;
00264     cfg -> minAmplitude =      w->min_amp;
00265     /*
00266     cfg -> mindiff =           w->min_dif;
00267     cfg -> nrDispCoefficients = w->na_coef;
00268     cfg -> nrCoefCoefficients = w->nb_coef;
00269     cfg -> pixel_tolerance =    w->pixel_tol;
00270     cfg -> yBox =               w->y_box;
00271     */
00272     cfg -> loPos =              DISTORTION_LOPOS;
00273     cfg -> hiPos =              DISTORTION_HIPOS;
00274     cfg -> pixel_tolerance =    w->pixel_tol;
00275         cfg-> diffTol = d->diff_tol[ins_set];
00276     /*
00277         sinfo_msg("cfg->guessBeginWavelength %g",cfg -> guessBeginWavelength);
00278         sinfo_msg("cfg->guessDispersion1 %g",cfg -> guessDispersion1);
00279         sinfo_msg("cfg->guessDispersion2 %g",cfg -> guessDispersion2);
00280         sinfo_msg("cfg->mindiff %g",cfg -> mindiff);
00281         sinfo_msg("cfg->halfWidth %d",cfg ->  halfWidth);
00282         sinfo_msg("cfg->fwhm %g",cfg -> fwhm);
00283         sinfo_msg("cfg->minAmplitude %g",cfg -> minAmplitude);
00284         sinfo_msg("cfg->nrDispCoefficients %d",cfg -> nrDispCoefficients);
00285         sinfo_msg("cfg->nrCoefCoefficients %d",cfg -> nrCoefCoefficients);
00286         sinfo_msg("cfg->pixel_tolerance  %g",cfg -> pixel_tolerance);
00287         sinfo_msg("cfg->loPos %d",cfg -> loPos);
00288         sinfo_msg("cfg->hiPos %d",cfg -> hiPos);
00289         sinfo_msg("cfg->yBox  %f",cfg -> yBox);
00290     */
00291         sinfo_distpar_delete(d);
00292     sinfo_wcal_delete(w);
00293         cpl_table_delete(drs_tab);
00294         if(-1 == sinfo_check_rec_status(0)) {
00295       (*status)++;
00296       return;
00297     }
00298 
00299    } else {
00300     sinfo_msg_error("Frame %s not found! Exit!", DRS_SETUP_WAVE);
00301         sinfo_distpar_delete(d);
00302     sinfo_wcal_delete(w);
00303         (*status)++;
00304         return;
00305    }
00306 
00307 
00308    nstp=sinfo_nstpar_new();  
00309    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.ns_fwhm");
00310    if(cpl_parameter_get_default_flag(p) == 0) {
00311       cfg->nsfwhm=nstp->fwhm[ins_set];
00312    } else {
00313       cfg->nsfwhm=cpl_parameter_get_double(p);
00314    }
00315 
00316    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.min_diff");
00317    if(cpl_parameter_get_default_flag(p) == 0) {
00318      cfg->minDiff=nstp->min_dif[ins_set];
00319    } else {
00320      cfg->minDiff=cpl_parameter_get_double(p);
00321    }
00322    sinfo_nstpar_delete(nstp);
00323    //sinfo_msg("cfg -> nsfwhm  %f",cfg -> nsfwhm);
00324    //sinfo_msg("cfg -> minDiff  %f",cfg -> minDiff);
00325 
00326 
00327    return;
00328 
00329 }
00330 
00331 
00340 static void     
00341 parse_section_findlines(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
00342 {
00343 
00344    cpl_parameter* p;
00345 
00346    p = cpl_parameterlist_find(cpl_cfg, 
00347                               "sinfoni.distortion.min_diff_mean_med_col_int");
00348    cfg -> mindiff =  cpl_parameter_get_double(p);
00349 
00350    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.half_width");
00351    cfg -> halfWidth = cpl_parameter_get_int(p);
00352 
00353    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.sigma");
00354    cfg -> sigma =  cpl_parameter_get_double(p);
00355 
00356    return ;
00357 
00358 }
00359 
00367 static void     
00368 parse_section_wavecalib(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
00369 {
00370 
00371 
00372    cpl_parameter* p;
00373 
00374    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.fwhm");
00375    cfg -> fwhm =  cpl_parameter_get_double(p);
00376 
00377    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.min_amplitude");
00378    cfg -> minAmplitude =  cpl_parameter_get_double(p);
00379 
00380    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.max_residual");
00381    cfg -> maxResidual =  cpl_parameter_get_double(p);
00382 
00383    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.n_a_coefficients");
00384    cfg -> nrDispCoefficients = cpl_parameter_get_int(p);
00385 
00386    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.n_b_coefficients");
00387    cfg -> nrCoefCoefficients = cpl_parameter_get_int(p);
00388 
00389    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.sigma_factor");
00390    cfg -> sigmaFactor =  cpl_parameter_get_double(p);
00391 
00392 
00393    cfg -> nslitlets = NSLITLETS;
00394 
00395    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.pixel_dist");
00396    cfg -> pixeldist = cpl_parameter_get_int(p);
00397 
00398    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.pixel_tol");
00399    cfg -> pixel_tolerance = cpl_parameter_get_double(p);
00400 
00401 
00402 
00403 }
00404 
00412 static void     
00413 parse_section_wavemap(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
00414 {
00415    cpl_parameter* p;
00416 
00417    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.mag_factor");
00418    cfg -> magFactor = cpl_parameter_get_int(p);
00419 
00420 }
00421 
00429 static void     
00430 parse_section_fitslits(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
00431 {
00432 
00433    cpl_parameter* p;
00434 
00435    cfg -> loPos =  DISTORTION_LOPOS;
00436    cfg -> hiPos =  DISTORTION_HIPOS;
00437 
00438    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.box_length");
00439    cfg -> boxLength = cpl_parameter_get_int(p);
00440 
00441    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.y_box");
00442    cfg -> yBox = cpl_parameter_get_double(p);
00443 
00444    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.diff_tol");
00445    cfg -> diffTol =  cpl_parameter_get_double(p);
00446 
00447 }
00448 
00456 static void     
00457 parse_section_qclog      (finddist_config * cfg, cpl_parameterlist* cpl_cfg)
00458 {
00459    cpl_parameter* p;
00460 
00461    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.qc_thresh_min");
00462    cfg ->  qc_thresh_min = cpl_parameter_get_int(p);
00463 
00464 
00465    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.qc_thresh_max");
00466    cfg ->  qc_thresh_max = cpl_parameter_get_int(p);
00467 
00468 
00469 }
00470 
00471 
00479 static void     
00480 parse_section_northsouthtest(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
00481 {
00482 
00483    cpl_parameter *p;   
00484    strcat(cfg -> fitsname, DISTORTION_NS_OUT_FILENAME);
00485 
00486    cfg -> nslits = NSLITLETS;
00487 
00488    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.ns_half_width");
00489    cfg -> nshalfWidth = cpl_parameter_get_int(p);
00490 
00491    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.ns_fwhm");
00492    cfg -> nsfwhm = cpl_parameter_get_double(p);
00493 
00494    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.min_diff");
00495    cfg -> minDiff = cpl_parameter_get_double(p);
00496 
00497    cfg -> estimated_dist = ESTIMATED_SLITLETS_DISTANCE;
00498 
00499    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.dev_tol");
00500    cfg -> devtol = cpl_parameter_get_double(p);
00501 
00502    return ;
00503 
00504 }
00505 
00513 void
00514 sinfo_finddist_free(finddist_config ** cfg)
00515 {  
00516 
00517   if(*cfg!=NULL) {
00518     sinfo_finddist_cfg_destroy(*cfg);
00519     *cfg=NULL;
00520   }
00521   return;
00522 
00523 }

Generated on 3 Mar 2013 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1