SINFONI Pipeline Reference Manual  2.6.0
sinfo_ns_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 
22  File name : sinfo_ns_ini_by_cpl.c
23  Author : Andrea Modigliani
24  Created on : May 19, 2003
25  Description : cpl input handling for the north-south test
26 
27  ---------------------------------------------------------------------------*/
28 
29 #ifdef HAVE_CONFIG_H
30 # include <config.h>
31 #endif
32 
33 
34 /*---------------------------------------------------------------------------
35  Includes
36  ---------------------------------------------------------------------------*/
37 
38 #include <string.h>
39 #include "sinfo_ns_ini_by_cpl.h"
40 #include "sinfo_pro_types.h"
41 #include "sinfo_hidden.h"
42 #include "sinfo_functions.h"
43 #include "sinfo_file_handling.h"
44 
45 /*---------------------------------------------------------------------------
46  Functions private to this module
47  ---------------------------------------------------------------------------*/
48 void sinfo_ns_free_alloc(ns_config * cfg);
49 static void
50 parse_section_frames (ns_config *,cpl_parameterlist* cpl_cfg,cpl_frameset* sof,
51  cpl_frameset** raw, int* status);
52 static void
53 parse_section_cleanmean (ns_config *,cpl_parameterlist* cpl_cfg);
54 static void
55 parse_section_gaussconvolution (ns_config *,cpl_parameterlist* cpl_cfg);
56 static void
57 parse_section_northsouthtest(ns_config *,cpl_parameterlist* cpl_cfg);
58 
59 
69 /* removed generateNS_ini_file */
70 
71 /*-------------------------------------------------------------------------*/
82 /*--------------------------------------------------------------------------*/
83 
84 ns_config *
85 sinfo_parse_cpl_input_ns(cpl_parameterlist * cpl_cfg, cpl_frameset* sof,
86  cpl_frameset** raw)
87 {
88  ns_config * cfg = sinfo_ns_cfg_create();
89  int status=0;
90  /*
91  * Perform sanity checks, fill up the structure with what was
92  * found in the ini file
93  */
94 
95  parse_section_cleanmean (cfg,cpl_cfg);
96  parse_section_gaussconvolution (cfg,cpl_cfg);
97  parse_section_northsouthtest (cfg,cpl_cfg);
98  parse_section_frames (cfg,cpl_cfg,sof,raw,&status);
99 
100  if (status > 0) {
101  sinfo_msg_error("parsing cpl input");
102  sinfo_ns_cfg_destroy(cfg);
103  cfg = NULL ;
104  return NULL ;
105  }
106  return cfg ;
107 }
108 
109 
110 
111 
112 static void
113 parse_section_frames(ns_config * cfg,
114  cpl_parameterlist * cpl_cfg,
115  cpl_frameset * sof,
116  cpl_frameset ** raw,
117  int* status)
118 {
119  int i;
120  int nobj ;
121  int noff ;
122  int nraw=0;
123  char* tag;
124  cpl_frame* frame = NULL;
125  cpl_parameter *p;
126  char spat_res[FILE_NAME_SZ];
127  char lamp_status[FILE_NAME_SZ];
128  char band[FILE_NAME_SZ];
129  int ins_set=0;
130  nstpar* nstp=sinfo_nstpar_new();
131 
132  sinfo_extract_raw_frames_type(sof,raw,PRO_FIBRE_NS_STACKED_DIST);
133 
134  nraw = cpl_frameset_get_size(*raw);
135 
136  if(nraw == 0) {
137  sinfo_msg_error("No input raw frames");
138  sinfo_nstpar_delete(nstp);
139  (*status)++;
140  return;
141  }
142 
143  /* Allocate structures to go into the blackboard */
144  cfg->framelist = cpl_malloc(nraw * sizeof(char*));
145  cfg->frametype = cpl_malloc(nraw * sizeof(int));
146 
147 
148 
149  /* Browse through the charmatrix to get names and file types */
150  i=0 ;
151  nobj = 0 ;
152  noff = 0 ;
153 
154  for (i=0 ; i<nraw ; i++) {
155  frame = cpl_frameset_get_frame(*raw,i);
156  if(sinfo_file_exists((char*) cpl_frame_get_filename(frame))==1)
157  {
158  /* to go on the file must exist */
159  tag=(char*) cpl_frame_get_tag(frame);
160  if(cpl_frame_get_tag(frame) != NULL) {
161  /* If the frame has a tag we process it. Else it is an object */
162  if((sinfo_frame_is_on(frame) == 0))
163  {
164  cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
165  cfg->frametype[i] = FRAME_OFF ;
166  noff++;
167  }
168  else if(sinfo_is_sky_flat(tag))
169  {
170  cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
171  cfg->frametype[i] = FRAME_OFF ;
172  noff++;
173  }
174  else if((sinfo_frame_is_on(frame) == 1))
175  {
176  cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
177  cfg->frametype[i] = FRAME_ON ;
178  nobj++;
179  }
180  else
181  {
182  /* without label the frame is assumed on */
183  cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
184  cfg->frametype[i] = FRAME_ON ;
185  nobj++;
186  }
187  }
188  else
189  {
190  /* without label the frame is assumed on */
191  cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
192  cfg->frametype[i] = FRAME_ON ;
193  nobj++;
194  }
195  /* Store file name into framelist */
196  }
197  else {
198  sinfo_msg_warning("file %s does not exist",
199  cpl_frame_get_filename(frame));
200  }
201 
202  }
203 
204 
205  if((noff == 0) && (nobj == 0)) {
206  sinfo_msg_error("Wrong input frames");
207  sinfo_nstpar_delete(nstp);
208  sinfo_ns_free_alloc(cfg);
209  (*status)++;
210  return;
211  }
212  /* Copy relevant information into the blackboard */
213  cfg->nframes = nraw ;
214  cfg->nobj = nobj ;
215  cfg->noff = noff ;
216 
217  strcpy(cfg -> outName, NS_TEST_DISTANCES_OUT_FILENAME);
218 
219 
220  frame = cpl_frameset_get_frame(*raw,0);
221  sinfo_get_spatial_res(frame,spat_res);
222 
223  switch(sinfo_frame_is_on(frame))
224  {
225  case 0:
226  strcpy(lamp_status,"on");
227  break;
228  case 1:
229  strcpy(lamp_status,"off");
230  break;
231  case -1:
232  strcpy(lamp_status,"undefined");
233  break;
234  default:
235  strcpy(lamp_status,"undefined");
236  break;
237 
238 
239  }
240 
241  sinfo_get_band(frame,band);
242  sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
243  spat_res, lamp_status, band);
244 
245 
246  sinfo_get_ins_set(band,&ins_set);
247 
248 
249  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.fwhm");
250  if(cpl_parameter_get_double(p) != cpl_parameter_get_default_double(p)) {
251  cfg -> fwhm = cpl_parameter_get_double(p);
252  } else {
253  cfg -> fwhm = nstp->fwhm[ins_set];
254  }
255 
256  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.min_diff");
257  if(cpl_parameter_get_double(p) != cpl_parameter_get_default_double(p)) {
258  cfg -> minDiff = cpl_parameter_get_double(p);
259  } else {
260  cfg -> minDiff = nstp->min_dif[ins_set];
261  }
262  sinfo_nstpar_delete(nstp);
263 
264 
265  if(cfg -> maskInd) {
266  if(NULL != cpl_frameset_find(sof,PRO_BP_MAP_DI)) {
267  frame = cpl_frameset_find(sof,PRO_BP_MAP_DI);
268  strcpy(cfg -> mask,cpl_frame_get_filename(frame));
269  } else {
270  sinfo_msg_error("Frame %s not found! Exit!", PRO_BP_MAP_DI);
271  sinfo_ns_free_alloc(cfg);
272  (*status)++;
273  return;
274  }
275  }
276 
277 
278  return ;
279 }
280 
281 static void
282 parse_section_cleanmean(ns_config * cfg,cpl_parameterlist * cpl_cfg)
283 {
284 
285  cpl_parameter *p;
286  p = cpl_parameterlist_find(cpl_cfg,
287  "sinfoni.north_south_test.low_rejection");
288  cfg -> loReject = cpl_parameter_get_double(p);
289 
290  p = cpl_parameterlist_find(cpl_cfg,
291  "sinfoni.north_south_test.high_rejection");
292  cfg -> hiReject = cpl_parameter_get_double(p);
293 
294  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.mask_ind");
295  cfg -> maskInd = cpl_parameter_get_bool(p);
296 
297  return ;
298 }
299 
300 static void
301 parse_section_gaussconvolution(ns_config * cfg,cpl_parameterlist * cpl_cfg)
302 {
303  cpl_parameter *p;
304  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.gauss_ind");
305  cfg -> gaussInd = cpl_parameter_get_bool(p);
306 
307  p = cpl_parameterlist_find(cpl_cfg,
308  "sinfoni.north_south_test.kernel_half_width");
309  cfg -> hw = cpl_parameter_get_int(p);
310 
311 }
312 
313 static void
314 parse_section_northsouthtest(ns_config * cfg,cpl_parameterlist * cpl_cfg)
315 {
316 
317  cpl_parameter *p;
318  strcat(cfg -> fitsname, NS_TEST_OUT_FILENAME);
319  cfg -> nslits = NSLITLETS;
320 
321  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.half_width");
322  cfg -> halfWidth = cpl_parameter_get_int(p);
323 
324  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.fwhm");
325  cfg -> fwhm = cpl_parameter_get_double(p);
326 
327  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.min_diff");
328  cfg -> minDiff = cpl_parameter_get_double(p);
329 
330  cfg -> estimated_dist = ESTIMATED_SLITLETS_DISTANCE;
331 
332  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.north_south_test.dev_tol");
333  cfg -> devtol = cpl_parameter_get_double(p);
334 
335  return ;
336 }
337 
338 void
339 sinfo_ns_free(ns_config ** cfg)
340 {
341  if(*cfg!=NULL) {
342  sinfo_ns_free_alloc(*cfg);
343  sinfo_ns_cfg_destroy(*cfg);
344  *cfg=NULL;
345  }
346  return;
347 
348 }
349 void
350 sinfo_ns_free_alloc(ns_config * cfg)
351 {
352  if(cfg->framelist != NULL) {
353  cpl_free(cfg->framelist);
354  cfg->framelist=NULL;
355  }
356  if(cfg->frametype != NULL) {
357  cpl_free(cfg->frametype);
358  cfg->frametype=NULL;
359  }
360 
361  return;
362 
363 }
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69
#define sinfo_msg_warning(...)
Print an warning message.
Definition: sinfo_msg.h:93