MUSE Pipeline Reference Manual  2.5.2
muse_illum_z.c
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set sw=2 sts=2 et cin: */
3 /*
4  * This file is part of the MUSE Instrument Pipeline
5  * Copyright (C) 2005-2015 European Southern Observatory
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 /* This file was automatically generated */
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 /*----------------------------------------------------------------------------*
29  * Includes *
30  *----------------------------------------------------------------------------*/
31 #include <string.h> /* strcmp(), strstr() */
32 #include <strings.h> /* strcasecmp() */
33 #include <cpl.h>
34 
35 #include "muse_illum_z.h" /* in turn includes muse.h */
36 
37 /*----------------------------------------------------------------------------*/
52 /*----------------------------------------------------------------------------*/
55 /*----------------------------------------------------------------------------*
56  * Static variables *
57  *----------------------------------------------------------------------------*/
58 static const char *muse_illum_help =
59  "The recipe copies the data of an illumination flat-field unmodified to the output file. However it alters the header data such that the result is a DFS compliant product file, which can be used in the on-line pipeline environment to correct the illumination of twilight and/or science observations. This recipe has no use in any environment other than the on-line pipeline environment!";
60 
61 static const char *muse_illum_help_esorex =
62  "\n\nInput frames for raw frame tag \"ILLUMFLAT\":\n"
63  "\n Frame tag Type Req #Fr Description"
64  "\n -------------------- ---- --- --- ------------"
65  "\n ILLUMFLAT raw Y 1 Illumination flat-field frame"
66  "\n\nProduct frames for raw frame tag \"ILLUMFLAT\":\n"
67  "\n Frame tag Level Description"
68  "\n -------------------- -------- ------------"
69  "\n ILLUM final \"Processed\" illumination flat-field";
70 
71 /*----------------------------------------------------------------------------*/
79 /*----------------------------------------------------------------------------*/
80 static cpl_recipeconfig *
81 muse_illum_new_recipeconfig(void)
82 {
83  cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
84 
85  cpl_recipeconfig_set_tag(recipeconfig, "ILLUMFLAT", 1, 1);
86  cpl_recipeconfig_set_output(recipeconfig, "ILLUMFLAT", "ILLUM");
87 
88  return recipeconfig;
89 } /* muse_illum_new_recipeconfig() */
90 
91 /*----------------------------------------------------------------------------*/
101 /*----------------------------------------------------------------------------*/
102 static cpl_error_code
103 muse_illum_prepare_header(const char *aFrametag, cpl_propertylist *aHeader)
104 {
105  cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
106  cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
107  if (!strcmp(aFrametag, "ILLUM")) {
108  } else {
109  cpl_msg_warning(__func__, "Frame tag %s is not defined", aFrametag);
110  return CPL_ERROR_ILLEGAL_INPUT;
111  }
112  return CPL_ERROR_NONE;
113 } /* muse_illum_prepare_header() */
114 
115 /*----------------------------------------------------------------------------*/
124 /*----------------------------------------------------------------------------*/
125 static cpl_frame_level
126 muse_illum_get_frame_level(const char *aFrametag)
127 {
128  if (!aFrametag) {
129  return CPL_FRAME_LEVEL_NONE;
130  }
131  if (!strcmp(aFrametag, "ILLUM")) {
132  return CPL_FRAME_LEVEL_FINAL;
133  }
134  return CPL_FRAME_LEVEL_NONE;
135 } /* muse_illum_get_frame_level() */
136 
137 /*----------------------------------------------------------------------------*/
146 /*----------------------------------------------------------------------------*/
147 static muse_frame_mode
148 muse_illum_get_frame_mode(const char *aFrametag)
149 {
150  if (!aFrametag) {
151  return MUSE_FRAME_MODE_ALL;
152  }
153  if (!strcmp(aFrametag, "ILLUM")) {
155  }
156  return MUSE_FRAME_MODE_ALL;
157 } /* muse_illum_get_frame_mode() */
158 
159 /*----------------------------------------------------------------------------*/
169 /*----------------------------------------------------------------------------*/
170 static int
171 muse_illum_create(cpl_plugin *aPlugin)
172 {
173  /* Check that the plugin is part of a valid recipe */
174  cpl_recipe *recipe;
175  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
176  recipe = (cpl_recipe *)aPlugin;
177  } else {
178  return -1;
179  }
180 
181  /* register the extended processing information (new FITS header creation, *
182  * getting of the frame level for a certain tag) */
184  muse_illum_new_recipeconfig(),
185  muse_illum_prepare_header,
186  muse_illum_get_frame_level,
187  muse_illum_get_frame_mode);
188 
189  /* XXX initialize timing in messages *
190  * since at least esorex is too stupid to turn it on, we have to do it */
192  cpl_msg_set_time_on();
193  }
194 
195  /* Create the parameter list in the cpl_recipe object */
196  recipe->parameters = cpl_parameterlist_new();
197  /* Fill the parameters list */
198 
199 
200  return 0;
201 } /* muse_illum_create() */
202 
203 /*----------------------------------------------------------------------------*/
214 /*----------------------------------------------------------------------------*/
215 static int
216 muse_illum_params_fill(muse_illum_params_t *aParams, cpl_parameterlist *aParameters)
217 {
218  cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
219  cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
220 
221 
222  return 0;
223 } /* muse_illum_params_fill() */
224 
225 /*----------------------------------------------------------------------------*/
232 /*----------------------------------------------------------------------------*/
233 static int
234 muse_illum_exec(cpl_plugin *aPlugin)
235 {
236  if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
237  return -1;
238  }
240  cpl_recipe *recipe = (cpl_recipe *)aPlugin;
241  cpl_msg_set_threadid_on();
242 
243  cpl_frameset *usedframes = cpl_frameset_new(),
244  *outframes = cpl_frameset_new();
245  muse_illum_params_t params;
246  muse_illum_params_fill(&params, recipe->parameters);
247 
248  cpl_errorstate prestate = cpl_errorstate_get();
249 
250  muse_processing *proc = muse_processing_new("muse_illum",
251  recipe);
252  int rc = muse_illum_compute(proc, &params);
253  cpl_frameset_join(usedframes, proc->usedframes);
254  cpl_frameset_join(outframes, proc->outframes);
256 
257  if (!cpl_errorstate_is_equal(prestate)) {
258  /* dump all errors from this recipe in chronological order */
259  cpl_errorstate_dump(prestate, CPL_FALSE, muse_cplerrorstate_dump_some);
260  /* reset message level to not get the same errors displayed again by esorex */
261  cpl_msg_set_level(CPL_MSG_INFO);
262  }
263  /* clean up duplicates in framesets of used and output frames */
266 
267  /* to get esorex to see our classification (frame groups etc.), *
268  * replace the original frameset with the list of used frames *
269  * before appending product output frames */
270  /* keep the same pointer, so just erase all frames, not delete the frameset */
271  muse_cplframeset_erase_all(recipe->frames);
272  cpl_frameset_join(recipe->frames, usedframes);
273  cpl_frameset_join(recipe->frames, outframes);
274  cpl_frameset_delete(usedframes);
275  cpl_frameset_delete(outframes);
276  return rc;
277 } /* muse_illum_exec() */
278 
279 /*----------------------------------------------------------------------------*/
286 /*----------------------------------------------------------------------------*/
287 static int
288 muse_illum_destroy(cpl_plugin *aPlugin)
289 {
290  /* Get the recipe from the plugin */
291  cpl_recipe *recipe;
292  if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
293  recipe = (cpl_recipe *)aPlugin;
294  } else {
295  return -1;
296  }
297 
298  /* Clean up */
299  cpl_parameterlist_delete(recipe->parameters);
301  return 0;
302 } /* muse_illum_destroy() */
303 
304 /*----------------------------------------------------------------------------*/
314 /*----------------------------------------------------------------------------*/
315 int
316 cpl_plugin_get_info(cpl_pluginlist *aList)
317 {
318  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
319  cpl_plugin *plugin = &recipe->interface;
320 
321  char *helptext;
323  helptext = cpl_sprintf("%s%s", muse_illum_help,
324  muse_illum_help_esorex);
325  } else {
326  helptext = cpl_sprintf("%s", muse_illum_help);
327  }
328 
329  /* Initialize the CPL plugin stuff for this module */
330  cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
331  CPL_PLUGIN_TYPE_RECIPE,
332  "muse_illum",
333  "Dummy recipe to convert a raw illumination flat field into a DFS product",
334  helptext,
335  "Ralf Palsa",
336  "usd-help@eso.org",
338  muse_illum_create,
339  muse_illum_exec,
340  muse_illum_destroy);
341  cpl_pluginlist_append(aList, plugin);
342  cpl_free(helptext);
343 
344  return 0;
345 } /* cpl_plugin_get_info() */
346 
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
Structure to hold the parameters of the muse_illum recipe.
Definition: muse_illum_z.h:48
muse_cplframework_type muse_cplframework(void)
Return the CPL framework the recipe is run under.
cpl_frameset * usedframes
muse_processing * muse_processing_new(const char *aName, cpl_recipe *aRecipe)
Create a new processing structure.
const char * muse_get_license(void)
Get the pipeline copyright and license.
Definition: muse_utils.c:83
muse_frame_mode
cpl_frameset * outframes
void muse_cplerrorstate_dump_some(unsigned aCurrent, unsigned aFirst, unsigned aLast)
Dump some CPL errors.
void muse_processinginfo_delete(cpl_recipe *)
Clear all information from the processing info and from the recipe config.
cpl_error_code muse_cplframeset_erase_duplicate(cpl_frameset *aFrames)
Erase all duplicate frames from a frameset.
cpl_error_code muse_cplframeset_erase_all(cpl_frameset *aFrames)
Erase all frames in a frameset.
void muse_processinginfo_register(cpl_recipe *, cpl_recipeconfig *, muse_processing_prepare_header_func *, muse_processing_get_frame_level_func *, muse_processing_get_frame_mode_func *)
Register extended functionalities for MUSE recipes.
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.