41 #include <irplib_utils.h>
43 #include <sinfo_tpl_utils.h>
44 #include <sinfo_pfits.h>
45 #include <sinfo_tpl_dfs.h>
46 #include <sinfo_key_names.h>
47 #include <sinfo_pro_types.h>
48 #include <sinfo_functions.h>
49 #include <sinfo_msg.h>
50 #include <sinfo_error.h>
51 #include <sinfo_utils_wrappers.h>
57 static int sinfo_utl_table_ex_create(cpl_plugin *) ;
58 static int sinfo_utl_table_ex_exec(cpl_plugin *) ;
59 static int sinfo_utl_table_ex_destroy(cpl_plugin *) ;
60 static int sinfo_utl_table_ex(cpl_parameterlist *, cpl_frameset *) ;
66 static char sinfo_utl_table_ex_description[] =
67 "This recipe produce a table,\n";
77 static char RECIPE_NAME[] =
"sinfoni.sinfo_utl_table_ex";
78 static char CLMN_NAME_SPECTRUM[] =
"spectrum";
79 static char CLMN_NAME_WAVELENGTH[] =
"wavelength";
80 static char CLMN_NAME_BKG_TOT[] =
"bkg_tot";
81 static char CLMN_NAME_COUNTS_BKG[] =
"counts_bkg";
103 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe ) ;
104 cpl_plugin * plugin = &recipe->interface ;
106 cpl_plugin_init(plugin,
108 SINFONI_BINARY_VERSION,
109 CPL_PLUGIN_TYPE_RECIPE,
110 "sinfo_utl_table_ex",
111 "Test example shows table manipulating utilities",
112 sinfo_utl_table_ex_description,
116 sinfo_utl_table_ex_create,
117 sinfo_utl_table_ex_exec,
118 sinfo_utl_table_ex_destroy) ;
120 cpl_pluginlist_append(list, plugin) ;
135 static int sinfo_utl_table_ex_create(cpl_plugin * plugin)
137 cpl_recipe * recipe ;
141 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
142 recipe = (cpl_recipe *)plugin ;
148 recipe->parameters = cpl_parameterlist_new() ;
176 static int sinfo_utl_table_ex_exec(cpl_plugin * plugin)
178 cpl_recipe * recipe ;
180 cpl_errorstate initial_errorstate = cpl_errorstate_get();
183 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
184 recipe = (cpl_recipe *)plugin ;
188 code = sinfo_utl_table_ex(recipe->parameters, recipe->frames) ;
191 if (!cpl_errorstate_is_equal(initial_errorstate)) {
194 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
207 static int sinfo_utl_table_ex_destroy(cpl_plugin * plugin)
209 cpl_recipe * recipe ;
212 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
213 recipe = (cpl_recipe *)plugin ;
216 cpl_parameterlist_delete(recipe->parameters) ;
229 sinfo_utl_table_ex( cpl_parameterlist * parlist,
230 cpl_frameset * framelist)
233 double range_min = 1.9;
234 double range_max = 2.;
237 const char * name_o = NULL ;
238 const char * sourceTableName = NULL;
241 cpl_propertylist * plist = NULL ;
242 cpl_frame * product_frame = NULL;
244 cpl_table * tblSource = NULL;
245 cpl_table * tblResult = NULL;
246 float * pValues = NULL;
248 sinfo_msg(
"Welcome to SINFONI Pipeline release %d.%d.%d",
249 SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
250 ck0(sinfo_dfs_set_groups(framelist),
"Cannot indentify RAW and CALIB frames");
262 check(plist=cpl_propertylist_new(),
"Cannot create a Property List");
268 cpl_frameset_iterator* it = cpl_frameset_iterator_new(framelist);
269 cpl_frame *product_frame = cpl_frameset_iterator_get(it);
271 check(sourceTableName = cpl_frame_get_filename(product_frame),
"Cannot get source table name");
272 check_nomsg(tblSource = cpl_table_load(sourceTableName, 1, 0));
275 check(tblResult = cpl_table_duplicate(tblSource),
"cannot duplicate table");
277 check_nomsg(nrow = cpl_table_get_nrow(tblResult));
278 sinfo_msg(
"%d rows in the source table", nrow);
283 check_nomsg(pValues = cpl_table_get_data_float(tblResult, CLMN_NAME_WAVELENGTH));
284 sinfo_msg(
"checking wavelenghts...");
285 check(cpl_table_unselect_all(tblResult),
"cannot unselect all");
286 for (i = 0; i < nrow; ++i)
288 if ((*(pValues + i) < range_min) || (*(pValues + i) > range_max))
291 check(cpl_table_select_row(tblResult, i),
"Cannot select a row in a table");
295 sinfo_msg(
"%d row(s) would be removed from the result", m);
297 check(cpl_table_erase_selected(tblResult),
"Cannot delete selected rows from a table");
301 check(cpl_table_duplicate_column(tblResult,CLMN_NAME_SPECTRUM, tblResult, CLMN_NAME_BKG_TOT),
"Unable to create new column in the table");
302 check(cpl_table_add_columns(tblResult, CLMN_NAME_SPECTRUM, CLMN_NAME_COUNTS_BKG),
"Error during sum the columns");
305 name_o =
"ima_res.fits" ;
308 check_nomsg(product_frame = cpl_frame_new());
309 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
310 check_nomsg(cpl_frame_set_tag(product_frame,
"table_example" )) ;
311 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
312 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
313 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
314 "Error while initialising the product frame") ;
317 check_nomsg(cpl_propertylist_erase_regexp(plist,
"^ESO PRO CATG",0));
319 check(cpl_dfs_setup_product_header(plist,
323 "sinfo_utl_table_ex",
325 KEY_VALUE_HPRO_DID,NULL),
326 "Problem in the product DFS-compliance") ;
330 cpl_table_dump(tblResult, 0, 3, stdout);
331 check(cpl_table_save(tblResult,
334 CPL_IO_DEFAULT),
"Cannot save table");
336 sinfo_free_propertylist(&plist) ;
338 check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
342 cpl_frameset_iterator_delete(it);
343 sinfo_free_propertylist(&plist) ;
344 cpl_table_delete(tblSource);
345 cpl_table_delete(tblResult);
351 return ((cpl_error_get_code()) ? -1 : 0 );
void irplib_reset(void)
Reset IRPLIB state.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.