SINFONI Pipeline Reference Manual  2.5.2
sinfo_objnod_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_object_ini_by_cpl.c
23  Author : Andrea Modigliani
24  Created on : May 22, 2004
25  Description : object cube creation cpl input handling for SPIFFI
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_objnod_ini_by_cpl.h"
40 #include "sinfo_pro_types.h"
41 #include "sinfo_hidden.h"
42 #include "sinfo_globals.h"
43 #include "sinfo_functions.h"
44 
45 #include "sinfo_file_handling.h"
46 
47 /*---------------------------------------------------------------------------
48  Functions private to this module
49  ---------------------------------------------------------------------------*/
50 static void
51 parse_section_frames(object_config *,cpl_frameset* sof,
52  cpl_frameset** stk, int* status);
53 static void parse_section_jittering(object_config *,
54  cpl_parameterlist * cpl_cfg);
55 static void parse_section_resampling(object_config *,
56  cpl_parameterlist * cpl_cfg);
57 static void parse_section_calibration(object_config *);
58 static void parse_section_cubecreation(object_config *,
59  cpl_parameterlist * cpl_cfg);
60 static void parse_section_finetuning(object_config *,
61  cpl_parameterlist * cpl_cfg);
62 static void parse_section_skyextraction(object_config *,
63  cpl_parameterlist * cpl_cfg);
73 /*-------------------------------------------------------------------------*/
84 /*--------------------------------------------------------------------------*/
85 
86 object_config *
87 sinfo_parse_cpl_input_objnod(cpl_parameterlist * cpl_cfg,cpl_frameset* sof,
88  cpl_frameset** stk)
89 {
90  object_config * cfg = sinfo_object_cfg_create();
91  int status=0;
92  /*
93  * Perform sanity checks, fill up the structure with what was
94  * found in the ini file
95  */
96 
97 
98  parse_section_resampling (cfg, cpl_cfg);
99  parse_section_calibration (cfg);
100  parse_section_cubecreation (cfg, cpl_cfg);
101  parse_section_finetuning (cfg, cpl_cfg);
102  parse_section_skyextraction(cfg, cpl_cfg);
103  parse_section_jittering (cfg, cpl_cfg);
104  parse_section_frames (cfg, sof,stk,&status);
105  if (status > 0) {
106  sinfo_msg_error("parsing cpl input");
107  sinfo_objnod_free(&cfg);
108  cfg = NULL ;
109  return NULL ;
110  }
111 
112  return cfg ;
113 }
114 
115 static void
116 parse_section_frames(object_config * cfg,
117  cpl_frameset* sof,
118  cpl_frameset** stk,
119  int* status)
120 {
121  int nraw_good =0;
122 
123 
124 
125  //int nframes=0;
126  int nraw=0;
127  cpl_frame* frame = NULL;
128  int nstk=0;
129  int i=0;
130  char spat_res[FILE_NAME_SZ];
131  char lamp_status[FILE_NAME_SZ];
132  char band[FILE_NAME_SZ];
133  int ins_set=0;
134 
135  //nframes = cpl_frameset_get_size(sof);
136 
137  sinfo_contains_frames_type(sof,stk,PRO_NODDING_STACKED);
138  nstk = cpl_frameset_get_size(*stk);
139 
140  if (nstk == 0) {
141  sinfo_contains_frames_type(sof,stk,PRO_PSF_CALIBRATOR_STACKED);
142  nstk = cpl_frameset_get_size(*stk);
143  }
144  if (nstk == 0) {
145  sinfo_contains_frames_type(sof,stk,PRO_PUPIL_LAMP_STACKED);
146  nstk = cpl_frameset_get_size(*stk);
147  }
148  if (nstk == 0) {
149  sinfo_msg_error( "Cannot find good frames") ;
150  (*status)++;
151  return ;
152  }
153 
154 
155 
156  /* TEMPORALLY COMMENTED OUT */
157  nraw = cpl_frameset_get_size(*stk);
158  /* Test if the rawframes have been found */
159  if (nraw < 1) {
160  sinfo_msg_error("Cannot find input stacked frames in the input list") ;
161  (*status)++;
162  return ;
163  }
164 
165  nraw = cpl_frameset_get_size(*stk);
166  if (nraw < 1) {
167  sinfo_msg_error( "no raw frame in input, something wrong!");
168  (*status)++;
169  return ;
170  }
171 
172  /* Allocate structures to go into the blackboard */
173  cfg->framelist = cpl_malloc(nraw * sizeof(char*));
174 
175  /* read input frames */
176  for (i=0 ; i<nraw ; i++) {
177  frame = cpl_frameset_get_frame(*stk,i);
178  if(sinfo_file_exists((char*)cpl_frame_get_filename(frame))==1)
179  {
180  cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
181  nraw_good++;
182  }
183  /* Store file name into framelist */
184  }
185 
186 
187  if (nraw_good < 1) {
188  sinfo_msg_error("no good raw frame in input!");
189  (*status)++;
190  return;
191  }
192  /* Copy relevant information into the blackboard */
193  cfg->nframes = nraw ;
194 
195  strcpy(cfg -> outName, OBJNOD_OUT_FILENAME);
196  strcpy(cfg -> maskname, OBJNOD_OUT_BPMAP);
197  strcpy(cfg -> med_cube_name, OBJNOD_OUT_MED_CUBE);
198 
199 
200  frame = cpl_frameset_get_frame(*stk,0);
201 
202  sinfo_get_spatial_res(frame,spat_res);
203  switch(sinfo_frame_is_on(frame))
204  {
205 
206  case 0:
207  strcpy(lamp_status,"on");
208  break;
209  case 1:
210  strcpy(lamp_status,"off");
211  break;
212  case -1:
213  strcpy(lamp_status,"undefined");
214  break;
215  default:
216  strcpy(lamp_status,"undefined");
217  break;
218  }
219  sinfo_get_band(frame,band);
220  sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s",
221  spat_res, lamp_status, band);
222 
223 
224  sinfo_get_ins_set(band,&ins_set);
225 
226  if(NULL != cpl_frameset_find(sof,PRO_WAVE_MAP)) {
227  frame = cpl_frameset_find(sof,PRO_WAVE_MAP);
228  strcpy(cfg -> wavemap, cpl_frame_get_filename(frame));
229  } else {
230  sinfo_msg("Frame %s not found!", PRO_WAVE_MAP);
231  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
232  (*status)++;
233  return ;
234  }
235 
236  if(NULL != cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP)) {
237  frame = cpl_frameset_find(sof,PRO_MASTER_FLAT_LAMP);
238  strcpy(cfg -> mflat, cpl_frame_get_filename(frame));
239  } else {
240  sinfo_msg("Frame %s not found!", PRO_MASTER_FLAT_LAMP);
241  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
242  (*status)++;
243  return ;
244  }
245 
246  if(NULL != cpl_frameset_find(sof,PRO_STACK_SKY_DIST)) {
247  frame = cpl_frameset_find(sof,PRO_STACK_SKY_DIST);
248  strcpy(cfg -> sky_dist, cpl_frame_get_filename(frame));
249  } else {
250  sinfo_msg_warning("Frame %s not found!", PRO_STACK_SKY_DIST);
251  strcpy(cfg -> sky_dist,"no_sky");
252  }
253 
254  if(NULL != cpl_frameset_find(sof,PRO_STACK_MFLAT_DIST)) {
255  frame = cpl_frameset_find(sof,PRO_STACK_MFLAT_DIST);
256  strcpy(cfg -> mflat_dist, cpl_frame_get_filename(frame));
257  } else {
258  strcpy(cfg -> mflat_dist, "not_found");
259  sinfo_msg("Frame %s not found!", PRO_STACK_MFLAT_DIST);
260  }
261 
262 
263  if(NULL != cpl_frameset_find(sof,PRO_STACK_MFLAT_DITHER_DIST)) {
264  frame = cpl_frameset_find(sof,PRO_STACK_MFLAT_DITHER_DIST);
265  strcpy(cfg -> mflat_dither_dist, cpl_frame_get_filename(frame));
266  } else {
267  strcpy(cfg -> mflat_dither_dist, "not_found");
268  sinfo_msg("Frame %s not found!", PRO_STACK_MFLAT_DITHER_DIST);
269  }
270 
271 
272  if(cfg -> northsouthInd) {
273 
274  if(NULL != cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE)) {
275  frame = cpl_frameset_find(sof,PRO_SLITLETS_DISTANCE);
276  strcpy(cfg -> distlist, cpl_frame_get_filename(frame));
277  } else {
278  sinfo_msg("Frame %s not found!", PRO_SLITLETS_DISTANCE);
279  (*status)++;
280  return ;
281  }
282 
283  } else {
284 
285  if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS)) {
286  frame = cpl_frameset_find(sof,PRO_SLIT_POS);
287  strcpy(cfg -> poslist, cpl_frame_get_filename(frame));
288  } else {
289  sinfo_msg("Frame %s not found!", PRO_SLIT_POS);
290  (*status)++;
291  return ;
292  }
293 
294  }
295  if(cfg -> halocorrectInd) {
296  if(NULL != cpl_frameset_find(sof,PRO_HALO_SPECT)) {
297  frame = cpl_frameset_find(sof,PRO_HALO_SPECT);
298  strcpy(cfg -> halospectrum, cpl_frame_get_filename(frame));
299  } else {
300  sinfo_msg("Frame %s not found!", PRO_HALO_SPECT);
301  (*status)++;
302  return ;
303  }
304 
305  }
306  if(NULL != cpl_frameset_find(sof, PRO_REF_ATM_REF_CORR))
307  {
308  frame = cpl_frameset_find(sof, PRO_REF_ATM_REF_CORR);
309  strcpy(cfg->polyshiftname, cpl_frame_get_filename(frame));
310  } else
311  {
312  sinfo_msg("Frame %s not found, shift due atmospheric refraction "
313  "would not be applied!", PRO_REF_ATM_REF_CORR);
314  cfg->polyshiftname[0] = 0;
315 // (*status)++;
316  }
317  /*
318  sinfo_msg("cfg -> wavemap %s",cfg -> wavemap);
319  sinfo_msg("cfg -> poslist %s",cfg -> poslist);
320  sinfo_msg("cfg -> firstCol %s",cfg -> firstCol);
321  */
322  return;
323 }
324 
325 
326 static void
327 parse_section_jittering(object_config * cfg,cpl_parameterlist * cpl_cfg)
328 {
329  cpl_parameter* p;
330 
331  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.jitter_index");
332  cfg -> jitterind = cpl_parameter_get_bool(p);
333 
334  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.size_x");
335  cfg -> size_x = cpl_parameter_get_int(p);
336 
337  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.size_y");
338  cfg -> size_y = cpl_parameter_get_int(p);
339 
340  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.kernel_type");
341  strcpy(cfg -> kernel_type, cpl_parameter_get_string(p));
342 
343 }
344 
345 static void
346 parse_section_resampling(object_config * cfg,cpl_parameterlist* cpl_cfg)
347 {
348  cpl_parameter* p;
349 
350  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.n_coeffs");
351  cfg -> ncoeffs = cpl_parameter_get_int(p);
352 
353  cfg -> nrows = SINFO_RESAMP_NROWS;
354  return ;
355 }
356 
357 static void
358 parse_section_calibration(object_config * cfg)
359 {
360  cfg -> halocorrectInd=0;
361 
362 
363 }
364 
365 static void
366 parse_section_cubecreation(object_config * cfg,cpl_parameterlist* cpl_cfg)
367 {
368  cpl_parameter* p;
369  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.nord_south_index");
370  cfg -> northsouthInd = cpl_parameter_get_bool(p);
371  cfg -> nslits = NSLITLETS;
372 
373  return ;
374 }
375 
376 static void
377 parse_section_finetuning(object_config * cfg,cpl_parameterlist* cpl_cfg)
378 {
379  cpl_parameter* p;
380 
381  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.fine_tuning_method");
382  strcpy(cfg -> method, cpl_parameter_get_string(p));
383 
384  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.order");
385  cfg -> order = cpl_parameter_get_int(p);
386 
387 }
388 
389 static void
390 parse_section_skyextraction(object_config * cfg,cpl_parameterlist* cpl_cfg)
391 {
392 
393  cpl_parameter* p;
394  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.low_rejection");
395  cfg -> loReject = cpl_parameter_get_double(p);
396 
397  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.high_rejection");
398  cfg -> hiReject = cpl_parameter_get_double(p);
399 
400  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.objnod.tolerance");
401  cfg -> tolerance = cpl_parameter_get_int(p);
402 
403 }
404 
405 /*-----------------------------------------------------------------*/
406 void
407 sinfo_objnod_free(object_config ** cfg) {
408  int i=0;
409  if(*cfg != NULL) {
410  for(i=0;i<(*cfg)->nframes;i++) {
411  if((*cfg)->framelist[i]!=NULL) {
412  cpl_free((*cfg)->framelist[i]);
413  (*cfg)->framelist[i]=NULL;
414  }
415  }
416  if((*cfg)->framelist != NULL) {
417  cpl_free((*cfg)->framelist);
418  (*cfg)->framelist=NULL;
419  }
420  sinfo_object_cfg_destroy (*cfg);
421  *cfg=NULL;
422  }
423  return;
424 }