FORS Pipeline Reference Manual  5.0.9
fors_bias.c
1 /* $Id: fors_bias.c,v 1.9 2011-10-12 14:59:57 cgarcia Exp $
2  *
3  * This file is part of the FORS Data Reduction Pipeline
4  * Copyright (C) 2002-2010 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: cgarcia $
23  * $Date: 2011-10-12 14:59:57 $
24  * $Revision: 1.9 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 #include <fors_bias_impl.h>
33 #include <fors_dfs.h>
34 #include <fors_utils.h>
35 
36 #include <cpl.h>
37 
38 static int fors_bias_create(cpl_plugin *);
39 static int fors_bias_exec(cpl_plugin *);
40 static int fors_bias_destroy(cpl_plugin *);
41 
62 int cpl_plugin_get_info(cpl_pluginlist *list)
63 {
64  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe );
65  cpl_plugin *plugin = &recipe->interface;
66 
67  if (FORS_BINARY_VERSION != fors_get_version_binary())
68  {
69  cpl_msg_error(cpl_func,
70  "I am fors_bias version %d, but I am linking "
71  "against the FORS library version %d. "
72  "This will not work. "
73  "Please remove all previous installations "
74  "of the " PACKAGE_NAME " and try again.",
75  FORS_BINARY_VERSION, fors_get_version_binary());
76  return 1;
77  }
78 
79  cpl_plugin_init(plugin,
80  CPL_PLUGIN_API,
81  FORS_BINARY_VERSION,
82  CPL_PLUGIN_TYPE_RECIPE,
83  fors_bias_name,
84  fors_bias_description_short,
85  fors_bias_description,
86  fors_bias_author,
87  fors_bias_email,
92 
93  cpl_pluginlist_append(list, plugin);
94 
95  return 0;
96 }
97 
98 
109 static int fors_bias_create(cpl_plugin *plugin)
110 {
111  cpl_recipe *recipe;
112 
113  if (cpl_error_get_code() != CPL_ERROR_NONE) {
114  cpl_msg_error(cpl_func,
115  "CPL error code is set (%s), "
116  "refusing to create recipe fors_bias",
117  cpl_error_get_message());
118  return 1;
119  }
120 
121  /*
122  * Check that the plugin is part of a valid recipe
123  */
124 
125  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) {
126  recipe = (cpl_recipe *)plugin;
127  }
128  else {
129  return 1;
130  }
131 
132  /*
133  * Create the parameters list in the cpl_recipe object
134  */
135 
136  recipe->parameters = cpl_parameterlist_new();
137 
138  fors_bias_define_parameters(recipe->parameters);
139 
140  if (cpl_error_get_code() != CPL_ERROR_NONE) {
141  cpl_msg_error(cpl_func,
142  "Could not create fors_bias parameters");
143  return 1;
144  }
145 
146  return 0;
147 }
148 
149 
158 static int fors_bias_exec(cpl_plugin *plugin)
159 {
160  cpl_recipe *recipe;
161  cpl_errorstate initial_errorstate = cpl_errorstate_get();
162 
163  if (cpl_error_get_code() != CPL_ERROR_NONE) {
164  cpl_msg_error(cpl_func,
165  "CPL error code is set (%s), "
166  "refusing to execute recipe fors_bias",
167  cpl_error_get_message());
168  return 1;
169  }
170 
171  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) {
172  recipe = (cpl_recipe *)plugin;
173  }
174  else {
175  return 1;
176  }
177 
178  if (recipe->frames == NULL) {
179  cpl_msg_error(cpl_func,
180  "Null frameset");
181  return 1;
182  }
183 
184  if (recipe->parameters == NULL) {
185  cpl_msg_error(cpl_func,
186  "Null parameter list");
187  return 1;
188  }
189 
190  /* Issue a banner */
192 
193  fors_bias(recipe->frames, recipe->parameters);
194 
195  return fors_end(recipe->frames, initial_errorstate);
196 }
197 
198 
207 static int fors_bias_destroy(cpl_plugin *plugin)
208 {
209  cpl_recipe *recipe;
210 
211  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) {
212  recipe = (cpl_recipe *)plugin;
213  }
214  else {
215  return -1;
216  }
217 
218  cpl_parameterlist_delete(recipe->parameters);
219 
220  return 0;
221 }
222 
void fors_print_banner(void)
Issue a banner with the pipeline version.
Definition: fors_utils.c:92
int fors_end(const cpl_frameset *frames, cpl_errorstate before_exec)
End recipe execution.
Definition: fors_dfs.c:219
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
Definition: fors_bias.c:62
static int fors_bias_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
Definition: fors_bias.c:158
static int fors_bias_create(cpl_plugin *)
Setup the recipe options.
Definition: fors_bias.c:109
int fors_get_version_binary(void)
Get FORS library binary version number.
Definition: fors_utils.c:107
static int fors_bias_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
Definition: fors_bias.c:207
Definition: list.c:74
const char * fors_get_license(void)
Get the pipeline copyright and license.
Definition: fors_utils.c:65