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

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