38 #include "gravi_utils.h"
39 #include "gravi_pfits.h"
40 #include "gravi_dfs.h"
46 static int rrrecipe_create(cpl_plugin *);
47 static int rrrecipe_exec(cpl_plugin *);
48 static int rrrecipe_destroy(cpl_plugin *);
49 static int rrrecipe(cpl_frameset *,
const cpl_parameterlist *);
55 static char rrrecipe_description[] =
56 "This example text is used to describe the recipe.\n"
57 "The description should include the required FITS-files and\n"
58 "their associated tags, e.g.\n"
59 "GRAVI-RRRECIPE-raw-file.fits " RRRECIPE_RAW
"\n"
60 "and any optional files, e.g.\n"
61 "GRAVI-RRRECIPE-flat-file.fits " GRAVI_CALIB_FLAT
"\n"
63 "Additionally, it should describe functionality of the expected output."
81 int cpl_plugin_get_info(cpl_pluginlist * list)
83 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
84 cpl_plugin * plugin = &recipe->interface;
86 if (cpl_plugin_init(plugin,
89 CPL_PLUGIN_TYPE_RECIPE,
91 "Short description of rrrecipe",
99 cpl_msg_error(cpl_func,
"Plugin initialization failed");
100 (void)cpl_error_set_where(cpl_func);
104 if (cpl_pluginlist_append(list, plugin)) {
105 cpl_msg_error(cpl_func,
"Error adding plugin to list");
106 (void)cpl_error_set_where(cpl_func);
122 static int rrrecipe_create(cpl_plugin * plugin)
128 if (cpl_error_get_code() != CPL_ERROR_NONE) {
129 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
130 cpl_func, __LINE__, cpl_error_get_where());
131 return (
int)cpl_error_get_code();
134 if (plugin == NULL) {
135 cpl_msg_error(cpl_func,
"Null plugin");
136 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
140 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
141 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
142 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
146 recipe = (cpl_recipe *)plugin;
149 recipe->parameters = cpl_parameterlist_new();
150 if (recipe->parameters == NULL) {
151 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
152 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
157 p = cpl_parameter_new_value(
"gravi.rrrecipe.str_option",
158 CPL_TYPE_STRING,
"the string option",
"gravi.rrrecipe",NULL);
159 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"stropt");
160 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
161 cpl_parameterlist_append(recipe->parameters, p);
164 p = cpl_parameter_new_value(
"gravi.rrrecipe.bool_option",
165 CPL_TYPE_BOOL,
"a flag",
"gravi.rrrecipe", TRUE);
166 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"boolopt");
167 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
168 cpl_parameterlist_append(recipe->parameters, p);
180 static int rrrecipe_exec(cpl_plugin * plugin)
185 cpl_errorstate initial_errorstate = cpl_errorstate_get();
188 if (cpl_error_get_code() != CPL_ERROR_NONE) {
189 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
190 cpl_func, __LINE__, cpl_error_get_where());
191 return (
int)cpl_error_get_code();
194 if (plugin == NULL) {
195 cpl_msg_error(cpl_func,
"Null plugin");
196 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
200 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
201 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
202 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
206 recipe = (cpl_recipe *)plugin;
209 if (recipe->parameters == NULL) {
210 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
211 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
213 if (recipe->frames == NULL) {
214 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
215 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
219 recipe_status = rrrecipe(recipe->frames, recipe->parameters);
222 if (cpl_dfs_update_product_header(recipe->frames)) {
223 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
226 if (!cpl_errorstate_is_equal(initial_errorstate)) {
229 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
232 return recipe_status;
242 static int rrrecipe_destroy(cpl_plugin * plugin)
246 if (plugin == NULL) {
247 cpl_msg_error(cpl_func,
"Null plugin");
248 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
252 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
253 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
254 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
258 recipe = (cpl_recipe *)plugin;
260 cpl_parameterlist_delete(recipe->parameters);
273 static int rrrecipe(cpl_frameset * frameset,
274 const cpl_parameterlist * parlist)
276 const cpl_parameter * param;
277 const char * str_option;
279 const cpl_frame * rawframe;
280 const cpl_frame * flat;
282 cpl_propertylist * plist;
283 cpl_propertylist * applist;
288 cpl_errorstate prestate = cpl_errorstate_get();
292 param = cpl_parameterlist_find_const(parlist,
293 "gravi.rrrecipe.str_option");
294 str_option = cpl_parameter_get_string(param);
297 param = cpl_parameterlist_find_const(parlist,
298 "gravi.rrrecipe.bool_option");
299 bool_option = cpl_parameter_get_bool(param);
301 if (!cpl_errorstate_is_equal(prestate)) {
302 return (
int)cpl_error_set_message(cpl_func, cpl_error_get_code(),
303 "Could not retrieve the input "
308 cpl_ensure_code(gravi_dfs_set_groups(frameset) == CPL_ERROR_NONE,
309 cpl_error_get_code());
313 rawframe = cpl_frameset_find_const(frameset, RRRECIPE_RAW);
314 if (rawframe == NULL) {
317 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
318 "SOF does not have any file tagged "
319 "with %s", RRRECIPE_RAW);
322 flat = cpl_frameset_find(frameset, GRAVI_CALIB_FLAT);
324 cpl_msg_warning(cpl_func,
"SOF does not have any file tagged with %s",
330 plist = cpl_propertylist_load_regexp(cpl_frame_get_filename(rawframe),
334 return (
int)cpl_error_set_message(cpl_func, cpl_error_get_code(),
335 "Could not read the FITS header");
338 qc_param = gravi_pfits_get_dit(plist);
339 cpl_propertylist_delete(plist);
343 cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
347 image = cpl_image_load(cpl_frame_get_filename(rawframe), CPL_TYPE_FLOAT, 0,
350 return (
int)cpl_error_set_message(cpl_func, cpl_error_get_code(),
351 "Could not load the image");
354 applist = cpl_propertylist_new();
357 cpl_propertylist_append_string(applist, CPL_DFS_PRO_CATG,
358 RRRECIPE_XXX_PROCATG);
361 cpl_propertylist_append_double(applist,
"ESO QC QCPARAM", qc_param);
364 if (cpl_dfs_save_image(frameset, NULL, parlist, frameset, NULL, image,
365 CPL_BPP_IEEE_FLOAT,
"rrrecipe", applist,
366 NULL, PACKAGE
"/" PACKAGE_VERSION,
369 (void)cpl_error_set_where(cpl_func);
372 cpl_image_delete(image);
373 cpl_propertylist_delete(applist);
375 return (
int)cpl_error_get_code();