31#include "moo_params.h"
33#include "moo_products.h"
37#include "moo_molecfit.h"
42int cpl_plugin_get_info(cpl_pluginlist *list);
48static int _moons_molecfit_calctrans_create(cpl_plugin *plugin);
49static int _moons_molecfit_calctrans_exec(cpl_plugin *plugin);
50static int _moons_molecfit_calctrans_destroy(cpl_plugin *plugin);
51static int _moons_molecfit_calctrans(cpl_frameset *frameset,
52 const cpl_parameterlist *parlist);
58static const char *
const _moons_molecfit_calctrans_description =
59 "Produces the model using molecfit\n"
61 " * file (RBN) with tag SCIENCE 1 file : "
62 "molecfit_calctrans star file\n"
63 " * file (MOLECULES) with tag MOLECULES 1 file : "
64 "molecules list file\n"
66 " * GDAS User GDAS profile"
67 " * GDAS_BEFORE If ESO DB GDAS is used, file before the MJD-OBS"
68 " * GDAS_AFTER If ESO DB GDAS is used, file after the MJD-OBS"
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_calctrans",
95 "Produces the instrumental response for relative flux "
96 "calibration, and the telluric absorption spectrum.",
97 _moons_molecfit_calctrans_description,
"Regis Haigron",
99 _moons_molecfit_calctrans_create,
100 _moons_molecfit_calctrans_exec,
101 _moons_molecfit_calctrans_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);
128_moons_molecfit_calctrans_create(cpl_plugin *plugin)
133 if (cpl_error_get_code() != CPL_ERROR_NONE) {
134 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
135 cpl_func, __LINE__, cpl_error_get_where());
136 return (
int)cpl_error_get_code();
139 if (plugin == NULL) {
140 cpl_msg_error(cpl_func,
"Null plugin");
141 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
145 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
146 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
147 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
151 recipe = (cpl_recipe *)plugin;
154 recipe->parameters = cpl_parameterlist_new();
155 if (recipe->parameters == NULL) {
156 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
157 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
160 moo_params *params =
moo_params_new(
"moons",
"moons_molecfit_calctrans");
180_moons_molecfit_calctrans_exec(cpl_plugin *plugin)
184 cpl_errorstate initial_errorstate = cpl_errorstate_get();
187 if (cpl_error_get_code() != CPL_ERROR_NONE) {
188 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
189 cpl_func, __LINE__, cpl_error_get_where());
190 return (
int)cpl_error_get_code();
193 if (plugin == NULL) {
194 cpl_msg_error(cpl_func,
"Null plugin");
195 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
199 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
200 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
201 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
205 recipe = (cpl_recipe *)plugin;
208 if (recipe->parameters == NULL) {
209 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
210 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
212 if (recipe->frames == NULL) {
213 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
214 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
219 _moons_molecfit_calctrans(recipe->frames, recipe->parameters);
222 if (cpl_dfs_update_product_header(recipe->frames)) {
224 recipe_status = (int)cpl_error_get_code();
227 if (!cpl_errorstate_is_equal(initial_errorstate)) {
230 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
233 return recipe_status;
246_moons_molecfit_calctrans_destroy(cpl_plugin *plugin)
250 if (plugin == NULL) {
251 cpl_msg_error(cpl_func,
"Null plugin");
252 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
256 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
257 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
258 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
262 recipe = (cpl_recipe *)plugin;
264 cpl_parameterlist_delete(recipe->parameters);
270_moons_molecfit_calctrans_check_sof(cpl_frameset *frameset,
271 const cpl_frame **sci_frame,
272 const cpl_frame **molecules_frame,
273 const cpl_frame **atm_frame,
274 const cpl_frame **best_fit_frame,
275 const cpl_frame **kernel_lib_frame)
278 cpl_error_get_code());
281 for (i = 0; i < cpl_frameset_get_size(frameset); ++i) {
282 cpl_frame *current_frame = cpl_frameset_get_position(frameset, i);
283 if (!strcmp(cpl_frame_get_tag(current_frame), MOONS_TAG_MOLECFIT_SCI)) {
284 *sci_frame = current_frame;
286 else if (!strcmp(cpl_frame_get_tag(current_frame),
287 MOONS_TAG_MOLECFIT_MOLECULES)) {
288 *molecules_frame = current_frame;
290 else if (!strcmp(cpl_frame_get_tag(current_frame),
291 MOONS_TAG_MOLECFIT_ATM_PARAMS)) {
292 *atm_frame = current_frame;
294 else if (!strcmp(cpl_frame_get_tag(current_frame),
295 MOONS_TAG_MOLECFIT_BEST_FIT_PARAMS)) {
296 *best_fit_frame = current_frame;
298 else if (!strcmp(cpl_frame_get_tag(current_frame),
299 MOONS_TAG_MOLECFIT_KERNEL_LIBRARY)) {
300 *kernel_lib_frame = current_frame;
303 if (*sci_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_SCI);
310 if (*molecules_frame == NULL) {
311 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
312 "SOF does not have any file tagged "
314 MOONS_TAG_MOLECFIT_MOLECULES);
317 if (*atm_frame == NULL) {
318 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
319 "SOF does not have any file tagged "
321 MOONS_TAG_MOLECFIT_ATM_PARAMS);
324 if (*best_fit_frame == NULL) {
325 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
326 "SOF does not have any file tagged "
328 MOONS_TAG_MOLECFIT_BEST_FIT_PARAMS);
330 return CPL_ERROR_NONE;
343_moons_molecfit_calctrans(cpl_frameset *frameset,
344 const cpl_parameterlist *parlist)
348 const char *modename = NULL;
350 const cpl_frame *science_frame = NULL;
351 const cpl_frame *molecule_frame = NULL;
352 const cpl_frame *atm_frame = NULL;
353 const cpl_frame *best_fit_frame = NULL;
354 const cpl_frame *kernel_lib_frame = NULL;
355 moo_telluric *telluric = NULL;
356 char *telluric_filename = NULL;
357 moo_molecfit_calctrans_params *molecfit_calctrans_params = NULL;
359 moo_products *products =
361 PACKAGE
"/" PACKAGE_VERSION);
365 moo_try_check(molecfit_calctrans_params =
370 moo_try_check(_moons_molecfit_calctrans_check_sof(frameset, &science_frame,
380 moo_try_check(telluric =
382 molecule_frame, atm_frame,
383 best_fit_frame, kernel_lib_frame,
384 molecfit_calctrans_params),
386 telluric_filename = cpl_sprintf(
"%s_%s.fits", MOONS_TAG_TELLURIC_CORR,
390 CPL_FRAME_LEVEL_FINAL,
391 MOONS_TAG_TELLURIC_CORR,
392 telluric_filename, science_frame),
396 cpl_free(telluric_filename);
399 moo_products_delete(products);
400 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.
cpl_error_code moo_params_add_molecfit_calctrans(moo_params *self, cpl_parameterlist *list)
Add default parameters for molecfit_calctrans.
moo_molecfit_calctrans_params * moo_params_get_molecfit_calctrans(const moo_params *self, const cpl_parameterlist *list)
Get molecfit calctrans parameters from moons parameters list.
void moo_molecfit_calctrans_params_delete(moo_molecfit_calctrans_params *self)
Delete a moo_molecfit_calctrans_params.
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_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.
moo_telluric * moo_molecfit_calctrans(const cpl_frame *rbn_frame, const char *modename, const cpl_frame *molecules_frame, const cpl_frame *atm_frame, const cpl_frame *best_fit_frame, const cpl_frame *kernel_lib_frame, moo_molecfit_calctrans_params *params)
Apply the molcecfit calctrans to the RBN to compute telle telluric correction.
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
const moo_params * moo_products_get_params(const moo_products *self)
get the moo_params object
cpl_frame * moo_products_add_telluric(moo_products *self, moo_telluric *tell, cpl_frame_level level, const char *tag, const char *filename, const cpl_frame *inherit_frame)
create a product from a TELLURIC object
const char * moo_get_license(void)
Get the pipeline copyright and license.