SINFONI Pipeline Reference Manual  2.6.0
sinfo_detnoise_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_detnoise_ini.c
22  Author : Andrea Modiglini
23  Created on : May 17, 2004
24  Description : produce and read an .ini file for the search of static
25  bad pixels
26  ---------------------------------------------------------------------------*/
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30 /*---------------------------------------------------------------------------
31  Includes
32  ---------------------------------------------------------------------------*/
33 #include <string.h>
34 #include "sinfo_detnoise_ini_by_cpl.h"
35 #include "sinfo_raw_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 
43 static void
44 parse_section_frames(detnoise_config * cfg, cpl_frameset* sof,
45  cpl_frameset** raw, int* status);
46 static void
47 parse_section_badsearch(detnoise_config * cfg, cpl_parameterlist* cpl_cfg);
48 
56 /****************************************************************************/
68 detnoise_config *
69 sinfo_parse_cpl_input_detnoise(cpl_parameterlist * cpl_cfg, cpl_frameset* sof,
70  cpl_frameset** raw)
71 {
72 
73  detnoise_config * cfg;
74  int status = 0;
75  /* Removed check on ini_file */
76  /* Removed load of ini file */
77 
78  cfg = sinfo_detnoise_cfg_create();
79 
80  /*
81  * Perform sanity checks, fill up the structure with what was
82  * found in the ini file
83  */
84  parse_section_badsearch(cfg, cpl_cfg);
85  parse_section_frames(cfg, sof, raw, &status);
86 
87  if (status > 0) {
88  sinfo_msg_error("parsing cpl input");
89  sinfo_detnoise_free(cfg);
90  cfg = NULL;
91  return NULL ;
92  }
93  return cfg;
94 }
95 
106 static void
107 parse_section_frames(detnoise_config * cfg, cpl_frameset * sof,
108  cpl_frameset** raw, int* status)
109 {
110  int i;
111 
112  int nraw = 0;
113  cpl_frame* frame = NULL;
114 
115  char spat_res[FILE_NAME_SZ];
116  char lamp_status[FILE_NAME_SZ];
117  char band[FILE_NAME_SZ];
118  int ins_set = 0;
119 
120  sinfo_extract_raw_frames_type2(sof, raw, RAW_DARK);
121 
122  nraw = cpl_frameset_get_size(*raw);
123  if (nraw < 1) {
124  sinfo_msg_error("Too few (%d) raw frames (%s) present in"
125  "frameset!Aborting...", nraw, RAW_DARK);
126  (*status)++;
127  return;
128  }
129 
130  /* get "general:infile" read it, check input sinfo_matrix */
131  /* Allocate structures to go into the blackboard */
132  /* Copy relevant information into the blackboard */
133  cfg->nframes = nraw;
134  cfg->framelist = cpl_malloc(nraw * sizeof(char*));
135  /* read input frames */
136  for (i = 0; i < nraw; i++) {
137  frame = cpl_frameset_get_frame(*raw, i);
138  /* Store file name into framelist */
139  cfg->framelist[i] = cpl_strdup(cpl_frame_get_filename(frame));
140  }
141 
142  strcpy(cfg->outName, BP_NOISE_OUT_FILENAME);
143 
144  frame = cpl_frameset_get_frame(*raw, 0);
145  sinfo_get_spatial_res(frame, spat_res);
146  switch (sinfo_frame_is_on(frame))
147  {
148  case 0:
149  strcpy(lamp_status, "on");
150  break;
151  case 1:
152  strcpy(lamp_status, "off");
153  break;
154  case -1:
155  strcpy(lamp_status, "undefined");
156  break;
157  default:
158  strcpy(lamp_status, "undefined");
159  break;
160  }
161 
162  sinfo_get_band(frame, band);
163  sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n", spat_res,
164  lamp_status, band);
165 
166  sinfo_get_ins_set(band, &ins_set);
167  return;
168 
169 }
170 
178 static void
179 parse_section_badsearch(detnoise_config * cfg, cpl_parameterlist * cpl_cfg)
180 {
181  cpl_parameter *p;
182 
183  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_noise.low_rejection");
184  cfg->loReject = cpl_parameter_get_double(p);
185 
186  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_noise.high_rejection");
187  cfg->hiReject = cpl_parameter_get_double(p);
188 
189  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_noise.thresh_sigma_factor");
190  cfg->threshSigmaFactor = cpl_parameter_get_double(p);
191 
192 }
200 void
201 sinfo_detnoise_free(detnoise_config * cfg)
202 {
203 
204  if (cfg != NULL ) {
205  int i = 0;
206  for (i = 0; i < cfg->nframes; i++) {
207  if (cfg->framelist[i] != NULL )
208  cpl_free(cfg->framelist[i]);
209  }
210  if (cfg->framelist) {
211  if (cfg->framelist != NULL )
212  cpl_free(cfg->framelist);
213  }
214  sinfo_detnoise_cfg_destroy(cfg);
215  }
216 }
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69