SINFONI Pipeline Reference Manual  2.5.2
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  cpl_parameter* p=NULL;
170  cpl_table* drs_tab=NULL;
171  wcal* w=sinfo_wcal_new();
172  int check=0;
173 
174  sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_LAMP_STACKED );
175  nraw=cpl_frameset_get_size ( *raw );
176  if ( nraw==0 )
177  {
178  sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_NS_STACKED );
179  }
180  nraw=cpl_frameset_get_size ( *raw );
181  if ( nraw==0 )
182  {
183  sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_SLITPOS_STACKED );
184  }
185 
186  nraw=cpl_frameset_get_size ( *raw );
187  if ( nraw==0 )
188  {
189  sinfo_msg ( "Frame %s or %s or %s not found!",
190  PRO_WAVE_LAMP_STACKED,PRO_WAVE_NS_STACKED,PRO_WAVE_SLITPOS_STACKED );
191  ( *status ) ++;
192  return ;
193  }
194 
195  frame = cpl_frameset_get_frame ( *raw,0 );
196  sinfo_get_spatial_res ( frame,spat_res );
197 
198  switch ( sinfo_frame_is_on ( frame ) )
199  {
200  case 0:
201  strcpy ( lamp_status,"on" );
202  break;
203  case 1:
204  strcpy ( lamp_status,"off" );
205  break;
206  case -1:
207  strcpy ( lamp_status,"undefined" );
208  break;
209  default:
210  strcpy ( lamp_status,"undefined" );
211  break;
212 
213 
214  }
215 
216  sinfo_get_band ( frame,band );
217  sinfo_msg ( "Spatial resolution: %s lamp status: %s band: %s \n",
218  spat_res, lamp_status, band );
219 
220 
221  sinfo_get_ins_set ( band,&ins_set );
222  if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_LAMP_STACKED ) )
223  {
224  frame = cpl_frameset_find ( sof,PRO_WAVE_LAMP_STACKED );
225  strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
226  }
227  else if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_NS_STACKED ) )
228  {
229  frame = cpl_frameset_find ( sof,PRO_WAVE_NS_STACKED );
230  strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
231  }
232  else if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_SLITPOS_STACKED ) )
233  {
234  frame = cpl_frameset_find ( sof,PRO_WAVE_SLITPOS_STACKED );
235  strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
236  }
237  else
238  {
239  sinfo_msg_error ( "Frame %s or %s not found! Exit!",
240  PRO_WAVE_LAMP_STACKED,PRO_WAVE_NS_STACKED );
241  ( *status ) ++;
242  return;
243  }
244 
245 
246  if ( NULL != cpl_frameset_find ( sof,DRS_SETUP_WAVE ) )
247  {
248  frame = cpl_frameset_find ( sof,DRS_SETUP_WAVE );
249  strcpy ( cfg -> drs_setup,cpl_frame_get_filename ( frame ) );
250  drs_tab = cpl_table_load ( cfg->drs_setup,1,0 );
251  w->wstart=cpl_table_get_double ( drs_tab,"W_START",ins_set,&check );
252  w->wgdisp1=cpl_table_get_double ( drs_tab,"W_DISP1",ins_set,&check );
253  w->wgdisp2=cpl_table_get_double ( drs_tab,"W_DISP2",ins_set,&check );
254  w->hw=cpl_table_get_int ( drs_tab,"W_HW",ins_set,&check );
255  w->fwhm=cpl_table_get_double ( drs_tab,"W_FWHM",ins_set,&check );
256  w->min_amp=cpl_table_get_double ( drs_tab,"W_MIN_AMP",ins_set,&check );
257  /*
258  w->min_dif=cpl_table_get_double(drs_tab,"W_MIN_DIF",ins_set,&check);
259  w->na_coef=cpl_table_get_int(drs_tab,"W_NA_COEFF",ins_set,&check);
260  w->nb_coef=cpl_table_get_int(drs_tab,"W_NB_COEFF",ins_set,&check);
261  w->pixel_tol=cpl_table_get_double(drs_tab,"W_PIX_TOL",ins_set,&check);
262  w->y_box=cpl_table_get_double(drs_tab,"W_Y_BOX",ins_set,&check);
263  */
264  w->low_pos=cpl_table_get_int ( drs_tab,"W_LOW_POS",ins_set,&check );
265  w->hig_pos=cpl_table_get_int ( drs_tab,"W_HI_POS",ins_set,&check );
266 
267  cfg -> guessBeginWavelength = w->wstart;
268  cfg -> guessDispersion1 = w->wgdisp1;
269  cfg -> guessDispersion2 = w->wgdisp2;
270  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.half_width" );
271  if ( sinfo_parameter_get_default_flag ( p ) == 0 )
272  {
273  /* cpl_msg_info(cpl_func, "param sinfoni.wavecal.half_width - using value from DRS [%i]", w->hw);*/
274  cfg -> halfWidth = w->hw;
275  }
276  else
277  {
278  /* cpl_msg_info(cpl_func, "param sinfoni.wavecal.half_width - using value from command line [%g]", cfg -> halfWidth); */
279  }
280 
281  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fwhm" );
282  if ( sinfo_parameter_get_default_flag ( p ) == 0 )
283  {
284  cfg -> fwhm = w->fwhm;
285  /* cpl_msg_info(cpl_func, "param sinfoni.wavecal.fwhm - using value from DRS [%g]", cfg -> fwhm); */
286  }
287  else
288  {
289  /* cpl_msg_info(cpl_func, "param sinfoni.wavecal.fwhm - using value from command line [%g]", cfg -> fwhm); */
290  }
291  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.min_amplitude" );
292  if ( sinfo_parameter_get_default_flag ( p ) == 0 )
293  {
294  cfg -> minAmplitude = w->min_amp;
295  /* cpl_msg_info(cpl_func, "param sinfoni.wavecal.min_amplitude - using value from DRS [%g]", cfg -> minAmplitude); */
296  }
297  else
298  {
299  /* cpl_msg_info(cpl_func, "param sinfoni.wavecal.min_amplitude - using value from command line [%g]", cfg -> minAmplitude); */
300  }
301  /*
302  cfg -> mindiff = w->min_dif;
303  cfg -> nrDispCoefficients = w->na_coef;
304  cfg -> nrCoefCoefficients = w->nb_coef;
305  cfg -> pixel_tolerance = w->pixel_tol;
306  cfg -> yBox = w->y_box;
307  */
308  cfg -> loPos = w->low_pos;
309  cfg -> hiPos = w->hig_pos;
310  /* cfg -> pixel_tolerance = w->pixel_tol; */
311  /*
312  sinfo_msg("cfg->guessBeginWavelength %g",cfg -> guessBeginWavelength);
313  sinfo_msg("cfg->guessDispersion1 %g",cfg -> guessDispersion1);
314  sinfo_msg("cfg->guessDispersion2 %g",cfg -> guessDispersion2);
315  sinfo_msg("cfg->mindiff %g",cfg -> mindiff);
316  sinfo_msg("cfg->halfWidth %d",cfg -> halfWidth);
317  sinfo_msg("cfg->fwhm %g",cfg -> fwhm);
318  sinfo_msg("cfg->minAmplitude %g",cfg -> minAmplitude);
319  sinfo_msg("cfg->nrDispCoefficients %d",cfg -> nrDispCoefficients);
320  sinfo_msg("cfg->nrCoefCoefficients %d",cfg -> nrCoefCoefficients);
321  sinfo_msg("cfg->pixel_tolerance %g",cfg -> pixel_tolerance);
322  sinfo_msg("cfg->loPos %d",cfg -> loPos);
323  sinfo_msg("cfg->hiPos %d",cfg -> hiPos);
324  sinfo_msg("cfg->yBox %f",cfg -> yBox);
325  */
326 
327  sinfo_wcal_delete ( w );
328  cpl_table_delete ( drs_tab );
329  if ( -1 == sinfo_check_rec_status ( 0 ) )
330  {
331  ( *status ) ++;
332  return;
333  }
334 
335  }
336  else
337  {
338  sinfo_msg_error ( "Frame %s not found! Exit!", DRS_SETUP_WAVE );
339  ( *status ) ++;
340  return;
341  }
342 
343 
344  if ( NULL != cpl_frameset_find ( sof,REF_LINE_OH ) )
345  {
346  frame = cpl_frameset_find ( sof,REF_LINE_OH );
347  strcpy ( cfg -> lineList,cpl_frame_get_filename ( frame ) );
348  }
349  else if ( NULL != cpl_frameset_find ( sof,REF_LINE_ARC ) )
350  {
351  frame = cpl_frameset_find ( sof,REF_LINE_ARC );
352  strcpy ( cfg -> lineList,cpl_frame_get_filename ( frame ) );
353  }
354  else
355  {
356  sinfo_msg_error ( "Frame %s not found! Exit!", REF_LINE_ARC );
357  ( *status ) ++;
358  return;
359  }
360 
361 
362  if ( NULL != cpl_frameset_find ( sof,PRO_SLIT_POS_GUESS ) )
363  {
364  frame = cpl_frameset_find ( sof,PRO_SLIT_POS_GUESS );
365  strcpy ( cfg -> slitposGuessName,cpl_frame_get_filename ( frame ) );
366  }
367  else
368  {
369  sinfo_msg ( "Frame %s not found!", PRO_SLIT_POS_GUESS );
370  }
371 
372  if ( cfg -> writeParInd ==0 )
373  {
374  if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_PAR_LIST ) )
375  {
376  frame = cpl_frameset_find ( sof,PRO_WAVE_PAR_LIST );
377  strcpy ( cfg -> paramsList,cpl_frame_get_filename ( frame ) );
378  }
379  else
380  {
381  sinfo_msg ( "Frame %s not found!", PRO_WAVE_PAR_LIST );
382  ( *status ) ++;
383  return ;
384  }
385 
386  }
387  else
388  {
389 
390  strcpy ( cfg -> paramsList, WAVECAL_FIT_PARAMS_OUT_FILENAME );
391  sinfo_msg ( "cfg -> paramsList %s not given\n",cfg -> paramsList );
392 
393  }
394 
395 
396 
397  if ( cfg -> calibIndicator == 0 )
398  {
399  if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_COEF_SLIT ) )
400  {
401  frame = cpl_frameset_find ( sof,PRO_WAVE_COEF_SLIT );
402  strcpy ( cfg -> coeffsName,cpl_frame_get_filename ( frame ) );
403  }
404  else
405  {
406  sinfo_msg_error ( "Frame %s not found! Exit!", PRO_WAVE_COEF_SLIT );
407  ( *status ) ++;
408  return;
409  }
410  }
411  else
412  {
413 
414  strcpy ( cfg -> coeffsName, WAVECAL_COEFF_SLIT_OUT_FILENAME );
415  sinfo_msg ( "cfg -> coeffsName %s not given\n",cfg -> coeffsName );
416 
417  }
418 
419  strcpy ( cfg -> outName, WAVECAL_OUT_FILENAME );
420  strcpy ( cfg -> slitposName, WAVECAL_SLIT_POS_OUT_FILENAME );
421 
422  return;
423 }
424 
425 
426 static void
427 parse_section_findlines ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
428 {
429 
430  cpl_parameter* p;
431 
432  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.calib_indicator" );
433  cfg -> calibIndicator = cpl_parameter_get_bool ( p );
434 
435  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.min_diff" );
436  cfg -> mindiff = cpl_parameter_get_double ( p );
437 
438  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.half_width" );
439  cfg -> halfWidth = cpl_parameter_get_int ( p );
440 
441  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.sigma" );
442  cfg -> sigma = cpl_parameter_get_double ( p );
443 
444  return ;
445 }
446 
447 static void
448 parse_section_wavecalib ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
449 {
450  cpl_parameter* p;
451 
452  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fwhm" );
453  cfg -> fwhm = cpl_parameter_get_double ( p );
454 
455  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.min_amplitude" );
456  cfg -> minAmplitude = cpl_parameter_get_double ( p );
457 
458  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.max_residual" );
459  cfg -> maxResidual = cpl_parameter_get_double ( p );
460 
461  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.n_a_coefficients" );
462  cfg -> nrDispCoefficients = cpl_parameter_get_int ( p );
463 
464  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.n_b_coefficients" );
465  cfg -> nrCoefCoefficients = cpl_parameter_get_int ( p );
466 
467  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.sigma_factor" );
468  cfg -> sigmaFactor = cpl_parameter_get_double ( p );
469 
470  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.write_coeffs_ind" );
471  cfg -> writeCoeffsInd = cpl_parameter_get_bool ( p );
472 
473  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.write_par_ind" );
474  cfg -> writeParInd = cpl_parameter_get_bool ( p );
475 
476  cfg -> nslitlets = NSLITLETS;
477 
478  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.pixel_dist" );
479  cfg -> pixeldist = cpl_parameter_get_int ( p );
480 
481  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.pixel_tol" );
482  cfg -> pixel_tolerance = cpl_parameter_get_double ( p );
483 
484 }
485 
486 static void
487 parse_section_wavemap ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
488 {
489  cpl_parameter* p;
490 
491  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.wave_map_ind" );
492  cfg -> wavemapInd = cpl_parameter_get_bool ( p );
493 
494  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.mag_factor" );
495  cfg -> magFactor = cpl_parameter_get_int ( p );
496 
497 
498 }
499 
500 static void
501 parse_section_fitslits ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
502 {
503 
504  cpl_parameter* p;
505 
506  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.slit_pos_indicator" );
507  cfg -> slitposIndicator = cpl_parameter_get_bool ( p );
508 
509  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fit_boltz_indicator" );
510  cfg -> fitBoltzIndicator = cpl_parameter_get_bool ( p );
511 
512  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fit_edge_indicator" );
513  cfg -> fitEdgeIndicator = cpl_parameter_get_bool ( p );
514 
515  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.estimate_indicator" );
516  cfg -> estimateIndicator = cpl_parameter_get_bool ( p );
517 
518  cfg -> loPos = 750;
519  cfg -> hiPos = 1000;
520 
521  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.box_length" );
522  cfg -> boxLength = cpl_parameter_get_int ( p );
523 
524  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.y_box" );
525  cfg -> yBox = cpl_parameter_get_double ( p );
526 
527  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.diff_tol" );
528  cfg -> diffTol = cpl_parameter_get_double ( p );
529 
530  /* input CDB
531  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.wavecal.slit_pos_guess_name");
532  strcpy(cfg -> slitposGuessName, cpl_parameter_get_default_string(p));
533  */
534 
535 }
536 
537 static void
538 parse_section_qclog ( wave_config * cfg, cpl_parameterlist* cpl_cfg )
539 {
540  cpl_parameter* p;
541 
542  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.qc_thresh_min" );
543  cfg -> qc_thresh_min = cpl_parameter_get_int ( p );
544 
545 
546  p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.qc_thresh_max" );
547  cfg -> qc_thresh_max = cpl_parameter_get_int ( p );
548 
549 
550 }
551 
552 void
553 sinfo_wavecal_free ( wave_config ** cfg )
554 {
555  if ( *cfg != NULL )
556  {
557  sinfo_wave_cfg_destroy ( *cfg );
558  *cfg=NULL;
559  }
560  return;
561 
562 }
563 
564