31#include "moo_molecfit.h"
32#include "moo_molectable.h"
33#include "moo_params.h"
35#include "moo_products.h"
43int cpl_plugin_get_info(cpl_pluginlist *list);
49static int _moons_molecfit_model_create(cpl_plugin *plugin);
50static int _moons_molecfit_model_exec(cpl_plugin *plugin);
51static int _moons_molecfit_model_destroy(cpl_plugin *plugin);
53_moons_molecfit_model(cpl_frameset *frameset,
const cpl_parameterlist *parlist);
59static const char *
const _moons_molecfit_model_description =
60 "Produces the model using molecfit\n"
62 " * file (SCI) with tag SCIENCE 1 file : "
63 "molecfit_model star file\n"
64 " * file (MOLECULES) with tag MOLECULES 1 file : "
65 "molecules list file\n"
67 " * GDAS User GDAS profile"
68 " * GDAS_BEFORE If ESO DB GDAS is used, file before the MJD-OBS"
69 " * GDAS_AFTER If ESO DB GDAS is used, file after the MJD-OBS"
89cpl_plugin_get_info(cpl_pluginlist *list)
91 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
92 cpl_plugin *plugin = &recipe->interface;
95 plugin, CPL_PLUGIN_API, MOONS_BINARY_VERSION,
96 CPL_PLUGIN_TYPE_RECIPE,
"moons_molecfit_model",
97 "Produces the instrumental response for relative flux calibration, "
98 "and the telluric absorption spectrum.",
99 _moons_molecfit_model_description,
"Regis Haigron",
101 _moons_molecfit_model_exec, _moons_molecfit_model_destroy)) {
102 cpl_msg_error(cpl_func,
"Plugin initialization failed");
103 (void)cpl_error_set_where(cpl_func);
107 if (cpl_pluginlist_append(list, plugin)) {
108 cpl_msg_error(cpl_func,
"Error adding plugin to list");
109 (void)cpl_error_set_where(cpl_func);
127_moons_molecfit_model_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_model");
178_moons_molecfit_model_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_model(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;
242_moons_molecfit_model_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);
266_moons_molecfit_model_check_sof(cpl_frameset *frameset,
267 const cpl_frame **sci_frame,
268 const cpl_frame **molecules_frame,
269 const cpl_frame **winc_frame)
272 cpl_error_get_code());
275 for (i = 0; i < cpl_frameset_get_size(frameset); ++i) {
276 cpl_frame *current_frame = cpl_frameset_get_position(frameset, i);
277 if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_MOLECFIT_SCI)) {
278 *sci_frame = current_frame;
280 else if (!strcmp(cpl_frame_get_tag(current_frame),
281 MOONS_TAG_MOLECFIT_MOLECULES)) {
282 *molecules_frame = current_frame;
284 else if (!strcmp(cpl_frame_get_tag(current_frame),
285 MOONS_TAG_MOLECFIT_WINCLUDE)) {
286 *winc_frame = current_frame;
289 if (*sci_frame == NULL) {
290 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
291 "SOF does not have any file tagged "
293 MOONS_TAG_MOLECFIT_SCI);
296 if (*molecules_frame == NULL) {
297 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
298 "SOF does not have any file tagged "
300 MOONS_TAG_MOLECFIT_MOLECULES);
303 if (*winc_frame == NULL) {
304 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
305 "SOF does not have any file tagged "
307 MOONS_TAG_MOLECFIT_WINCLUDE);
309 return CPL_ERROR_NONE;
321_moons_molecfit_model(cpl_frameset *frameset,
const cpl_parameterlist *parlist)
325 const char *modename = NULL;
326 const cpl_frame *sci_frame = NULL;
327 const cpl_frame *molecule_frame = NULL;
328 const cpl_frame *winc_frame = NULL;
329 moo_molecfit_model_params *molecfit_model_params = NULL;
331 moo_molectable *atm_fitted = NULL;
332 moo_molectable *best_fitted_params = NULL;
333 moo_molectable *best_fitted_model = NULL;
335 char *best_fitted_params_name = NULL;
336 char *best_fitted_model_name = NULL;
337 char *atm_fitted_name = NULL;
339 moo_products *products =
341 PACKAGE
"/" PACKAGE_VERSION);
344 moo_try_check(molecfit_model_params =
349 moo_try_check(_moons_molecfit_model_check_sof(frameset, &sci_frame,
350 &molecule_frame, &winc_frame),
357 moo_try_check(best_fitted_params =
359 winc_frame, &atm_fitted,
361 molecfit_model_params),
363 atm_fitted_name = cpl_sprintf(
"%s_%s.fits", MOONS_TAG_MOLECFIT_ATM_PARAMS,
365 best_fitted_params_name =
366 cpl_sprintf(
"%s_%s.fits", MOONS_TAG_MOLECFIT_BEST_FIT_PARAMS,
368 best_fitted_model_name =
369 cpl_sprintf(
"%s_%s.fits", MOONS_TAG_MOLECFIT_BEST_FIT_MODEL,
373 products, best_fitted_params, CPL_FRAME_LEVEL_FINAL,
374 MOONS_TAG_MOLECFIT_BEST_FIT_PARAMS,
375 best_fitted_params_name, sci_frame),
378 CPL_FRAME_LEVEL_INTERMEDIATE,
379 MOONS_TAG_MOLECFIT_BEST_FIT_MODEL,
380 best_fitted_model_name,
384 CPL_FRAME_LEVEL_FINAL,
385 MOONS_TAG_MOLECFIT_ATM_PARAMS,
386 atm_fitted_name, sci_frame),
390 cpl_free(best_fitted_params_name);
391 cpl_free(best_fitted_model_name);
392 cpl_free(atm_fitted_name);
397 moo_products_delete(products);
398 return (
int)cpl_error_get_code();
moo_mode_type moo_mode_get(const cpl_frame *frame)
Get the name of a mode from a frame.
const char * moo_mode_get_name(moo_mode_type type)
Get the name of a mode.
void moo_molectable_delete(moo_molectable *self)
Delete a moo_molectable.
void moo_molecfit_model_params_delete(moo_molecfit_model_params *self)
Delete a moo_molecfit_model_params.
void moo_params_delete(moo_params *self)
Delete a moo_params.
cpl_error_code moo_params_add_molecfit_model(moo_params *self, cpl_parameterlist *list)
Add default parameters for molecfit_model.
moo_molecfit_model_params * moo_params_get_molecfit_model(const moo_params *self, const cpl_parameterlist *list)
Get molecfit model parameters from moons parameters list.
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.
cpl_error_code moo_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
moo_molectable * moo_molecfit_model(const cpl_frame *sci_frame, const char *modename, const cpl_frame *molecule_frame, const cpl_frame *winc_frame, moo_molectable **pmt_atm_fitted, moo_molectable **best_fitted_model, moo_molecfit_model_params *params)
Apply the relative flux calibration to 1D rebinned spectra.
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_molectable(moo_products *self, moo_molectable *mtable, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
create a product from a MOLECTABLE object
const moo_params * moo_products_get_params(const moo_products *self)
get the moo_params object
const char * moo_get_license(void)
Get the pipeline copyright and license.