crires_spec_wavecal.c

00001 /* $Id: crires_spec_wavecal.c,v 1.74 2012/09/25 07:04:35 yjung Exp $
00002  *
00003  * This file is part of the CRIRES Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: yjung $
00023  * $Date: 2012/09/25 07:04:35 $
00024  * $Revision: 1.74 $
00025  * $Name: crire-2_3_0 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include "crires_recipe.h"
00037 
00038 #include "crires_combine.h"
00039 #include "crires_wlcalib.h"
00040 #include "crires_extract.h"
00041 #include "crires_model_kernel.h"
00042 
00043 /*-----------------------------------------------------------------------------
00044                                 Define
00045  -----------------------------------------------------------------------------*/
00046 
00047 #define RECIPE_STRING "crires_spec_wavecal"
00048 
00049 /*-----------------------------------------------------------------------------
00050                             Functions prototypes
00051  -----------------------------------------------------------------------------*/
00052 
00053 static int crires_spec_wavecal_save(const cpl_imagelist *, 
00054         const cpl_imagelist *, const cpl_table **, const cpl_parameterlist *, 
00055         cpl_frameset *) ;
00056 
00057 static char crires_spec_wavecal_description[] =
00058 "crires_spec_wavecal -- Wavelength calibration\n"
00059 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00060 "raw-file.fits "CRIRES_SPEC_WAVECAL_SKY_RAW" or\n"
00061 "raw-file.fits "CRIRES_SPEC_WAVECAL_LAMP_RAW" or\n" 
00062 "raw-file.fits "CRIRES_SPEC_WAVECAL_ABS_RAW" or\n" 
00063 "flat-file.fits "CRIRES_CALPRO_FLAT" or\n"
00064 "bpm-file.fits "CRIRES_CALPRO_BPM" or\n"
00065 "dark-file.fits "CRIRES_CALPRO_DARK" or\n"
00066 "detlin-file.fits "CRIRES_CALPRO_COEFFS_CUBE" or\n"
00067 "catalog-file.fits "CRIRES_CALPRO_THAR_CAT" or\n" 
00068 "catalog-file.fits "CRIRES_CALPRO_OH_CAT" or\n" 
00069 "catalog-file.fits "CRIRES_CALPRO_HITRAN_CAT" or\n" 
00070 "model-config-file.fits "CRIRES_CALPRO_MODEL_CONFIG".\n"
00071 "\n"
00072 "This recipe produces 3 files:\n"
00073 "First product:     the image with the wavelength values.\n"
00074 "                   (PRO TYPE = "CRIRES_PROTYPE_WL_MAP")\n"
00075 "Second product:    the image with the wavelength values from the model.\n"
00076 "                   (PRO TYPE = "CRIRES_PROTYPE_WL_MAP")\n"
00077 "Third product:     the table with the wavelength polynomial coefficients.\n"
00078 "                   (PRO TYPE = "CRIRES_PROTYPE_WL_POLY")\n" ;
00079 
00080 CRIRES_RECIPE_DEFINE(crires_spec_wavecal,
00081         CRIRES_PARAM_WAVES          |
00082         CRIRES_PARAM_DISPLAY        |
00083         CRIRES_PARAM_WL_LOG         |
00084         CRIRES_PARAM_WL_NOLIMIT     |
00085         CRIRES_PARAM_WL_ERROR       |
00086         CRIRES_PARAM_XC_LIMIT       |
00087         CRIRES_PARAM_WL_NBSAMPLES   |
00088         CRIRES_PARAM_Y_POS_CHIP1    |
00089         CRIRES_PARAM_Y_POS_CHIP2    |
00090         CRIRES_PARAM_Y_POS_CHIP3    |
00091         CRIRES_PARAM_Y_POS_CHIP4    |
00092         CRIRES_PARAM_Y_WIDTH        |
00093         CRIRES_PARAM_DEGREE         |
00094         CRIRES_PARAM_WL_CLEAN,
00095         "Wavelength calibration",
00096         crires_spec_wavecal_description) ;
00097 
00098 /*-----------------------------------------------------------------------------
00099                             Static variables
00100  -----------------------------------------------------------------------------*/
00101 
00102 static struct {
00103     /* Inputs */
00104     double              wstart[CRIRES_NB_DETECTORS] ;
00105     double              wstop[CRIRES_NB_DETECTORS] ;
00106     int                 wl_nolimit ;
00107     int                 wl_log ;
00108     const char      *   wl_ypos_c1 ;
00109     const char      *   wl_ypos_c2 ;
00110     const char      *   wl_ypos_c3 ;
00111     const char      *   wl_ypos_c4 ;
00112     int                 wl_width ;
00113     double              wl_fwhm ;
00114     double              wl_slitw ;
00115     int                 wl_degree ;
00116     double              wl_err ;
00117     int                 wl_samples ;
00118     int                 wl_clean ;
00119     double              wl_xclimit ;
00120     int                 wl_ppm ;
00121     int                 display ;
00122     /* Outputs */
00123     crires_illum_period period ;
00124     int                 mode ;
00125     double              qc_wlxc[CRIRES_NB_DETECTORS] ;
00126     double              qc_wlcent[CRIRES_NB_DETECTORS] ;
00127     double              qc_wldisp[CRIRES_NB_DETECTORS] ;
00128     double              qc_lines_flux[CRIRES_NB_DETECTORS] ;
00129     double              qc_fwhm[CRIRES_NB_DETECTORS] ;
00130     double              qc_rpower[CRIRES_NB_DETECTORS] ;
00131 } crires_spec_wavecal_config ;
00132 
00133 /*-----------------------------------------------------------------------------
00134                                 Functions code
00135  -----------------------------------------------------------------------------*/
00136 
00137 /*----------------------------------------------------------------------------*/
00144 /*----------------------------------------------------------------------------*/
00145 static int crires_spec_wavecal(
00146         cpl_frameset            *   frameset,
00147         const cpl_parameterlist *   parlist)
00148 {
00149     const char          *   sval ;
00150     const char          *   wl_ypos ;
00151     cpl_frameset        *   rawframes ;
00152     const char          *   fname ;
00153     const char          *   flat ;
00154     const char          *   dark ;
00155     const char          *   bpm ;
00156     const char          *   detlin ;
00157     const char          *   thar_cat ;
00158     const char          *   n2o_cat ;
00159     const char          *   oh_cat ;
00160     const char          *   hitran_cat ;
00161     const char          *   cfg_model ;
00162     cpl_propertylist    *   plist ;
00163     double                  wmin, wmax ;
00164     cpl_table           *   wave_tab[CRIRES_NB_DETECTORS] ;
00165     cpl_imagelist       *   wl_map ;
00166     cpl_imagelist       *   wl_map_model ;
00167     cpl_vector          *   wave_ypos ;
00168     int                     pix ;
00169     int                     i, j ;
00170 
00171     /* Initialise */
00172     rawframes = NULL ;
00173     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00174         crires_spec_wavecal_config.qc_wlxc[i] = -1.0 ;
00175         crires_spec_wavecal_config.qc_wlcent[i] = -1.0 ;
00176         crires_spec_wavecal_config.qc_wldisp[i] = -1.0 ;
00177         crires_spec_wavecal_config.qc_lines_flux[i] = -1.0 ;
00178         crires_spec_wavecal_config.qc_fwhm[i] = -1.0 ;
00179         crires_spec_wavecal_config.qc_rpower[i] = -1.0 ;
00180     }
00181     crires_spec_wavecal_config.wl_ppm = 0 ;
00182     crires_spec_wavecal_config.wl_slitw = 2.0 ;
00183     crires_spec_wavecal_config.wl_fwhm = 2.0 ;
00184     
00185     /* Retrieve input parameters */
00186 
00187     sval = crires_parameterlist_get_string(parlist, RECIPE_STRING,
00188             CRIRES_PARAM_WAVES) ;
00189     if (sscanf(sval, "%lg,%lg,%lg,%lg,%lg,%lg,%lg,%lg",
00190                     &crires_spec_wavecal_config.wstart[0],
00191                     &crires_spec_wavecal_config.wstop[0],
00192                     &crires_spec_wavecal_config.wstart[1],
00193                     &crires_spec_wavecal_config.wstop[1],
00194                     &crires_spec_wavecal_config.wstart[2],
00195                     &crires_spec_wavecal_config.wstop[2],
00196                     &crires_spec_wavecal_config.wstart[3],
00197                     &crires_spec_wavecal_config.wstop[3])!=2*CRIRES_NB_DETECTORS){
00198         return -1 ;
00199     }
00200     crires_spec_wavecal_config.display = crires_parameterlist_get_int(parlist,
00201             RECIPE_STRING, CRIRES_PARAM_DISPLAY) ;
00202     crires_spec_wavecal_config.wl_log = crires_parameterlist_get_bool(parlist,
00203             RECIPE_STRING, CRIRES_PARAM_WL_LOG) ;
00204     crires_spec_wavecal_config.wl_nolimit = crires_parameterlist_get_bool(
00205             parlist, RECIPE_STRING, CRIRES_PARAM_WL_NOLIMIT) ;
00206     crires_spec_wavecal_config.wl_degree = crires_parameterlist_get_int(parlist,
00207             RECIPE_STRING, CRIRES_PARAM_DEGREE) ;
00208     crires_spec_wavecal_config.wl_err = crires_parameterlist_get_double(parlist,
00209             RECIPE_STRING, CRIRES_PARAM_WL_ERROR) ;
00210     crires_spec_wavecal_config.wl_xclimit = crires_parameterlist_get_double(
00211             parlist, RECIPE_STRING, CRIRES_PARAM_XC_LIMIT) ;
00212     crires_spec_wavecal_config.wl_ypos_c1=crires_parameterlist_get_string(
00213             parlist, RECIPE_STRING, CRIRES_PARAM_Y_POS_CHIP1) ;
00214     crires_spec_wavecal_config.wl_ypos_c2=crires_parameterlist_get_string(
00215             parlist, RECIPE_STRING, CRIRES_PARAM_Y_POS_CHIP2) ;
00216     crires_spec_wavecal_config.wl_ypos_c3=crires_parameterlist_get_string(
00217             parlist, RECIPE_STRING, CRIRES_PARAM_Y_POS_CHIP3) ;
00218     crires_spec_wavecal_config.wl_ypos_c4=crires_parameterlist_get_string(
00219             parlist, RECIPE_STRING, CRIRES_PARAM_Y_POS_CHIP4) ;
00220     crires_spec_wavecal_config.wl_width= crires_parameterlist_get_int(parlist,
00221             RECIPE_STRING, CRIRES_PARAM_Y_WIDTH) ;
00222     crires_spec_wavecal_config.wl_samples = crires_parameterlist_get_int(
00223             parlist, RECIPE_STRING, CRIRES_PARAM_WL_NBSAMPLES) ;
00224     crires_spec_wavecal_config.wl_clean = crires_parameterlist_get_bool(parlist,
00225             RECIPE_STRING, CRIRES_PARAM_WL_CLEAN) ;
00226 
00227     /* Identify the RAW and CALIB frames in the input frameset */
00228     if (crires_dfs_set_groups(frameset, "crires_spec_wavecal")) {
00229         cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00230         return -1 ;
00231     }
00232 
00233     /* Retrieve calibration data */
00234     flat        = crires_extract_filename(frameset, CRIRES_CALPRO_FLAT) ;
00235     dark        = crires_extract_filename(frameset, CRIRES_CALPRO_DARK) ;
00236     bpm         = crires_extract_filename(frameset, CRIRES_CALPRO_BPM) ;
00237     detlin      = crires_extract_filename(frameset, CRIRES_CALPRO_COEFFS_CUBE) ;
00238     thar_cat = crires_extract_filename(frameset, CRIRES_CALPRO_THAR_CAT) ;
00239     n2o_cat = crires_extract_filename(frameset, CRIRES_CALPRO_N2O_CAT) ;
00240     oh_cat = crires_extract_filename(frameset, CRIRES_CALPRO_OH_CAT) ;
00241     hitran_cat = crires_extract_filename(frameset, CRIRES_CALPRO_HITRAN_CAT) ;
00242     cfg_model = crires_extract_filename(frameset, CRIRES_CALPRO_MODEL_CONFIG) ;
00243     
00244     /* Retrieve raw frames */
00245     if ((rawframes = crires_extract_frameset(frameset,
00246                     CRIRES_SPEC_WAVECAL_SKY_RAW)) != NULL) {
00247         crires_spec_wavecal_config.mode = 1 ;
00248     } else if ((rawframes = crires_extract_frameset(frameset, 
00249                     CRIRES_SPEC_WAVECAL_LAMP_RAW)) != NULL) {
00250         crires_spec_wavecal_config.mode = 2 ;
00251     } else if ((rawframes = crires_extract_frameset(frameset, 
00252                     CRIRES_SPEC_WAVECAL_ABS_RAW)) != NULL) {
00253         crires_spec_wavecal_config.mode = 3 ;
00254     } else {
00255         cpl_msg_error(__func__, "No raw frame in input") ;
00256         return -1 ;
00257     }
00258 
00259     /* Get the detector illumination period */
00260     crires_spec_wavecal_config.period =
00261         crires_get_detector_illum_period(
00262                 cpl_frame_get_filename(cpl_frameset_get_frame(rawframes, 0))) ;
00263     if (crires_spec_wavecal_config.period == CRIRES_ILLUM_UNKNOWN) {
00264         cpl_msg_error(__func__,
00265                 "Cannot determine the detector illumination period") ;
00266         cpl_frameset_delete(rawframes) ;
00267         return -1 ;
00268     } else {
00269         crires_display_detector_illum(crires_spec_wavecal_config.period) ;
00270     }
00271 
00272     /* Reduce the first raw frame */
00273     fname = cpl_frame_get_filename(cpl_frameset_get_frame(rawframes,0)) ;
00274 
00275     /* Get the Minimum and Maximum wavelengths */
00276     if (crires_spec_wavecal_config.wl_nolimit == 0) {
00277         plist = cpl_propertylist_load(fname, 0) ;
00278         wmin = crires_pfits_get_wlen_min(plist) ;
00279         wmax = crires_pfits_get_wlen_max(plist) ;
00280         cpl_propertylist_delete(plist) ;
00281         if (cpl_error_get_code()) {
00282             wmin = wmax = -1.0 ;
00283             cpl_error_reset() ;
00284         }
00285     } else {
00286         wmin = wmax = -1.0 ;
00287     }
00288    
00289     /* Wavelength calibration */
00290     cpl_msg_info(__func__, "Apply the Wavelength Calibration") ;
00291     cpl_msg_indent_more() ;
00292     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00293         cpl_msg_info(__func__, "Calibrate chip number %d", i+1) ;
00294         cpl_msg_indent_more() ;
00295 
00296         /* Where Compute the wavelength from ? */
00297         wl_ypos = "" ;
00298         if (i+1 == 1) wl_ypos = crires_spec_wavecal_config.wl_ypos_c1 ;
00299         if (i+1 == 2) wl_ypos = crires_spec_wavecal_config.wl_ypos_c2 ;
00300         if (i+1 == 3) wl_ypos = crires_spec_wavecal_config.wl_ypos_c3 ;
00301         if (i+1 == 4) wl_ypos = crires_spec_wavecal_config.wl_ypos_c4 ;
00302 
00303         /* Try to parse the user specified positions */
00304         if (!strcmp(wl_ypos, "")) {
00305             wave_ypos = NULL ;
00306         } else {
00307             if ((wave_ypos = crires_parse_y_positions(wl_ypos)) == NULL) {
00308                 cpl_msg_warning(__func__,
00309                         "Cannot parse the y_positions value : %s", wl_ypos) ;
00310             }
00311         }
00312         
00313         /* Otherwise use defaults */
00314         if (wave_ypos == NULL) {
00315             if (i+1 == 1) wave_ypos = 
00316                 crires_parse_y_positions(CRIRES_WAVE_LAMP_YPOS_CHIP1) ;
00317             if (i+1 == 2) wave_ypos = 
00318                 crires_parse_y_positions(CRIRES_WAVE_LAMP_YPOS_CHIP2) ;
00319             if (i+1 == 3) wave_ypos = 
00320                 crires_parse_y_positions(CRIRES_WAVE_LAMP_YPOS_CHIP3) ;
00321             if (i+1 == 4) wave_ypos = 
00322                 crires_parse_y_positions(CRIRES_WAVE_LAMP_YPOS_CHIP4) ;
00323         }
00324 
00325         /* Try to detect the positions */
00326         if (wave_ypos == NULL) 
00327             wave_ypos = crires_wlcalib_detect_wave_ypos(fname, 
00328                     crires_spec_wavecal_config.period, i+1);
00329 
00330         /* Check the Mode */
00331         if (crires_spec_wavecal_config.mode == 1) {
00332             /* Calibrate from the sky */
00333             cpl_msg_info(__func__,"Get the calibration from the oh/hitran sky");
00334             wave_tab[i] = crires_wlcalib_sky(fname,
00335                     crires_spec_wavecal_config.period,
00336                     oh_cat, hitran_cat, crires_spec_wavecal_config.wl_log,
00337                     flat, dark, bpm, detlin,
00338                     crires_spec_wavecal_config.wstart[i],
00339                     crires_spec_wavecal_config.wstop[i],
00340                     wmin, wmax, i+1, 
00341                     wave_ypos,
00342                     crires_spec_wavecal_config.wl_width,
00343                     crires_spec_wavecal_config.wl_degree,
00344                     crires_spec_wavecal_config.wl_slitw,
00345                     crires_spec_wavecal_config.wl_fwhm,
00346                     crires_spec_wavecal_config.wl_err,
00347                     crires_spec_wavecal_config.wl_samples,
00348                     crires_spec_wavecal_config.wl_clean,
00349                     crires_spec_wavecal_config.wl_xclimit,
00350                     crires_spec_wavecal_config.wl_ppm,
00351                     (i+1==crires_spec_wavecal_config.display)) ;
00352         } else if (crires_spec_wavecal_config.mode == 2) {
00353             /* Calibrate from the lamp */
00354             cpl_msg_info(__func__, "Get the calibration from the thar lamp") ;
00355             wave_tab[i] = crires_wlcalib_lamp(fname,
00356                     crires_spec_wavecal_config.period,
00357                     thar_cat, crires_spec_wavecal_config.wl_log,
00358                     flat, dark, bpm, detlin,
00359                     crires_spec_wavecal_config.wstart[i],
00360                     crires_spec_wavecal_config.wstop[i],
00361                     wmin, wmax, i+1,
00362                     wave_ypos,
00363                     crires_spec_wavecal_config.wl_width,
00364                     crires_spec_wavecal_config.wl_degree,
00365                     crires_spec_wavecal_config.wl_slitw,
00366                     crires_spec_wavecal_config.wl_fwhm,
00367                     crires_spec_wavecal_config.wl_err,
00368                     crires_spec_wavecal_config.wl_samples,
00369                     crires_spec_wavecal_config.wl_clean,
00370                     crires_spec_wavecal_config.wl_xclimit,
00371                     crires_spec_wavecal_config.wl_ppm,
00372                     (i+1==crires_spec_wavecal_config.display),
00373                     &(crires_spec_wavecal_config.qc_lines_flux[i]),
00374                     &(crires_spec_wavecal_config.qc_fwhm[i]),
00375                     &(crires_spec_wavecal_config.qc_rpower[i])) ;
00376         } else if (crires_spec_wavecal_config.mode == 3) {
00377             /* Calibrate from the gas cell */
00378             cpl_msg_info(__func__, "Get the calibration from the n2o gas cell");
00379             wave_tab[i] = crires_wlcalib_lamp(fname,
00380                     crires_spec_wavecal_config.period,
00381                     n2o_cat, crires_spec_wavecal_config.wl_log, 
00382                     flat, dark, bpm, detlin,
00383                     crires_spec_wavecal_config.wstart[i],
00384                     crires_spec_wavecal_config.wstop[i],
00385                     wmin, wmax, i+1,
00386                     wave_ypos,
00387                     crires_spec_wavecal_config.wl_width,
00388                     crires_spec_wavecal_config.wl_degree,
00389                     crires_spec_wavecal_config.wl_slitw,
00390                     crires_spec_wavecal_config.wl_fwhm,
00391                     crires_spec_wavecal_config.wl_err,
00392                     crires_spec_wavecal_config.wl_samples,
00393                     crires_spec_wavecal_config.wl_clean,
00394                     crires_spec_wavecal_config.wl_xclimit,
00395                     crires_spec_wavecal_config.wl_ppm,
00396                     (i+1==crires_spec_wavecal_config.display),
00397                     &(crires_spec_wavecal_config.qc_lines_flux[i]), 
00398                     &(crires_spec_wavecal_config.qc_fwhm[i]),
00399                     &(crires_spec_wavecal_config.qc_rpower[i])) ;
00400         }
00401         cpl_msg_indent_less() ;
00402     cpl_vector_delete(wave_ypos) ;
00403     }
00404     cpl_msg_indent_less() ;
00405 
00406     /* Create the wave map */
00407     if ((wl_map = crires_wlcalib_gen_wlmap((const cpl_table **)wave_tab))
00408             == NULL) {
00409         cpl_msg_error(__func__, "Cannot compute the Wavelength Map") ;
00410         cpl_frameset_delete(rawframes) ;
00411         for (j=0 ; j<CRIRES_NB_DETECTORS ; j++) {
00412             if (wave_tab[j] != NULL) cpl_table_delete(wave_tab[j]);
00413         }
00414         return -1 ;
00415     }
00416 
00417     /* Compute the QC parameters */
00418     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00419         crires_spec_wavecal_config.qc_wlcent[i] =
00420             cpl_image_get(cpl_imagelist_get(wl_map, i),
00421                     512, 256, &pix) ;
00422         crires_spec_wavecal_config.qc_wldisp[i] =
00423             ((cpl_image_get(cpl_imagelist_get(wl_map, i), 1024,
00424                             256, &pix)) -
00425              (cpl_image_get(cpl_imagelist_get(wl_map, i), 1,
00426                             256, &pix)))
00427             / 1023 ;
00428         crires_spec_wavecal_config.qc_wlxc[i] =
00429             crires_wlcalib_get_better_xc(wave_tab[i]) ;
00430     }
00431 
00432     /* Get the wl map from the model */
00433     if ((cfg_model != NULL) && (!crires_model_off()) && 
00434             (crires_model_config_check(cfg_model, fname) == 0)) {
00435         cpl_msg_info(__func__, "Call the model to get the wavelength map") ;
00436         cpl_msg_indent_more() ;
00437         wl_map_model = crires_model_wavpix(fname, cfg_model, -1) ;
00438         if (wl_map_model == NULL) {
00439             cpl_msg_warning(__func__, "Model function returns NULL") ;
00440             cpl_error_reset() ;
00441         }
00442         cpl_msg_indent_less() ;
00443     } else {
00444         wl_map_model = NULL ;
00445     }
00446     cpl_frameset_delete(rawframes) ;
00447     
00448     /* Save the product */
00449     cpl_msg_info(__func__, "Save the product") ;
00450     cpl_msg_indent_more() ;
00451     if (crires_spec_wavecal_save(wl_map, wl_map_model, 
00452                 (const cpl_table **)wave_tab, parlist, frameset)) {
00453         cpl_msg_error(__func__, "Cannot save the product") ;
00454         for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) 
00455             if (wave_tab[i] != NULL) cpl_table_delete(wave_tab[i]);
00456         cpl_imagelist_delete(wl_map) ;
00457         if (wl_map_model) cpl_imagelist_delete(wl_map_model) ;
00458         cpl_msg_indent_less() ;
00459         return -1 ;
00460     }
00461     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++)
00462         if (wave_tab[i] != NULL) cpl_table_delete(wave_tab[i]);
00463     cpl_imagelist_delete(wl_map) ;
00464     if (wl_map_model) cpl_imagelist_delete(wl_map_model) ;
00465     cpl_msg_indent_less() ;
00466 
00467     /* Return */
00468     if (cpl_error_get_code()) return -1 ;
00469     else return 0 ;
00470 }
00471 
00472 /*----------------------------------------------------------------------------*/
00482 /*----------------------------------------------------------------------------*/
00483 static int crires_spec_wavecal_save(
00484         const cpl_imagelist     *   ilist,
00485         const cpl_imagelist     *   ilist_model,
00486         const cpl_table         **  wl_tab,
00487         const cpl_parameterlist *   parlist,
00488         cpl_frameset            *   set)
00489 {
00490     cpl_propertylist    **  qclists ;
00491     const cpl_frame     *   ref_frame ;
00492     cpl_propertylist    *   inputlist ;
00493     const char          *   recipe_name = "crires_spec_wavecal" ;
00494     int                     i ;
00495 
00496     /* Get the reference frame */
00497     ref_frame = irplib_frameset_get_first_from_group(set, CPL_FRAME_GROUP_RAW) ;
00498 
00499     /* Create the QC lists */
00500     qclists = cpl_malloc(CRIRES_NB_DETECTORS * sizeof(cpl_propertylist*)) ;
00501     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00502         qclists[i] = cpl_propertylist_new() ;
00503         cpl_propertylist_append_double(qclists[i], "ESO QC CENTWL",
00504                 crires_spec_wavecal_config.qc_wlcent[i]) ;
00505         cpl_propertylist_append_double(qclists[i], "ESO QC DISPWL",
00506                 crires_spec_wavecal_config.qc_wldisp[i]) ;
00507         cpl_propertylist_append_double(qclists[i], "ESO QC XCORR",
00508                 crires_spec_wavecal_config.qc_wlxc[i]) ;
00509         cpl_propertylist_append_double(qclists[i], "ESO QC LINES FLUX",
00510                 crires_spec_wavecal_config.qc_lines_flux[i]) ;
00511         cpl_propertylist_append_double(qclists[i], "ESO QC FWHM MED",
00512                 crires_spec_wavecal_config.qc_fwhm[i]) ;
00513         cpl_propertylist_append_double(qclists[i], "ESO QC RESOL MED",
00514                 crires_spec_wavecal_config.qc_rpower[i]) ;
00515 
00516         /* Propagate some keywords from input raw frame extensions */
00517         inputlist = cpl_propertylist_load_regexp(
00518                 cpl_frame_get_filename(ref_frame), i+1,
00519                 CRIRES_HEADER_EXT_FORWARD, 0) ;
00520         cpl_propertylist_copy_property_regexp(qclists[i], inputlist,
00521                 CRIRES_HEADER_EXT_FORWARD, 0) ;
00522         cpl_propertylist_delete(inputlist) ;
00523     }
00524 
00525     /* Write the image */
00526     crires_image_save(set,
00527             parlist,
00528             set,
00529             ilist,
00530             recipe_name,
00531             CRIRES_WL_MAP_IMA,
00532             CRIRES_PROTYPE_WL_MAP,
00533             crires_spec_wavecal_config.period,
00534             NULL,
00535             (const cpl_propertylist **)qclists,
00536             PACKAGE "/" PACKAGE_VERSION,
00537             "crires_spec_wavecal_ima.fits") ;
00538 
00539     if (ilist_model != NULL) {
00540         /* Write the image */
00541         crires_image_save(set,
00542                 parlist,
00543                 set,
00544                 ilist_model,
00545                 recipe_name,
00546                 CRIRES_WL_MAP_MODEL_IMA,
00547                 CRIRES_PROTYPE_WL_MAP,
00548                 crires_spec_wavecal_config.period,
00549                 NULL,
00550                 (const cpl_propertylist **)qclists,
00551                 PACKAGE "/" PACKAGE_VERSION,
00552                 "crires_spec_wavecal_ima_model.fits") ;
00553     }
00554 
00555     /* Write the table */
00556     crires_table_save(set,
00557             parlist,
00558             set, 
00559             wl_tab, 
00560             recipe_name,
00561             CRIRES_CALPRO_WAVE, 
00562             CRIRES_PROTYPE_WL_POLY,
00563             NULL,
00564             (const cpl_propertylist **)qclists, 
00565             PACKAGE "/" PACKAGE_VERSION,
00566             "crires_spec_wavecal_tab.fits") ;
00567 
00568     /* Free and return */
00569     for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00570         cpl_propertylist_delete(qclists[i]) ;
00571     }
00572     cpl_free(qclists) ;
00573     return  0;
00574 }

Generated on 25 Sep 2012 for CRIRES Pipeline Reference Manual by  doxygen 1.6.1