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_convert"
00043
00044
00045
00046
00047
00048 static int crires_util_convert_save(cpl_imagelist **,
00049 const cpl_parameterlist *, cpl_frameset *) ;
00050
00051 static char crires_util_convert_description[] =
00052 "This recipe accepts 3 files (produced by crires_spec_detlin):\n"
00053 "First parameter: the image with the A coefficients.\n"
00054 "Second parameter: the image with the B coefficients.\n"
00055 "Third parameter: the image with the C coefficients.\n"
00056 "\n"
00057 "This recipe produces 1 file:\n"
00058 "First parameter: the file with the detlin coefficients.\n"
00059 " (PRO TYPE = "CRIRES_PROTYPE_COEFFS_CUBE")\n" ;
00060
00061 CRIRES_RECIPE_DEFINE(crires_util_convert,
00062 0,
00063 "Convert the detlin coefficients",
00064 crires_util_convert_description) ;
00065
00066
00067
00068
00069
00070
00077
00078 static int crires_util_convert(
00079 cpl_frameset * frameset,
00080 const cpl_parameterlist * parlist)
00081 {
00082 cpl_imagelist ** coeffs ;
00083 cpl_frame * fr[3] ;
00084 cpl_image * cur_ima ;
00085 int i, j ;
00086
00087
00088
00089
00090 if (crires_dfs_set_groups(frameset, NULL)) {
00091 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00092 return -1 ;
00093 }
00094
00095
00096 if (cpl_frameset_get_size(frameset) != 3) {
00097 cpl_msg_error(__func__, "Expects 3 file in input") ;
00098 return -1 ;
00099 }
00100 fr[0] = cpl_frameset_get_frame(frameset, 0);
00101 fr[1] = cpl_frameset_get_frame(frameset, 1);
00102 fr[2] = cpl_frameset_get_frame(frameset, 2);
00103
00104
00105 coeffs = cpl_malloc(CRIRES_NB_DETECTORS * sizeof(cpl_imagelist*)) ;
00106 for (i=0 ; i<CRIRES_NB_DETECTORS; i++)
00107 coeffs[i] = cpl_imagelist_new() ;
00108
00109
00110 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00111 cpl_msg_info(__func__, "Get the coefficients for chip number %d", i+1) ;
00112
00113 if ((cur_ima = cpl_image_load(cpl_frame_get_filename(fr[0]),
00114 CPL_TYPE_FLOAT, 0, i+1)) == NULL) {
00115 cpl_msg_error(__func__, "Cannot load ext %d", i+1) ;
00116 for (j=0 ; j<CRIRES_NB_DETECTORS; j++)
00117 cpl_imagelist_delete(coeffs[j]) ;
00118 cpl_free(coeffs) ;
00119 return -1 ;
00120 }
00121 cpl_imagelist_set(coeffs[i], cur_ima, 0) ;
00122
00123
00124 if ((cur_ima = cpl_image_load(cpl_frame_get_filename(fr[1]),
00125 CPL_TYPE_FLOAT, 0, i+1)) == NULL) {
00126 cpl_msg_error(__func__, "Cannot load ext %d", i+1) ;
00127 for (j=0 ; j<CRIRES_NB_DETECTORS; j++)
00128 cpl_imagelist_delete(coeffs[j]) ;
00129 cpl_free(coeffs) ;
00130 return -1 ;
00131 }
00132 cpl_imagelist_set(coeffs[i], cur_ima, 1) ;
00133
00134
00135 if ((cur_ima = cpl_image_load(cpl_frame_get_filename(fr[2]),
00136 CPL_TYPE_FLOAT, 0, i+1)) == NULL) {
00137 cpl_msg_error(__func__, "Cannot load ext %d", i+1) ;
00138 for (j=0 ; j<CRIRES_NB_DETECTORS ; j++)
00139 cpl_imagelist_delete(coeffs[j]) ;
00140 cpl_free(coeffs) ;
00141 return -1 ;
00142 }
00143 cpl_imagelist_set(coeffs[i], cur_ima, 2) ;
00144 }
00145
00146
00147 cpl_msg_info(__func__, "Save the products") ;
00148 cpl_msg_indent_more() ;
00149 if (crires_util_convert_save(coeffs, parlist, frameset)==-1) {
00150 cpl_msg_error(__func__, "Cannot save the products") ;
00151 for (j=0 ; j<CRIRES_NB_DETECTORS; j++) cpl_imagelist_delete(coeffs[j]) ;
00152 cpl_free(coeffs) ;
00153 cpl_msg_indent_less() ;
00154 return -1 ;
00155 }
00156 cpl_msg_indent_less() ;
00157
00158
00159 for (i=0 ; i<CRIRES_NB_DETECTORS; i++) cpl_imagelist_delete(coeffs[i]) ;
00160 cpl_free(coeffs) ;
00161 if (cpl_error_get_code()) return -1 ;
00162 else return 0 ;
00163 }
00164
00165
00173
00174 static int crires_util_convert_save(
00175 cpl_imagelist ** coeffs,
00176 const cpl_parameterlist * parlist,
00177 cpl_frameset * set)
00178 {
00179 const char * recipe_name = "crires_util_convert" ;
00180 cpl_propertylist * pro_list ;
00181 cpl_propertylist * qc_ext_list ;
00182 char sval[16] ;
00183 char * filename ;
00184 int i ;
00185
00186
00187 filename = cpl_sprintf("crires_util_convert.fits") ;
00188
00189
00190 pro_list = cpl_propertylist_new() ;
00191 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_CATG,
00192 CRIRES_CALPRO_COEFFS_CUBE) ;
00193 cpl_propertylist_append_string(pro_list, CPL_DFS_PRO_TYPE,
00194 CRIRES_PROTYPE_COEFFS_CUBE) ;
00195
00196
00197 if (cpl_dfs_save_image(set, NULL, parlist, set, NULL, NULL,
00198 CPL_BPP_IEEE_FLOAT, recipe_name, pro_list, NULL,
00199 PACKAGE "/" PACKAGE_VERSION, filename) != CPL_ERROR_NONE) {
00200 cpl_msg_error(__func__, "Cannot save the empty primary HDU") ;
00201 cpl_propertylist_delete(pro_list) ;
00202 cpl_free(filename) ;
00203 return -1 ;
00204 }
00205
00206 cpl_propertylist_delete(pro_list) ;
00207
00208
00209 for (i=0 ; i<CRIRES_NB_DETECTORS ; i++) {
00210
00211 qc_ext_list = cpl_propertylist_new() ;
00212 sprintf(sval, "CHIP%d.INT1", i+1) ;
00213 cpl_propertylist_prepend_string(qc_ext_list, "EXTNAME", sval) ;
00214 cpl_imagelist_save(coeffs[i],
00215 filename, CPL_BPP_IEEE_FLOAT, qc_ext_list, CPL_IO_EXTEND) ;
00216 cpl_propertylist_delete(qc_ext_list) ;
00217 }
00218 cpl_free(filename) ;
00219 return 0;
00220 }
00221