GIRAFFE Pipeline Reference Manual

gifibers.c

00001 /* $Id: gifibers.c,v 1.12 2006/07/12 15:25:57 rpalsa Exp $
00002  *
00003  * This file is part of the GIRAFFE Pipeline
00004  * Copyright (C) 2002-2006 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 /*
00022  * $Author: rpalsa $
00023  * $Date: 2006/07/12 15:25:57 $
00024  * $Revision: 1.12 $
00025  * $Name: giraffe-2_5_1 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #  include <config.h>
00030 #endif
00031 
00032 #include <cxmemory.h>
00033 #include <cxmessages.h>
00034 #include <cxstrutils.h>
00035 
00036 #include <cpl_msg.h>
00037 #include <cpl_parameterlist.h>
00038 
00039 #include "giframe.h"
00040 #include "gifiberutils.h"
00041 #include "gifibers.h"
00042 
00043 
00072 GiTable *
00073 giraffe_fibers_select(const cpl_frame *frame, GiFibersConfig *config)
00074 {
00075 
00076     const cxchar *fctid = "giraffe_fibers_select";
00077 
00078     const cxchar *filename;
00079 
00080     cxint nspec = 0;
00081     cxint *spectra = NULL;
00082 
00083     cpl_table *_fibers;
00084 
00085     GiTable *fibers;
00086 
00087 
00088     if (!frame || !config) {
00089         return NULL;
00090     }
00091 
00092     filename = cpl_frame_get_filename(frame);
00093     cx_assert(filename != NULL);
00094 
00095 
00096     if (config->spectra && *config->spectra != '\0') {
00097         spectra = giraffe_parse_spectrum_selection(config->spectra,
00098                                                    &nspec);
00099         if (!spectra) {
00100             cpl_msg_error(fctid, "Invalid selection string `%s'!",
00101                           config->spectra);
00102             return NULL;
00103         }
00104 
00105         if (config->nspec > 0) {
00106 
00107             /*
00108              * Both, the number of spectra and a selection list were
00109              * given
00110              */
00111 
00112             if (config->nspec < nspec) {
00113 
00114                 spectra = cx_realloc(spectra,
00115                                      config->nspec * sizeof(cxint));
00116                 nspec = config->nspec;
00117 
00118                 cpl_msg_warning(fctid, "Requested number of spectra (%d) "
00119                                 "is less than number of listed spectra "
00120                                 "(%d). Using %d spectra.", config->nspec,
00121                                 nspec, config->nspec);
00122 
00123             }
00124             else {
00125                 if (config->nspec > nspec) {
00126 
00127                     cpl_msg_warning(fctid, "Number of requested spectra "
00128                                     "(%d) exceeds the number of listed "
00129                                     "spectra (%d). Using all spectra in "
00130                                     "the list!", config->nspec, nspec);
00131 
00132                 }
00133             }
00134         }
00135     }
00136     else {
00137 
00138         if (config->nspec > 0) {
00139 
00140             /*
00141              * No selection list, but the number of spectra to process
00142              * was given.
00143              */
00144 
00145             register cxint i;
00146 
00147             nspec = config->nspec;
00148             spectra = cx_malloc(nspec * sizeof(cxint));
00149 
00150             /*
00151              * Fiber positions in the image are counted starting from 1!
00152              */
00153 
00154             for (i = 0; i < nspec; i++) {
00155                 spectra[i] = i + 1;
00156             }
00157         }
00158     }
00159 
00160     _fibers = giraffe_fiberlist_create(filename, nspec, spectra);
00161 
00162     fibers = giraffe_table_new();
00163     giraffe_table_set(fibers, _fibers);
00164 
00165     cpl_table_delete(_fibers);
00166 
00167 
00168     /*
00169      * Cleanup
00170      */
00171 
00172     if (spectra) {
00173         cx_free(spectra);
00174     }
00175 
00176     return fibers;
00177 
00178 }
00179 
00180 
00199 GiTable *
00200 giraffe_fibers_setup(const cpl_frame *frame, const cpl_frame *reference)
00201 {
00202 
00203     const cxchar *fctid = "giraffe_fibers_setup";
00204 
00205     cxchar *filename = NULL;
00206 
00207     cpl_table *_fibers =NULL;
00208 
00209     GiTable *fibers = NULL;
00210 
00211 
00212     if (frame == NULL) {
00213         cpl_error_set(fctid, CPL_ERROR_NULL_INPUT);
00214         return NULL;
00215     }
00216 
00217     filename = (cxchar *)cpl_frame_get_filename(frame);
00218 
00219     if (filename == NULL) {
00220         cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
00221         return NULL;
00222     }
00223 
00224     _fibers = giraffe_fiberlist_create(filename, 0, NULL);
00225 
00226     if (_fibers == NULL) {
00227         return NULL;
00228     }
00229 
00230     fibers = giraffe_table_new();
00231     giraffe_table_set(fibers, _fibers);
00232 
00233     cpl_table_delete(_fibers);
00234     _fibers = NULL;
00235 
00236 
00237     /*
00238      * Associate the newly created fiber setup list with a reference list
00239      * if it was given.
00240      */
00241 
00242     if (reference != NULL) {
00243 
00244         cxint status;
00245 
00246         GiTable *rfibers = 0;
00247 
00248 
00249         filename = (cxchar *)cpl_frame_get_filename(reference);
00250 
00251         if (filename == NULL) {
00252             cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
00253             return NULL;
00254         }
00255 
00256         rfibers = giraffe_fiberlist_load(filename, 1, GIFRAME_FIBER_SETUP);
00257 
00258         if (rfibers == NULL) {
00259             giraffe_table_delete(fibers);
00260             return NULL;
00261         }
00262 
00263         status = giraffe_fiberlist_associate(fibers, rfibers);
00264 
00265         if (status) {
00266             giraffe_table_delete(fibers);
00267             giraffe_table_delete(rfibers);
00268 
00269             return NULL;
00270         }
00271 
00272         giraffe_table_delete(rfibers);
00273 
00274     }
00275 
00276     return fibers;
00277 
00278 }
00279 
00280 
00291 GiFibersConfig *
00292 giraffe_fibers_config_create(cpl_parameterlist *list)
00293 {
00294 
00295     cpl_parameter *p;
00296 
00297     GiFibersConfig *config = NULL;
00298 
00299 
00300     if (!list) {
00301         return NULL;
00302     }
00303 
00304     config = cx_calloc(1, sizeof *config);
00305 
00306 
00307     /*
00308      * Some defaults
00309      */
00310 
00311     config->nspec = 0;
00312     config->spectra = NULL;
00313 
00314 
00315     p = cpl_parameterlist_find(list, "giraffe.fibers.nspectra");
00316     config->nspec = cpl_parameter_get_int(p);
00317 
00318 
00319     p = cpl_parameterlist_find(list, "giraffe.fibers.spectra");
00320     config->spectra = cx_strdup(cpl_parameter_get_string(p));
00321 
00322     return config;
00323 
00324 }
00325 
00326 
00339 void
00340 giraffe_fibers_config_destroy(GiFibersConfig *config)
00341 {
00342 
00343     if (config) {
00344         if (config->spectra) {
00345             cx_free(config->spectra);
00346             config->spectra = NULL;
00347         }
00348 
00349         cx_free(config);
00350     }
00351 
00352     return;
00353 }
00354 
00355 
00367 void
00368 giraffe_fibers_config_add(cpl_parameterlist *list)
00369 {
00370 
00371     cpl_parameter *p;
00372 
00373 
00374     if (!list) {
00375         return;
00376     }
00377 
00378     p = cpl_parameter_new_value("giraffe.fibers.spectra",
00379                                 CPL_TYPE_STRING,
00380                                 "Index list of spectra to use for "
00381                                 "localization (e.g. 2,10,30-40,55).",
00382                                 "giraffe.fibers",
00383                                 "");
00384     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "fiber-splist");
00385     cpl_parameterlist_append(list, p);
00386 
00387     p = cpl_parameter_new_range("giraffe.fibers.nspectra",
00388                                 CPL_TYPE_INT,
00389                                 "Number of spectra to localize.",
00390                                 "giraffe.fibers",
00391                                 0, 0, CX_MAXINT - 1);
00392     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "fiber-nspec");
00393     cpl_parameterlist_append(list, p);
00394 
00395     return;
00396 
00397 }

This file is part of the GIRAFFE Pipeline Reference Manual 2.5.1.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Tue Mar 18 10:47:41 2008 by doxygen 1.4.6 written by Dimitri van Heesch, © 1997-2004