00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032 #include <math.h>
00033 #include <cpl.h>
00034 #include <moses.h>
00035 #include <fors_dfs.h>
00036 #include <fors_qc.h>
00037
00038 static int test_hough_create(cpl_plugin *);
00039 static int test_hough_exec(cpl_plugin *);
00040 static int test_hough_destroy(cpl_plugin *);
00041 static int test_hough(cpl_parameterlist *, cpl_frameset *);
00042
00043 static char test_hough_description[] =
00044 "This recipe is used to test the Hough transformation on any table.\n\n"
00045 "Input files:\n\n"
00046 " DO category: Type: Explanation:\n"
00047 " TABLE Raw Table with at least 2 numerical columns.\n\n"
00048 "Output files:\n\n"
00049 " DO category: Data type: Explanation:\n"
00050 " TRANSFORMED FITS table Table with estimates.\n\n";
00051
00052 #define test_hough_exit(message) \
00053 { \
00054 if (message) cpl_msg_error(recipe, message); \
00055 cpl_table_delete(table); \
00056 cpl_table_delete(output); \
00057 cpl_msg_indent_less(); \
00058 return -1; \
00059 }
00060
00061 #define test_hough_exit_memcheck(message) \
00062 { \
00063 if (message) cpl_msg_info(recipe, message); \
00064 cpl_table_delete(table); \
00065 cpl_table_delete(output); \
00066 cpl_msg_indent_less(); \
00067 return 0; \
00068 }
00069
00070
00082 int cpl_plugin_get_info(cpl_pluginlist *list)
00083 {
00084 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe );
00085 cpl_plugin *plugin = &recipe->interface;
00086
00087 cpl_plugin_init(plugin,
00088 CPL_PLUGIN_API,
00089 FORS_BINARY_VERSION,
00090 CPL_PLUGIN_TYPE_RECIPE,
00091 "test_hough",
00092 "Test Hough transform on any table of points",
00093 test_hough_description,
00094 "Carlo Izzo",
00095 PACKAGE_BUGREPORT,
00096 "This file is currently part of the FORS Instrument Pipeline\n"
00097 "Copyright (C) 2002-2010 European Southern Observatory\n\n"
00098 "This program is free software; you can redistribute it and/or modify\n"
00099 "it under the terms of the GNU General Public License as published by\n"
00100 "the Free Software Foundation; either version 2 of the License, or\n"
00101 "(at your option) any later version.\n\n"
00102 "This program is distributed in the hope that it will be useful,\n"
00103 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00104 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
00105 "GNU General Public License for more details.\n\n"
00106 "You should have received a copy of the GNU General Public License\n"
00107 "along with this program; if not, write to the Free Software Foundation,\n"
00108 "Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n",
00109 test_hough_create,
00110 test_hough_exec,
00111 test_hough_destroy);
00112
00113 cpl_pluginlist_append(list, plugin);
00114
00115 return 0;
00116 }
00117
00118
00129 static int test_hough_create(cpl_plugin *plugin)
00130 {
00131 cpl_recipe *recipe;
00132 cpl_parameter *p;
00133
00134
00135
00136
00137
00138
00139 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00140 recipe = (cpl_recipe *)plugin;
00141 else
00142 return -1;
00143
00144
00145
00146
00147
00148 recipe->parameters = cpl_parameterlist_new();
00149
00150
00151
00152
00153
00154
00155 p = cpl_parameter_new_value("fors.test_hough.xcolumn",
00156 CPL_TYPE_STRING,
00157 "Table column with x coordinate",
00158 "fors.test_hough",
00159 "0");
00160 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "xcolumn");
00161 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00162 cpl_parameterlist_append(recipe->parameters, p);
00163
00164
00165
00166
00167
00168 p = cpl_parameter_new_value("fors.test_hough.ycolumn",
00169 CPL_TYPE_STRING,
00170 "Table column with y coordinate",
00171 "fors.test_hough",
00172 "0");
00173 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "ycolumn");
00174 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00175 cpl_parameterlist_append(recipe->parameters, p);
00176
00177 return 0;
00178 }
00179
00180
00189 static int test_hough_exec(cpl_plugin *plugin)
00190 {
00191 cpl_recipe *recipe;
00192
00193 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00194 recipe = (cpl_recipe *)plugin;
00195 else
00196 return -1;
00197
00198 return test_hough(recipe->parameters, recipe->frames);
00199 }
00200
00201
00210 static int test_hough_destroy(cpl_plugin *plugin)
00211 {
00212 cpl_recipe *recipe;
00213
00214 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00215 recipe = (cpl_recipe *)plugin;
00216 else
00217 return -1;
00218
00219 cpl_parameterlist_delete(recipe->parameters);
00220
00221 return 0;
00222 }
00223
00224
00234 static int test_hough(cpl_parameterlist *parlist, cpl_frameset *frameset)
00235 {
00236
00237 const char *recipe = "test_hough";
00238
00239
00240
00241
00242
00243
00244 const char *xcolumn;
00245 const char *ycolumn;
00246
00247
00248
00249
00250
00251 cpl_table *table = NULL;
00252 cpl_table *output = NULL;
00253
00254
00255
00256
00257
00258 int nframes;
00259
00260 cpl_msg_set_indentation(2);
00261
00262 if (dfs_files_dont_exist(frameset))
00263 test_hough_exit(NULL);
00264
00265
00266
00267
00268
00269
00270 cpl_msg_info(recipe, "Recipe %s configuration parameters:", recipe);
00271 cpl_msg_indent_more();
00272
00273 xcolumn = dfs_get_parameter_string(parlist,
00274 "fors.test_hough.xcolumn", NULL);
00275 ycolumn = dfs_get_parameter_string(parlist,
00276 "fors.test_hough.ycolumn", NULL);
00277
00278 if (cpl_error_get_code())
00279 test_hough_exit("Failure getting the configuration parameters");
00280
00281
00282
00283
00284
00285 cpl_msg_indent_less();
00286 cpl_msg_info(recipe, "Check input set-of-frames:");
00287 cpl_msg_indent_more();
00288
00289 nframes = cpl_frameset_count_tags(frameset, "TABLE");
00290
00291 if (nframes == 0)
00292 test_hough_exit("Missing input table");
00293
00294 if (nframes > 1) {
00295 cpl_msg_error(recipe, "Too many input tables found (%d). "
00296 "Just one is required.", nframes);
00297 test_hough_exit(NULL);
00298 }
00299
00300 cpl_msg_info(recipe, "Load %s frame...", "TABLE");
00301 cpl_msg_indent_more();
00302
00303 table = dfs_load_table(frameset, "TABLE", 1);
00304
00305 output = mos_hough_table(table, xcolumn, ycolumn);
00306 cpl_table_delete(table); table = NULL;
00307
00308 if (dfs_save_table(frameset, output, "TRANSFORMED", NULL,
00309 parlist, recipe, "test_version"))
00310 test_hough_exit(NULL);
00311
00312 cpl_table_delete(output); output = NULL;
00313
00314 return 0;
00315
00316 }