SINFONI Pipeline Reference Manual  2.6.0
sinfo_detlin_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_detlin_ini_by_cpl.c
22  Author : Andrea Modigliani
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_detlin_ini_by_cpl.h"
35 #include "sinfo_error.h"
36 #include "sinfo_hidden.h"
37 #include "sinfo_raw_types.h"
38 #include "sinfo_functions.h"
39 #include "sinfo_file_handling.h"
40 /*---------------------------------------------------------------------------
41  Functions private to this module
42  ---------------------------------------------------------------------------*/
43 static void
44 parse_section_frames(detlin_config *,
45  cpl_frameset* sof, cpl_frameset** raw,int* status);
46 static void
47 parse_section_response(detlin_config *, cpl_parameterlist* cpl_cfg);
48 
68 detlin_config *
69 sinfo_parse_cpl_input_detlin(cpl_parameterlist * cpl_cfg, cpl_frameset* sof,
70  cpl_frameset** raw)
71 {
72 
73  detlin_config * cfg ;
74  int status ;
75 
76  /* check on input ini file removed */
77  /* loading input ini file removed */
78 
79 
80  cfg = sinfo_detlin_cfg_create();
81 
82  /*
83  * Perform sanity checks, fill up the structure with what was
84  * found in the ini file
85  */
86 
87  status = 0 ;
88  parse_section_response(cfg, cpl_cfg);
89  parse_section_frames(cfg, sof, raw, &status);
90  if (status > 0) {
91  sinfo_msg_error("parsing cpl input");
92  sinfo_detlin_free(&cfg);
93  cfg = NULL ;
94  return NULL ;
95  }
96  return cfg ;
97 }
98 
110 static void
111 parse_section_frames(detlin_config * cfg,
112  cpl_frameset * sof,
113  cpl_frameset** raw,
114  int* status)
115 {
116 
117  int i=0;
118  char* tag=NULL;
119  int nraw = 0;
120  int nraw_good = 0;
121  cpl_frame* frame=NULL;
122  char spat_res[FILE_NAME_SZ];
123  char lamp_status[FILE_NAME_SZ];
124  char band[FILE_NAME_SZ];
125  int ins_set=0;
126 
127  sinfo_extract_raw_frames_type(sof,raw,RAW_LINEARITY_LAMP);
128 
129  nraw=cpl_frameset_get_size(*raw);
130 
131  if (nraw < 1) {
132  sinfo_msg_error( "Too few (%d) raw frames (%s) present in"
133  "frameset!Aborting...",nraw, RAW_LINEARITY_LAMP);
134  (*status)++;
135  return;
136  }
137 
138 
139 
140  /* get "general:infile" read it, check input sinfo_matrix */
141  /* Allocate structures to go into the blackboard */
142  cfg->framelist = cpl_malloc(nraw * sizeof(char*));
143 
144  /* read input frames */
145  for (i=0 ; i<nraw ; i++) {
146  /* cfg->framelist[i] = cpl_malloc(FILE_NAME_SZ * sizeof(char)); */
147  frame = cpl_frameset_get_frame(*raw,i);
148  if(sinfo_file_exists((char*)cpl_frame_get_filename(frame))==1)
149  {
150  tag = (char*)cpl_frame_get_tag(frame) ;
151  if(sinfo_is_flat_lindet(tag) || sinfo_is_dark(tag)) {
152  /* Store file name into framelist */
153  cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
154  nraw_good++;
155  }
156  }
157  }
158 
159  /* Copy relevant information into the blackboard */
160  cfg->nframes = nraw_good ;
161 
162 
163  if (nraw_good < (cfg->order+1)) {
164  sinfo_msg_error( "Too few (%d) raw frames (%s) present in"
165  "frameset as we do a %d order polymnomial fit"
166  "!Aborting...",nraw_good,
167  RAW_LINEARITY_LAMP,cfg->order);
168 
169  (*status)++;
170  return;
171  }
172 
173 
174  strcpy(cfg -> outName, BP_LIN_OUT_FILENAME);
175 
176  check_nomsg(frame = cpl_frameset_get_frame(*raw,0));
177  sinfo_get_spatial_res(frame,spat_res);
178 
179  switch(sinfo_frame_is_on(frame))
180  {
181  case 0:
182  strcpy(lamp_status,"on");
183  break;
184  case 1:
185  strcpy(lamp_status,"off");
186  break;
187  case -1:
188  strcpy(lamp_status,"undefined");
189  break;
190  default:
191  strcpy(lamp_status,"undefined");
192  break;
193 
194 
195  }
196 
197  sinfo_get_band(frame,band);
198  sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
199  spat_res, lamp_status, band);
200 
201 
202  sinfo_get_ins_set(band,&ins_set);
203 
204 
205  cleanup:
206 
207  return;
208 }
217 static void
218 parse_section_response(detlin_config * cfg,cpl_parameterlist * cpl_cfg)
219 {
220  cpl_parameter *p;
221 
222  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.order");
223  cfg -> order = cpl_parameter_get_int(p);
224 
225  p = cpl_parameterlist_find(cpl_cfg,"sinfoni.bp_lin.thresh_sigma_factor");
226  cfg->threshSigmaFactor = (float) cpl_parameter_get_double(p);
227 
228  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.low_rejection");
229  cfg -> loReject = (float) cpl_parameter_get_double(p);
230 
231  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.bp_lin.high_rejection");
232  cfg -> hiReject = (float) cpl_parameter_get_double(p);
233 
234  p = cpl_parameterlist_find(cpl_cfg,"sinfoni.bp_lin.nlin_threshold");
235  cfg->nonlinearThresh = (float) cpl_parameter_get_double(p);
236 
237  /* name of the data cube storing the found polynomial coefficients */
238  strcpy(cfg->coeffsCubeName, BP_LIN_COEFFS_CUBE_OUT_FILENAME);
239 
240  return ;
241 }
248 void
249 sinfo_detlin_free(detlin_config ** cfg)
250 {
251 
252  if(*cfg!=NULL) {
253  int i=0;
254  for(i=0;i<(*cfg)->nframes; i++) {
255  if((*cfg)->framelist[i] != NULL) cpl_free((*cfg)->framelist[i]);
256  }
257  cpl_free((*cfg)->framelist);
258  sinfo_detlin_cfg_destroy((*cfg));
259  *cfg = NULL;
260  }
261  return;
262 
263 }
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69