GIRAFFE Pipeline Reference Manual

gifibers.c
1 /* $Id$
2  *
3  * This file is part of the GIRAFFE Pipeline
4  * Copyright (C) 2002-2006 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$
23  * $Date$
24  * $Revision$
25  * $Name$
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 
32 #include <cxmemory.h>
33 #include <cxmessages.h>
34 #include <cxstrutils.h>
35 
36 #include <cpl_msg.h>
37 #include <cpl_parameterlist.h>
38 
39 #include "giframe.h"
40 #include "gifiberutils.h"
41 #include "gifibers.h"
42 
43 
79 GiTable *
80 giraffe_fibers_select(const cpl_frame *frame, const GiTable *reference,
81  GiFibersConfig *config)
82 {
83 
84  const cxchar *fctid = "giraffe_fibers_select";
85 
86  const cxchar *filename;
87 
88  cxint nspec = 0;
89  cxint *spectra = NULL;
90 
91  cpl_table *_fibers;
92 
93  GiTable *fibers;
94 
95 
96  if (!frame || !config) {
97  return NULL;
98  }
99 
100  filename = cpl_frame_get_filename(frame);
101  cx_assert(filename != NULL);
102 
103 
104  if (config->spectra && *config->spectra != '\0') {
105 
106  if (strcmp(config->spectra, "setup") == 0) {
107 
108  if (reference != NULL) {
109  spectra = giraffe_create_spectrum_selection(filename, reference,
110  &nspec);
111  }
112 
113  if (!spectra) {
114  cpl_msg_error(fctid, "Invalid fiber setup!");
115  return NULL;
116  }
117 
118  }
119  else {
120 
121  spectra = giraffe_parse_spectrum_selection(config->spectra,
122  &nspec);
123  if (!spectra) {
124  cpl_msg_error(fctid, "Invalid selection string `%s'!",
125  config->spectra);
126  return NULL;
127  }
128 
129  }
130 
131  if (config->nspec > 0) {
132 
133  /*
134  * Both, the number of spectra and a selection list were
135  * given
136  */
137 
138  if (config->nspec < nspec) {
139 
140  spectra = cx_realloc(spectra,
141  config->nspec * sizeof(cxint));
142  nspec = config->nspec;
143 
144  cpl_msg_warning(fctid, "Requested number of spectra (%d) "
145  "is less than number of listed spectra "
146  "(%d). Using %d spectra.", config->nspec,
147  nspec, config->nspec);
148 
149  }
150  else {
151  if (config->nspec > nspec) {
152 
153  cpl_msg_warning(fctid, "Number of requested spectra "
154  "(%d) exceeds the number of listed "
155  "spectra (%d). Using all spectra in "
156  "the list!", config->nspec, nspec);
157 
158  }
159  }
160  }
161  }
162  else {
163 
164  if (config->nspec > 0) {
165 
166  /*
167  * No selection list, but the number of spectra to process
168  * was given.
169  */
170 
171  register cxint i;
172 
173  nspec = config->nspec;
174  spectra = cx_malloc(nspec * sizeof(cxint));
175 
176  /*
177  * Fiber positions in the image are counted starting from 1!
178  */
179 
180  for (i = 0; i < nspec; i++) {
181  spectra[i] = i + 1;
182  }
183  }
184  }
185 
186  _fibers = giraffe_fiberlist_create(filename, nspec, spectra);
187 
188  fibers = giraffe_table_new();
189  giraffe_table_set(fibers, _fibers);
190 
191  cpl_table_delete(_fibers);
192 
193 
194  /*
195  * Cleanup
196  */
197 
198  if (spectra) {
199  cx_free(spectra);
200  }
201 
202  return fibers;
203 
204 }
205 
206 
225 GiTable *
226 giraffe_fibers_setup(const cpl_frame *frame, const cpl_frame *reference)
227 {
228 
229  const cxchar *fctid = "giraffe_fibers_setup";
230 
231  cxchar *filename = NULL;
232 
233  cpl_table *_fibers =NULL;
234 
235  GiTable *fibers = NULL;
236 
237 
238  if (frame == NULL) {
239  cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
240  return NULL;
241  }
242 
243  filename = (cxchar *)cpl_frame_get_filename(frame);
244 
245  if (filename == NULL) {
246  cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
247  return NULL;
248  }
249 
250  _fibers = giraffe_fiberlist_create(filename, 0, NULL);
251 
252  if (_fibers == NULL) {
253  return NULL;
254  }
255 
256  fibers = giraffe_table_new();
257  giraffe_table_set(fibers, _fibers);
258 
259  cpl_table_delete(_fibers);
260  _fibers = NULL;
261 
262 
263  /*
264  * Associate the newly created fiber setup list with a reference list
265  * if it was given.
266  */
267 
268  if (reference != NULL) {
269 
270  cxint status;
271 
272  GiTable *rfibers = 0;
273 
274 
275  filename = (cxchar *)cpl_frame_get_filename(reference);
276 
277  if (filename == NULL) {
278 
279  giraffe_table_delete(fibers);
280  cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
281  return NULL;
282 
283  }
284 
285  rfibers = giraffe_fiberlist_load(filename, 1, GIFRAME_FIBER_SETUP);
286 
287  if (rfibers == NULL) {
288 
289  giraffe_table_delete(fibers);
290  return NULL;
291 
292  }
293 
294  status = giraffe_fiberlist_associate(fibers, rfibers);
295 
296  if (status) {
297  giraffe_table_delete(fibers);
298  giraffe_table_delete(rfibers);
299 
300  return NULL;
301  }
302 
303  giraffe_table_delete(rfibers);
304 
305  }
306 
307  return fibers;
308 
309 }
310 
311 
322 GiFibersConfig *
323 giraffe_fibers_config_create(cpl_parameterlist *list)
324 {
325 
326  cpl_parameter *p;
327 
328  GiFibersConfig *config = NULL;
329 
330 
331  if (!list) {
332  return NULL;
333  }
334 
335  config = cx_calloc(1, sizeof *config);
336 
337 
338  /*
339  * Some defaults
340  */
341 
342  config->nspec = 0;
343  config->spectra = NULL;
344 
345 
346  p = cpl_parameterlist_find(list, "giraffe.fibers.nspectra");
347  config->nspec = cpl_parameter_get_int(p);
348 
349 
350  p = cpl_parameterlist_find(list, "giraffe.fibers.spectra");
351  config->spectra = cx_strdup(cpl_parameter_get_string(p));
352 
353  return config;
354 
355 }
356 
357 
370 void
371 giraffe_fibers_config_destroy(GiFibersConfig *config)
372 {
373 
374  if (config) {
375  if (config->spectra) {
376  cx_free(config->spectra);
377  config->spectra = NULL;
378  }
379 
380  cx_free(config);
381  }
382 
383  return;
384 }
385 
386 
398 void
399 giraffe_fibers_config_add(cpl_parameterlist *list)
400 {
401 
402  cpl_parameter *p;
403 
404 
405  if (!list) {
406  return;
407  }
408 
409  p = cpl_parameter_new_value("giraffe.fibers.spectra",
410  CPL_TYPE_STRING,
411  "Index list of spectra to use for "
412  "localization (e.g. 2,10,30-40,55).",
413  "giraffe.fibers",
414  "");
415  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "fiber-splist");
416  cpl_parameterlist_append(list, p);
417 
418  p = cpl_parameter_new_range("giraffe.fibers.nspectra",
419  CPL_TYPE_INT,
420  "Number of spectra to localize.",
421  "giraffe.fibers",
422  0, 0, CX_MAXINT - 1);
423  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "fiber-nspec");
424  cpl_parameterlist_append(list, p);
425 
426  return;
427 
428 }
void giraffe_fibers_config_add(cpl_parameterlist *list)
Adds parameters for the spectrum selection.
Definition: gifibers.c:399
cxint giraffe_table_set(GiTable *self, cpl_table *table)
Sets the table data.
Definition: gitable.c:464
cpl_table * giraffe_fiberlist_create(const cxchar *filename, cxint nspec, const cxint *spectra)
Creates the fiber table.
Definition: gifiberutils.c:93
void giraffe_table_delete(GiTable *self)
Destroys a Giraffe table.
Definition: gitable.c:162
GiTable * giraffe_table_new(void)
Creates a new, empty Giraffe table.
Definition: gitable.c:93
cxint * giraffe_parse_spectrum_selection(const cxchar *selection, cxint *nspec)
Parses a spectrum selection string.
void giraffe_fibers_config_destroy(GiFibersConfig *config)
Destroys a fibers setup structure.
Definition: gifibers.c:371
GiTable * giraffe_fibers_setup(const cpl_frame *frame, const cpl_frame *reference)
Setup a fiber list.
Definition: gifibers.c:226
cxint giraffe_fiberlist_associate(GiTable *fibers, const GiTable *reference)
Associate a fiberlist with a reference list.
Definition: gifiberutils.c:991
GiFibersConfig * giraffe_fibers_config_create(cpl_parameterlist *list)
Creates a setup structure for the fiber selection.
Definition: gifibers.c:323
cxint * giraffe_create_spectrum_selection(const cxchar *filename, const GiTable *reference, cxint *nspec)
Create a spectrum selection from a reference table.
GiTable * giraffe_fibers_select(const cpl_frame *frame, const GiTable *reference, GiFibersConfig *config)
Selects the spectra to process.
Definition: gifibers.c:80
GiTable * giraffe_fiberlist_load(const cxchar *filename, cxint dataset, const cxchar *tag)
Load a fiber table from a file.
Definition: gifiberutils.c:723

This file is part of the GIRAFFE Pipeline Reference Manual 2.14.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Wed Mar 11 2015 13:19:41 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2004