SINFONI Pipeline Reference Manual  2.6.0
sinfo_finddist_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_finddist_ini_by_cpl.c
22  Author : Andrea Modigliani
23  Created on : Aug 12, 2004
24  Description : distortion, slitlet distances, first column CPL input
25  handling for SINFONI
26  ---------------------------------------------------------------------------*/
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30 /*---------------------------------------------------------------------------
31  Includes
32  ---------------------------------------------------------------------------*/
33 #include <string.h>
34 #include "sinfo_finddist_ini_by_cpl.h"
35 #include "sinfo_pro_types.h"
36 #include "sinfo_hidden.h"
37 #include "sinfo_raw_types.h"
38 #include "sinfo_ref_types.h"
39 /*---------------------------------------------------------------------------
40  Functions private to this module
41  ---------------------------------------------------------------------------*/
42 static void
43 parse_section_frames(finddist_config *, cpl_parameterlist* cpl_cfg,
44  cpl_frameset* sof, cpl_frameset** raw, int* status);
45 static void
46 parse_section_findlines(finddist_config *, cpl_parameterlist* cpl_cfg);
47 static void
48 parse_section_wavecalib(finddist_config *, cpl_parameterlist* cpl_cfg);
49 static void
50 parse_section_wavemap(finddist_config *, cpl_parameterlist* cpl_cfg);
51 static void
52 parse_section_fitslits(finddist_config *, cpl_parameterlist* cpl_cfg);
53 static void
54 parse_section_northsouthtest(finddist_config *, cpl_parameterlist* cpl_cfg);
55 static void
56 parse_section_qclog (finddist_config * cfg, cpl_parameterlist* cpl_cfg);
57 
77 finddist_config *
78 sinfo_parse_cpl_input_finddist(cpl_parameterlist * cpl_cfg,
79  cpl_frameset* sof,
80  cpl_frameset** raw)
81 {
82  finddist_config * cfg ;
83  int status =0;
84 
85  cfg = sinfo_finddist_cfg_create();
86 
87  parse_section_findlines (cfg, cpl_cfg);
88  parse_section_wavecalib (cfg, cpl_cfg);
89  parse_section_wavemap (cfg, cpl_cfg);
90  parse_section_fitslits (cfg, cpl_cfg);
91  parse_section_northsouthtest (cfg, cpl_cfg);
92  parse_section_qclog(cfg,cpl_cfg);
93  parse_section_frames (cfg, cpl_cfg, sof, raw, &status);
94 
95  if (status > 0) {
96  sinfo_msg_error("parsing cpl input");
97  sinfo_finddist_cfg_destroy(cfg);
98  cfg = NULL ;
99  return NULL ;
100  }
101  return cfg ;
102 }
103 
104 
116 static void
117 parse_section_frames(finddist_config * cfg,
118  cpl_parameterlist * cpl_cfg,
119  cpl_frameset * sof,
120  cpl_frameset** raw,
121  int* status)
122 {
123 
124 
125 
126  //int nframes=0;
127  int nraw=0;
128  cpl_frame* frame = NULL;
129  cpl_parameter *p;
130 
131 
132  char spat_res[FILE_NAME_SZ];
133  char lamp_status[FILE_NAME_SZ];
134  char band[FILE_NAME_SZ];
135  int ins_set=0;
136 
137  wcal* w=NULL;
138  int check=0;
139  nstpar* nstp=NULL;
140  distpar* d=NULL;
141 
142  d=sinfo_distpar_new();
143  w=sinfo_wcal_new();
144 
145  //nframes = cpl_frameset_get_size(sof);
146 
147  /* Get the raw and the calibration files */
148 
149 
150  sinfo_extract_raw_frames_type(sof,raw,PRO_FIBRE_NS_STACKED);
151 
152 
153  nraw=cpl_frameset_get_size(*raw);
154  if (nraw < 1) {
155  sinfo_msg_error("Too few (%d) raw frames (%s) present "
156  "in frameset!Aborting...",nraw,PRO_FIBRE_NS_STACKED);
157  sinfo_distpar_delete(d);
158  sinfo_wcal_delete(w);
159  (*status)++;
160  return;
161  }
162 
163 
164  if(NULL != cpl_frameset_find(sof,PRO_WAVE_LAMP_STACKED)) {
165  frame = cpl_frameset_find(sof,PRO_WAVE_LAMP_STACKED);
166  strcpy(cfg -> inFrame,cpl_frame_get_filename(frame));
167  } else {
168  sinfo_msg_error("Frame %s not found! Exit!", PRO_WAVE_LAMP_STACKED);
169  sinfo_distpar_delete(d);
170  sinfo_wcal_delete(w);
171  (*status)++;
172  return;
173  }
174 
175  strcpy(cfg -> outName, DISTORTION_OUT_FILENAME);
176 
177 
178  if(NULL != cpl_frameset_find(sof,REF_LINE_ARC)) {
179  frame = cpl_frameset_find(sof,REF_LINE_ARC);
180  strcpy(cfg -> lineList,cpl_frame_get_filename(frame));
181  } else {
182  sinfo_msg_error("Frame %s not found! Exit!", REF_LINE_ARC);
183  sinfo_distpar_delete(d);
184  sinfo_wcal_delete(w);
185  (*status)++;
186  return;
187  }
188 
189  if(NULL != cpl_frameset_find(sof,PRO_FIBRE_NS_STACKED)) {
190  frame = cpl_frameset_find(sof,PRO_FIBRE_NS_STACKED);
191  strcpy(cfg -> nsFrame,cpl_frame_get_filename(frame));
192  } else {
193  sinfo_msg_error("Frame %s not found! Exit!", PRO_FIBRE_NS_STACKED);
194  sinfo_distpar_delete(d);
195  sinfo_wcal_delete(w);
196  (*status)++;
197  return;
198  }
199 
200 
201  if(NULL != cpl_frameset_find(sof,PRO_BP_MAP_DI)) {
202  frame = cpl_frameset_find(sof,PRO_BP_MAP_DI);
203  strcpy(cfg -> mask,cpl_frame_get_filename(frame));
204  } else {
205  sinfo_msg_error("Frame %s not found! Exit!", PRO_BP_MAP_DI);
206  sinfo_distpar_delete(d);
207  sinfo_wcal_delete(w);
208  (*status)++;
209  return;
210  }
211 
212 
213 
214  frame = cpl_frameset_get_frame(*raw,0);
215  sinfo_get_spatial_res(frame,spat_res);
216 
217  switch(sinfo_frame_is_on(frame))
218  {
219  case 0:
220  strcpy(lamp_status,"on");
221  break;
222  case 1:
223  strcpy(lamp_status,"off");
224  break;
225  case -1:
226  strcpy(lamp_status,"undefined");
227  break;
228  default:
229  strcpy(lamp_status,"undefined");
230  break;
231  }
232 
233  sinfo_get_band(frame,band);
234  sinfo_msg("Spatial resolution: %s lamp_status: %s band: %s \n",
235  spat_res, lamp_status, band);
236 
237 
238  sinfo_get_ins_set(band,&ins_set);
239  if(NULL != cpl_frameset_find(sof,DRS_SETUP_WAVE)) {
240  frame = cpl_frameset_find(sof,DRS_SETUP_WAVE);
241  strcpy(cfg -> drs_setup,cpl_frame_get_filename(frame));
242  cpl_table* drs_tab = cpl_table_load(cfg->drs_setup,1,0);
243  w->wstart=cpl_table_get_double(drs_tab,"W_START",ins_set,&check);
244  w->wgdisp1=cpl_table_get_double(drs_tab,"W_DISP1",ins_set,&check);
245  w->wgdisp2=cpl_table_get_double(drs_tab,"W_DISP2",ins_set,&check);
246  w->hw=cpl_table_get_int(drs_tab,"W_HW",ins_set,&check);
247  w->fwhm=cpl_table_get_double(drs_tab,"W_FWHM",ins_set,&check);
248  w->min_amp=cpl_table_get_double(drs_tab,"W_MIN_AMP",ins_set,&check);
249  /*
250  w->min_dif=cpl_table_get_double(drs_tab,"W_MIN_DIF",ins_set,&check);
251  w->na_coef=cpl_table_get_int(drs_tab,"W_NA_COEFF",ins_set,&check);
252  w->nb_coef=cpl_table_get_int(drs_tab,"W_NB_COEFF",ins_set,&check);
253  w->pixel_tol=cpl_table_get_double(drs_tab,"W_PIX_TOL",ins_set,&check);
254  w->y_box=cpl_table_get_double(drs_tab,"W_Y_BOX",ins_set,&check);
255  */
256  w->low_pos=cpl_table_get_int(drs_tab,"W_LOW_POS",ins_set,&check);
257  w->hig_pos=cpl_table_get_int(drs_tab,"W_HI_POS",ins_set,&check);
258 
259  cfg -> guessBeginWavelength = w->wstart;
260  cfg -> guessDispersion1 = w->wgdisp1;
261  cfg -> guessDispersion2 = w->wgdisp2;
262  cfg -> halfWidth = w->hw;
263  cfg -> fwhm = w->fwhm;
264  cfg -> minAmplitude = w->min_amp;
265  /*
266  cfg -> mindiff = w->min_dif;
267  cfg -> nrDispCoefficients = w->na_coef;
268  cfg -> nrCoefCoefficients = w->nb_coef;
269  cfg -> pixel_tolerance = w->pixel_tol;
270  cfg -> yBox = w->y_box;
271  */
272  cfg -> loPos = DISTORTION_LOPOS;
273  cfg -> hiPos = DISTORTION_HIPOS;
274  cfg -> pixel_tolerance = w->pixel_tol;
275  cfg-> diffTol = d->diff_tol[ins_set];
276  /*
277  sinfo_msg("cfg->guessBeginWavelength %g",cfg -> guessBeginWavelength);
278  sinfo_msg("cfg->guessDispersion1 %g",cfg -> guessDispersion1);
279  sinfo_msg("cfg->guessDispersion2 %g",cfg -> guessDispersion2);
280  sinfo_msg("cfg->mindiff %g",cfg -> mindiff);
281  sinfo_msg("cfg->halfWidth %d",cfg -> halfWidth);
282  sinfo_msg("cfg->fwhm %g",cfg -> fwhm);
283  sinfo_msg("cfg->minAmplitude %g",cfg -> minAmplitude);
284  sinfo_msg("cfg->nrDispCoefficients %d",cfg -> nrDispCoefficients);
285  sinfo_msg("cfg->nrCoefCoefficients %d",cfg -> nrCoefCoefficients);
286  sinfo_msg("cfg->pixel_tolerance %g",cfg -> pixel_tolerance);
287  sinfo_msg("cfg->loPos %d",cfg -> loPos);
288  sinfo_msg("cfg->hiPos %d",cfg -> hiPos);
289  sinfo_msg("cfg->yBox %f",cfg -> yBox);
290  */
291  sinfo_distpar_delete(d);
292  sinfo_wcal_delete(w);
293  cpl_table_delete(drs_tab);
294  if(-1 == sinfo_check_rec_status(0)) {
295  (*status)++;
296  return;
297  }
298 
299  } else {
300  sinfo_msg_error("Frame %s not found! Exit!", DRS_SETUP_WAVE);
301  sinfo_distpar_delete(d);
302  sinfo_wcal_delete(w);
303  (*status)++;
304  return;
305  }
306 
307 
308  nstp=sinfo_nstpar_new();
309  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.ns_fwhm");
310  if(cpl_parameter_get_default_flag(p) == 0) {
311  cfg->nsfwhm=nstp->fwhm[ins_set];
312  } else {
313  cfg->nsfwhm=cpl_parameter_get_double(p);
314  }
315 
316  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.min_diff");
317  if(cpl_parameter_get_default_flag(p) == 0) {
318  cfg->minDiff=nstp->min_dif[ins_set];
319  } else {
320  cfg->minDiff=cpl_parameter_get_double(p);
321  }
322  sinfo_nstpar_delete(nstp);
323  //sinfo_msg("cfg -> nsfwhm %f",cfg -> nsfwhm);
324  //sinfo_msg("cfg -> minDiff %f",cfg -> minDiff);
325 
326 
327  return;
328 
329 }
330 
331 
340 static void
341 parse_section_findlines(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
342 {
343 
344  cpl_parameter* p;
345 
346  p = cpl_parameterlist_find(cpl_cfg,
347  "sinfoni.distortion.min_diff_mean_med_col_int");
348  cfg -> mindiff = cpl_parameter_get_double(p);
349 
350  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.half_width");
351  cfg -> halfWidth = cpl_parameter_get_int(p);
352 
353  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.sigma");
354  cfg -> sigma = cpl_parameter_get_double(p);
355 
356  return ;
357 
358 }
359 
367 static void
368 parse_section_wavecalib(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
369 {
370 
371 
372  cpl_parameter* p;
373 
374  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.fwhm");
375  cfg -> fwhm = cpl_parameter_get_double(p);
376 
377  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.min_amplitude");
378  cfg -> minAmplitude = cpl_parameter_get_double(p);
379 
380  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.max_residual");
381  cfg -> maxResidual = cpl_parameter_get_double(p);
382 
383  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.n_a_coefficients");
384  cfg -> nrDispCoefficients = cpl_parameter_get_int(p);
385 
386  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.n_b_coefficients");
387  cfg -> nrCoefCoefficients = cpl_parameter_get_int(p);
388 
389  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.sigma_factor");
390  cfg -> sigmaFactor = cpl_parameter_get_double(p);
391 
392 
393  cfg -> nslitlets = NSLITLETS;
394 
395  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.pixel_dist");
396  cfg -> pixeldist = cpl_parameter_get_int(p);
397 
398  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.pixel_tol");
399  cfg -> pixel_tolerance = cpl_parameter_get_double(p);
400 
401 
402 
403 }
404 
412 static void
413 parse_section_wavemap(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
414 {
415  cpl_parameter* p;
416 
417  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.mag_factor");
418  cfg -> magFactor = cpl_parameter_get_int(p);
419 
420 }
421 
429 static void
430 parse_section_fitslits(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
431 {
432 
433  cpl_parameter* p;
434 
435  cfg -> loPos = DISTORTION_LOPOS;
436  cfg -> hiPos = DISTORTION_HIPOS;
437 
438  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.box_length");
439  cfg -> boxLength = cpl_parameter_get_int(p);
440 
441  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.y_box");
442  cfg -> yBox = cpl_parameter_get_double(p);
443 
444  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.diff_tol");
445  cfg -> diffTol = cpl_parameter_get_double(p);
446 
447 }
448 
456 static void
457 parse_section_qclog (finddist_config * cfg, cpl_parameterlist* cpl_cfg)
458 {
459  cpl_parameter* p;
460 
461  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.qc_thresh_min");
462  cfg -> qc_thresh_min = cpl_parameter_get_int(p);
463 
464 
465  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.qc_thresh_max");
466  cfg -> qc_thresh_max = cpl_parameter_get_int(p);
467 
468 
469 }
470 
471 
479 static void
480 parse_section_northsouthtest(finddist_config * cfg,cpl_parameterlist * cpl_cfg)
481 {
482 
483  cpl_parameter *p;
484  strcat(cfg -> fitsname, DISTORTION_NS_OUT_FILENAME);
485 
486  cfg -> nslits = NSLITLETS;
487 
488  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.ns_half_width");
489  cfg -> nshalfWidth = cpl_parameter_get_int(p);
490 
491  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.ns_fwhm");
492  cfg -> nsfwhm = cpl_parameter_get_double(p);
493 
494  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.min_diff");
495  cfg -> minDiff = cpl_parameter_get_double(p);
496 
497  cfg -> estimated_dist = ESTIMATED_SLITLETS_DISTANCE;
498 
499  p = cpl_parameterlist_find(cpl_cfg, "sinfoni.distortion.dev_tol");
500  cfg -> devtol = cpl_parameter_get_double(p);
501 
502  return ;
503 
504 }
505 
513 void
514 sinfo_finddist_free(finddist_config ** cfg)
515 {
516 
517  if(*cfg!=NULL) {
518  sinfo_finddist_cfg_destroy(*cfg);
519  *cfg=NULL;
520  }
521  return;
522 
523 }
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69