SINFONI Pipeline Reference Manual  2.6.0
sinfo_focus_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_focus_ini_by_cpl.c
22  Author : Andrea Modigliani
23  Created on : May 20, 2004
24  Description : 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_focus_ini_by_cpl.h"
34 #include "sinfo_pro_types.h"
35 #include "sinfo_functions.h"
36 #include "sinfo_file_handling.h"
37 /*---------------------------------------------------------------------------
38  Functions private to this module
39  ---------------------------------------------------------------------------*/
40 static void
41 parse_section_frames(focus_config *, cpl_parameterlist* cpl_cfg,
42  cpl_frameset* sof,cpl_frameset** stk, int* status);
43 static void
44 parse_section_reconstruction(focus_config *, cpl_parameterlist* cpl_cfg);
45 static void
46 parse_section_gauss2dfit(focus_config *, cpl_parameterlist* cpl_cfg);
47 
70 focus_config *
71 sinfo_parse_cpl_input_focus(cpl_parameterlist * cpl_cfg, cpl_frameset* sof,
72  cpl_frameset** stk)
73 {
74  focus_config * cfg = sinfo_focus_cfg_create();
75  int status=0;
76  /*
77  * Perform sanity checks, fill up the structure with what was
78  * found in the ini file
79  */
80 
81  parse_section_reconstruction (cfg, cpl_cfg);
82  parse_section_gauss2dfit (cfg, cpl_cfg);
83  parse_section_frames (cfg, cpl_cfg,sof,stk,&status);
84  if (status > 0) {
85  sinfo_msg_error("parsing cpl input");
86  sinfo_focus_cfg_destroy(cfg);
87  cfg = NULL ;
88  return NULL ;
89  }
90  return cfg ;
91 }
92 
103 static void
104 parse_section_frames(focus_config * cfg,
105  cpl_parameterlist* cpl_cfg,
106  cpl_frameset* sof,
107  cpl_frameset** raw,
108  int* status)
109 {
110 
111 
112  //int nframes=0;
113  int nraw=0;
114  cpl_frame* frame = NULL;
115  cpl_parameter *p;
116 
117 
118  char spat_res[FILE_NAME_SZ];
119  char lamp_status[FILE_NAME_SZ];
120  char band[FILE_NAME_SZ];
121  int ins_set=0;
122 
123 
124  char * tag;
125  int i=0;
126  //nframes = cpl_frameset_get_size(sof);
127  /* Get the raw and the calibration files */
128  /* Labelise the input frames according to their tags */
129 
130  *raw=cpl_frameset_new();
131  sinfo_extract_raw_frames_type(sof,raw,PRO_FOCUS_STACKED);
132 
133 
134  nraw=cpl_frameset_get_size(*raw);
135  if (nraw < 1) {
136  sinfo_msg_error("Too few (%d) raw frames (%s) present in"
137  "frameset!Aborting...",nraw,PRO_FOCUS_STACKED);
138  (*status)++;
139  return;
140  }
141  /* Allocate structures to go into the blackboard */
142  cfg->inFrameList = cpl_malloc(nraw * sizeof(char*));
143 
144  /* Browse through the charmatrix to get names and file types */
145  for (i=0 ; i<nraw ; i++) {
146  frame = cpl_frameset_get_frame(*raw,i);
147  char* name= (char*) cpl_frame_get_filename(frame);
148  if(sinfo_file_exists(name)==1) {
149  /* to go on the file must exist */
150  if(cpl_frame_get_tag(frame) != NULL) {
151  /* If the frame has a tag we process it. Else it is an object */
152  tag= (char*) cpl_frame_get_tag(frame);
153  if(sinfo_is_stack(tag))
154  {
155  cfg->inFrameList[i]=cpl_strdup(cpl_frame_get_filename(frame));
156  }
157  else {
158  sinfo_msg_error("No good frame tag %s in input frame set",tag);
159  (*status)++;
160  return;
161  }
162  }
163  }
164  /* Store file name into inFrameList */
165  }
166 
167  /* Copy relevant information into the blackboard */
168  cfg->nframes = nraw ;
169 
170 
171  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.output_filename");
172  strcpy(cfg -> outName, cpl_parameter_get_string(p));
173 
174  if(NULL != cpl_frameset_find(sof,PRO_FIRST_COL)) {
175  frame = cpl_frameset_find(sof,PRO_FIRST_COL);
176  strcpy(cfg -> firstCol,cpl_strdup(cpl_frame_get_filename(frame)));
177  } else {
178  sinfo_msg_error("Frame %s not found! Exit!", PRO_FIRST_COL);
179  (*status)++;
180  return;
181  }
182 
183  if(NULL != cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE)) {
184  frame = cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE);
185  strcpy(cfg -> poslist,cpl_strdup(cpl_frame_get_filename(frame)));
186  } else {
187  sinfo_msg_error("Frame %s not found! Exit!", PRO_SLITLETS_DISTANCE);
188  (*status)++;
189  return;
190  }
191 
192 
193 
194  frame = cpl_frameset_get_frame(*raw,0);
195  sinfo_get_spatial_res(frame,spat_res);
196 
197  switch(sinfo_frame_is_on(frame))
198  {
199  case 0:
200  strcpy(lamp_status,"on");
201  break;
202  case 1:
203  strcpy(lamp_status,"off");
204  break;
205  case -1:
206  strcpy(lamp_status,"undefined");
207  break;
208  default:
209  strcpy(lamp_status,"undefined");
210  break;
211  }
212 
213  sinfo_get_band(frame,band);
214  sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
215  spat_res, lamp_status, band);
216 
217 
218  sinfo_get_ins_set(band,&ins_set);
219  return;
220 }
221 
229 static void
230 parse_section_reconstruction(focus_config * cfg,cpl_parameterlist * cpl_cfg)
231 {
232 
233 
234  cpl_parameter* p;
235 
236  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.lower_rejection");
237  cfg -> lo_reject = cpl_parameter_get_double(p);
238 
239  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.higher_rejection");
240  cfg -> hi_reject = cpl_parameter_get_double(p);
241 
242  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.north_south_index");
243  cfg -> northsouthInd = cpl_parameter_get_bool(p);
244 
245  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.nslits");
246  cfg -> nslits = cpl_parameter_get_int(p);
247 
248  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.method");
249  strcpy(cfg->method, cpl_parameter_get_string(p));
250 
251  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.order");
252  cfg -> order= cpl_parameter_get_int(p);
253 
254 }
255 
263 static void
264 parse_section_gauss2dfit(focus_config * cfg,cpl_parameterlist * cpl_cfg)
265 {
266  cpl_parameter* p;
267  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.llx");
268  cfg -> llx = cpl_parameter_get_int(p);
269 
270  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.lly");
271  cfg -> lly = cpl_parameter_get_int(p);
272 
273  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.halfbox_x");
274  cfg -> halfbox_x = cpl_parameter_get_int(p);
275 
276  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.halfbox_y");
277  cfg -> halfbox_y = cpl_parameter_get_int(p);
278 
279  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar0");
280  cfg -> mpar0 = cpl_parameter_get_int(p);
281 
282  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar1");
283  cfg -> mpar1 = cpl_parameter_get_int(p);
284 
285  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar2");
286  cfg -> mpar2 = cpl_parameter_get_int(p);
287 
288  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar3");
289  cfg -> mpar3 = cpl_parameter_get_int(p);
290 
291  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar4");
292  cfg -> mpar4 = cpl_parameter_get_int(p);
293 
294  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar5");
295  cfg -> mpar5 = cpl_parameter_get_int(p);
296 
297  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar6");
298  cfg -> mpar6 = cpl_parameter_get_int(p);
299 
300  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.fit_list");
301  strcpy(cfg -> fitlist, cpl_parameter_get_string(p));
302 
303  /* int or string ?*/
304  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.plot_gauss_ind");
305  cfg -> plotGaussInd = cpl_parameter_get_bool(p);
306 
307  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.gauss_plot_name");
308  strcpy( cfg -> gaussplotName, cpl_parameter_get_string(p));
309 
310  return ;
311 }
318 void
319 sinfo_free_focus(focus_config * cfg) {
320  cpl_free(cfg->inFrameList);
321  sinfo_focus_cfg_destroy (cfg);
322 
323  return;
324 }
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69