SINFONI Pipeline Reference Manual  2.6.0
sinfo_standstar_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_standstar_ini_by_cpl.c
23  Author : Andrea Modigliani
24  Created on : May 23, 2004
25  Description : standard star reduction cpl input handling for SPIFFI
26 
27  ---------------------------------------------------------------------------*/
28 
29 #ifdef HAVE_CONFIG_H
30 # include <config.h>
31 #endif
32 
33 /*---------------------------------------------------------------------------
34  Includes
35  ---------------------------------------------------------------------------*/
36 #include <string.h>
37 #include "sinfo_standstar_ini_by_cpl.h"
38 #include "sinfo_pro_types.h"
39 #include "sinfo_hidden.h"
40 #include "sinfo_functions.h"
41 #include "sinfo_file_handling.h"
42 
43 /*---------------------------------------------------------------------------
44  Functions private to this module
45  ---------------------------------------------------------------------------*/
46 
47 static void
48 parse_section_frames(standstar_config *, cpl_frameset* sof, cpl_frameset** raw,
49  int* status);
50 static void
51 parse_section_extraction(standstar_config *, cpl_parameterlist* cpl_cfg);
60 /*-------------------------------------------------------------------------*/
71 /*--------------------------------------------------------------------------*/
72 
73 standstar_config *
74 sinfo_parse_cpl_input_standstar(cpl_parameterlist* cpl_cfg, cpl_frameset* sof,
75  cpl_frameset** raw)
76 {
77 
78  standstar_config * cfg = sinfo_standstar_cfg_create();
79  int status = 0;
80  /*
81  * Perform sanity checks, fill up the structure with what was
82  * found in the ini file
83  */
84  parse_section_extraction(cfg, cpl_cfg);
85  parse_section_frames(cfg, sof, raw, &status);
86  if (status > 0) {
87  sinfo_msg_error("parsing cpl input");
88  sinfo_standstar_cfg_destroy(cfg);
89  cfg = NULL;
90  return NULL ;
91  }
92  return cfg;
93 }
94 
95 static void
96 parse_section_frames(standstar_config * cfg, cpl_frameset* sof,
97  cpl_frameset** raw, int* status)
98 {
99  int i;
100  int nval;
101  cpl_frame* frame = NULL;
102  char spat_res[FILE_NAME_SZ];
103  char lamp_status[FILE_NAME_SZ];
104  char band[FILE_NAME_SZ];
105  int ins_set = 0;
106  cpl_frameset* tmp = NULL;
107  /* AMO BEWARE only STD frames should be here checked for */
108  sinfo_extract_frames_group_type(sof, &tmp, CPL_FRAME_GROUP_PRODUCT);
109  sinfo_extract_raw_frames_type(tmp, raw, PRO_COADD_STD);
110  cpl_frameset_delete(tmp);
111  nval = cpl_frameset_get_size(*raw);
112  if (nval < 1) {
113  sinfo_extract_raw_frames_type(sof, raw, PRO_OBS_STD);
114  }
115  nval = cpl_frameset_get_size(*raw);
116  if (nval < 1) {
117  sinfo_extract_raw_frames_type(sof, raw, PRO_COADD_PSF);
118  }
119  nval = cpl_frameset_get_size(*raw);
120  if (nval < 1) {
121  sinfo_extract_raw_frames_type(sof, raw, PRO_OBS_PSF);
122  }
123  nval = cpl_frameset_get_size(*raw);
124  if (nval < 1) {
125  sinfo_extract_raw_frames_type(sof, raw, PRO_COADD_OBJ);
126  }
127  nval = cpl_frameset_get_size(*raw);
128  if (nval < 1) {
129  sinfo_extract_raw_frames_type(sof, raw, PRO_OBS_OBJ);
130  }
131  nval = cpl_frameset_get_size(*raw);
132  if (nval < 1) {
133  sinfo_msg_error("Too few (%d) raw frames "
134  "(%s or %s or %s or %s or %s or %s ) "
135  "present in frameset!Aborting...", nval, PRO_COADD_STD,
136  PRO_OBS_STD, PRO_COADD_PSF, PRO_OBS_PSF, PRO_COADD_OBJ,
137  PRO_OBS_OBJ);
138  (*status)++;
139  return;
140  }
141 
142  /* Allocate structures to go into the blackboard */
143  cfg->inFrameList = cpl_malloc(nval * sizeof(char*));
144  /* Browse through the charmatrix to get names and file types */
145  /* read input frames */
146  for (i = 0; i < nval; i++) {
147  frame = cpl_frameset_get_frame(*raw, i);
148  if (sinfo_file_exists((char*) cpl_frame_get_filename(frame)) == 1) {
149  /* Store file name into framelist */
150  cfg->inFrameList[i] = cpl_strdup(cpl_frame_get_filename(frame));
151  }
152  }
153 
154  /* Copy relevant information into the blackboard */
155  cfg->nframes = nval;
156 
157  strcpy(cfg->outName, STDSTAR_OUT_FILENAME);
158 
159  frame = cpl_frameset_get_frame(*raw, 0);
160 
161  sinfo_get_spatial_res(frame, spat_res);
162  switch (sinfo_frame_is_on(frame))
163  {
164 
165  case 0:
166  strcpy(lamp_status, "on");
167  break;
168  case 1:
169  strcpy(lamp_status, "off");
170  break;
171  case -1:
172  strcpy(lamp_status, "undefined");
173  break;
174  default:
175  strcpy(lamp_status, "undefined");
176  break;
177  }
178  sinfo_get_band(frame, band);
179  sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s", spat_res,
180  lamp_status, band);
181 
182  sinfo_get_ins_set(band, &ins_set);
183  return;
184 }
185 
186 static void
187 parse_section_extraction(standstar_config * cfg, cpl_parameterlist* cpl_cfg)
188 {
189  cpl_parameter* p;
190  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.std_star.low_rejection");
191  cfg->lo_reject = cpl_parameter_get_double(p);
192 
193  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.std_star.high_rejection");
194  cfg->hi_reject = cpl_parameter_get_double(p);
195 
196  cfg->llx = 8;
197  cfg->lly = 8;
198  cfg->halfbox_x = 16;
199  cfg->halfbox_y = 16;
200 
201  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.std_star.fwhm_factor");
202  cfg->fwhm_factor = cpl_parameter_get_double(p);
203 
204  cfg->backvariance = BKG_VARIANCE;
205  cfg->sky = SKY_FLUX;
206  cfg->gain = GAIN;
207 
208  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.std_star.conversion_index");
209  cfg->convInd = cpl_parameter_get_bool(p);
210 
211  strcpy(cfg->convName, STDSTAR_CONV_OUT_FILENAME);
212 
213  cfg->mag = 0;
214 
215  return;
216 }
217 
218 void
219 sinfo_stdstar_free(standstar_config ** cfg)
220 {
221  if ((*cfg) != NULL ) {
222  for (int i = 0; i < (*cfg)->nframes; i++) {
223  if ((*cfg)->inFrameList[i] != NULL ) {
224  cpl_free((*cfg)->inFrameList[i]);
225  (*cfg)->inFrameList[i] = NULL;
226  }
227  }
228  cpl_free((*cfg)->inFrameList);
229  (*cfg)->inFrameList = NULL;
230  sinfo_standstar_cfg_destroy(*cfg);
231  (*cfg) = NULL;
232  }
233 }
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69