SINFONI Pipeline Reference Manual  2.5.2
sinfo_lamp_ini_by_cpl.c
1 /*
2  * This file is part of the ESO SINFONI Pipeline
3  * Copyright (C) 2004,2005 European Southern Observatory
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18  */
19 /*----------------------------------------------------------------------------
20 
21  File name : sinfo_lamp_ini_by_cpl.c
22  Author : Andrea Modigliani
23  Created on : May 26, 2004
24  Description : lamp spectrum cpl input handling for SPIFFI
25  ---------------------------------------------------------------------------*/
26 #ifdef HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29 /*---------------------------------------------------------------------------
30  Includes
31  ---------------------------------------------------------------------------*/
32 #include <string.h>
33 #include "sinfo_lamp_ini_by_cpl.h"
34 #include "sinfo_functions.h"
35 #include "sinfo_pro_types.h"
36 /*---------------------------------------------------------------------------
37  Functions private to this module
38  ---------------------------------------------------------------------------*/
39 static void
40 parse_section_frames(lamp_config *,
41  cpl_parameterlist* cpl_cfg,
42  cpl_frameset* sof,
43  cpl_frameset** raw,
44  int* status);
45 
46 static void
47 parse_section_resampling(lamp_config *, cpl_parameterlist* cpl_cfg);
48 static void
49 parse_section_extractspectrum(lamp_config *, cpl_parameterlist* cpl_cfg);
50 
69 lamp_config *
70 sinfo_parse_cpl_input_lamp(cpl_parameterlist* cpl_cfg,
71  cpl_frameset* sof,
72  cpl_frameset** raw)
73 
74 {
75  lamp_config * cfg= sinfo_lamp_cfg_create();
76  int status=0;
77  /*
78  * Perform sanity checks, fill up the structure with what was
79  * found in the ini file
80  */
81 
82 
83  parse_section_resampling (cfg, cpl_cfg);
84  parse_section_extractspectrum (cfg, cpl_cfg);
85  parse_section_frames (cfg, cpl_cfg, sof, raw,&status);
86 
87  if (status > 0) {
88  sinfo_msg_error("parsing cpl input");
89  sinfo_lamp_cfg_destroy(cfg);
90  cfg = NULL ;
91  return NULL ;
92  }
93  return cfg ;
94 }
95 
96 
106 static void
107 parse_section_frames(lamp_config * cfg,
108  cpl_parameterlist * cpl_cfg,
109  cpl_frameset * sof,
110  cpl_frameset ** raw,
111  int* status)
112 {
113 
114  cpl_frame* frame = NULL;
115  cpl_parameter *p;
116  int nraw=0;
117  char spat_res[FILE_NAME_SZ];
118  char lamp_status[FILE_NAME_SZ];
119  char band[FILE_NAME_SZ];
120  int ins_set=0;
121 
122  /* Input */
123 
124  *raw=cpl_frameset_new();
125  sinfo_extract_raw_frames_type(sof,raw,PRO_FLUX_LAMP_STACKED);
126 
127  nraw = cpl_frameset_get_size(*raw);
128 
129  if(nraw<1) {
130  sinfo_msg_error("no good raw frame %s in input!",PRO_FLUX_LAMP_STACKED);
131  (*status)++;
132  return;
133  }
134  frame = cpl_frameset_get_frame(*raw,0);
135  strcpy(cfg -> inFrame,cpl_strdup(cpl_frame_get_filename(frame)));
136 
137  /* Output */
138  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_spec.output_filename");
139  strcpy(cfg -> outName, cpl_parameter_get_string(p));
140 
141  sinfo_get_spatial_res(frame,spat_res);
142  switch(sinfo_frame_is_on(frame))
143  {
144 
145  case 0:
146  strcpy(lamp_status,"on");
147  break;
148  case 1:
149  strcpy(lamp_status,"off");
150  break;
151  case -1:
152  strcpy(lamp_status,"undefined");
153  break;
154  default:
155  strcpy(lamp_status,"undefined");
156  break;
157 
158  }
159  sinfo_get_band(frame,band);
160  sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
161  spat_res, lamp_status, band);
162 
163 
164  sinfo_get_ins_set(band,&ins_set);
165 
166  if(NULL != cpl_frameset_find(sof,PRO_WAVE_MAP)) {
167  frame = cpl_frameset_find(sof,PRO_WAVE_MAP);
168  strcpy(cfg -> wavemapim,cpl_strdup(cpl_frame_get_filename(frame)));
169  } else {
170  sinfo_msg_error("Frame %s not found! Exit!", PRO_WAVE_MAP);
171  (*status)++;
172  return;
173  }
174 
175 
176  return ;
177 
178 }
179 
180 
181 
189 static void
190 parse_section_resampling(lamp_config * cfg, cpl_parameterlist * cpl_cfg)
191 {
192 
193  cpl_parameter *p;
194  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_spec.ncoeffs");
195  cfg -> ncoeffs = cpl_parameter_get_int(p);
196 
197  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_spec.nrows");
198  cfg -> nrows = cpl_parameter_get_int(p);
199 
200  return ;
201 
202 }
210 static void
211 parse_section_extractspectrum(lamp_config * cfg, cpl_parameterlist * cpl_cfg)
212 {
213  cpl_parameter *p;
214 
215  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_spec.lower_rejection");
216  cfg -> loReject = cpl_parameter_get_double(p);
217 
218  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_spec.higher_rejection");
219  cfg -> hiReject = cpl_parameter_get_double(p);
220 
221  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_spec.counts_to_intensity");
222  cfg -> countsToIntensity = cpl_parameter_get_double(p);
223 
224  return ;
225 
226 }
233 void
234 sinfo_lamp_free(lamp_config * cfg)
235 {
236  sinfo_lamp_cfg_destroy(cfg);
237  return;
238 
239 }