ERIS Pipeline Reference Manual 1.8.15
eris_recipe_calib.c
1/* $Id: eris_recipe_calib.c,v 1.6 2013-03-26 17:17:32 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:17:32 $
24 * $Revision: 1.6 $
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#include <string.h>
43
44/*-----------------------------------------------------------------------------
45 Static variables
46 -----------------------------------------------------------------------------*/
47
48static char eris_recipe_calib_description[] =
49"This example text is used to describe the recipe.\n"
50"The description should include the required FITS-files and\n"
51"their associated tags, e.g.\n"
52"ERIS-ERIS_RECIPE-CALIB-raw-file.fits " ERIS_RECIPE_CALIB_RAW "\n"
53"\n"
54"Additionally, it should describe functionality of the expected output."
55"\n";
56
57/*-----------------------------------------------------------------------------
58 Private function prototypes
59 -----------------------------------------------------------------------------*/
60
61cpl_recipe_define(eris_recipe_calib, ERIS_BINARY_VERSION, "Firstname Lastname",
62 PACKAGE_BUGREPORT, "2017",
63 "Short description of eris_recipe_calib",
64 eris_recipe_calib_description);
65
66/*-----------------------------------------------------------------------------
67 Function code
68 -----------------------------------------------------------------------------*/
69
70
71/*----------------------------------------------------------------------------*/
79/*----------------------------------------------------------------------------*/
80static
81cpl_error_code eris_recipe_calib_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_recipe_calib.str_option",
89 CPL_TYPE_STRING, "the string option",
90 "eris.eris_recipe_calib",NULL);
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 /* --boolopt */
96 p = cpl_parameter_new_value("eris.eris_recipe_calib.bool_option",
97 CPL_TYPE_BOOL, "a flag", "eris.eris_recipe_calib", TRUE);
98 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "boolopt");
99 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
100 cpl_parameterlist_append(self, p);
101
102 return cpl_errorstate_is_equal(prestate) ? CPL_ERROR_NONE
103 : cpl_error_set_where(cpl_func);
104}
105
106/*----------------------------------------------------------------------------*/
113/*----------------------------------------------------------------------------*/
114static int eris_recipe_calib(cpl_frameset * frameset,
115 const cpl_parameterlist * parlist)
116{
117 const cpl_parameter * param;
118 const char * str_option;
119 int bool_option;
120 cpl_frameset * rawframes;
121 const cpl_frame * firstframe;
122 double qc_param;
123 cpl_propertylist * plist;
124 cpl_propertylist * applist;
125 cpl_image * image;
126 int nraw;
127 int i;
128
129 /* Use the errorstate to detect an error in a function that does not
130 return an error code. */
131 cpl_errorstate prestate = cpl_errorstate_get();
132
133 /* HOW TO RETRIEVE INPUT PARAMETERS */
134 /* --stropt */
135 param = cpl_parameterlist_find_const(parlist,
136 "eris.eris_recipe_calib.str_option");
137 str_option = cpl_parameter_get_string(param);
138
139 /* --boolopt */
140 param = cpl_parameterlist_find_const(parlist,
141 "eris.eris_recipe_calib.bool_option");
142 bool_option = cpl_parameter_get_bool(param);
143
144 if (!cpl_errorstate_is_equal(prestate)) {
145 return (int)cpl_error_set_message(cpl_func, cpl_error_get_code(),
146 "Could not retrieve the input "
147 "parameters");
148 }
149
150 /* Identify the RAW and CALIB frames in the input frameset */
151 cpl_ensure_code(eris_dfs_set_groups(frameset) == CPL_ERROR_NONE,
152 cpl_error_get_code());
153
154 /* HOW TO ACCESS INPUT DATA */
155 /* - A required file */
156 rawframes = cpl_frameset_new();
157 nraw = 0;
158 for (i = 0; i<cpl_frameset_get_size(frameset); i++) {
159 const cpl_frame * current_frame;
160 current_frame = cpl_frameset_get_position_const(frameset, i);
161 if(!strcmp(cpl_frame_get_tag(current_frame), ERIS_RECIPE_CALIB_RAW)) {
162 cpl_frame * new_frame = cpl_frame_duplicate(current_frame);
163 cpl_frameset_insert(rawframes, new_frame);
164 nraw++;
165 }
166 }
167 if (nraw == 0) {
168 return (int)cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
169 "SOF does not have any file tagged "
170 "with %s", ERIS_RECIPE_CALIB_RAW);
171 }
172
173
174 /* HOW TO GET THE FIRST FRAME OF A FRAME */
175 firstframe = cpl_frameset_get_position_const(rawframes, 0);
176
177 /* HOW TO GET THE VALUE OF A FITS KEYWORD */
178 /* - Load only DETector related keys */
179 plist = cpl_propertylist_load_regexp(cpl_frame_get_filename(firstframe),
180 0, "ESO DET ", 0);
181 if (plist == NULL) {
182 /* In this case an error message is added to the error propagation */
183 return (int)cpl_error_set_message(cpl_func, cpl_error_get_code(),
184 "Could not read the FITS header");
185 }
186
187 if (bool_option == CPL_FALSE) {
188 cpl_msg_info(cpl_func, "Bool option unset: String: %s", str_option);
189 }
190
191 qc_param = eris_pfits_get_dit(plist);
192 cpl_propertylist_delete(plist);
193
194 /* Check for a change in the CPL error state */
195 /* - if it did change then propagate the error and return */
196 cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
197
198 /* NOW PERFORMING THE DATA REDUCTION */
199 /* Let's just load an image for the example */
200 image = cpl_image_load(cpl_frame_get_filename(firstframe), CPL_TYPE_FLOAT, 0,
201 0);
202 if (image == NULL) {
203 return (int)cpl_error_set_message(cpl_func, cpl_error_get_code(),
204 "Could not load the image");
205 }
206
207 applist = cpl_propertylist_new();
208
209 /* Add the product category */
210 cpl_propertylist_append_string(applist, CPL_DFS_PRO_CATG,
211 ERIS_RECIPE_OUT_CALIB_PROCATG);
212
213 /* Add a QC parameter */
214 cpl_propertylist_append_double(applist, "ESO QC QCPARAM", qc_param);
215
216 /* HOW TO SAVE A DFS-COMPLIANT PRODUCT TO DISK */
217 if (cpl_dfs_save_image(frameset, NULL, parlist, frameset, NULL, image,
218 CPL_BPP_IEEE_FLOAT, "eris_recipe_calib", applist,
219 NULL, PACKAGE "/" PACKAGE_VERSION,
220 "eris_recipe_calib.fits")) {
221 /* Propagate the error */
222 (void)cpl_error_set_where(cpl_func);
223 }
224
225 cpl_image_delete(image);
226 cpl_propertylist_delete(applist);
227
228 return (int)cpl_error_get_code();
229}
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