GIRAFFE Pipeline Reference Manual

gifibers.c

00001 /* $Id: gifibers.c,v 1.13 2008/05/15 14:47:35 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: 2008/05/15 14:47:35 $
00024  * $Revision: 1.13 $
00025  * $Name: giraffe-2_8_8 $
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             
00253             giraffe_table_delete(fibers);
00254             cpl_error_set(fctid, CPL_ERROR_ILLEGAL_INPUT);
00255             return NULL;
00256             
00257         }
00258 
00259         rfibers = giraffe_fiberlist_load(filename, 1, GIFRAME_FIBER_SETUP);
00260 
00261         if (rfibers == NULL) {
00262 
00263             giraffe_table_delete(fibers);
00264             return NULL;
00265             
00266         }
00267 
00268         status = giraffe_fiberlist_associate(fibers, rfibers);
00269 
00270         if (status) {
00271             giraffe_table_delete(fibers);
00272             giraffe_table_delete(rfibers);
00273             
00274             return NULL;
00275         }
00276 
00277         giraffe_table_delete(rfibers);
00278 
00279     }
00280 
00281     return fibers;
00282 
00283 }
00284 
00285 
00296 GiFibersConfig *
00297 giraffe_fibers_config_create(cpl_parameterlist *list)
00298 {
00299 
00300     cpl_parameter *p;
00301 
00302     GiFibersConfig *config = NULL;
00303 
00304 
00305     if (!list) {
00306         return NULL;
00307     }
00308 
00309     config = cx_calloc(1, sizeof *config);
00310 
00311 
00312     /*
00313      * Some defaults
00314      */
00315 
00316     config->nspec = 0;
00317     config->spectra = NULL;
00318 
00319 
00320     p = cpl_parameterlist_find(list, "giraffe.fibers.nspectra");
00321     config->nspec = cpl_parameter_get_int(p);
00322 
00323 
00324     p = cpl_parameterlist_find(list, "giraffe.fibers.spectra");
00325     config->spectra = cx_strdup(cpl_parameter_get_string(p));
00326 
00327     return config;
00328 
00329 }
00330 
00331 
00344 void
00345 giraffe_fibers_config_destroy(GiFibersConfig *config)
00346 {
00347 
00348     if (config) {
00349         if (config->spectra) {
00350             cx_free(config->spectra);
00351             config->spectra = NULL;
00352         }
00353 
00354         cx_free(config);
00355     }
00356 
00357     return;
00358 }
00359 
00360 
00372 void
00373 giraffe_fibers_config_add(cpl_parameterlist *list)
00374 {
00375 
00376     cpl_parameter *p;
00377 
00378 
00379     if (!list) {
00380         return;
00381     }
00382 
00383     p = cpl_parameter_new_value("giraffe.fibers.spectra",
00384                                 CPL_TYPE_STRING,
00385                                 "Index list of spectra to use for "
00386                                 "localization (e.g. 2,10,30-40,55).",
00387                                 "giraffe.fibers",
00388                                 "");
00389     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "fiber-splist");
00390     cpl_parameterlist_append(list, p);
00391 
00392     p = cpl_parameter_new_range("giraffe.fibers.nspectra",
00393                                 CPL_TYPE_INT,
00394                                 "Number of spectra to localize.",
00395                                 "giraffe.fibers",
00396                                 0, 0, CX_MAXINT - 1);
00397     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "fiber-nspec");
00398     cpl_parameterlist_append(list, p);
00399 
00400     return;
00401 
00402 }

This file is part of the GIRAFFE Pipeline Reference Manual 2.8.8.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Fri Mar 4 10:50:26 2011 by doxygen 1.6.3 written by Dimitri van Heesch, © 1997-2004