CRIRES Pipeline Reference Manual
2.3.2
|
00001 /* $Id: crires_model_wlmap.c,v 1.35 2011-03-22 09:17:12 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: 2011-03-22 09:17:12 $ 00024 * $Revision: 1.35 $ 00025 * $Name: not supported by cvs2svn $ 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_model_kernel.h" 00039 00040 /*----------------------------------------------------------------------------- 00041 Define 00042 -----------------------------------------------------------------------------*/ 00043 00044 #define RECIPE_STRING "crires_model_wlmap" 00045 00046 /*----------------------------------------------------------------------------- 00047 Functions prototypes 00048 -----------------------------------------------------------------------------*/ 00049 00050 static int crires_model_wlmap_save(const cpl_imagelist *, 00051 const cpl_parameterlist *, cpl_frameset *) ; 00052 00053 static char crires_model_wlmap_description[] = 00054 "crires_model_wlmap -- Wavelength map creation using the model\n" 00055 "The files listed in the Set Of Frames (sof-file) must be tagged:\n" 00056 "raw-file.fits "CRIRES_MODEL_WLMAP_RAW" or\n" 00057 "config-file.fits "CRIRES_CALPRO_MODEL_CONFIG" or\n" 00058 "config-file.fits "CRIRES_CALPRO_MODEL_REFINE_CONF".\n" ; 00059 00060 CRIRES_RECIPE_DEFINE(crires_model_wlmap, 00061 CRIRES_PARAM_ORDER, 00062 "Model wavelength map recipe", 00063 crires_model_wlmap_description) ; 00064 00065 /*----------------------------------------------------------------------------- 00066 Static variables 00067 -----------------------------------------------------------------------------*/ 00068 00069 static struct { 00070 /* Inputs */ 00071 int order ; 00072 /* Outputs */ 00073 crires_illum_period period ; 00074 } crires_model_wlmap_config ; 00075 00076 /*----------------------------------------------------------------------------- 00077 Functions code 00078 -----------------------------------------------------------------------------*/ 00079 00080 /*----------------------------------------------------------------------------*/ 00087 /*----------------------------------------------------------------------------*/ 00088 static int crires_model_wlmap( 00089 cpl_frameset * frameset, 00090 const cpl_parameterlist * parlist) 00091 { 00092 cpl_frameset * rawframes ; 00093 const char * config ; 00094 cpl_frame * ref_frame ; 00095 cpl_imagelist * wlmap ; 00096 //cpl_vector * profile ; 00097 00098 /* The Model is switched off */ 00099 if (crires_model_off()) { 00100 return 0 ; 00101 } 00102 00103 /* Initialise */ 00104 rawframes = NULL ; 00105 00106 /* Retrieve input parameters */ 00107 crires_model_wlmap_config.order = crires_parameterlist_get_int(parlist, 00108 RECIPE_STRING, CRIRES_PARAM_ORDER) ; 00109 00110 /* Identify the RAW and CALIB frames in the input frameset */ 00111 if (crires_dfs_set_groups(frameset, "crires_model_wlmap")) { 00112 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ; 00113 return -1 ; 00114 } 00115 00116 /* Retrieve calibration data */ 00117 config = crires_extract_filename(frameset, CRIRES_CALPRO_MODEL_CONFIG) ; 00118 if (config == NULL) { 00119 config = crires_extract_filename(frameset, 00120 CRIRES_CALPRO_MODEL_REFINE_CONF) ; 00121 } 00122 if (config == NULL) { 00123 cpl_msg_error(__func__, "No config file in input") ; 00124 return -1 ; 00125 } 00126 00127 /* Retrieve raw frames */ 00128 if ((rawframes = crires_extract_frameset(frameset, 00129 CRIRES_MODEL_WLMAP_RAW)) == NULL) { 00130 cpl_msg_error(__func__, "No raw frame in input") ; 00131 return -1 ; 00132 } 00133 ref_frame = cpl_frameset_get_position(rawframes, 0) ; 00134 00135 /* Check the model config file validity vs. the current data */ 00136 if (crires_model_config_check(config, 00137 cpl_frame_get_filename(ref_frame)) != 0) { 00138 cpl_msg_error(__func__, 00139 "The model configuration file version is wrong") ; 00140 cpl_frameset_delete(rawframes) ; 00141 return -1 ; 00142 } 00143 00144 /* Get the detector illumination period */ 00145 crires_model_wlmap_config.period = 00146 crires_get_detector_illum_period(cpl_frame_get_filename(ref_frame)) ; 00147 if (crires_model_wlmap_config.period == CRIRES_ILLUM_UNKNOWN) { 00148 cpl_msg_error(__func__, 00149 "Cannot determine the detector illumination period") ; 00150 cpl_frameset_delete(rawframes) ; 00151 return -1 ; 00152 } else { 00153 crires_display_detector_illum(crires_model_wlmap_config.period) ; 00154 } 00155 00156 /* if ((profile=crires_model_profile(cpl_frame_get_filename(ref_frame), 00157 config, -1, 00158 1000.0)) == NULL) { 00159 cpl_msg_error(__func__, "Cannot compute the profile") ; 00160 cpl_frameset_delete(rawframes) ; 00161 return -1 ; 00162 } 00163 if ((line_list=crires_model_predict(cpl_frame_get_filename(ref_frame), 00164 "ThAr_use.fits", 00165 config,-1)) == NULL) { 00166 cpl_msg_error(__func__, "cannot predict the line positions") ; 00167 cpl_frameset_delete(rawframes) ; 00168 return -1 ; 00169 } 00170 int ii=0; 00171 while (line_list[0][ii]!=0.0) { 00172 printf("here %lf %lf %lf %lf %lf %lf \n",line_list[0][ii],line_list[1][ii],line_list[2][ii],line_list[3][ii],line_list[4][ii],line_list[5][ii]); 00173 ii+=1; 00174 } 00175 crires_model_free2Darray(line_list,6); 00176 cpl_vector_delete(profile); 00177 */ 00178 00179 /* Compute the wavelength map */ 00180 if ((wlmap = crires_model_wavpix(cpl_frame_get_filename(ref_frame), 00181 config, crires_model_wlmap_config.order)) == NULL) { 00182 cpl_msg_error(__func__, "Cannot compute the WL map") ; 00183 cpl_frameset_delete(rawframes) ; 00184 return -1 ; 00185 } 00186 cpl_frameset_delete(rawframes) ; 00187 00188 /* Save the product */ 00189 if (crires_model_wlmap_save(wlmap, parlist, frameset) == -1) { 00190 cpl_msg_error(__func__, "Cannot save products") ; 00191 cpl_imagelist_delete(wlmap) ; 00192 return -1 ; 00193 } 00194 cpl_imagelist_delete(wlmap) ; 00195 00196 /* Return */ 00197 if (cpl_error_get_code()) return -1 ; 00198 else return 0 ; 00199 } 00200 00201 /*----------------------------------------------------------------------------*/ 00209 /*----------------------------------------------------------------------------*/ 00210 static int crires_model_wlmap_save( 00211 const cpl_imagelist * wlmap, 00212 const cpl_parameterlist * parlist, 00213 cpl_frameset * set) 00214 { 00215 const char * recipe_name = "crires_model_wlmap" ; 00216 00217 /* Write the flat image */ 00218 crires_image_save(set, 00219 parlist, 00220 set, 00221 wlmap, 00222 recipe_name, 00223 CRIRES_WL_MAP_MODEL_IMA, 00224 CRIRES_PROTYPE_WL_MAP, 00225 crires_model_wlmap_config.period, 00226 NULL, 00227 NULL, 00228 PACKAGE "/" PACKAGE_VERSION, 00229 "crires_model_wlmap.fits") ; 00230 00231 return 0; 00232 }