31#include "moo_params.h"
33#include "moo_products.h"
37#include "moo_correct_tell.h"
38#include "moo_molecfit.h"
43int cpl_plugin_get_info(cpl_pluginlist *list);
49static int _moons_molecfit_correct_create(cpl_plugin *plugin);
50static int _moons_molecfit_correct_exec(cpl_plugin *plugin);
51static int _moons_molecfit_correct_destroy(cpl_plugin *plugin);
52static int _moons_molecfit_correct(cpl_frameset *frameset,
53 const cpl_parameterlist *parlist);
59static const char *
const _moons_molecfit_correct_description =
60 "Apply telluric correction on science files\n"
62 " * file (SCI) with tag SCIENCE 1 to n files : "
63 " star file to correct \n"
64 " * file (TELLURIC_CORR) with tag TELLURIC_CORR 1 file : "
65 "telluric correction file\n"
67 " * SCIENCE_TELLCORSPECTRA_i.fits (SCI) with tag SCIENCE_TELLCORSPECTRA : "
68 "science with telluric correction apply"
88cpl_plugin_get_info(cpl_pluginlist *list)
90 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
91 cpl_plugin *plugin = &recipe->interface;
93 if (cpl_plugin_init(plugin, CPL_PLUGIN_API, MOONS_BINARY_VERSION,
94 CPL_PLUGIN_TYPE_RECIPE,
"moons_molecfit_correct",
95 "Apply telluric correction to the science",
96 _moons_molecfit_correct_description,
"Regis Haigron",
98 _moons_molecfit_correct_create,
99 _moons_molecfit_correct_exec,
100 _moons_molecfit_correct_destroy)) {
101 cpl_msg_error(cpl_func,
"Plugin initialization failed");
102 (void)cpl_error_set_where(cpl_func);
106 if (cpl_pluginlist_append(list, plugin)) {
107 cpl_msg_error(cpl_func,
"Error adding plugin to list");
108 (void)cpl_error_set_where(cpl_func);
127_moons_molecfit_correct_create(cpl_plugin *plugin)
132 if (cpl_error_get_code() != CPL_ERROR_NONE) {
133 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
134 cpl_func, __LINE__, cpl_error_get_where());
135 return (
int)cpl_error_get_code();
138 if (plugin == NULL) {
139 cpl_msg_error(cpl_func,
"Null plugin");
140 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
144 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
145 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
146 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
150 recipe = (cpl_recipe *)plugin;
153 recipe->parameters = cpl_parameterlist_new();
154 if (recipe->parameters == NULL) {
155 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
156 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
159 moo_params *params =
moo_params_new(
"moons",
"moons_molecfit_correct");
178_moons_molecfit_correct_exec(cpl_plugin *plugin)
182 cpl_errorstate initial_errorstate = cpl_errorstate_get();
185 if (cpl_error_get_code() != CPL_ERROR_NONE) {
186 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
187 cpl_func, __LINE__, cpl_error_get_where());
188 return (
int)cpl_error_get_code();
191 if (plugin == NULL) {
192 cpl_msg_error(cpl_func,
"Null plugin");
193 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
197 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
198 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
199 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
203 recipe = (cpl_recipe *)plugin;
206 if (recipe->parameters == NULL) {
207 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
208 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
210 if (recipe->frames == NULL) {
211 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
212 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
216 recipe_status = _moons_molecfit_correct(recipe->frames, recipe->parameters);
219 if (cpl_dfs_update_product_header(recipe->frames)) {
221 recipe_status = (int)cpl_error_get_code();
224 if (!cpl_errorstate_is_equal(initial_errorstate)) {
227 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
230 return recipe_status;
243_moons_molecfit_correct_destroy(cpl_plugin *plugin)
247 if (plugin == NULL) {
248 cpl_msg_error(cpl_func,
"Null plugin");
249 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
253 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
254 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
255 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
259 recipe = (cpl_recipe *)plugin;
261 cpl_parameterlist_delete(recipe->parameters);
267_moons_molecfit_correct_check_sof(cpl_frameset *frameset,
268 cpl_frameset **sci_frameset,
269 const cpl_frame **tell_frame)
272 cpl_error_get_code());
275 moo_try_check(*sci_frameset = cpl_frameset_new(),
" ");
277 for (i = 0; i < cpl_frameset_get_size(frameset); ++i) {
278 cpl_frame *current_frame = cpl_frameset_get_position(frameset, i);
279 if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_MOLECFIT_SCI)) {
280 cpl_frame *new_frame = cpl_frame_duplicate(current_frame);
281 cpl_frameset_insert(*sci_frameset, new_frame);
283 else if (!strcmp(cpl_frame_get_tag(current_frame),
284 MOONS_TAG_TELLURIC_CORR)) {
285 *tell_frame = current_frame;
288 if (*tell_frame == NULL) {
289 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
290 "SOF does not have any file tagged "
292 MOONS_TAG_TELLURIC_CORR);
296 return CPL_ERROR_NONE;
301_moons_correct_set(cpl_frameset *set,
303 moo_products *products)
306 char *sci_name = NULL;
307 cpl_ensure(set != NULL, CPL_ERROR_NULL_INPUT, NULL);
308 cpl_ensure(tell != NULL, CPL_ERROR_NULL_INPUT, NULL);
309 cpl_ensure(products != NULL, CPL_ERROR_NULL_INPUT, NULL);
311 cpl_frameset *result = cpl_frameset_new();
314 cpl_errorstate prestate = cpl_errorstate_get();
316 for (i = 0; i < cpl_frameset_get_size(set); ++i) {
317 const cpl_frame *current_frame = NULL;
318 moo_try_check(current_frame = cpl_frameset_get_position_const(set, i),
323 cpl_sprintf(
"%s_%d.fits", MOONS_TAG_SCIENCE_TELLCORRSPECTRA, i);
326 MOONS_TAG_SCIENCE_TELLCORRSPECTRA, sci_name,
329 moo_try_check(cpl_frameset_insert(result, cpl_frame_duplicate(product)),
335 if (!cpl_errorstate_is_equal(prestate)) {
336 cpl_msg_error(__func__,
"dump error ");
337 cpl_errorstate_dump(prestate, CPL_FALSE, cpl_errorstate_dump_one);
339 cpl_frameset_delete(result);
354_moons_molecfit_correct(cpl_frameset *frameset,
355 const cpl_parameterlist *parlist)
358 cpl_frameset *science_set = NULL;
359 const cpl_frame *tell_frame = NULL;
360 moo_telluric *tell = NULL;
361 cpl_frameset *result_set = NULL;
363 moo_products *products =
365 PACKAGE
"/" PACKAGE_VERSION);
369 moo_try_check(_moons_molecfit_correct_check_sof(frameset, &science_set,
374 moo_try_check(result_set = _moons_correct_set(science_set, tell, products),
378 moo_products_delete(products);
379 cpl_frameset_delete(science_set);
381 cpl_frameset_delete(result_set);
383 return (
int)cpl_error_get_code();
void moo_params_delete(moo_params *self)
Delete a moo_params.
cpl_error_code moo_params_add_keep_temp(moo_params *self, cpl_parameterlist *list)
Add default parameters for keep-temp.
moo_params * moo_params_new(const char *pid, const char *recipe_id)
Create a new moo_params.
void moo_sci_delete(moo_sci *self)
Delete a moo_sci.
moo_sci * moo_sci_create(const cpl_frame *frame)
Create a new empty SCI filename.
moo_telluric * moo_telluric_load(const cpl_frame *frame)
Load a TELLURIC frame and create a moo_telluric.
void moo_telluric_delete(moo_telluric *self)
Delete a moo_telluric.
cpl_error_code moo_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
cpl_error_code moo_correct_tell_science(moo_sci *sci, moo_telluric *tell)
Apply the telluric correction to SCI.
moo_products * moo_products_new(cpl_frameset *framelist, const cpl_parameterlist *parlist, const char *recid, const char *pipeline_id)
create a moo_product object for a recipe
cpl_frame * moo_products_add_sci(moo_products *self, moo_sci *sci, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
create a product from a SCI object
const char * moo_get_license(void)
Get the pipeline copyright and license.