25 #include <cxmessages.h>
26 #include <cxstrutils.h>
29 #include <cpl_parameterlist.h>
32 #include "gifiberutils.h"
73 GiFibersConfig *config)
76 const cxchar *fctid =
"giraffe_fibers_select";
78 const cxchar *filename;
81 cxint *spectra = NULL;
88 if (!frame || !config) {
92 filename = cpl_frame_get_filename(frame);
93 cx_assert(filename != NULL);
96 if (config->spectra && *config->spectra !=
'\0') {
98 if (strcmp(config->spectra,
"setup") == 0) {
100 if (reference != NULL) {
106 cpl_msg_error(fctid,
"Invalid fiber setup!");
116 cpl_msg_error(fctid,
"Invalid selection string `%s'!",
123 if (config->nspec > 0) {
130 if (config->nspec < nspec) {
132 spectra = cx_realloc(spectra,
133 config->nspec *
sizeof(cxint));
134 nspec = config->nspec;
136 cpl_msg_warning(fctid,
"Requested number of spectra (%d) "
137 "is less than number of listed spectra "
138 "(%d). Using %d spectra.", config->nspec,
139 nspec, config->nspec);
143 if (config->nspec > nspec) {
145 cpl_msg_warning(fctid,
"Number of requested spectra "
146 "(%d) exceeds the number of listed "
147 "spectra (%d). Using all spectra in "
148 "the list!", config->nspec, nspec);
156 if (config->nspec > 0) {
165 nspec = config->nspec;
166 spectra = cx_malloc(nspec *
sizeof(cxint));
172 for (i = 0; i < nspec; i++) {
183 cpl_table_delete(_fibers);
221 const cxchar *fctid =
"giraffe_fibers_setup";
223 cxchar *filename = NULL;
225 cpl_table *_fibers =NULL;
227 GiTable *fibers = NULL;
231 cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
235 filename = (cxchar *)cpl_frame_get_filename(frame);
237 if (filename == NULL) {
238 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
244 if (_fibers == NULL) {
251 cpl_table_delete(_fibers);
260 if (reference != NULL) {
264 GiTable *rfibers = 0;
267 filename = (cxchar *)cpl_frame_get_filename(reference);
269 if (filename == NULL) {
272 cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
279 if (rfibers == NULL) {
320 GiFibersConfig *config = NULL;
327 config = cx_calloc(1,
sizeof *config);
335 config->spectra = NULL;
338 p = cpl_parameterlist_find(list,
"giraffe.fibers.nspectra");
339 config->nspec = cpl_parameter_get_int(p);
342 p = cpl_parameterlist_find(list,
"giraffe.fibers.spectra");
343 config->spectra = cx_strdup(cpl_parameter_get_string(p));
367 if (config->spectra) {
368 cx_free(config->spectra);
369 config->spectra = NULL;
401 p = cpl_parameter_new_value(
"giraffe.fibers.spectra",
403 "Index list of spectra to use for "
404 "localization (e.g. 2,10,30-40,55).",
407 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"fiber-splist");
408 cpl_parameterlist_append(list, p);
410 p = cpl_parameter_new_range(
"giraffe.fibers.nspectra",
412 "Number of spectra to localize.",
414 0, 0, CX_MAXINT - 1);
415 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"fiber-nspec");
416 cpl_parameterlist_append(list, p);
GiTable * giraffe_fibers_select(const cpl_frame *frame, const GiTable *reference, GiFibersConfig *config)
Selects the spectra to process.
void giraffe_fibers_config_destroy(GiFibersConfig *config)
Destroys a fibers setup structure.
void giraffe_fibers_config_add(cpl_parameterlist *list)
Adds parameters for the spectrum selection.
GiFibersConfig * giraffe_fibers_config_create(cpl_parameterlist *list)
Creates a setup structure for the fiber selection.
GiTable * giraffe_fibers_setup(const cpl_frame *frame, const cpl_frame *reference)
Setup a fiber list.
cxint * giraffe_create_spectrum_selection(const cxchar *filename, const GiTable *reference, cxint *nspec)
Create a spectrum selection from a reference table.
cxint * giraffe_parse_spectrum_selection(const cxchar *selection, cxint *nspec)
Parses a spectrum selection string.
cpl_table * giraffe_fiberlist_create(const cxchar *filename, cxint nspec, const cxint *spectra)
Creates the fiber table.
GiTable * giraffe_fiberlist_load(const cxchar *filename, cxint dataset, const cxchar *tag)
Load a fiber table from a file.
cxint giraffe_fiberlist_associate(GiTable *fibers, const GiTable *reference)
Associate a fiberlist with a reference list.
cxint giraffe_table_set(GiTable *self, cpl_table *table)
Sets the table data.
GiTable * giraffe_table_new(void)
Creates a new, empty Giraffe table.
void giraffe_table_delete(GiTable *self)
Destroys a Giraffe table.