ERIS Pipeline Reference Manual 1.9.2
eris_ifu_recipe.c
1/* $Id: eris_ifu_recipe.c,v 1.33 2013-03-26 17:00:45 jtaylor Exp $
2 *
3 * This file is part of the ERIS Pipeline
4 * Copyright (C) 2002,2003 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/*
22 * $Author: jtaylor $
23 * $Date: 2013-03-26 17:00:45 $
24 * $Revision: 1.33 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32/*-----------------------------------------------------------------------------
33 Includes
34 -----------------------------------------------------------------------------*/
35
36#include "eris_utils.h"
37#include "eris_pfits.h"
38#include "eris_dfs.h"
39
40#include <cpl.h>
41
42/*-----------------------------------------------------------------------------
43 Static variables
44 -----------------------------------------------------------------------------*/
45
46static const char eris_ifu_recipe_description[] =
47"This example text is used to describe the recipe.\n"
48"The description should include the required FITS-files and\n"
49"their associated tags, e.g.\n"
50"ERIS-ERIS_IFU_RECIPE-raw-file.fits " ERIS_IFU_RECIPE_RAW "\n"
51"and any optional files, e.g.\n"
52"ERIS-ERIS_IFU_RECIPE-flat-file.fits " ERIS_CALIB_FLAT "\n"
53"\n"
54"Additionally, it should describe functionality of the expected output."
55"\n";
56
57static const char eris_ifu_recipe_name[] = "eris_ifu_recipe";
58
59/*-----------------------------------------------------------------------------
60 Private function prototypes
61 -----------------------------------------------------------------------------*/
62
63cpl_recipe_define(eris_ifu_recipe, ERIS_BINARY_VERSION, "Firstname Lastname",
64 PACKAGE_BUGREPORT, "2017",
65 "Short description of eris_ifu_recipe",
66 eris_ifu_recipe_description);
67
68/*-----------------------------------------------------------------------------
69 Function code
70 -----------------------------------------------------------------------------*/
71
72/*----------------------------------------------------------------------------*/
80/*----------------------------------------------------------------------------*/
81static cpl_error_code eris_ifu_recipe_fill_parameterlist(cpl_parameterlist *self)
82{
83 cpl_errorstate prestate = cpl_errorstate_get();
84 cpl_parameter* p;
85
86 /* Fill the parameters list */
87 /* --stropt */
88 p = cpl_parameter_new_value("eris.eris_ifu_recipe.str_option",
89 CPL_TYPE_STRING, "the string option",
90 "eris.eris_ifu_recipe", "NONE");
91 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "stropt");
92 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
93 cpl_parameterlist_append(self, p);
94
95 p = cpl_parameter_new_value("eris.eris_ifu_recipe.file_option",
96 CPL_TYPE_STRING, "the file option",
97 "eris.eris_ifu_recipe", "NONE");
98 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "fileopt");
99 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
100 cpl_parameterlist_append(self, p);
101
102 /* --boolopt */
103 p = cpl_parameter_new_value("eris.eris_ifu_recipe.bool_option",
104 CPL_TYPE_BOOL, "a flag",
105 "eris.eris_ifu_recipe", TRUE);
106 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "boolopt");
107 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
108 cpl_parameterlist_append(self, p);
109
110 p = cpl_parameter_new_value("eris.eris_ifu_recipe.int_option",
111 CPL_TYPE_INT, "an integer",
112 "eris.eris_ifu_recipe", 3);
113 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intopt");
114 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
115 cpl_parameterlist_append(self, p);
116
117 p = cpl_parameter_new_value("eris.eris_ifu_recipe.float_option", CPL_TYPE_DOUBLE,
118 "A float",
119 "Example", 0.5);
120 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "floatopt");
121 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
122 cpl_parameterlist_append(self, p);
123
124 p = cpl_parameter_new_range("eris.eris_ifu_recipe.range_option", CPL_TYPE_INT,
125 "This is a value range of type int",
126 "Example", 3, 0, 10);
127 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "rangeopt");
128 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
129 cpl_parameterlist_append(self, p);
130
131 p = cpl_parameter_new_enum("eris.eris_ifu_recipe.enum_option", CPL_TYPE_STRING,
132 "This is an enumeration of type string",
133 "Example", "first", 3, "first", "second", "third");
134 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "enumopt");
135 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
136 cpl_parameterlist_append(self, p);
137
138 p = cpl_parameter_new_range("eris.eris_ifu_recipe.float_range_option", CPL_TYPE_DOUBLE,
139 "This is a value range of type float."
140 " Valid ragne is [-5.5, 5.5]",
141 "Example", 3.5, -5.5, 5.5);
142 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "floatrangeopt");
143 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
144 cpl_parameterlist_append(self, p);
145
146 return cpl_errorstate_is_equal(prestate) ? CPL_ERROR_NONE
147 : cpl_error_set_where(cpl_func);
148}
149
150/*----------------------------------------------------------------------------*/
157/*----------------------------------------------------------------------------*/
158static int eris_ifu_recipe(cpl_frameset * frameset,
159 const cpl_parameterlist * parlist)
160{
161 const cpl_parameter * param;
162 const char * str_option;
163 int bool_option;
164 const cpl_frame * rawframe;
165 const cpl_frame * flat;
166 double qc_param;
167 cpl_propertylist * plist;
168 cpl_propertylist * applist;
169 cpl_image * image;
170
171 /* Use the errorstate to detect an error in a function that does not
172 return an error code. */
173 cpl_errorstate prestate = cpl_errorstate_get();
174
175 /* HOW TO RETRIEVE INPUT PARAMETERS */
176 /* --stropt */
177 param = cpl_parameterlist_find_const(parlist,
178 "eris.eris_ifu_recipe.str_option");
179 str_option = cpl_parameter_get_string(param);
180
181 /* --boolopt */
182 param = cpl_parameterlist_find_const(parlist,
183 "eris.eris_ifu_recipe.bool_option");
184 bool_option = cpl_parameter_get_bool(param);
185
186 if (!cpl_errorstate_is_equal(prestate)) {
187 return (int)cpl_error_set_message(cpl_func, cpl_error_get_code(),
188 "Could not retrieve the input "
189 "parameters");
190 }
191
192 /* Identify the RAW and CALIB frames in the input frameset */
193 cpl_ensure_code(eris_dfs_set_groups(frameset) == CPL_ERROR_NONE,
194 cpl_error_get_code());
195
196 /* HOW TO ACCESS INPUT DATA */
197 /* - A required file */
198 rawframe = cpl_frameset_find_const(frameset, ERIS_IFU_RECIPE_RAW);
199 if (rawframe == NULL) {
200 /* cpl_frameset_find_const() does not set an error code, when a frame
201 is not found, so we will set one here. */
202 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
203 "SOF does not have any file tagged "
204 "with %s", ERIS_IFU_RECIPE_RAW);
205 }
206 /* - A recommended file */
207 flat = cpl_frameset_find(frameset, ERIS_CALIB_FLAT);
208 if (flat == NULL) {
209 cpl_msg_warning(cpl_func, "SOF does not have any file tagged with %s",
210 ERIS_CALIB_FLAT);
211 }
212
213 /* HOW TO GET THE VALUE OF A FITS KEYWORD */
214 /* - Load only DETector related keys */
215 plist = cpl_propertylist_load_regexp(cpl_frame_get_filename(rawframe),
216 0, "ESO DET ", 0);
217 if (plist == NULL) {
218 /* In this case an error message is added to the error propagation */
219 return (int)cpl_error_set_message(cpl_func, cpl_error_get_code(),
220 "Could not read the FITS header");
221 }
222
223 if (bool_option == CPL_FALSE) {
224 cpl_msg_info(cpl_func, "Bool option unset: String: %s", str_option);
225 }
226
227 qc_param = eris_pfits_get_dit(plist);
228 cpl_propertylist_delete(plist);
229
230 /* Check for a change in the CPL error state */
231 /* - if it did change then propagate the error and return */
232 cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
233
234 /* NOW PERFORMING THE DATA REDUCTION */
235 /* Let's just load an image for the example */
236 image = cpl_image_load(cpl_frame_get_filename(rawframe), CPL_TYPE_FLOAT, 0,
237 0);
238 if (image == NULL) {
239 return (int)cpl_error_set_message(cpl_func, cpl_error_get_code(),
240 "Could not load the image");
241 }
242
243 applist = cpl_propertylist_new();
244
245 /* Add the product category */
246 cpl_propertylist_append_string(applist, CPL_DFS_PRO_CATG,
247 ERIS_IFU_RECIPE_OUT_PROCATG);
248
249 /* Add a QC parameter */
250 cpl_propertylist_append_double(applist, "ESO QC QCPARAM", qc_param);
251
252 /* HOW TO SAVE A DFS-COMPLIANT PRODUCT TO DISK */
253 if (cpl_dfs_save_image(frameset, NULL, parlist, frameset, NULL, image,
254 CPL_BPP_IEEE_FLOAT, "eris_ifu_recipe", applist,
255 NULL, PACKAGE "/" PACKAGE_VERSION,
256 "eris_ifu_recipe.fits")) {
257 /* Propagate the error */
258 (void)cpl_error_set_where(cpl_func);
259 }
260
261 cpl_image_delete(image);
262 cpl_propertylist_delete(applist);
263
264 return (int)cpl_error_get_code();
265}
cpl_error_code eris_dfs_set_groups(cpl_frameset *self)
Set the group as RAW or CALIB in a frameset.
Definition: eris_dfs.c:57
double eris_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
Definition: eris_pfits.c:98