FORS Pipeline Reference Manual  4.12.5
test_hough.c
1 /* $Id: test_hough.c,v 1.5 2013-04-24 14:14:13 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: 2013-04-24 14:14:13 $
24  * $Revision: 1.5 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 #include <math.h>
33 #include <cpl.h>
34 #include <moses.h>
35 #include <fors_dfs.h>
36 #include <fors_qc.h>
37 
38 static int test_hough_create(cpl_plugin *);
39 static int test_hough_exec(cpl_plugin *);
40 static int test_hough_destroy(cpl_plugin *);
41 static int test_hough(cpl_parameterlist *, cpl_frameset *);
42 
43 static char test_hough_description[] =
44 "This recipe is used to test the Hough transformation on any table.\n\n"
45 "Input files:\n\n"
46 " DO category: Type: Explanation:\n"
47 " TABLE Raw Table with at least 2 numerical columns.\n\n"
48 "Output files:\n\n"
49 " DO category: Data type: Explanation:\n"
50 " TRANSFORMED FITS table Table with estimates.\n\n";
51 
52 #define test_hough_exit(message) \
53 { \
54 if (message) cpl_msg_error(recipe, message); \
55 cpl_table_delete(table); \
56 cpl_table_delete(output); \
57 cpl_msg_indent_less(); \
58 return -1; \
59 }
60 
61 #define test_hough_exit_memcheck(message) \
62 { \
63 if (message) cpl_msg_info(recipe, message); \
64 cpl_table_delete(table); \
65 cpl_table_delete(output); \
66 cpl_msg_indent_less(); \
67 return 0; \
68 }
69 
70 
82 int cpl_plugin_get_info(cpl_pluginlist *list)
83 {
84  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe );
85  cpl_plugin *plugin = &recipe->interface;
86 
87  cpl_plugin_init(plugin,
88  CPL_PLUGIN_API,
89  FORS_BINARY_VERSION,
90  CPL_PLUGIN_TYPE_RECIPE,
91  "test_hough",
92  "Test Hough transform on any table of points",
93  test_hough_description,
94  "Carlo Izzo",
95  PACKAGE_BUGREPORT,
96  "This file is currently part of the FORS Instrument Pipeline\n"
97  "Copyright (C) 2002-2010 European Southern Observatory\n\n"
98  "This program is free software; you can redistribute it and/or modify\n"
99  "it under the terms of the GNU General Public License as published by\n"
100  "the Free Software Foundation; either version 2 of the License, or\n"
101  "(at your option) any later version.\n\n"
102  "This program is distributed in the hope that it will be useful,\n"
103  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
104  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
105  "GNU General Public License for more details.\n\n"
106  "You should have received a copy of the GNU General Public License\n"
107  "along with this program; if not, write to the Free Software Foundation,\n"
108  "Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n",
109  test_hough_create,
110  test_hough_exec,
111  test_hough_destroy);
112 
113  cpl_pluginlist_append(list, plugin);
114 
115  return 0;
116 }
117 
118 
129 static int test_hough_create(cpl_plugin *plugin)
130 {
131  cpl_recipe *recipe;
132  cpl_parameter *p;
133 
134 
135  /*
136  * Check that the plugin is part of a valid recipe
137  */
138 
139  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
140  recipe = (cpl_recipe *)plugin;
141  else
142  return -1;
143 
144  /*
145  * Create the parameters list in the cpl_recipe object
146  */
147 
148  recipe->parameters = cpl_parameterlist_new();
149 
150 
151  /*
152  * Table column with x coordinate
153  */
154 
155  p = cpl_parameter_new_value("fors.test_hough.xcolumn",
156  CPL_TYPE_STRING,
157  "Table column with x coordinate",
158  "fors.test_hough",
159  "0");
160  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "xcolumn");
161  cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
162  cpl_parameterlist_append(recipe->parameters, p);
163 
164  /*
165  * Table column with y coordinate
166  */
167 
168  p = cpl_parameter_new_value("fors.test_hough.ycolumn",
169  CPL_TYPE_STRING,
170  "Table column with y coordinate",
171  "fors.test_hough",
172  "0");
173  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ycolumn");
174  cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
175  cpl_parameterlist_append(recipe->parameters, p);
176 
177  return 0;
178 }
179 
180 
189 static int test_hough_exec(cpl_plugin *plugin)
190 {
191  cpl_recipe *recipe;
192 
193  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
194  recipe = (cpl_recipe *)plugin;
195  else
196  return -1;
197 
198  return test_hough(recipe->parameters, recipe->frames);
199 }
200 
201 
210 static int test_hough_destroy(cpl_plugin *plugin)
211 {
212  cpl_recipe *recipe;
213 
214  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
215  recipe = (cpl_recipe *)plugin;
216  else
217  return -1;
218 
219  cpl_parameterlist_delete(recipe->parameters);
220 
221  return 0;
222 }
223 
224 
234 static int test_hough(cpl_parameterlist *parlist, cpl_frameset *frameset)
235 {
236 
237  const char *recipe = "test_hough";
238 
239 
240  /*
241  * Input parameters
242  */
243 
244  const char *xcolumn;
245  const char *ycolumn;
246 
247  /*
248  * CPL objects
249  */
250 
251  cpl_table *table = NULL;
252  cpl_table *output = NULL;
253 
254  /*
255  * Auxiliary variables
256  */
257 
258  int nframes;
259 
260  cpl_msg_set_indentation(2);
261 
262 
263  /*
264  * Get configuration parameters
265  */
266 
267  cpl_msg_info(recipe, "Recipe %s configuration parameters:", recipe);
268  cpl_msg_indent_more();
269 
270  xcolumn = dfs_get_parameter_string(parlist,
271  "fors.test_hough.xcolumn", NULL);
272  ycolumn = dfs_get_parameter_string(parlist,
273  "fors.test_hough.ycolumn", NULL);
274 
275  if (cpl_error_get_code())
276  test_hough_exit("Failure getting the configuration parameters");
277 
278  /*
279  * Check input set-of-frames
280  */
281 
282  cpl_msg_indent_less();
283  cpl_msg_info(recipe, "Check input set-of-frames:");
284  cpl_msg_indent_more();
285 
286  nframes = cpl_frameset_count_tags(frameset, "TABLE");
287 
288  if (nframes == 0)
289  test_hough_exit("Missing input table");
290 
291  if (nframes > 1) {
292  cpl_msg_error(recipe, "Too many input tables found (%d). "
293  "Just one is required.", nframes);
294  test_hough_exit(NULL);
295  }
296 
297  cpl_msg_info(recipe, "Load %s frame...", "TABLE");
298  cpl_msg_indent_more();
299 
300  table = dfs_load_table(frameset, "TABLE", 1);
301 
302  output = mos_hough_table(table, xcolumn, ycolumn);
303  cpl_table_delete(table); table = NULL;
304 
305  if (dfs_save_table(frameset, output, "TRANSFORMED", NULL,
306  parlist, recipe, "test_version"))
307  test_hough_exit(NULL);
308 
309  cpl_table_delete(output); output = NULL;
310 
311  return 0;
312 
313 }
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
Definition: fors_bias.c:62
const char * dfs_get_parameter_string(cpl_parameterlist *parlist, const char *name, const cpl_table *defaults)
Reading a recipe string parameter value.
Definition: fors_dfs.c:587
cpl_table * dfs_load_table(cpl_frameset *frameset, const char *category, int ext)
Loading table data of given category.
Definition: fors_dfs.c:901
int dfs_save_table(cpl_frameset *frameset, const cpl_table *table, const char *category, cpl_propertylist *header, const cpl_parameterlist *parlist, const char *recipename, const char *version)
Saving table data of given category.
Definition: fors_dfs.c:1574
Definition: list.c:74