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_ima_arith_create(cpl_plugin *) ;
58 static int sinfo_utl_ima_arith_exec(cpl_plugin *) ;
59 static int sinfo_utl_ima_arith_destroy(cpl_plugin *) ;
60 static int sinfo_utl_ima_arith(cpl_parameterlist *, cpl_frameset *) ;
66 static char sinfo_utl_ima_arith_description[] =
67 "This recipe performs image computation.\n"
68 "The input files are 2 images\n"
69 "their associated tags should be IMA.\n"
70 "The output is an image resulting from the IMA op IMA where op indicates\n"
71 "the operation to be performed specified by the parameter \n"
72 "sinfoni.sinfo_utl_ima_arith.op having alias 'op'\n"
96 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe ) ;
97 cpl_plugin * plugin = &recipe->interface ;
99 cpl_plugin_init(plugin,
101 SINFONI_BINARY_VERSION,
102 CPL_PLUGIN_TYPE_RECIPE,
103 "sinfo_utl_ima_arith",
104 "Computes result of ima1 op ima2",
105 sinfo_utl_ima_arith_description,
107 "Andrea.Modigliani@eso.org",
109 sinfo_utl_ima_arith_create,
110 sinfo_utl_ima_arith_exec,
111 sinfo_utl_ima_arith_destroy) ;
113 cpl_pluginlist_append(list, plugin) ;
128 static int sinfo_utl_ima_arith_create(cpl_plugin * plugin)
130 cpl_recipe * recipe ;
134 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
135 recipe = (cpl_recipe *)plugin ;
141 recipe->parameters = cpl_parameterlist_new() ;
145 p = cpl_parameter_new_value(
"sinfoni.sinfo_utl_ima_arith.op",
147 "A possible operation",
148 "sinfoni.sinfo_utl_ima_arith",
"+");
149 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"op") ;
150 cpl_parameterlist_append(recipe->parameters, p) ;
153 p = cpl_parameter_new_value(
"sinfoni.sinfo_utl_ima_arith.value",
154 CPL_TYPE_DOUBLE,
"a value",
"sinfoni.sinfo_utl_ima_arith", 9999.) ;
155 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"value") ;
156 cpl_parameterlist_append(recipe->parameters, p) ;
169 static int sinfo_utl_ima_arith_exec(cpl_plugin * plugin)
171 cpl_recipe * recipe ;
173 cpl_errorstate initial_errorstate = cpl_errorstate_get();
176 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
177 recipe = (cpl_recipe *)plugin ;
181 code = sinfo_utl_ima_arith(recipe->parameters, recipe->frames) ;
184 if (!cpl_errorstate_is_equal(initial_errorstate)) {
187 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
200 static int sinfo_utl_ima_arith_destroy(cpl_plugin * plugin)
202 cpl_recipe * recipe ;
205 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
206 recipe = (cpl_recipe *)plugin ;
209 cpl_parameterlist_delete(recipe->parameters) ;
222 sinfo_utl_ima_arith( cpl_parameterlist * parlist,
223 cpl_frameset * framelist)
225 cpl_parameter * param= NULL ;
226 const char * operation=NULL;
228 cpl_frame * frm_ima1=NULL ;
229 cpl_frame * frm_ima2=NULL ;
230 cpl_image * ima1=NULL ;
231 cpl_image * ima2=NULL ;
233 const char * name_o=NULL ;
234 cpl_propertylist * plist=NULL ;
235 cpl_image * image=NULL ;
236 cpl_frame * product_frame=NULL;
237 cpl_frameset * raw_set=NULL;
240 sinfo_msg(
"Welcome to SINFONI Pipeline release %d.%d.%d",
241 SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
245 check_nomsg(param=cpl_parameterlist_find(parlist,
246 "sinfoni.sinfo_utl_ima_arith.op"));
247 check_nomsg(operation=cpl_parameter_get_string(param));
250 check_nomsg(param=cpl_parameterlist_find(parlist,
251 "sinfoni.sinfo_utl_ima_arith.value"));
252 check_nomsg(value = cpl_parameter_get_double(param)) ;
255 check(sinfo_dfs_set_groups(framelist),
256 "Cannot identify RAW and CALIB frames") ;
259 n=cpl_frameset_get_size(framelist);
266 check_nomsg(raw_set=cpl_frameset_new());
268 check(sinfo_contains_frames_kind(framelist,raw_set,PRO_IMA),
269 "Found no input frames with tag %s",PRO_IMA);
270 check_nomsg(nraw=cpl_frameset_get_size(raw_set));
275 check_nomsg(frm_ima1=cpl_frameset_get_frame(framelist,0));
276 check_nomsg(ima1=cpl_image_load(cpl_frame_get_filename(frm_ima1),
277 CPL_TYPE_FLOAT,0,0));
279 check_nomsg(frm_ima2=cpl_frameset_get_frame(framelist,1));
280 check_nomsg(ima2 = cpl_image_load(cpl_frame_get_filename(frm_ima2),
281 CPL_TYPE_FLOAT,0,0));
283 }
else if (value == 9999.) {
287 sinfo_msg(
"Perform image arithmetics on frame %s",PRO_IMA);
291 sinfo_free_frameset(&raw_set);
294 check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_ima1),0),
295 "Cannot read the FITS header") ;
299 if (value == 9999.) {
301 if(ima1 != NULL && ima2 != NULL) {
302 sinfo_msg(
"ima1 %s ima2",operation);
303 if (strcmp(operation,
"+") == 0 ) {
304 check(image = cpl_image_add_create(ima1, ima2),
305 "Cannot generate the %s image",operation) ;
306 }
else if (strcmp(operation,
"-") == 0 ) {
307 check(image = cpl_image_subtract_create(ima1, ima2),
308 "Cannot generate the %s image",operation) ;
309 }
else if (strcmp(operation,
"*") == 0 ) {
310 check(image = cpl_image_multiply_create(ima1, ima2),
311 "Cannot generate the %s image",operation) ;
312 }
else if (strcmp(operation,
"/") == 0 ) {
313 check(image = cpl_image_divide_create(ima1, ima2),
314 "Cannot generate the %s image",operation) ;
319 sinfo_free_image(&ima1);
320 sinfo_free_image(&ima2);
325 sinfo_msg(
"ima1 %s %f",operation,value);
327 if(switch_ima2 == 1) {
328 sinfo_free_image(&ima2);
331 if (strcmp(operation,
"+") == 0 ) {
332 check(image = cpl_image_add_scalar_create(ima1, value),
333 "Cannot apply the %s operator",operation) ;
334 }
else if (strcmp(operation,
"-") == 0 ) {
335 check(image = cpl_image_subtract_scalar_create(ima1, value),
336 "Cannot apply the %s operator",operation) ;
337 }
else if (strcmp(operation,
"*") == 0 ) {
338 check(image = cpl_image_multiply_scalar_create(ima1, value),
339 "Cannot apply the %s operator",operation) ;
340 }
else if (strcmp(operation,
"/") == 0 ) {
341 check(image = cpl_image_divide_scalar_create(ima1, value),
342 "Cannot apply the %s operator",operation) ;
348 sinfo_free_image(&ima1);
355 name_o =
"ima_res.fits" ;
358 check_nomsg(product_frame = cpl_frame_new());
359 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
360 check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_IMA_ARITH_PROIMA)) ;
361 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
362 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
363 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
364 "Error while initialising the product frame") ;
367 check_nomsg(cpl_propertylist_erase_regexp(plist,
"^ESO PRO CATG",0));
368 check(cpl_dfs_setup_product_header(plist,
372 "sinfo_utl_ima_arith",
374 KEY_VALUE_HPRO_DID,NULL),
375 "Problem in the product DFS-compliance") ;
378 check(cpl_image_save(image,
383 "Could not save product");
384 sinfo_free_propertylist(&plist) ;
385 sinfo_free_image(&image);
388 check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
393 sinfo_free_image(&ima1);
394 sinfo_free_image(&ima2);
395 sinfo_free_frameset(&raw_set);
396 sinfo_free_propertylist(&plist) ;
400 sinfo_free_image(&image) ;
402 if (cpl_error_get_code()) {
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
void irplib_reset(void)
Reset IRPLIB state.
#define sinfo_msg_error(...)
Print an error message.