FORS Pipeline Reference Manual  4.12.5
fors_instrument.c
1 /* $Id: fors_instrument.c,v 1.4 2010-09-14 07:49:30 cizzo Exp $
2  *
3  * This file is part of the FORS Library
4  * Copyright (C) 2002-2010 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: cizzo $
23  * $Date: 2010-09-14 07:49:30 $
24  * $Revision: 1.4 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 #include <fors_instrument.h>
33 #include <string.h>
34 
35 const struct fors_filterlist {
36  const char name[10];
37  const char band;
38 } fors_filterlist[15] = {
39  /* FORS1 */
40  {"U_BESS", 'U'},
41  {"u_HIGH", 'U'},
42  {"B_BESS", 'B'},
43  {"b_HIGH", 'B'},
44  {"g_HIGH", 'V'}, /* G uses V ?????????????????????????????????? */
45  {"V_BESS", 'V'},
46  {"v_HIGH", 'V'},
47  {"R_BESS", 'R'},
48  {"I_BESS", 'I'},
49 
50  /* FORS2 */
51  {"U_SPECIAL", 'U'},
52  {"B_BESS" , 'B'},
53  {"V_BESS" , 'V'},
54  {"R_SPECIAL", 'R'},
55  {"I_BESS" , 'I'},
56  {"" , '\0'}
57 };
58 
59 const char fors_filterband_unknown = '?',
60  fors_filterband_none = '\0';
61 
76 char
77 fors_instrument_filterband_get_by_setting( const fors_setting *setting)
78 {
79  char band;
80  cpl_errorstate errstat = cpl_errorstate_get();
81 
82  if (setting == NULL)
83  {
84  cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
85  return fors_filterband_unknown;
86  }
87 
88  band = fors_instrument_filterband_get_by_name(setting->filter_name);
89  if (!cpl_errorstate_is_equal(errstat))
90  cpl_error_set_where(cpl_func);
91 
92  return band;
93 }
94 
106 char
107 fors_instrument_filterband_get_by_name( const char *filtername)
108 {
109  int n;
110 
111  if (filtername == NULL || filtername[0] == '\0')
112  return fors_filterband_none;
113 
114  n = 0;
115  while ((fors_filterlist[n].name)[0] != '\0')
116  {
117  if (strcmp(filtername, fors_filterlist[n].name) == 0)
118  return fors_filterlist[n].band;
119  n++;
120  }
121 
122  cpl_error_set_message( cpl_func,
123  CPL_ERROR_ILLEGAL_INPUT,
124  "unknown filter name \"%s\"",
125  filtername);
126  return fors_filterband_unknown;
127 }
128 
137 bool
138 fors_instrument_filterband_is_defined( char band)
139 {
140  return (band >= 'A' && band <= 'Z');
141 }
142 
150 bool
151 fors_instrument_filterband_is_none( char band)
152 {
153  return (band == '\0');
154 }
155 
164 bool
165 fors_instrument_filterband_is_unknown( char band)
166 {
167  return !( fors_instrument_filterband_is_defined(band)
168  || fors_instrument_filterband_is_none(band));
169 }
170 
175 char
176 fors_instrument_filterband_value_unknown( void)
177 {
178  return fors_filterband_unknown;
179 }
180 
185 int
186 fors_instrument_known_filters_get_number( void)
187 {
188  return (sizeof(fors_filterlist)/sizeof(*fors_filterlist)) - 1;
189 }
190 
199 const char *
200 fors_instrument_known_filters_get_name( int n)
201 {
202  if (n < 0
203  || n >= fors_instrument_known_filters_get_number())
204  {
205  cpl_error_set( cpl_func,
206  CPL_ERROR_ACCESS_OUT_OF_RANGE);
207  return NULL;
208  }
209  return fors_filterlist[n].name;
210 }
211 
221 char
222 fors_instrument_known_filters_get_band( int n)
223 {
224  if (n < 0
225  || n >= fors_instrument_known_filters_get_number())
226  {
227  cpl_error_set( cpl_func,
228  CPL_ERROR_ACCESS_OUT_OF_RANGE);
229  return fors_filterband_unknown;
230  }
231  return fors_filterlist[n].band;
232 }
233 
234