SINFONI Pipeline Reference Manual  2.6.0
sinfo_wavecal_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_wavecal_ini_by_cpl.c
22  Author : Andrea Modigliani
23  Created on : May 21, 2004
24  Description : wavelength calibration cpl input handling for SPIFFI
25 
26  ---------------------------------------------------------------------------*/
27 
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 
32 
33 /*---------------------------------------------------------------------------
34  Includes
35  ---------------------------------------------------------------------------*/
36 
37 #include <string.h>
38 #include "sinfo_wavecal_ini_by_cpl.h"
39 #include "sinfo_raw_types.h"
40 #include "sinfo_pro_types.h"
41 #include "sinfo_ref_types.h"
42 #include "sinfo_hidden.h"
43 #include "sinfo_functions.h"
44 #include "sinfo_utils.h"
45 /*---------------------------------------------------------------------------
46  Functions private to this module
47  ---------------------------------------------------------------------------*/
48 
49 static void
50 parse_section_frames ( wave_config *, cpl_parameterlist* cpl_cfg, cpl_frameset* sof,
51  cpl_frameset** raw, int* status );
52 
53 static void
54 parse_section_findlines ( wave_config *, cpl_parameterlist* cpl_cfg );
55 static void
56 parse_section_wavecalib ( wave_config *, cpl_parameterlist* cpl_cfg );
57 static void
58 parse_section_wavemap ( wave_config *, cpl_parameterlist* cpl_cfg );
59 static void
60 parse_section_qclog ( wave_config *, cpl_parameterlist* cpl_cfg );
61 static void
62 parse_section_fitslits ( wave_config *, cpl_parameterlist* cpl_cfg );
63 
64 
65 
74 /*-------------------------------------------------------------------------*/
92 /*--------------------------------------------------------------------------*/
93 
94 /* Removed generateWave_ini_file */
95 
96 /*-------------------------------------------------------------------------*/
107 /*--------------------------------------------------------------------------*/
108 
109 wave_config *
110 sinfo_parse_cpl_input_wave ( cpl_parameterlist* cpl_cfg,
111  cpl_frameset* sof, cpl_frameset** raw )
112 {
113 
114  int status=0;
115  wave_config * cfg= sinfo_wave_cfg_create();
116  /*
117  * Perform sanity checks, fill up the structure with what was
118  * found in the ini file
119  */
120 
121  parse_section_findlines ( cfg, cpl_cfg );
122  parse_section_wavecalib ( cfg, cpl_cfg );
123  parse_section_wavemap ( cfg, cpl_cfg );
124  parse_section_fitslits ( cfg, cpl_cfg );
125  parse_section_qclog ( cfg, cpl_cfg );
126  parse_section_frames ( cfg, cpl_cfg, sof, raw, &status );
127 
128  if ( status > 0 )
129  {
130  sinfo_msg_error ( "parsing cpl input" );
131  sinfo_wave_cfg_destroy ( cfg );
132  cfg = NULL ;
133  return NULL ;
134  }
135  return cfg ;
136 }
137 
138 
139 /*---------------------------------------------------------------------------
140  Functions: parse_section_xxx()
141  In : symbolic table read from ini file
142  Out : void
143  Job : update a wave_config structure from what can be
144  found in the ini file.
145  Notice : all of these functions update a status integer to
146  indicate if an error occurred, or leave it as it is if
147  everything went Ok.
148 
149  parse_section_general()
150  parse_section_findlines()
151  parse_section_wavecalib()
152  parse_section_wavemap()
153  parse_section_fitslits()
154 
155  ---------------------------------------------------------------------------*/
156 
157 
158 
159 static void
160 parse_section_frames ( wave_config * cfg,cpl_parameterlist* cpl_cfg, cpl_frameset* sof,
161  cpl_frameset** raw, int* status )
162 {
163  cpl_frame* frame = NULL;
164  char spat_res[FILE_NAME_SZ];
165  char lamp_status[FILE_NAME_SZ];
166  char band[FILE_NAME_SZ];
167  int ins_set=0;
168  int nraw=0;
169 
170  wcal* w=sinfo_wcal_new();
171  int check=0;
172 
173  sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_LAMP_STACKED );
174  nraw=cpl_frameset_get_size ( *raw );
175  if ( nraw==0 )
176  {
177  sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_NS_STACKED );
178  }
179  nraw=cpl_frameset_get_size ( *raw );
180  if ( nraw==0 )
181  {
182  sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_SLITPOS_STACKED );
183  }
184 
185  nraw=cpl_frameset_get_size ( *raw );
186  if ( nraw==0 )
187  {
188  sinfo_msg ( "Frame %s or %s or %s not found!",
189  PRO_WAVE_LAMP_STACKED,PRO_WAVE_NS_STACKED,PRO_WAVE_SLITPOS_STACKED );
190  ( *status ) ++;
191  return ;
192  }
193 
194  frame = cpl_frameset_get_frame ( *raw,0 );
195  sinfo_get_spatial_res ( frame,spat_res );
196 
197  switch ( sinfo_frame_is_on ( frame ) )
198  {
199  case 0:
200  strcpy ( lamp_status,"on" );
201  break;
202  case 1:
203  strcpy ( lamp_status,"off" );
204  break;
205  case -1:
206  strcpy ( lamp_status,"undefined" );
207  break;
208  default:
209  strcpy ( lamp_status,"undefined" );
210  break;
211 
212 
213  }
214 
215  sinfo_get_band ( frame,band );
216  sinfo_msg ( "Spatial resolution: %s lamp status: %s band: %s \n",
217  spat_res, lamp_status, band );
218 
219 
220  sinfo_get_ins_set ( band,&ins_set );
221  if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_LAMP_STACKED ) )
222  {
223  frame = cpl_frameset_find ( sof,PRO_WAVE_LAMP_STACKED );
224  strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
225  }
226  else if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_NS_STACKED ) )
227  {
228  frame = cpl_frameset_find ( sof,PRO_WAVE_NS_STACKED );
229  strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
230  }
231  else if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_SLITPOS_STACKED ) )
232  {
233  frame = cpl_frameset_find ( sof,PRO_WAVE_SLITPOS_STACKED );
234  strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
235  }
236  else
237  {
238  sinfo_msg_error ( "Frame %s or %s not found! Exit!",
239  PRO_WAVE_LAMP_STACKED,PRO_WAVE_NS_STACKED );
240  ( *status ) ++;
241  return;
242  }
243 
244 
245  if ( NULL != cpl_frameset_find ( sof,DRS_SETUP_WAVE ) )
246  {
247  frame = cpl_frameset_find ( sof,DRS_SETUP_WAVE );
248  strcpy ( cfg -> drs_setup,cpl_frame_get_filename ( frame ) );
249  cpl_table* drs_tab = cpl_table_load ( cfg->drs_setup,1,0 );
250  w->wstart=cpl_table_get_double ( drs_tab,"W_START",ins_set,&check );
251  w->wgdisp1=cpl_table_get_double ( drs_tab,"W_DISP1",ins_set,&check );
252  w->wgdisp2=cpl_table_get_double ( drs_tab,"W_DISP2",ins_set,&check );
253  w->hw=cpl_table_get_int ( drs_tab,"W_HW",ins_set,&check );
254  w->fwhm=cpl_table_get_double ( drs_tab,"W_FWHM",ins_set,&check );
255  w->min_amp=cpl_table_get_double ( drs_tab,"W_MIN_AMP",ins_set,&check );
256  /*
257  w->min_dif=cpl_table_get_double(drs_tab,"W_MIN_DIF",ins_set,&check);
258  w->na_coef=cpl_table_get_int(drs_tab,"W_NA_COEFF",ins_set,&check);
259  w->nb_coef=cpl_table_get_int(drs_tab,"W_NB_COEFF",ins_set,&check);
260  w->pixel_tol=cpl_table_get_double(drs_tab,"W_PIX_TOL",ins_set,&check);
261  w->y_box=cpl_table_get_double(drs_tab,"W_Y_BOX",ins_set,&check);
262  */
263  w->low_pos=cpl_table_get_int ( drs_tab,"W_LOW_POS",ins_set,&check );
264  w->hig_pos=cpl_table_get_int ( drs_tab,"W_HI_POS",ins_set,&check );
265 
266  cfg -> guessBeginWavelength = w->wstart;
267  cfg -> guessDispersion1 = w->wgdisp1;
268  cfg -> guessDispersion2 = w->wgdisp2;
269  cpl_parameter* p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.half_width" );
270  if ( sinfo_parameter_get_default_flag ( p ) == 0 )
271  {
272  /* cpl_msg_info(cpl_func, "param sinfoni.wavecal.half_width - using value from DRS [%i]", w->hw);*/
273  cfg -> halfWidth = w->hw;
274  }
275  else
276  {
277  /* cpl_msg_info(cpl_func, "param sinfoni.wavecal.half_width - using value from command line [%g]", cfg -> halfWidth); */
278  }
279 
280  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fwhm" );
281  if ( sinfo_parameter_get_default_flag ( p ) == 0 )
282  {
283  cfg -> fwhm = w->fwhm;
284  /* cpl_msg_info(cpl_func, "param sinfoni.wavecal.fwhm - using value from DRS [%g]", cfg -> fwhm); */
285  }
286  else
287  {
288  /* cpl_msg_info(cpl_func, "param sinfoni.wavecal.fwhm - using value from command line [%g]", cfg -> fwhm); */
289  }
290  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.min_amplitude" );
291  if ( sinfo_parameter_get_default_flag ( p ) == 0 )
292  {
293  cfg -> minAmplitude = w->min_amp;
294  /* cpl_msg_info(cpl_func, "param sinfoni.wavecal.min_amplitude - using value from DRS [%g]", cfg -> minAmplitude); */
295  }
296  else
297  {
298  /* cpl_msg_info(cpl_func, "param sinfoni.wavecal.min_amplitude - using value from command line [%g]", cfg -> minAmplitude); */
299  }
300  /*
301  cfg -> mindiff = w->min_dif;
302  cfg -> nrDispCoefficients = w->na_coef;
303  cfg -> nrCoefCoefficients = w->nb_coef;
304  cfg -> pixel_tolerance = w->pixel_tol;
305  cfg -> yBox = w->y_box;
306  */
307  cfg -> loPos = w->low_pos;
308  cfg -> hiPos = w->hig_pos;
309  /* cfg -> pixel_tolerance = w->pixel_tol; */
310  /*
311  sinfo_msg("cfg->guessBeginWavelength %g",cfg -> guessBeginWavelength);
312  sinfo_msg("cfg->guessDispersion1 %g",cfg -> guessDispersion1);
313  sinfo_msg("cfg->guessDispersion2 %g",cfg -> guessDispersion2);
314  sinfo_msg("cfg->mindiff %g",cfg -> mindiff);
315  sinfo_msg("cfg->halfWidth %d",cfg -> halfWidth);
316  sinfo_msg("cfg->fwhm %g",cfg -> fwhm);
317  sinfo_msg("cfg->minAmplitude %g",cfg -> minAmplitude);
318  sinfo_msg("cfg->nrDispCoefficients %d",cfg -> nrDispCoefficients);
319  sinfo_msg("cfg->nrCoefCoefficients %d",cfg -> nrCoefCoefficients);
320  sinfo_msg("cfg->pixel_tolerance %g",cfg -> pixel_tolerance);
321  sinfo_msg("cfg->loPos %d",cfg -> loPos);
322  sinfo_msg("cfg->hiPos %d",cfg -> hiPos);
323  sinfo_msg("cfg->yBox %f",cfg -> yBox);
324  */
325 
326  sinfo_wcal_delete ( w );
327  cpl_table_delete ( drs_tab );
328  if ( -1 == sinfo_check_rec_status ( 0 ) )
329  {
330  ( *status ) ++;
331  return;
332  }
333 
334  }
335  else
336  {
337  sinfo_msg_error ( "Frame %s not found! Exit!", DRS_SETUP_WAVE );
338  ( *status ) ++;
339  return;
340  }
341 
342 
343  if ( NULL != cpl_frameset_find ( sof,REF_LINE_OH ) )
344  {
345  frame = cpl_frameset_find ( sof,REF_LINE_OH );
346  strcpy ( cfg -> lineList,cpl_frame_get_filename ( frame ) );
347  }
348  else if ( NULL != cpl_frameset_find ( sof,REF_LINE_ARC ) )
349  {
350  frame = cpl_frameset_find ( sof,REF_LINE_ARC );
351  strcpy ( cfg -> lineList,cpl_frame_get_filename ( frame ) );
352  }
353  else
354  {
355  sinfo_msg_error ( "Frame %s not found! Exit!", REF_LINE_ARC );
356  ( *status ) ++;
357  return;
358  }
359 
360 
361  if ( NULL != cpl_frameset_find ( sof,PRO_SLIT_POS_GUESS ) )
362  {
363  frame = cpl_frameset_find ( sof,PRO_SLIT_POS_GUESS );
364  strcpy ( cfg -> slitposGuessName,cpl_frame_get_filename ( frame ) );
365  }
366  else
367  {
368  sinfo_msg ( "Frame %s not found!", PRO_SLIT_POS_GUESS );
369  }
370 
371  if ( cfg -> writeParInd ==0 )
372  {
373  if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_PAR_LIST ) )
374  {
375  frame = cpl_frameset_find ( sof,PRO_WAVE_PAR_LIST );
376  strcpy ( cfg -> paramsList,cpl_frame_get_filename ( frame ) );
377  }
378  else
379  {
380  sinfo_msg ( "Frame %s not found!", PRO_WAVE_PAR_LIST );
381  ( *status ) ++;
382  return ;
383  }
384 
385  }
386  else
387  {
388 
389  strcpy ( cfg -> paramsList, WAVECAL_FIT_PARAMS_OUT_FILENAME );
390  sinfo_msg ( "cfg -> paramsList %s not given\n",cfg -> paramsList );
391 
392  }
393 
394 
395 
396  if ( cfg -> calibIndicator == 0 )
397  {
398  if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_COEF_SLIT ) )
399  {
400  frame = cpl_frameset_find ( sof,PRO_WAVE_COEF_SLIT );
401  strcpy ( cfg -> coeffsName,cpl_frame_get_filename ( frame ) );
402  }
403  else
404  {
405  sinfo_msg_error ( "Frame %s not found! Exit!", PRO_WAVE_COEF_SLIT );
406  ( *status ) ++;
407  return;
408  }
409  }
410  else
411  {
412 
413  strcpy ( cfg -> coeffsName, WAVECAL_COEFF_SLIT_OUT_FILENAME );
414  sinfo_msg ( "cfg -> coeffsName %s not given\n",cfg -> coeffsName );
415 
416  }
417 
418  strcpy ( cfg -> outName, WAVECAL_OUT_FILENAME );
419  strcpy ( cfg -> slitposName, WAVECAL_SLIT_POS_OUT_FILENAME );
420 
421  return;
422 }
423 
424 
425 static void
426 parse_section_findlines ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
427 {
428 
429  cpl_parameter* p;
430 
431  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.calib_indicator" );
432  cfg -> calibIndicator = cpl_parameter_get_bool ( p );
433 
434  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.min_diff" );
435  cfg -> mindiff = cpl_parameter_get_double ( p );
436 
437  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.half_width" );
438  cfg -> halfWidth = cpl_parameter_get_int ( p );
439 
440  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.sigma" );
441  cfg -> sigma = cpl_parameter_get_double ( p );
442 
443  return ;
444 }
445 
446 static void
447 parse_section_wavecalib ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
448 {
449  cpl_parameter* p;
450 
451  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fwhm" );
452  cfg -> fwhm = cpl_parameter_get_double ( p );
453 
454  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.min_amplitude" );
455  cfg -> minAmplitude = cpl_parameter_get_double ( p );
456 
457  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.max_residual" );
458  cfg -> maxResidual = cpl_parameter_get_double ( p );
459 
460  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.n_a_coefficients" );
461  cfg -> nrDispCoefficients = cpl_parameter_get_int ( p );
462 
463  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.n_b_coefficients" );
464  cfg -> nrCoefCoefficients = cpl_parameter_get_int ( p );
465 
466  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.sigma_factor" );
467  cfg -> sigmaFactor = cpl_parameter_get_double ( p );
468 
469  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.write_coeffs_ind" );
470  cfg -> writeCoeffsInd = cpl_parameter_get_bool ( p );
471 
472  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.write_par_ind" );
473  cfg -> writeParInd = cpl_parameter_get_bool ( p );
474 
475  cfg -> nslitlets = NSLITLETS;
476 
477  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.pixel_dist" );
478  cfg -> pixeldist = cpl_parameter_get_int ( p );
479 
480  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.pixel_tol" );
481  cfg -> pixel_tolerance = cpl_parameter_get_double ( p );
482 
483 }
484 
485 static void
486 parse_section_wavemap ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
487 {
488  cpl_parameter* p;
489 
490  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.wave_map_ind" );
491  cfg -> wavemapInd = cpl_parameter_get_bool ( p );
492 
493  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.mag_factor" );
494  cfg -> magFactor = cpl_parameter_get_int ( p );
495 
496 
497 }
498 
499 static void
500 parse_section_fitslits ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
501 {
502 
503  cpl_parameter* p;
504 
505  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.slit_pos_indicator" );
506  cfg -> slitposIndicator = cpl_parameter_get_bool ( p );
507 
508  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fit_boltz_indicator" );
509  cfg -> fitBoltzIndicator = cpl_parameter_get_bool ( p );
510 
511  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fit_edge_indicator" );
512  cfg -> fitEdgeIndicator = cpl_parameter_get_bool ( p );
513 
514  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.estimate_indicator" );
515  cfg -> estimateIndicator = cpl_parameter_get_bool ( p );
516 
517  cfg -> loPos = 750;
518  cfg -> hiPos = 1000;
519 
520  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.box_length" );
521  cfg -> boxLength = cpl_parameter_get_int ( p );
522 
523  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.y_box" );
524  cfg -> yBox = cpl_parameter_get_double ( p );
525 
526  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.diff_tol" );
527  cfg -> diffTol = cpl_parameter_get_double ( p );
528 
529  /* input CDB
530  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.slit_pos_guess_name");
531  strcpy(cfg -> slitposGuessName, cpl_parameter_get_default_string(p));
532  */
533 
534 }
535 
536 static void
537 parse_section_qclog ( wave_config * cfg, cpl_parameterlist* cpl_cfg )
538 {
539  cpl_parameter* p;
540 
541  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.qc_thresh_min" );
542  cfg -> qc_thresh_min = cpl_parameter_get_int ( p );
543 
544 
545  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.qc_thresh_max" );
546  cfg -> qc_thresh_max = cpl_parameter_get_int ( p );
547 
548 
549 }
550 
551 void
552 sinfo_wavecal_free ( wave_config ** cfg )
553 {
554  if ( *cfg != NULL )
555  {
556  sinfo_wave_cfg_destroy ( *cfg );
557  *cfg=NULL;
558  }
559  return;
560 
561 }
562 
563 
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69