00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include "crires_recipe.h"
00037
00038
00039
00040
00041
00042 #define RECIPE_STRING "crires_util_genlines"
00043
00044
00045
00046
00047
00048 static int crires_util_genlines_save(cpl_table *, const cpl_parameterlist *,
00049 cpl_frameset *);
00050
00051 static char crires_util_genlines_description[] =
00052 "This recipe is used to generate spectrum calibration tables.\n"
00053 "The sof file contains the names of the input ASCII file\n"
00054 "tagged with "CRIRES_UTIL_GENLINES_RAW".\n"
00055 "The ASCII file must contain two columns:\n"
00056 "1st: Wavelengths in increasing order (the unit is corrected by\n"
00057 " the factor option to obtain nanometers).\n"
00058 "2nd: The atmospheric emission.\n"
00059 "The ASCII files are in the catalogs/ directory of the CRIRES distribution.\n"
00060 "This recipe produces 1 file:\n"
00061 "First product: the table with the lines.\n"
00062 " (PRO TYPE = "CRIRES_PROTYPE_CATALOG")\n" ;
00063
00064 CRIRES_RECIPE_DEFINE(crires_util_genlines,
00065 CRIRES_PARAM_FILL_BLANKS |
00066 CRIRES_PARAM_PLOT |
00067 CRIRES_PARAM_LINES_MODE |
00068 CRIRES_PARAM_WL_FACTOR,
00069 "Generate spectrum calibration FITS tables",
00070 crires_util_genlines_description) ;
00071
00072
00073
00074
00075
00076 static struct {
00077
00078 int fill_blanks ;
00079 int display ;
00080 int mode ;
00081 double wl_factor ;
00082
00083 } crires_util_genlines_config ;
00084
00085
00086
00087
00088
00089
00098
00099 static int crires_util_genlines(
00100 cpl_frameset * framelist,
00101 const cpl_parameterlist * parlist)
00102 {
00103 cpl_bivector * bivec ;
00104 double * pbivec_x ;
00105 double * pbivec_y ;
00106 cpl_bivector * bivec_fill ;
00107 double * pbivec_fill_x ;
00108 double * pbivec_fill_y ;
00109 cpl_frame * cur_frame ;
00110 int nvals, nb_new_vals ;
00111 double wavel ;
00112 cpl_table * tab ;
00113 int i ;
00114
00115
00116 crires_util_genlines_config.fill_blanks = crires_parameterlist_get_bool(
00117 parlist, RECIPE_STRING, CRIRES_PARAM_FILL_BLANKS) ;
00118 crires_util_genlines_config.display = crires_parameterlist_get_bool(
00119 parlist, RECIPE_STRING, CRIRES_PARAM_PLOT) ;
00120 crires_util_genlines_config.mode = crires_parameterlist_get_int(
00121 parlist, RECIPE_STRING, CRIRES_PARAM_LINES_MODE) ;
00122 crires_util_genlines_config.wl_factor = crires_parameterlist_get_double(
00123 parlist, RECIPE_STRING, CRIRES_PARAM_WL_FACTOR) ;
00124
00125
00126 if (crires_dfs_set_groups(framelist, NULL)) {
00127 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00128 return -1 ;
00129 }
00130
00131
00132 cur_frame = cpl_frameset_get_frame(framelist, 0) ;
00133 if ((bivec=cpl_bivector_read(cpl_frame_get_filename(cur_frame)))==NULL) {
00134 cpl_msg_error(__func__, "Cannot load the file in the bivector") ;
00135 return -1 ;
00136 }
00137 nvals = cpl_bivector_get_size(bivec) ;
00138
00139
00140 if (crires_util_genlines_config.fill_blanks) {
00141 nb_new_vals = 3 * nvals ;
00142 bivec_fill = cpl_bivector_new(nb_new_vals) ;
00143 pbivec_fill_x = cpl_bivector_get_x_data(bivec_fill) ;
00144 pbivec_fill_y = cpl_bivector_get_y_data(bivec_fill) ;
00145 pbivec_x = cpl_bivector_get_x_data(bivec) ;
00146 pbivec_y = cpl_bivector_get_y_data(bivec) ;
00147 for (i=0 ; i<nvals ; i++) {
00148 wavel = pbivec_x[i] * crires_util_genlines_config.wl_factor ;
00149 pbivec_fill_x[3*i] = wavel - 0.01 ;
00150 pbivec_fill_y[3*i] = 0.0 ;
00151 pbivec_fill_x[3*i+1] = wavel ;
00152 pbivec_fill_y[3*i+1] = pbivec_y[i] ;
00153 pbivec_fill_x[3*i+2] = wavel + 0.01 ;
00154 pbivec_fill_y[3*i+2] = 0.0 ;
00155 }
00156 cpl_bivector_delete(bivec);
00157 bivec = bivec_fill ;
00158 bivec_fill = NULL ;
00159 nvals = cpl_bivector_get_size(bivec) ;
00160 } else {
00161 cpl_vector_multiply_scalar(cpl_bivector_get_x(bivec),
00162 crires_util_genlines_config.wl_factor) ;
00163 }
00164
00165
00166 if (crires_util_genlines_config.display) {
00167 irplib_bivector_plot(
00168 "set grid;set xlabel 'Wavelength (nm)';set ylabel 'Emission';",
00169 "t 'Catalog lines' w lines", "", bivec);
00170 }
00171
00172
00173 tab = cpl_table_new(nvals) ;
00174 cpl_table_wrap_double(tab, cpl_bivector_get_x_data(bivec),
00175 CRIRES_COL_WAVELENGTH) ;
00176 cpl_table_wrap_double(tab, cpl_bivector_get_y_data(bivec),
00177 CRIRES_COL_EMISSION) ;
00178
00179
00180 cpl_msg_info(__func__, "Saving the table with %d rows", nvals) ;
00181 if (crires_util_genlines_save(tab, parlist, framelist) == -1) {
00182 cpl_msg_error(__func__, "Cannot write the table") ;
00183 cpl_bivector_delete(bivec) ;
00184 cpl_table_unwrap(tab, CRIRES_COL_WAVELENGTH) ;
00185 cpl_table_unwrap(tab, CRIRES_COL_EMISSION) ;
00186 cpl_table_delete(tab) ;
00187 return -1 ;
00188 }
00189 cpl_bivector_delete(bivec) ;
00190 cpl_table_unwrap(tab, CRIRES_COL_WAVELENGTH) ;
00191 cpl_table_unwrap(tab, CRIRES_COL_EMISSION) ;
00192 cpl_table_delete(tab) ;
00193 return 0 ;
00194 }
00195
00196
00204
00205 static int crires_util_genlines_save(
00206 cpl_table * out_table,
00207 const cpl_parameterlist * parlist,
00208 cpl_frameset * set)
00209 {
00210 cpl_propertylist * plist ;
00211 const char * procat ;
00212
00213 if (crires_util_genlines_config.mode == 1)
00214 procat = CRIRES_CALPRO_HITRAN_CAT ;
00215 else if (crires_util_genlines_config.mode == 2)
00216 procat = CRIRES_CALPRO_OH_CAT ;
00217 else if (crires_util_genlines_config.mode == 3)
00218 procat = CRIRES_CALPRO_THAR_CAT ;
00219 else if (crires_util_genlines_config.mode == 4)
00220 procat = CRIRES_CALPRO_N2O_CAT ;
00221 else if (crires_util_genlines_config.mode == 5)
00222 procat = CRIRES_CALPRO_MODEL_WAVEEG ;
00223 else
00224 procat = "UNKNOWN" ;
00225
00226 plist = cpl_propertylist_new();
00227 cpl_propertylist_append_string(plist, "INSTRUME", "CRIRES") ;
00228 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG, procat) ;
00229 cpl_propertylist_append_string(plist, CPL_DFS_PRO_TYPE,
00230 CRIRES_PROTYPE_CATALOG) ;
00231
00232 if (cpl_dfs_save_table(set, NULL, parlist, set, NULL, out_table,
00233 NULL, "crires_util_genlines", plist, NULL,
00234 PACKAGE "/" PACKAGE_VERSION,
00235 "crires_util_genlines.fits") != CPL_ERROR_NONE) {
00236 cpl_msg_error(__func__, "Cannot save the table") ;
00237 return -1 ;
00238 }
00239 cpl_propertylist_delete(plist) ;
00240
00241
00242 return 0 ;
00243 }