51static int gravity_image(cpl_frameset *,
const cpl_parameterlist *);
58"This recipe launch a Yorick batch executing mira-script.i to process an\n"
59"input OIFITS file to produce an image in fits file.\n"
60"The input frame is an OIFITS file :\n"
62"and the recipe generates a fits image\n"
82 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
83 cpl_plugin * plugin = &recipe->interface;
85 if (cpl_plugin_init(plugin,
88 CPL_PLUGIN_TYPE_RECIPE,
98 cpl_msg_error(cpl_func,
"Plugin initialization failed");
99 (void)cpl_error_set_where(cpl_func);
103 if (cpl_pluginlist_append(list, plugin)) {
104 cpl_msg_error(cpl_func,
"Error adding plugin to list");
105 (void)cpl_error_set_where(cpl_func);
127 if (cpl_error_get_code() != CPL_ERROR_NONE) {
128 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
129 cpl_func, __LINE__, cpl_error_get_where());
130 return (
int)cpl_error_get_code();
133 if (plugin == NULL) {
134 cpl_msg_error(cpl_func,
"Null plugin");
135 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
139 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
140 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
141 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
145 recipe = (cpl_recipe *)plugin;
148 recipe->parameters = cpl_parameterlist_new();
149 if (recipe->parameters == NULL) {
150 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
151 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
171 cpl_errorstate initial_errorstate = cpl_errorstate_get();
174 if (cpl_error_get_code() != CPL_ERROR_NONE) {
175 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
176 cpl_func, __LINE__, cpl_error_get_where());
177 return (
int)cpl_error_get_code();
180 if (plugin == NULL) {
181 cpl_msg_error(cpl_func,
"Null plugin");
182 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
186 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
187 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
188 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
192 recipe = (cpl_recipe *)plugin;
195 if (recipe->parameters == NULL) {
196 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
197 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
199 if (recipe->frames == NULL) {
200 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
201 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
205 recipe_status =
gravity_image(recipe->frames, recipe->parameters);
208 if (cpl_dfs_update_product_header(recipe->frames)) {
209 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
212 if (!cpl_errorstate_is_equal(initial_errorstate)) {
215 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
218 return recipe_status;
232 if (plugin == NULL) {
233 cpl_msg_error(cpl_func,
"Null plugin");
234 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
238 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
239 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
240 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
244 recipe = (cpl_recipe *)plugin;
246 cpl_parameterlist_delete(recipe->parameters);
261 const cpl_parameterlist * parlist)
264 const cpl_frame * rawframe;
265 double qc_param = 0.0;
266 cpl_propertylist * applist;
268 cpl_frameset * usedframes;
272 cpl_errorstate prestate = cpl_errorstate_get();
276 if (!cpl_errorstate_is_equal(prestate)) {
277 return (
int)cpl_error_set_message(cpl_func, cpl_error_get_code(),
278 "Could not retrieve the input "
284 cpl_error_get_code());
289 if (rawframe == NULL) {
292 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
293 "SOF does not have any file tagged "
299 cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
301 cpl_msg_set_component_on();
304 const char * filename = cpl_frame_get_filename(rawframe);
307 int n_target = cpl_table_get_nrow(oi_target_table);
310 for (
int i_target = 0; i_target < n_target; i_target++) {
314 const char *target_name = cpl_table_get_string(oi_target_table,
"TARGET", i_target);
315 image =
gravi_image(rawframe, parlist, target_name);
320 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT,
321 "The gravi_image function return NULL pointer");
324 applist = cpl_propertylist_new();
329 cpl_propertylist_append_string(applist, CPL_DFS_PRO_CATG, proCatg);
333 for(i = 0; proCatg[i]; i++)
if (proCatg[i]!=
'_') { catg_ext[j] = tolower(proCatg[i]); j++; }
337 cpl_propertylist_append_double(applist,
"ESO QC QCPARAM", qc_param);
343 usedframes = cpl_frameset_new();
344 cpl_frameset_insert(usedframes, cpl_frame_duplicate(rawframe));
372 char * product_name = NULL;
374 if ( cpl_parameterlist_find_const (parlist,
"gravity.dfs.static-name") &&
378 product_name = cpl_sprintf (
"%s_%s_%s.fits",
"gravity_image", catg_ext, target_name);
383 char * filenoext = cpl_strdup (
FILESHORT(filename));
384 char * lastdot = strrchr (filenoext,
'.');
385 if (lastdot != NULL) *lastdot =
'\0';
386 product_name = cpl_sprintf (
"%s_%s_%s.fits", filenoext, catg_ext, target_name);
387 FREE (cpl_free, filenoext);
390 cpl_dfs_save_image(frameset, NULL, parlist, usedframes,
391 rawframe, image, CPL_BPP_IEEE_DOUBLE,
392 "gravity_image", applist, NULL,
393 PACKAGE
"/" PACKAGE_VERSION , product_name);
394 cpl_msg_info(cpl_func,
"Reconstructed image saved in image_out.fits");
398 cpl_propertylist_delete(applist);
399 cpl_frameset_delete(usedframes);
400 FREE (cpl_free, product_name);
405 return (
int)cpl_error_get_code();
407 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT,
408 "This recipe is only available if "
409 "the pipeline was compiled with yorick "
410 "support. Check configure --help");
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
#define GRAVI_MIRA_OUTPUT_PROCATG
#define GRAVI_MIRA_INPUT_PROCATG
cpl_image * gravi_image(const cpl_frame *input_frame, const cpl_parameterlist *input_param, const char *target_name)
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
cpl_image_delete(flat_profiled)
#define FREE(function, variable)
static int gravity_image_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static char gravity_image_short[]
static int gravity_image(cpl_frameset *, const cpl_parameterlist *)
Interpret the command line options and execute the data processing.
static int gravity_image_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int gravity_image_create(cpl_plugin *)
Setup the recipe options
static char gravity_image_description[]
gravi_data * gravi_data_load_ext(const char *filename, const char *extensions_regexp)
Low-level function to load FITS file.
cpl_table * gravi_data_get_table(gravi_data *self, const char *extname)
Return a pointer on a table extension by its EXTNAME.
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
int gravi_param_get_bool(const cpl_parameterlist *parlist, const char *name)
cpl_error_code gravi_parameter_add_image(cpl_parameterlist *self)
cpl_error_code gravi_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
const char * gravi_get_license(void)
Get the pipeline copyright and license.