38 static int fors_config_create(cpl_plugin *);
39 static int fors_config_exec(cpl_plugin *);
40 static int fors_config_destroy(cpl_plugin *);
41 static int fors_config(cpl_parameterlist *, cpl_frameset *);
43 static char fors_config_description[] =
44 "This recipe is used to create the so-called GRISM_TABLE, containing all\n"
45 "the FORS spectral pipeline configuration parameters related to a specific\n"
46 "grism. This is a way to provide for each specific instrument mode a set of\n"
47 "appropriate defaults for the recipe parameters.\n"
48 "The values assigned to each input parameter of fors_config are simply\n"
49 "copied to a FITS table consisting of one row, and as many columns as the\n"
50 "input parameter: each column will have the same name and type of each\n"
51 "parameter. Only the three parameters \"instrument\", \"grism\", and\n"
52 "\"id\" are not written to the table columns, but to the descriptor header\n"
53 "keywords INSTRUME, ESO INS GRIS1 NAME, and ESO INS GRIS1 ID, that will be\n"
54 "used by the automatic pipeline for appropriate data association.\n\n"
55 "Input files: none\n\n"
56 " DO category: Type: Explanation: Required:\n"
58 " DO category: Data type: Explanation:\n"
59 " GRISM_TABLE FITS table Recipe configuration parameters\n\n";
61 #define fors_config_exit(message) \
63 if ((const char *)message != NULL) cpl_msg_error(recipe, message); \
64 cpl_table_delete(table); \
65 cpl_propertylist_delete(header); \
84 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe );
85 cpl_plugin *plugin = &recipe->interface;
87 cpl_plugin_init(plugin,
90 CPL_PLUGIN_TYPE_RECIPE,
92 "Creation of FORS recipes configuration tables",
93 fors_config_description,
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",
111 fors_config_destroy);
113 cpl_pluginlist_append(list, plugin);
129 static int fors_config_create(cpl_plugin *plugin)
139 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
140 recipe = (cpl_recipe *)plugin;
148 recipe->parameters = cpl_parameterlist_new();
155 p = cpl_parameter_new_value(
"fors.fors_config.dispersion",
157 "Expected spectral dispersion (Angstrom/pixel)",
160 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"dispersion");
161 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
162 cpl_parameterlist_append(recipe->parameters, p);
168 p = cpl_parameter_new_value(
"fors.fors_config.peakdetection",
170 "Peak detection threshold (ADU)",
173 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"peakdetection");
174 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
175 cpl_parameterlist_append(recipe->parameters, p);
181 p = cpl_parameter_new_value(
"fors.fors_config.wdegree",
183 "Degree of wavelength calibration polynomial",
186 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"wdegree");
187 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
188 cpl_parameterlist_append(recipe->parameters, p);
244 p = cpl_parameter_new_value(
"fors.fors_config.cdegree",
246 "Degree of spectral curvature polynomial",
249 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"cdegree");
250 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
251 cpl_parameterlist_append(recipe->parameters, p);
272 p = cpl_parameter_new_value(
"fors.fors_config.startwavelength",
274 "Start wavelength in spectral extraction",
277 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"startwavelength");
278 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
279 cpl_parameterlist_append(recipe->parameters, p);
285 p = cpl_parameter_new_value(
"fors.fors_config.endwavelength",
287 "End wavelength in spectral extraction",
290 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"endwavelength");
291 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
292 cpl_parameterlist_append(recipe->parameters, p);
398 p = cpl_parameter_new_value(
"fors.fors_config.instrument",
400 "Name of instrument",
403 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"instrument");
404 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
405 cpl_parameterlist_append(recipe->parameters, p);
411 p = cpl_parameter_new_value(
"fors.fors_config.grism",
416 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"grism");
417 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
418 cpl_parameterlist_append(recipe->parameters, p);
424 p = cpl_parameter_new_value(
"fors.fors_config.grism_id",
429 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"grism_id");
430 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
431 cpl_parameterlist_append(recipe->parameters, p);
437 p = cpl_parameter_new_value(
"fors.fors_config.filter",
442 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"filter");
443 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
444 cpl_parameterlist_append(recipe->parameters, p);
450 p = cpl_parameter_new_value(
"fors.fors_config.filter_id",
455 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"filter_id");
456 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
457 cpl_parameterlist_append(recipe->parameters, p);
471 static int fors_config_exec(cpl_plugin *plugin)
475 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
476 recipe = (cpl_recipe *)plugin;
480 return fors_config(recipe->parameters, recipe->frames);
492 static int fors_config_destroy(cpl_plugin *plugin)
496 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
497 recipe = (cpl_recipe *)plugin;
501 cpl_parameterlist_delete(recipe->parameters);
516 static int fors_config(cpl_parameterlist *parlist, cpl_frameset *frameset)
519 const char *recipe =
"fors_config";
527 double peakdetection;
530 double startwavelength;
531 double endwavelength;
545 const char *instrument;
547 const char *grism_id;
549 const char *filter_id;
551 char *filename = NULL;
557 cpl_table *table = NULL;
558 cpl_propertylist *header = NULL;
573 cpl_msg_info(recipe,
"Recipe %s configuration parameters:", recipe);
574 cpl_msg_indent_more();
576 table = cpl_table_new(1);
579 "fors.fors_config.dispersion", NULL);
581 if (dispersion <= 0.0)
582 fors_config_exit(
"Invalid spectral dispersion value");
584 cpl_table_new_column(table,
"dispersion", CPL_TYPE_DOUBLE);
585 cpl_table_set_double(table,
"dispersion", 0, dispersion);
588 "fors.fors_config.peakdetection", NULL);
589 if (peakdetection <= 0.0)
590 fors_config_exit(
"Invalid peak detection level");
592 cpl_table_new_column(table,
"peakdetection", CPL_TYPE_DOUBLE);
593 cpl_table_set_double(table,
"peakdetection", 0, peakdetection);
598 fors_config_exit(
"Invalid polynomial degree");
601 fors_config_exit(
"Max allowed polynomial degree is 5");
603 cpl_table_new_column(table,
"wdegree", CPL_TYPE_INT);
604 cpl_table_set_int(table,
"wdegree", 0, wdegree);
637 fors_config_exit(
"Invalid polynomial degree");
640 fors_config_exit(
"Max allowed polynomial degree is 5");
642 cpl_table_new_column(table,
"cdegree", CPL_TYPE_INT);
643 cpl_table_set_int(table,
"cdegree", 0, cdegree);
654 "fors.fors_config.startwavelength", NULL);
655 if (startwavelength > 1.0)
656 if (startwavelength < 3000.0 || startwavelength > 13000.0)
657 fors_config_exit(
"Invalid wavelength");
659 cpl_table_new_column(table,
"startwavelength", CPL_TYPE_DOUBLE);
660 cpl_table_set_double(table,
"startwavelength", 0, startwavelength);
663 "fors.fors_config.endwavelength", NULL);
664 if (endwavelength > 1.0)
665 if (endwavelength < 3000.0 || endwavelength > 13000.0)
666 fors_config_exit(
"Invalid wavelength");
668 if (startwavelength > 1.0 && endwavelength > 1.0)
669 if (endwavelength - startwavelength <= 0.0)
670 fors_config_exit(
"Invalid wavelength interval");
672 cpl_table_new_column(table,
"endwavelength", CPL_TYPE_DOUBLE);
673 cpl_table_set_double(table,
"endwavelength", 0, endwavelength);
714 header = cpl_propertylist_new();
717 "fors.fors_config.instrument", NULL);
718 cpl_propertylist_update_string(header,
"INSTRUME", instrument);
721 cpl_propertylist_update_string(header,
"ESO INS GRIS1 NAME", grism);
724 "fors.fors_config.grism_id", NULL);
725 cpl_propertylist_update_string(header,
"ESO INS GRIS1 ID", grism_id);
728 cpl_propertylist_update_string(header,
"ESO INS FILT1 NAME", filter);
731 "fors.fors_config.filter_id", NULL);
732 cpl_propertylist_update_string(header,
"ESO INS FILT1 ID", filter_id);
734 if (cpl_error_get_code())
735 fors_config_exit(
"Failed to get the configuration parameters");
737 cpl_propertylist_update_string(header,
"ESO PRO CATG",
"GRISM_TABLE");
740 len += strlen(instrument);
741 len += strlen(grism + 5);
742 len += strlen(grism_id);
743 len += strlen(filter);
744 len += strlen(filter_id);
746 filename = cpl_calloc(len,
sizeof(
char));
748 sprintf(filename,
"%s_GRS_%s_%s_%s_%s.fits",
749 instrument, grism + 5, grism_id+1, filter, filter_id+1);
751 cpl_table_save(table, header, NULL, filename, CPL_IO_DEFAULT);
752 cpl_propertylist_delete(header); header = NULL;
753 cpl_table_delete(table); table = NULL;
754 cpl_free(filename); filename = NULL;
756 if (cpl_error_get_code()) {
757 cpl_msg_error(cpl_error_get_where(),
"%s", cpl_error_get_message());
758 fors_config_exit(NULL);
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
const char * dfs_get_parameter_string(cpl_parameterlist *parlist, const char *name, const cpl_table *defaults)
Reading a recipe string parameter value.
int dfs_get_parameter_int(cpl_parameterlist *parlist, const char *name, const cpl_table *defaults)
Reading a recipe integer parameter value.
double dfs_get_parameter_double(cpl_parameterlist *parlist, const char *name, const cpl_table *defaults)
Reading a recipe double parameter value.