SINFONI Pipeline Reference Manual  2.5.2
sinfo_dark_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_dark_ini_by_cpl.c
22  Author : Andrea Modigliani
23  Created on : May 18, 2004
24  Description : sinfo_dark cpl input file 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_dark_ini_by_cpl.h"
34 #include "sinfo_raw_types.h"
35 #include "sinfo_pro_types.h"
36 #include "sinfo_globals.h"
37 #include "sinfo_hidden.h"
38 #include "sinfo_functions.h"
39 /*---------------------------------------------------------------------------
40  Functions private to this module
41  ---------------------------------------------------------------------------*/
42 static void
43 parse_section_frames(dark_config *, cpl_frameset* sof,
44  cpl_frameset** raw, int* status);
45 static void
46 parse_section_cleanmean(dark_config *, cpl_parameterlist* cpl_cfg);
47 static void
48 parse_section_qclog(dark_config * cfg, cpl_parameterlist * cpl_cfg);
49 
50 void sinfo_detnoise_free(dark_config * cfg);
51 
72 dark_config *
73 sinfo_parse_cpl_input_dark(cpl_parameterlist * cpl_cfg,
74  cpl_frameset* sof,
75  cpl_frameset** raw)
76 {
77  int status=0;
78 
79  dark_config * cfg ;
80 
81  /* Removed check on ini_file */
82  /* Removed load of ini file */
83 
84  cfg = sinfo_dark_cfg_create();
85 
86  /*
87  * Perform sanity checks, fill up the structure with what was
88  * found in the ini file
89  */
90  parse_section_cleanmean (cfg, cpl_cfg);
91  parse_section_qclog (cfg, cpl_cfg);
92  parse_section_frames (cfg, sof, raw, &status);
93  if (status > 0) {
94  sinfo_msg_error("parsing cpl input");
95  sinfo_dark_cfg_destroy(cfg);
96  cfg = NULL ;
97  return NULL ;
98  }
99 
100  return cfg ;
101 }
102 
113 static void
114 parse_section_frames(dark_config * cfg,
115  cpl_frameset * sof,
116  cpl_frameset** raw,
117  int* status)
118 {
119 
120  int i;
121  int nraw=0;
122  int nraw_good=0;
123  cpl_frame* frame=NULL;
124 
125  char spat_res[FILE_NAME_SZ];
126  char lamp_status[FILE_NAME_SZ];
127  char band[FILE_NAME_SZ];
128  int ins_set=0;
129  sinfo_extract_raw_frames_type(sof,raw,RAW_DARK);
130 
131  nraw=cpl_frameset_get_size(*raw);
132  if (nraw < 1) {
133  sinfo_msg_error("Too few (%d) raw frames (%s) present in"
134  "frameset!Aborting...",nraw,RAW_DARK);
135  (*status)++;
136  return;
137  }
138 
139 
140 
141  /* Removed: get "general:infile" read it, check input sinfo_matrix */
142  /* Allocate structures to go into the blackboard */
143  cfg->inFrameList = cpl_malloc(nraw * sizeof(char*));
144 
145 
146  /* read input frames */
147  for (i=0 ; i<nraw ; i++) {
148  frame = cpl_frameset_get_frame(*raw,i);
149  /* Store file name into framelist */
150  cfg->inFrameList[i]=cpl_strdup(cpl_frame_get_filename(frame));
151  nraw_good++;
152  }
153 
154  if(nraw_good<1) {
155  sinfo_msg_error("no good raw frame in input, something wrong!");
156  (*status)++;
157  return;
158  }
159  /* Copy relevant information into the blackboard */
160  cfg->nframes = nraw ;
161 
162  strcpy(cfg -> outName, DARK_OUT_FILENAME);
163 
164 
165  frame = cpl_frameset_get_frame(*raw,0);
166  sinfo_get_spatial_res(frame,spat_res);
167 
168  switch(sinfo_frame_is_on(frame))
169  {
170  case 0:
171  strcpy(lamp_status,"on");
172  break;
173  case 1:
174  strcpy(lamp_status,"off");
175  break;
176  case -1:
177  strcpy(lamp_status,"undefined");
178  break;
179  default:
180  strcpy(lamp_status,"undefined");
181  break;
182 
183 
184  }
185 
186  sinfo_get_band(frame,band);
187  sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
188  spat_res, lamp_status, band);
189 
190 
191  sinfo_get_ins_set(band,&ins_set);
192  return ;
193 }
194 
203 static void
204 parse_section_cleanmean(dark_config * cfg, cpl_parameterlist * cpl_cfg)
205 {
206  cpl_parameter *p;
207 
208  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.low_rejection");
209  cfg -> lo_reject = cpl_parameter_get_double(p);
210 
211  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.high_rejection");
212  cfg -> hi_reject = cpl_parameter_get_double(p);
213 
214 }
215 
223 static void
224 parse_section_qclog(dark_config * cfg, cpl_parameterlist * cpl_cfg)
225 {
226  cpl_parameter *p;
227 
228  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_ron_xmin");
229  cfg -> qc_ron_xmin = cpl_parameter_get_int(p);
230 
231  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_ron_xmax");
232  cfg -> qc_ron_xmax = cpl_parameter_get_int(p);
233 
234  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_ron_ymin");
235  cfg -> qc_ron_ymin = cpl_parameter_get_int(p);
236 
237  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_ron_ymax");
238  cfg -> qc_ron_ymax = cpl_parameter_get_int(p);
239 
240  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_ron_hsize");
241  cfg -> qc_ron_hsize = cpl_parameter_get_int(p);
242 
243  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_ron_nsamp");
244  cfg -> qc_ron_nsamp = cpl_parameter_get_int(p);
245 
246 
247 
248  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_fpn_xmin");
249  cfg -> qc_fpn_xmin = cpl_parameter_get_int(p);
250 
251  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_fpn_xmax");
252  cfg -> qc_fpn_xmax = cpl_parameter_get_int(p);
253 
254  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_fpn_ymin");
255  cfg -> qc_fpn_ymin = cpl_parameter_get_int(p);
256 
257  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_fpn_ymax");
258  cfg -> qc_fpn_ymax = cpl_parameter_get_int(p);
259 
260  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_fpn_hsize");
261  cfg -> qc_fpn_hsize = cpl_parameter_get_int(p);
262 
263  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.dark.qc_fpn_nsamp");
264  cfg -> qc_fpn_nsamp = cpl_parameter_get_int(p);
265 
266 
267 }
268 
275 void
276 sinfo_dark_free(dark_config ** cfg)
277 {
278  int i=0;
279 
280  if((*cfg) != NULL) {
281  for(i=0;i<(*cfg)->nframes;i++) {
282  if((*cfg)->inFrameList[i] != NULL) {
283  cpl_free((*cfg)->inFrameList[i]);
284  (*cfg)->inFrameList[i]=NULL;
285  }
286  }
287  cpl_free((*cfg)->inFrameList);
288  (*cfg)->inFrameList=NULL;
289  sinfo_dark_cfg_destroy((*cfg));
290  *cfg = NULL;
291  }
292  return;
293 
294 }