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 <math.h>
00037 #include <cpl.h>
00038
00039 #include "irplib_utils.h"
00040
00041
00042 #include "sinfo_raw_types.h"
00043 #include "sinfo_pro_types.h"
00044 #include "sinfo_tpl_utils.h"
00045 #include "sinfo_tpl_dfs.h"
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 static int sinfo_utl_seds_create(cpl_plugin *) ;
00058 static int sinfo_utl_seds_exec(cpl_plugin *) ;
00059 static int sinfo_utl_seds_destroy(cpl_plugin *) ;
00060 static int sinfo_utl_seds(cpl_parameterlist *, cpl_frameset *) ;
00061 static int sinfo_utl_seds_save(cpl_table *, cpl_parameterlist *,
00062 cpl_frameset *) ;
00063
00064
00065
00066
00067
00068 static char sinfo_utl_seds_description[] =
00069 "sinfo_utl_seds -- SINFONI SEDS table creation.\n"
00070 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00071 "raw-file.fits "SINFO_UTL_SEDS_RAW"\n" ;
00072
00073
00074
00075
00076
00077
00085
00086 int cpl_plugin_get_info(cpl_pluginlist * list)
00087 {
00088 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe)) ;
00089 cpl_plugin * plugin = &recipe->interface ;
00090
00091 cpl_plugin_init(plugin,
00092 CPL_PLUGIN_API,
00093 SINFONI_BINARY_VERSION,
00094 CPL_PLUGIN_TYPE_RECIPE,
00095 "sinfo_utl_seds",
00096 "SEDS table creation",
00097 sinfo_utl_seds_description,
00098 "Yves Jung",
00099 "yjung@eso.org",
00100 sinfo_get_license(),
00101 sinfo_utl_seds_create,
00102 sinfo_utl_seds_exec,
00103 sinfo_utl_seds_destroy) ;
00104
00105 cpl_pluginlist_append(list, plugin) ;
00106
00107 return 0;
00108 }
00109
00110
00119
00120 static int sinfo_utl_seds_create(cpl_plugin * plugin)
00121 {
00122 cpl_recipe * recipe ;
00123
00124
00125 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00126 recipe = (cpl_recipe *)plugin ;
00127 else return -1 ;
00128
00129
00130 recipe->parameters = cpl_parameterlist_new() ;
00131
00132
00133 return 0;
00134 }
00135
00136
00142
00143 static int sinfo_utl_seds_exec(cpl_plugin * plugin)
00144 {
00145 cpl_recipe * recipe ;
00146
00147
00148 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00149 recipe = (cpl_recipe *)plugin ;
00150 else return -1 ;
00151
00152 return sinfo_utl_seds(recipe->parameters, recipe->frames) ;
00153 }
00154
00155
00161
00162 static int sinfo_utl_seds_destroy(cpl_plugin * plugin)
00163 {
00164 cpl_recipe * recipe ;
00165
00166
00167 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00168 recipe = (cpl_recipe *)plugin ;
00169 else return -1 ;
00170
00171 cpl_parameterlist_delete(recipe->parameters) ;
00172 return 0 ;
00173 }
00174
00175
00182
00183 static int sinfo_utl_seds(
00184 cpl_parameterlist * parlist,
00185 cpl_frameset * framelist)
00186 {
00187 cpl_frame * cur_frame ;
00188 cpl_frameset * rawframes ;
00189 int nframes, nlines ;
00190 cpl_table * out ;
00191 cpl_bivector ** seds ;
00192 char * name ;
00193 cpl_vector * tmp_vec ;
00194 int i, j ;
00195
00196
00197 if (sinfo_dfs_set_groups(framelist)) {
00198 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00199 return -1 ;
00200 }
00201
00202
00203 if ((rawframes = sinfo_extract_frameset(framelist,
00204 SINFO_UTL_SEDS_RAW)) == NULL) {
00205 cpl_msg_error(__func__, "Cannot find raw frames in the input list") ;
00206 return -1 ;
00207 }
00208 nframes = cpl_frameset_get_size(rawframes) ;
00209
00210
00211 seds = cpl_malloc(nframes * sizeof(cpl_bivector*)) ;
00212 for (i=0 ; i<nframes ; i++) {
00213 cur_frame = cpl_frameset_get_frame(rawframes, i) ;
00214 if ((seds[i] = cpl_bivector_read(cpl_frame_get_filename(cur_frame)))
00215 == NULL) {
00216 cpl_msg_error(__func__, "Cannot load the sed %d", i+1) ;
00217 for (j=0 ; j<i ; j++) cpl_bivector_delete(seds[j]) ;
00218 cpl_free(seds) ;
00219 cpl_frameset_delete(rawframes) ;
00220 return -1 ;
00221 }
00222 }
00223
00224
00225 nlines = cpl_bivector_get_size(seds[0]) ;
00226 for (i=1 ; i<nframes ; i++) {
00227 if (cpl_bivector_get_size(seds[i]) != nlines) {
00228 cpl_msg_error(__func__, "Wrong SED size abort") ;
00229 for (j=0 ; j<nframes ; j++) cpl_bivector_delete(seds[j]) ;
00230 cpl_free(seds) ;
00231 cpl_frameset_delete(rawframes) ;
00232 return -1 ;
00233 }
00234 }
00235
00236
00237 out = cpl_table_new(nlines) ;
00238 tmp_vec = cpl_vector_duplicate(cpl_bivector_get_x(seds[0])) ;
00239 cpl_table_wrap_double(out, cpl_vector_get_data(tmp_vec), "Wavelength") ;
00240 cpl_vector_unwrap(tmp_vec) ;
00241
00242
00243 for (i=0 ; i<nframes ; i++) {
00244
00245 cur_frame = cpl_frameset_get_frame(rawframes, i) ;
00246 name = cpl_strdup(cpl_frame_get_filename(cur_frame)) ;
00247 name[3] = (char)0 ;
00248 tmp_vec = cpl_vector_duplicate(cpl_bivector_get_y(seds[i])) ;
00249 cpl_table_wrap_double(out, cpl_vector_get_data(tmp_vec), name) ;
00250 cpl_vector_unwrap(tmp_vec) ;
00251 cpl_free(name) ;
00252 }
00253 cpl_frameset_delete(rawframes) ;
00254 cpl_free(seds) ;
00255
00256
00257 if (sinfo_utl_seds_save(out, parlist, framelist) != 0) {
00258 cpl_msg_error(__func__, "Cannot create product") ;
00259 cpl_table_delete(out) ;
00260 return -1 ;
00261 }
00262
00263
00264 cpl_table_delete(out) ;
00265 return 0 ;
00266 }
00267
00268
00276
00277 static int sinfo_utl_seds_save(
00278 cpl_table * sed,
00279 cpl_parameterlist * parlist,
00280 cpl_frameset * set)
00281 {
00282 cpl_propertylist * plist ;
00283
00284
00285 plist = cpl_propertylist_new() ;
00286 cpl_propertylist_append_string(plist, "INSTRUME", "SINFO") ;
00287
00288
00289 cpl_dfs_save_table(set,
00290 parlist,
00291 set,
00292 sed,
00293 NULL,
00294 "sinfo_utl_seds",
00295 SINFO_UTL_SEDS_RES,
00296 plist,
00297 NULL,
00298 PACKAGE "/" PACKAGE_VERSION,
00299 "sinfo_utl_seds.fits") ;
00300
00301 cpl_propertylist_delete(plist) ;
00302
00303 return 0 ;
00304 }
00305
00306