SINFONI Pipeline Reference Manual  2.5.2
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  char * name ;
113  //int nframes=0;
114  int nraw=0;
115  cpl_frame* frame = NULL;
116  cpl_parameter *p;
117 
118 
119  char spat_res[FILE_NAME_SZ];
120  char lamp_status[FILE_NAME_SZ];
121  char band[FILE_NAME_SZ];
122  int ins_set=0;
123 
124 
125  char * tag;
126  int i=0;
127  //nframes = cpl_frameset_get_size(sof);
128  /* Get the raw and the calibration files */
129  /* Labelise the input frames according to their tags */
130 
131  *raw=cpl_frameset_new();
132  sinfo_extract_raw_frames_type(sof,raw,PRO_FOCUS_STACKED);
133 
134 
135  nraw=cpl_frameset_get_size(*raw);
136  if (nraw < 1) {
137  sinfo_msg_error("Too few (%d) raw frames (%s) present in"
138  "frameset!Aborting...",nraw,PRO_FOCUS_STACKED);
139  (*status)++;
140  return;
141  }
142  /* Allocate structures to go into the blackboard */
143  cfg->inFrameList = cpl_malloc(nraw * sizeof(char*));
144 
145  /* Browse through the charmatrix to get names and file types */
146  for (i=0 ; i<nraw ; i++) {
147  frame = cpl_frameset_get_frame(*raw,i);
148  name= (char*) cpl_frame_get_filename(frame);
149  if(sinfo_file_exists(name)==1) {
150  /* to go on the file must exist */
151  if(cpl_frame_get_tag(frame) != NULL) {
152  /* If the frame has a tag we process it. Else it is an object */
153  tag= (char*) cpl_frame_get_tag(frame);
154  if(sinfo_is_stack(tag))
155  {
156  cfg->inFrameList[i]=cpl_strdup(cpl_frame_get_filename(frame));
157  }
158  else {
159  sinfo_msg_error("No good frame tag %s in input frame set",tag);
160  (*status)++;
161  return;
162  }
163  }
164  }
165  /* Store file name into inFrameList */
166  }
167 
168  /* Copy relevant information into the blackboard */
169  cfg->nframes = nraw ;
170 
171 
172  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.output_filename");
173  strcpy(cfg -> outName, cpl_parameter_get_string(p));
174 
175  if(NULL != cpl_frameset_find(sof,PRO_FIRST_COL)) {
176  frame = cpl_frameset_find(sof,PRO_FIRST_COL);
177  strcpy(cfg -> firstCol,cpl_strdup(cpl_frame_get_filename(frame)));
178  } else {
179  sinfo_msg_error("Frame %s not found! Exit!", PRO_FIRST_COL);
180  (*status)++;
181  return;
182  }
183 
184  if(NULL != cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE)) {
185  frame = cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE);
186  strcpy(cfg -> poslist,cpl_strdup(cpl_frame_get_filename(frame)));
187  } else {
188  sinfo_msg_error("Frame %s not found! Exit!", PRO_SLITLETS_DISTANCE);
189  (*status)++;
190  return;
191  }
192 
193 
194 
195  frame = cpl_frameset_get_frame(*raw,0);
196  sinfo_get_spatial_res(frame,spat_res);
197 
198  switch(sinfo_frame_is_on(frame))
199  {
200  case 0:
201  strcpy(lamp_status,"on");
202  break;
203  case 1:
204  strcpy(lamp_status,"off");
205  break;
206  case -1:
207  strcpy(lamp_status,"undefined");
208  break;
209  default:
210  strcpy(lamp_status,"undefined");
211  break;
212  }
213 
214  sinfo_get_band(frame,band);
215  sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
216  spat_res, lamp_status, band);
217 
218 
219  sinfo_get_ins_set(band,&ins_set);
220  return;
221 }
222 
230 static void
231 parse_section_reconstruction(focus_config * cfg,cpl_parameterlist * cpl_cfg)
232 {
233 
234 
235  cpl_parameter* p;
236 
237  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.lower_rejection");
238  cfg -> lo_reject = cpl_parameter_get_double(p);
239 
240  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.higher_rejection");
241  cfg -> hi_reject = cpl_parameter_get_double(p);
242 
243  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.north_south_index");
244  cfg -> northsouthInd = cpl_parameter_get_bool(p);
245 
246  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.nslits");
247  cfg -> nslits = cpl_parameter_get_int(p);
248 
249  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.method");
250  strcpy(cfg->method, cpl_parameter_get_string(p));
251 
252  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.order");
253  cfg -> order= cpl_parameter_get_int(p);
254 
255 }
256 
264 static void
265 parse_section_gauss2dfit(focus_config * cfg,cpl_parameterlist * cpl_cfg)
266 {
267  cpl_parameter* p;
268  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.llx");
269  cfg -> llx = cpl_parameter_get_int(p);
270 
271  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.lly");
272  cfg -> lly = cpl_parameter_get_int(p);
273 
274  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.halfbox_x");
275  cfg -> halfbox_x = cpl_parameter_get_int(p);
276 
277  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.halfbox_y");
278  cfg -> halfbox_y = cpl_parameter_get_int(p);
279 
280  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar0");
281  cfg -> mpar0 = cpl_parameter_get_int(p);
282 
283  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar1");
284  cfg -> mpar1 = cpl_parameter_get_int(p);
285 
286  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar2");
287  cfg -> mpar2 = cpl_parameter_get_int(p);
288 
289  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar3");
290  cfg -> mpar3 = cpl_parameter_get_int(p);
291 
292  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar4");
293  cfg -> mpar4 = cpl_parameter_get_int(p);
294 
295  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar5");
296  cfg -> mpar5 = cpl_parameter_get_int(p);
297 
298  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.mpar6");
299  cfg -> mpar6 = cpl_parameter_get_int(p);
300 
301  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.fit_list");
302  strcpy(cfg -> fitlist, cpl_parameter_get_string(p));
303 
304  /* int or string ?*/
305  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.plot_gauss_ind");
306  cfg -> plotGaussInd = cpl_parameter_get_bool(p);
307 
308  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.focus.gauss_plot_name");
309  strcpy( cfg -> gaussplotName, cpl_parameter_get_string(p));
310 
311  return ;
312 }
319 void
320 sinfo_free_focus(focus_config * cfg) {
321  cpl_free(cfg->inFrameList);
322  sinfo_focus_cfg_destroy (cfg);
323 
324  return;
325 }