crires_util_genypos.c
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_genypos"
00043
00044
00045
00046
00047
00048 static int crires_util_genypos_save(cpl_table *, const cpl_parameterlist *,
00049 cpl_frameset *);
00050
00051 static char crires_util_genypos_description[] =
00052 "This recipe is used to generate the FITS table with the Y positions.\n"
00053 "The sof file contains the names of the input ASCII file\n"
00054 "tagged with "CRIRES_UTIL_GENYPOS_RAW".\n"
00055 "The ASCII file must contain two columns:\n"
00056 "1st: Chip Number\n"
00057 "2nd: Y Position\n"
00058 "The ASCII file is in the catalogs/ directory of the CRIRES distribution.\n"
00059 "This recipe produces 1 file:\n"
00060 "First product: the table with the positions.\n"
00061 " (PRO TYPE = "CRIRES_PROTYPE_YPOS")\n" ;
00062
00063 CRIRES_RECIPE_DEFINE(crires_util_genypos, 0,
00064 "Generate Y Positions FITS table",
00065 crires_util_genypos_description) ;
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00084
00085 static int crires_util_genypos(
00086 cpl_frameset * framelist,
00087 const cpl_parameterlist * parlist)
00088 {
00089 cpl_bivector * bivec ;
00090 double * pbivec_x ;
00091 double * pbivec_y ;
00092 cpl_bivector * bivec_fill ;
00093 double * pbivec_fill_x ;
00094 double * pbivec_fill_y ;
00095 cpl_frame * cur_frame ;
00096 int nvals, nb_new_vals ;
00097 double wavel ;
00098 cpl_table * tab ;
00099 int i ;
00100
00101
00102 if (crires_dfs_set_groups(framelist, NULL)) {
00103 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00104 return -1 ;
00105 }
00106
00107
00108 cur_frame = cpl_frameset_get_frame(framelist, 0) ;
00109 if ((bivec=cpl_bivector_read(cpl_frame_get_filename(cur_frame)))==NULL) {
00110 cpl_msg_error(__func__, "Cannot load the file in the bivector") ;
00111 return -1 ;
00112 }
00113 nvals = cpl_bivector_get_size(bivec) ;
00114
00115
00116 tab = cpl_table_new(nvals) ;
00117 cpl_table_wrap_double(tab, cpl_bivector_get_x_data(bivec),
00118 CRIRES_CHIP_NB) ;
00119 cpl_table_wrap_double(tab, cpl_bivector_get_y_data(bivec),
00120 CRIRES_COL_DETPOSY) ;
00121
00122
00123 cpl_msg_info(__func__, "Saving the table with %d rows", nvals) ;
00124 if (crires_util_genypos_save(tab, parlist, framelist) == -1) {
00125 cpl_msg_error(__func__, "Cannot write the table") ;
00126 cpl_bivector_delete(bivec) ;
00127 cpl_table_unwrap(tab, CRIRES_CHIP_NB) ;
00128 cpl_table_unwrap(tab, CRIRES_COL_DETPOSY) ;
00129 cpl_table_delete(tab) ;
00130 return -1 ;
00131 }
00132 cpl_bivector_delete(bivec) ;
00133 cpl_table_unwrap(tab, CRIRES_CHIP_NB) ;
00134 cpl_table_unwrap(tab, CRIRES_COL_DETPOSY) ;
00135 cpl_table_delete(tab) ;
00136 return 0 ;
00137 }
00138
00139
00147
00148 static int crires_util_genypos_save(
00149 cpl_table * out_table,
00150 const cpl_parameterlist * parlist,
00151 cpl_frameset * set)
00152 {
00153 cpl_propertylist * plist ;
00154
00155 plist = cpl_propertylist_new();
00156 cpl_propertylist_append_string(plist, "INSTRUME", "CRIRES") ;
00157 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG,
00158 CRIRES_CALPRO_THAR_POS) ;
00159 cpl_propertylist_append_string(plist, CPL_DFS_PRO_TYPE,
00160 CRIRES_PROTYPE_YPOS) ;
00161
00162 if (cpl_dfs_save_table(set, NULL, parlist, set, NULL, out_table,
00163 NULL, "crires_util_genypos", plist, NULL,
00164 PACKAGE "/" PACKAGE_VERSION,
00165 "crires_util_genypos.fits") != CPL_ERROR_NONE) {
00166 cpl_msg_error(__func__, "Cannot save the table") ;
00167 return -1 ;
00168 }
00169 cpl_propertylist_delete(plist) ;
00170
00171
00172 return 0 ;
00173 }