IIINSTRUMENT Pipeline Reference Manual 6.2.5
isaac_spc_wlmodel.c
1/* $Id: isaac_spc_wlmodel.c,v 1.7 2013-03-12 08:06:48 llundin Exp $
2 *
3 * This file is part of the ISAAC 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 02111-1307 USA
19 */
20
21/*
22 * $Author: llundin $
23 * $Date: 2013-03-12 08:06:48 $
24 * $Revision: 1.7 $
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 <math.h>
37#include <cpl.h>
38
39#include "isaac_physicalmodel.h"
40#include "isaac_utils.h"
41
42/*-----------------------------------------------------------------------------
43 Functions prototypes
44 -----------------------------------------------------------------------------*/
45
46static int isaac_spc_wlmodel_create(cpl_plugin *);
47static int isaac_spc_wlmodel_exec(cpl_plugin *);
48static int isaac_spc_wlmodel_destroy(cpl_plugin *);
49static int isaac_spc_wlmodel(cpl_parameterlist *);
50
51/*-----------------------------------------------------------------------------
52 Static variables
53 -----------------------------------------------------------------------------*/
54
55static char isaac_spc_wlmodel_description[] =
56"isaac_spc_wlmodel -- ISAAC spectro wavelength model\n";
57
58/*-----------------------------------------------------------------------------
59 Functions code
60 -----------------------------------------------------------------------------*/
61
62/*----------------------------------------------------------------------------*/
70/*----------------------------------------------------------------------------*/
71int cpl_plugin_get_info(cpl_pluginlist * list)
72{
73 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe));
74 cpl_plugin * plugin = &recipe->interface;
75
76 cpl_plugin_init(plugin,
77 CPL_PLUGIN_API,
78 ISAAC_BINARY_VERSION,
79 CPL_PLUGIN_TYPE_RECIPE,
80 "isaac_spc_wlmodel",
81 "Spectro wavelength model recipe",
82 isaac_spc_wlmodel_description,
83 "Lars Lundin",
84 PACKAGE_BUGREPORT,
86 isaac_spc_wlmodel_create,
87 isaac_spc_wlmodel_exec,
88 isaac_spc_wlmodel_destroy);
89
90 cpl_pluginlist_append(list, plugin);
91
92 return 0;
93}
94
95/*----------------------------------------------------------------------------*/
104/*----------------------------------------------------------------------------*/
105static int isaac_spc_wlmodel_create(cpl_plugin * plugin)
106{
107 cpl_recipe * recipe;
108 cpl_parameter * p;
109
110 /* Get the recipe out of the plugin */
111 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
112 recipe = (cpl_recipe *)plugin;
113 else return CPL_ERROR_UNSPECIFIED;
114
115 /* Create the parameters list in the cpl_recipe object */
116 recipe->parameters = cpl_parameterlist_new();
117
118 /* Fill the parameters list */
119 /* --wcen */
120 p = cpl_parameter_new_value("isaac.isaac_spc_wlmodel.wcen",CPL_TYPE_DOUBLE,
121 "the central wavelength in angstroms", "isaac.isaac_spc_wlmodel",
122 22000.0);
123 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wcen");
124 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
125 cpl_parameterlist_append(recipe->parameters, p);
126
127 /* --obj */
128 p = cpl_parameter_new_value("isaac.isaac_spc_wlmodel.obj",
129 CPL_TYPE_STRING, "objective (S1/S2/L1/L2/L3)",
130 "isaac.isaac_spc_wlmodel", "S2");
131 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "obj");
132 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
133 cpl_parameterlist_append(recipe->parameters, p);
134
135 /* --res */
136 p = cpl_parameter_new_value("isaac.isaac_spc_wlmodel.res",
137 CPL_TYPE_STRING, "resolution (LR/MR)",
138 "isaac.isaac_spc_wlmodel", "MR");
139 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "res");
140 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
141 cpl_parameterlist_append(recipe->parameters, p);
142
143 return 0;
144}
145
146/*----------------------------------------------------------------------------*/
152/*----------------------------------------------------------------------------*/
153static int isaac_spc_wlmodel_exec(cpl_plugin * plugin)
154{
155 cpl_recipe * recipe;
156
157 /* Get the recipe out of the plugin */
158 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
159 recipe = (cpl_recipe *)plugin;
160 else return CPL_ERROR_UNSPECIFIED;
161
162 return isaac_spc_wlmodel(recipe->parameters);
163}
164
165/*----------------------------------------------------------------------------*/
171/*----------------------------------------------------------------------------*/
172static int isaac_spc_wlmodel_destroy(cpl_plugin * plugin)
173{
174 cpl_recipe * recipe;
175
176 /* Get the recipe out of the plugin */
177 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
178 recipe = (cpl_recipe *)plugin;
179 else return CPL_ERROR_UNSPECIFIED;
180
181 cpl_parameterlist_delete(recipe->parameters);
182 return 0;
183}
184
185/*----------------------------------------------------------------------------*/
192/*----------------------------------------------------------------------------*/
193static int isaac_spc_wlmodel(cpl_parameterlist * parlist)
194{
195 cpl_parameter * par;
196 double * wlcal;
197 double wcen;
198 const char * obj;
199 const char * res;
200 FILE * fp;
201 int i;
202
203 /* Initialise */
204 par = NULL;
205
206 /* Retrieve input parameters */
207 /* --wcen */
208 par = cpl_parameterlist_find(parlist, "isaac.isaac_spc_wlmodel.wcen");
209 wcen = cpl_parameter_get_double(par);
210
211 /* --obj */
212 par = cpl_parameterlist_find(parlist, "isaac.isaac_spc_wlmodel.obj");
213 obj = cpl_parameter_get_string(par);
214
215 /* --res */
216 par = cpl_parameterlist_find(parlist, "isaac.isaac_spc_wlmodel.res");
217 res = cpl_parameter_get_string(par);
218
219 /* Physical model */
220 wlcal = isaac_physical_model(wcen, obj, res, 1024);
221 if (wlcal == NULL) {
222 cpl_msg_error(cpl_func, "Cannot compute the physical model");
223 return CPL_ERROR_UNSPECIFIED;
224 }
225
226 /* Save results */
227 if ((fp = fopen("wavecal.txt", "w")) == NULL) {
228 cpl_msg_error(cpl_func, "Cannot open the output file");
229 cpl_free(wlcal);
230 return CPL_ERROR_UNSPECIFIED;
231 }
232 for (i=0; i<1024; i++) fprintf(fp, "%d\t\t%g\n", i+1, wlcal[i]);
233 fclose(fp);
234 cpl_free(wlcal);
235 return 0;
236}
237
double * isaac_physical_model(double lambda_c, const char *objective, const char *resolution, int nbpix)
ISAAC physical model.
const char * isaac_get_license(void)
Get the pipeline copyright and license.
Definition: isaac_utils.c:62