39 #include "irplib_utils.h"
42 #include "sinfo_raw_types.h"
43 #include "sinfo_pro_types.h"
44 #include "sinfo_tpl_utils.h"
45 #include "sinfo_tpl_dfs.h"
57 static int sinfo_utl_seds_create(cpl_plugin *) ;
58 static int sinfo_utl_seds_exec(cpl_plugin *) ;
59 static int sinfo_utl_seds_destroy(cpl_plugin *) ;
60 static int sinfo_utl_seds(cpl_parameterlist *, cpl_frameset *) ;
61 static int sinfo_utl_seds_save(cpl_table *, cpl_parameterlist *,
68 static char sinfo_utl_seds_description[] =
69 "sinfo_utl_seds -- SINFONI SEDS table creation.\n"
70 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
71 "raw-file.fits "SINFO_UTL_SEDS_RAW
"\n" ;
88 cpl_recipe * recipe = cpl_calloc(1,
sizeof(*recipe)) ;
89 cpl_plugin * plugin = &recipe->interface ;
91 cpl_plugin_init(plugin,
93 SINFONI_BINARY_VERSION,
94 CPL_PLUGIN_TYPE_RECIPE,
96 "SEDS table creation",
97 sinfo_utl_seds_description,
101 sinfo_utl_seds_create,
103 sinfo_utl_seds_destroy) ;
105 cpl_pluginlist_append(list, plugin) ;
120 static int sinfo_utl_seds_create(cpl_plugin * plugin)
122 cpl_recipe * recipe ;
125 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
126 recipe = (cpl_recipe *)plugin ;
130 recipe->parameters = cpl_parameterlist_new() ;
143 static int sinfo_utl_seds_exec(cpl_plugin * plugin)
145 cpl_recipe * recipe ;
148 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
149 recipe = (cpl_recipe *)plugin ;
152 return sinfo_utl_seds(recipe->parameters, recipe->frames) ;
162 static int sinfo_utl_seds_destroy(cpl_plugin * plugin)
164 cpl_recipe * recipe ;
167 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
168 recipe = (cpl_recipe *)plugin ;
171 cpl_parameterlist_delete(recipe->parameters) ;
183 static int sinfo_utl_seds(
184 cpl_parameterlist * parlist,
185 cpl_frameset * framelist)
187 cpl_frame * cur_frame ;
188 cpl_frameset * rawframes ;
189 int nframes, nlines ;
191 cpl_bivector ** seds ;
193 cpl_vector * tmp_vec ;
197 if (sinfo_dfs_set_groups(framelist)) {
198 cpl_msg_error(__func__,
"Cannot identify RAW and CALIB frames") ;
203 if ((rawframes = sinfo_extract_frameset(framelist,
204 SINFO_UTL_SEDS_RAW)) == NULL) {
205 cpl_msg_error(__func__,
"Cannot find raw frames in the input list") ;
208 nframes = cpl_frameset_get_size(rawframes) ;
211 seds = cpl_malloc(nframes *
sizeof(cpl_bivector*)) ;
212 for (i=0 ; i<nframes ; i++) {
213 cur_frame = cpl_frameset_get_frame(rawframes, i) ;
214 if ((seds[i] = cpl_bivector_read(cpl_frame_get_filename(cur_frame)))
216 cpl_msg_error(__func__,
"Cannot load the sed %d", i+1) ;
217 for (j=0 ; j<i ; j++) cpl_bivector_delete(seds[j]) ;
219 cpl_frameset_delete(rawframes) ;
225 nlines = cpl_bivector_get_size(seds[0]) ;
226 for (i=1 ; i<nframes ; i++) {
227 if (cpl_bivector_get_size(seds[i]) != nlines) {
228 cpl_msg_error(__func__,
"Wrong SED size abort") ;
229 for (j=0 ; j<nframes ; j++) cpl_bivector_delete(seds[j]) ;
231 cpl_frameset_delete(rawframes) ;
237 out = cpl_table_new(nlines) ;
238 tmp_vec = cpl_vector_duplicate(cpl_bivector_get_x(seds[0])) ;
239 cpl_table_wrap_double(out, cpl_vector_get_data(tmp_vec),
"Wavelength") ;
240 cpl_vector_unwrap(tmp_vec) ;
243 for (i=0 ; i<nframes ; i++) {
245 cur_frame = cpl_frameset_get_frame(rawframes, i) ;
246 char* name = cpl_strdup(cpl_frame_get_filename(cur_frame)) ;
248 tmp_vec = cpl_vector_duplicate(cpl_bivector_get_y(seds[i])) ;
249 cpl_table_wrap_double(out, cpl_vector_get_data(tmp_vec), name) ;
250 cpl_vector_unwrap(tmp_vec) ;
253 cpl_frameset_delete(rawframes) ;
257 if (sinfo_utl_seds_save(out, parlist, framelist) != 0) {
258 cpl_msg_error(__func__,
"Cannot create product") ;
259 cpl_table_delete(out) ;
264 cpl_table_delete(out) ;
277 static int sinfo_utl_seds_save(
279 cpl_parameterlist * parlist,
282 cpl_propertylist * plist ;
285 plist = cpl_propertylist_new() ;
286 cpl_propertylist_append_string(plist,
"INSTRUME",
"SINFO") ;
289 cpl_dfs_save_table(set,
298 PACKAGE
"/" PACKAGE_VERSION,
299 "sinfo_utl_seds.fits") ;
301 cpl_propertylist_delete(plist) ;
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.