41 #include <irplib_utils.h>
44 #include <uves_pfits.h>
50 #include <uves_error.h>
51 #include <uves_utils_wrappers.h>
52 #define KEY_VALUE_HPRO_DID "PRO-1.15"
67 static char uves_utl_ima_arith_description[] =
68 "This recipe performs image computation.\n"
69 "The input files are 2 images\n"
70 "their associated tags should be IMA.\n"
71 "The output is an image resulting from the IMA op IMA where op indicates\n"
72 "the operation to be performed specified by the parameter \n"
73 "uves.uves_utl_ima_arith.op having alias 'op'\n"
74 "Information on relevant parameters can be found with\n"
75 "esorex --params uves_utl_ima_arith\n"
76 "esorex --help uves_utl_ima_arith\n"
100 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe ) ;
101 cpl_plugin * plugin = &recipe->interface ;
103 cpl_plugin_init(plugin,
106 CPL_PLUGIN_TYPE_RECIPE,
107 "uves_utl_ima_arith",
108 "Computes result of ima1 op ima2",
109 uves_utl_ima_arith_description,
111 "Andrea.Modigliani@eso.org",
117 cpl_pluginlist_append(list, plugin) ;
134 cpl_recipe * recipe ;
138 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
139 recipe = (cpl_recipe *)plugin ;
145 recipe->parameters = cpl_parameterlist_new() ;
149 p = cpl_parameter_new_value(
"uves.uves_utl_ima_arith.op",
151 "A possible operation",
152 "uves.uves_utl_ima_arith",
"+");
153 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"op") ;
154 cpl_parameterlist_append(recipe->parameters, p) ;
157 p = cpl_parameter_new_value(
"uves.uves_utl_ima_arith.value",
158 CPL_TYPE_DOUBLE,
"a value",
"uves.uves_utl_ima_arith", 9999.) ;
159 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"value") ;
160 cpl_parameterlist_append(recipe->parameters, p) ;
175 cpl_recipe * recipe ;
177 cpl_errorstate initial_errorstate = cpl_errorstate_get();
180 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
181 recipe = (cpl_recipe *)plugin ;
188 if (!cpl_errorstate_is_equal(initial_errorstate)) {
191 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
206 cpl_recipe * recipe ;
209 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
210 recipe = (cpl_recipe *)plugin ;
213 cpl_parameterlist_delete(recipe->parameters) ;
227 cpl_frameset * framelist)
229 cpl_parameter * param= NULL ;
230 const char * operation=NULL;
232 cpl_frame * frm_ima1=NULL ;
233 cpl_frame * frm_ima2=NULL ;
234 cpl_image * ima1=NULL ;
235 cpl_image * ima2=NULL ;
237 const char * name_o=NULL ;
238 cpl_propertylist * plist=NULL ;
239 cpl_image * image=NULL ;
240 cpl_frame * product_frame=NULL;
241 cpl_frameset * raw_set=NULL;
244 uves_msg(
"Welcome to UVES Pipeline release %d.%d.%d",
245 UVES_MAJOR_VERSION,UVES_MINOR_VERSION,UVES_MICRO_VERSION);
250 "uves.uves_utl_ima_arith.op"));
251 check_nomsg(operation=cpl_parameter_get_string(param));
255 "uves.uves_utl_ima_arith.value"));
256 check_nomsg(value = cpl_parameter_get_double(param)) ;
259 check(uves_dfs_set_groups(framelist),
260 "Cannot identify RAW and CALIB frames") ;
263 n=cpl_frameset_get_size(framelist);
272 check(uves_contains_frames_kind(framelist,raw_set,PRO_IMA),
273 "Found no input frames with tag %s",PRO_IMA);
279 check_nomsg(frm_ima1=cpl_frameset_get_frame(framelist,0));
280 check_nomsg(ima1=cpl_image_load(cpl_frame_get_filename(frm_ima1),
281 CPL_TYPE_FLOAT,0,0));
283 check_nomsg(frm_ima2=cpl_frameset_get_frame(framelist,1));
284 check_nomsg(ima2 = cpl_image_load(cpl_frame_get_filename(frm_ima2),
285 CPL_TYPE_FLOAT,0,0));
287 }
else if (value == 9999.) {
288 uves_msg_error(
"Found only one input frames with tag %s",PRO_IMA);
291 uves_msg(
"Perform image arithmetics on frame %s",PRO_IMA);
295 uves_free_frameset(&raw_set);
298 check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_ima1),0),
299 "Cannot read the FITS header") ;
303 if (value == 9999.) {
305 if(ima1 != NULL && ima2 != NULL) {
307 if (strcmp(operation,
"+") == 0 ) {
308 check(image = cpl_image_add_create(ima1, ima2),
309 "Cannot generate the %s image",operation) ;
310 }
else if (strcmp(operation,
"-") == 0 ) {
311 check(image = cpl_image_subtract_create(ima1, ima2),
312 "Cannot generate the %s image",operation) ;
313 }
else if (strcmp(operation,
"*") == 0 ) {
314 check(image = cpl_image_multiply_create(ima1, ima2),
315 "Cannot generate the %s image",operation) ;
316 }
else if (strcmp(operation,
"/") == 0 ) {
317 check(image = cpl_image_divide_create(ima1, ima2),
318 "Cannot generate the %s image",operation) ;
323 uves_free_image(&ima1);
324 uves_free_image(&ima2);
329 uves_msg(
"ima1 %s %f",operation,value);
331 if(switch_ima2 == 1) {
332 uves_free_image(&ima2);
335 if (strcmp(operation,
"+") == 0 ) {
336 check(image = cpl_image_add_scalar_create(ima1, value),
337 "Cannot apply the %s operator",operation) ;
338 }
else if (strcmp(operation,
"-") == 0 ) {
339 check(image = cpl_image_subtract_scalar_create(ima1, value),
340 "Cannot apply the %s operator",operation) ;
341 }
else if (strcmp(operation,
"*") == 0 ) {
342 check(image = cpl_image_multiply_scalar_create(ima1, value),
343 "Cannot apply the %s operator",operation) ;
344 }
else if (strcmp(operation,
"/") == 0 ) {
345 check(image = cpl_image_divide_scalar_create(ima1, value),
346 "Cannot apply the %s operator",operation) ;
352 uves_free_image(&ima1);
359 name_o =
"ima_res.fits" ;
363 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
364 check_nomsg(cpl_frame_set_tag(product_frame, PRO_IMA)) ;
365 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
366 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
367 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
368 "Error while initialising the product frame") ;
371 check_nomsg(cpl_propertylist_erase_regexp(plist,
"^ESO PRO CATG",0));
373 check(cpl_dfs_setup_product_header(plist,
377 "uves_utl_ima_arith",
379 KEY_VALUE_HPRO_DID,NULL),
380 "Problem in the product DFS-compliance") ;
383 check(cpl_image_save(image,
388 "Could not save product");
391 cpl_propertylist_delete(plist) ;
395 uves_free_image(&image);
398 check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
403 uves_free_image(&ima1);
404 uves_free_image(&ima2);
405 uves_free_frameset(&raw_set);
407 cpl_propertylist_delete(plist) ;
413 uves_free_image(&image) ;
415 if (cpl_error_get_code()) {