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"
66 static char uves_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 RAW_IMA.\n"
70 "The output is an image resulting from the RAW_IMA op RAW_IMA where op indicates\n"
71 "the operation to be performed specified by the parameter \n"
72 "uves.uves_utl_ima_arith.op having alias 'op'\n"
73 "Information on relevant parameters can be found with\n"
74 "esorex --params uves_utl_ima_arith\n"
75 "esorex --help uves_utl_ima_arith\n"
99 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe ) ;
100 cpl_plugin * plugin = &recipe->interface ;
102 cpl_plugin_init(plugin,
105 CPL_PLUGIN_TYPE_RECIPE,
106 "uves_utl_ima_arith",
107 "Computes result of ima1 op ima2",
108 uves_utl_ima_arith_description,
110 "Andrea.Modigliani@eso.org",
116 cpl_pluginlist_append(list, plugin) ;
133 cpl_recipe * recipe ;
137 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
138 recipe = (cpl_recipe *)plugin ;
144 recipe->parameters = cpl_parameterlist_new() ;
148 p = cpl_parameter_new_value(
"uves.uves_utl_ima_arith.op",
150 "A possible operation",
151 "uves.uves_utl_ima_arith",
"+");
152 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"op") ;
153 cpl_parameterlist_append(recipe->parameters, p) ;
156 p = cpl_parameter_new_value(
"uves.uves_utl_ima_arith.value",
157 CPL_TYPE_DOUBLE,
"a value",
"uves.uves_utl_ima_arith", 9999.) ;
158 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"value") ;
159 cpl_parameterlist_append(recipe->parameters, p) ;
174 cpl_recipe * recipe ;
176 cpl_errorstate initial_errorstate = cpl_errorstate_get();
179 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
180 recipe = (cpl_recipe *)plugin ;
187 if (!cpl_errorstate_is_equal(initial_errorstate)) {
190 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
205 cpl_recipe * recipe ;
208 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
209 recipe = (cpl_recipe *)plugin ;
212 cpl_parameterlist_delete(recipe->parameters) ;
226 cpl_frameset * framelist)
228 cpl_parameter * param= NULL ;
229 const char * operation=NULL;
231 cpl_frame * frm_ima1=NULL ;
232 cpl_frame * frm_ima2=NULL ;
233 cpl_image * ima1=NULL ;
234 cpl_image * ima2=NULL ;
236 const char * name_o=NULL ;
237 cpl_propertylist * plist=NULL ;
238 cpl_image * image=NULL ;
239 cpl_frame * product_frame=NULL;
240 cpl_frameset * raw_set=NULL;
243 uves_msg(
"Welcome to UVES Pipeline release %d.%d.%d",
244 UVES_MAJOR_VERSION,UVES_MINOR_VERSION,UVES_MICRO_VERSION);
249 "uves.uves_utl_ima_arith.op"));
250 check_nomsg(operation=cpl_parameter_get_string(param));
254 "uves.uves_utl_ima_arith.value"));
255 check_nomsg(value = cpl_parameter_get_double(param)) ;
258 check(uves_dfs_set_groups(framelist),
259 "Cannot identify RAW and CALIB frames") ;
262 n=cpl_frameset_get_size(framelist);
271 check(uves_contains_frames_kind(framelist,raw_set,RAW_IMA),
272 "Found no input frames with tag %s",RAW_IMA);
278 check_nomsg(frm_ima1=cpl_frameset_get_frame(framelist,0));
279 check_nomsg(ima1=cpl_image_load(cpl_frame_get_filename(frm_ima1),
280 CPL_TYPE_FLOAT,0,0));
282 check_nomsg(frm_ima2=cpl_frameset_get_frame(framelist,1));
283 check_nomsg(ima2 = cpl_image_load(cpl_frame_get_filename(frm_ima2),
284 CPL_TYPE_FLOAT,0,0));
286 }
else if (value == 9999.) {
287 uves_msg_error(
"Found only one input frames with tag %s",RAW_IMA);
290 uves_msg(
"Perform image arithmetics on frame %s",RAW_IMA);
294 uves_free_frameset(&raw_set);
297 check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_ima1),0),
298 "Cannot read the FITS header") ;
302 if (value == 9999.) {
304 if(ima1 != NULL && ima2 != NULL) {
306 if (strcmp(operation,
"+") == 0 ) {
307 check(image = cpl_image_add_create(ima1, ima2),
308 "Cannot generate the %s image",operation) ;
309 }
else if (strcmp(operation,
"-") == 0 ) {
310 check(image = cpl_image_subtract_create(ima1, ima2),
311 "Cannot generate the %s image",operation) ;
312 }
else if (strcmp(operation,
"*") == 0 ) {
313 check(image = cpl_image_multiply_create(ima1, ima2),
314 "Cannot generate the %s image",operation) ;
315 }
else if (strcmp(operation,
"/") == 0 ) {
316 check(image = cpl_image_divide_create(ima1, ima2),
317 "Cannot generate the %s image",operation) ;
322 uves_free_image(&ima1);
323 uves_free_image(&ima2);
328 uves_msg(
"ima1 %s %f",operation,value);
330 if(switch_ima2 == 1) {
331 uves_free_image(&ima2);
334 if (strcmp(operation,
"+") == 0 ) {
335 check(image = cpl_image_add_scalar_create(ima1, value),
336 "Cannot apply the %s operator",operation) ;
337 }
else if (strcmp(operation,
"-") == 0 ) {
338 check(image = cpl_image_subtract_scalar_create(ima1, value),
339 "Cannot apply the %s operator",operation) ;
340 }
else if (strcmp(operation,
"*") == 0 ) {
341 check(image = cpl_image_multiply_scalar_create(ima1, value),
342 "Cannot apply the %s operator",operation) ;
343 }
else if (strcmp(operation,
"/") == 0 ) {
344 check(image = cpl_image_divide_scalar_create(ima1, value),
345 "Cannot apply the %s operator",operation) ;
351 uves_free_image(&ima1);
358 name_o =
"ima_res.fits" ;
362 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
363 check_nomsg(cpl_frame_set_tag(product_frame, RAW_IMA)) ;
364 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
365 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
366 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
367 "Error while initialising the product frame") ;
370 check_nomsg(cpl_propertylist_erase_regexp(plist,
"^ESO PRO CATG",0));
372 check(cpl_dfs_setup_product_header(plist,
376 "uves_utl_ima_arith",
378 KEY_VALUE_HPRO_DID,NULL),
379 "Problem in the product DFS-compliance") ;
382 check(cpl_image_save(image,
387 "Could not save product");
390 cpl_propertylist_delete(plist) ;
394 uves_free_image(&image);
397 check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
402 uves_free_image(&ima1);
403 uves_free_image(&ima2);
404 uves_free_frameset(&raw_set);
406 cpl_propertylist_delete(plist) ;
412 uves_free_image(&image) ;
414 if (cpl_error_get_code()) {
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
#define uves_msg_error(...)
Print an error message.
static int uves_utl_ima_arith_create(cpl_plugin *)
Setup the recipe options.
void irplib_reset(void)
Reset IRPLIB state.
const char * uves_get_license(void)
Get the pipeline copyright and license.
#define uves_msg(...)
Print a message on 'info' or 'debug' level.
static int uves_utl_ima_arith_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int uves_utl_ima_arith_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int uves_utl_ima_arith(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.