SINFONI Pipeline Reference Manual  2.6.0
sinfo_flat_ini.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 : flat_ini.c
22  Author : Juergen Schreiber
23  Created on : Mar 04, 2002
24  Description : prepare flatfield frames ini file handling for SPIFFI
25  ---------------------------------------------------------------------------*/
26 #ifdef HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29 /*---------------------------------------------------------------------------
30  Includes
31  ---------------------------------------------------------------------------*/
32 #include "sinfo_flat_ini.h"
33 /*---------------------------------------------------------------------------
34  Functions private to this module
35  ---------------------------------------------------------------------------*/
36 static void parse_section_general(dictionary *, flat_config *, int *);
37 static void parse_section_frames(dictionary *, flat_config *, int *);
38 static void parse_section_cleanmean(dictionary *, flat_config *, int *);
39 static void parse_section_badpixel(dictionary *, flat_config *, int *);
40 static void parse_section_badpix(dictionary *, flat_config *, int *);
41 static void parse_section_thresh(dictionary *, flat_config *, int *);
60 flat_config *
61 parse_flat_ini_file(char * ini_name)
62 {
63  dictionary * sym ;
64  flat_config * cfg ;
65  int status ;
66 
67  if (!sinfo_file_exists(ini_name)) {
68  sinfo_msg_error("cannot find ini file [%s]: aborting", ini_name) ;
69  return NULL ;
70  }
71  sym = iniparser_load(ini_name) ;
72  if (sym == NULL) {
73  sinfo_msg_error("in parsing ini file [%s]: aborting", ini_name) ;
74  return NULL ;
75  }
76 
77  cfg = sinfo_flat_cfg_create();
78  if (cfg==NULL) {
79  sinfo_msg_error("allocating flat_config struct");
80  iniparser_freedict(sym) ;
81  return NULL ;
82  }
83 
84  /*
85  * Perform sanity checks, fill up the structure with what was
86  * found in the ini file
87  */
88 
89  status = 0 ;
90  parse_section_general (sym, cfg, &status);
91  parse_section_frames (sym, cfg, &status);
92  parse_section_cleanmean (sym, cfg, &status);
93  parse_section_badpixel (sym, cfg, &status);
94  parse_section_badpix (sym, cfg, &status);
95  parse_section_thresh (sym, cfg, &status);
96 
97  iniparser_freedict(sym);
98 
99  if (status>0) {
100  sinfo_msg_error("%d errors in ini file [%s]", status, ini_name);
101  sinfo_flat_cfg_destroy(cfg);
102  cfg = NULL ;
103  return NULL ;
104  }
105  return cfg ;
106 }
107 
108 
109 /*---------------------------------------------------------------------------
110  Functions: parse_section_xxx()
111  In : symbolic table read from ini file
112  Out : void
113  Job : update a flat_config structure from what can be
114  found in the ini file.
115  Notice : all of these functions update a status integer to
116  indicate if an error occurred, or leave it as it is if
117  everything went Ok.
118 
119  parse_section_general()
120  parse_section_frames ()
121  parse_section_cleanmean ()
122  parse_section_badpixel ()
123  parse_section_badpix ()
124  parse_section_thresh ()
125 
126  ---------------------------------------------------------------------------*/
127 
128 
129 static void parse_section_general(
130  dictionary * sym,
131  flat_config * cfg,
132  int *status
133 )
134 {
135  char * cval ;
136  int ival ;
137 
138  /*
139  * General section
140  */
141  cval = iniparser_getstr(sym, "eclipse:versionnumber") ;
142  if (cval!=NULL) {
143  if (strcmp(cval, get_eclipse_version())) {
144  sinfo_msg_warning("this ini file produced by version %s", cval);
145  sinfo_msg_warning("you are running version %s",
146  get_eclipse_version());
147  }
148  } else {
149  sinfo_msg_warning("no eclipse version number found in file");
150  }
151 
152  ival = iniparser_getint(sym, "general:maximummemory", -1);
153  if (ival>0) sinfo_set_memory_parameter("max_ram", ival);
154  ival = iniparser_getint(sym, "general:maximumswap", -1);
155  if (ival>0) sinfo_set_memory_parameter("max_swap", ival);
156  sinfo_set_verbose(iniparser_getboolean(sym, "general:verbose", 0));
157  sinfo_set_debug(iniparser_getboolean(sym, "general:debug", 0));
158 
159  cval = iniparser_getstr(sym, "general:tmpdirname");
160  if (cval!=NULL) {
161  sinfo_set_tmpdirname(cval);
162  } else {
163  sinfo_set_tmpdirname(".");
164  }
165 
166  ival = iniparser_getboolean(sym, "general:logfile", 0);
167  if (ival) {
168  cval = iniparser_getstr(sym, "general:logfilename");
169  if (cval!=NULL) {
170  sinfo_set_logfile(1);
171  sinfo_set_logfilename(cval);
172  } else {
173  sinfo_set_logfile(0) ;
174  }
175  }
176  cval = iniparser_getstr(sym, "general:outname");
177  if (cval!=NULL) {
178  strcpy (cfg -> outName , cval ) ;
179  } else {
180  sinfo_msg_error(" OutName in the .ini file was not found!\n") ;
181  (*status)++ ;
182  }
183 
184  if (sinfo_verbose_active())
185  sinfo_print_memory_parameters();
186  return ;
187 }
188 
189 static void parse_section_frames(
190  dictionary * sym,
191  flat_config * cfg,
192  int *status
193 )
194 {
195  char * listname ;
196  charmatrix * charm ;
197  int i, j ;
198  char * name,
199  * type ;
200  int nval, nobj, noff ;
201  int nditherobj, nditheroff ;
202  int found_sky ;
203  int found_dither ;
204  char ** framelist ;
205  int * frametypes ;
206  int * frameposition ;
207 
208  listname = iniparser_getstr(sym, "general:infile");
209  if (sinfo_is_ascii_list(listname)!=1) {
210  sinfo_msg_error("file [%s] is not an ASCII list: aborting",listname);
211  (*status)++ ;
212  return ;
213  }
214 
215  /* Read input char sinfo_matrix */
216  charm = sinfo_charmatrix_read(listname);
217  if (charm==NULL) {
218  sinfo_msg_error("parsing input list [%s]", listname);
219  (*status)++;
220  return ;
221  }
222 
223  /* Check input sinfo_matrix */
224  nval = charm->ly ;
225  for (j=0 ; j<charm->ly ; j++) {
226  /* Check file existence */
227  name = charmatrix_elem(charm, 0, j);
228  if (sinfo_file_exists(name)!=1) {
229  sinfo_msg_warning("file [%s] declared in list does not exist",
230  name);
231  nval -- ;
232  }
233  }
234  if (nval<1) {
235  sinfo_msg_error("no valid plane found in list [%s]", listname);
236  sinfo_charmatrix_del(charm);
237  (*status)++ ;
238  return ;
239  }
240 
241  /* Allocate structures to go into the blackboard */
242  framelist = cpl_malloc(nval * sizeof(char*));
243  frametypes = cpl_malloc(nval * sizeof(int));
244  frameposition = cpl_malloc(nval * sizeof(int));
245 
246  found_sky = 0 ;
247  found_dither = 0 ;
248  nobj = 0 ;
249  noff = 0 ;
250  nditheroff = 0 ;
251  nditherobj = 0 ;
252 
253  /* Browse through the charmatrix to get names and file types */
254  i = 0 ;
255  for (j=0 ; j<charm->ly ; j++)
256  {
257  name = charmatrix_elem(charm, 0, j);
258  if (sinfo_file_exists(name)==1)
259  {
260  /* Store file name into framelist */
261  framelist[i] = cpl_strdup(name);
262  /* Check if a file type is present */
263  if (charm->lx>1)
264  {
265  /* Get file type */
266  type = charmatrix_elem(charm, 1, j);
267  strlwc(type);
268  /* Checking if the type contains 'off' or 'sky' */
269  if (strstr(type, "sky")!=NULL || strstr(type, "off") != NULL)
270  {
271  frametypes[i] = FRAME_OFF ;
272  found_sky = 1 ;
273  /* Checking if the type contains 'pos1' or 'pos2' */
274  if (strstr(type, "2")!=NULL)
275  {
276  frameposition[i] = FRAME_POS2 ;
277  found_dither = 1 ;
278  nditheroff++ ;
279  }
280  else
281  {
282  frameposition[i] = FRAME_POS1 ;
283  noff++ ;
284  }
285 
286  }
287  else
288  {
289  frametypes[i] = FRAME_ON ;
290  /* Checking if the type contains 'pos1' or 'pos2' */
291  if (strstr(type, "2")!=NULL)
292  {
293  frameposition[i] = FRAME_POS2 ;
294  found_dither = 1 ;
295  nditherobj++ ;
296  }
297  else
298  {
299  frameposition[i] = FRAME_POS1 ;
300  nobj++ ;
301  }
302  }
303  }
304  else
305  {
306  /* No type means an object */
307  frametypes[i] = FRAME_ON ;
308  /* No type means position 1 */
309  frameposition[i] = FRAME_POS1 ;
310  nobj ++ ;
311  }
312  i++ ;
313  }
314  }
315  sinfo_charmatrix_del(charm);
316 
317  /* Copy relevant information into the blackboard */
318  cfg->framelist = framelist ;
319  cfg->frametype = frametypes ;
320  cfg->frameposition = frameposition ;
321  cfg->nframes = nval ;
322  cfg->nobj = nobj ;
323  cfg->noff = noff ;
324  cfg->nditherobj = nditherobj ;
325  cfg->nditheroff = nditheroff ;
326  cfg->contains_sky = found_sky ;
327  cfg->contains_dither = found_dither ;
328 
329  return ;
330 }
331 
332 static void parse_section_cleanmean(
333  dictionary * sym,
334  flat_config * cfg,
335  int *status )
336 {
337  float dval ;
338 
339  dval = iniparser_getdouble(sym, "cleanmean:loreject", -1.) ;
340  if (dval!=-1.)
341  {
342  cfg -> loReject = dval ;
343  }
344  else
345  {
346  sinfo_msg_error(" LoReject in the .ini file was not found!\n") ;
347  (*status)++ ;
348  }
349  dval = iniparser_getdouble(sym, "cleanmean:hireject", -1.) ;
350  if (dval!=-1.)
351  {
352  cfg -> hiReject = dval ;
353  }
354  else
355  {
356  sinfo_msg_error(" hiReject in the .ini file was not found!\n") ;
357  (*status)++ ;
358  }
359  return ;
360 }
361 
362 static void parse_section_badpixel(
363  dictionary * sym,
364  flat_config * cfg,
365  int *status )
366 {
367  int ival ;
368  char * cval ;
369 
370  ival = iniparser_getboolean(sym, "badpixel:interpolind", -1) ;
371  if (ival != -1)
372  {
373  cfg -> interpolInd = ival ;
374  }
375  else
376  {
377  sinfo_msg_error(" interpolInd in the .ini file was not found!\n") ;
378  (*status)++ ;
379  }
380  cval = iniparser_getstr(sym, "badpixel:mask") ;
381  if (cval != NULL)
382  {
383  strcpy (cfg -> mask , cval) ;
384  }
385  else
386  {
387  sinfo_msg_error(" mask in the .ini file was not found!\n") ;
388  (*status)++ ;
389  }
390  ival = iniparser_getint(sym, "badpixel:maxrad", -1) ;
391  if (ival!=-1)
392  {
393  cfg -> maxRad = ival ;
394  }
395  else
396  {
397  sinfo_msg_error(" MaxRad in the .ini file was not found!\n") ;
398  (*status)++ ;
399  }
400  cval = iniparser_getstr(sym, "badpixel:slitposlist") ;
401  if (cval != NULL)
402  {
403  strcpy (cfg -> slitposList , cval) ;
404  }
405  else
406  {
407  sinfo_msg_error(" SlitposList in the .ini file was not found!\n") ;
408  (*status)++ ;
409  }
410 }
411 
412 static void parse_section_badpix(
413  dictionary * sym,
414  flat_config * cfg,
415  int *status )
416 {
417  int ival ;
418  float dval ;
419  char * cval ;
420 
421  ival = iniparser_getboolean(sym, "badpix:badind", -1) ;
422  if (ival != -1)
423  {
424  cfg -> badInd = ival ;
425  }
426  else
427  {
428  sinfo_msg_error(" badInd in the .ini file was not found!\n") ;
429  (*status)++ ;
430  }
431  cval = iniparser_getstr(sym, "badpix:maskname") ;
432  if (cval != NULL)
433  {
434  strcpy (cfg -> maskname , cval) ;
435  }
436  else
437  {
438  sinfo_msg_error(" mask in the .ini file was not found!\n") ;
439  (*status)++ ;
440  }
441  dval = iniparser_getdouble(sym, "badpix:sigmafactor", -1.) ;
442  if (dval!=-1.)
443  {
444  cfg -> sigmaFactor = dval ;
445  }
446  else
447  {
448  sinfo_msg_error(" sigmaFactor in the .ini file was not found!\n") ;
449  (*status)++ ;
450  }
451  dval = iniparser_getdouble(sym, "badpix:factor", -1.) ;
452  if (dval!=-1.)
453  {
454  cfg -> factor = dval ;
455  }
456  else
457  {
458  sinfo_msg_error(" factor in the .ini file was not found!\n") ;
459  (*status)++ ;
460  }
461  ival = iniparser_getint(sym, "badpix:iterations", -1) ;
462  if (ival!=-1)
463  {
464  cfg -> iterations = ival ;
465  }
466  else
467  {
468  sinfo_msg_error(" iterations in the .ini file was not found!\n") ;
469  (*status)++ ;
470  }
471  dval = iniparser_getdouble(sym, "badpix:badloreject", -1.) ;
472  if (dval!=-1.)
473  {
474  cfg -> badLoReject = dval ;
475  }
476  else
477  {
478  sinfo_msg_error(" badLoReject in the .ini file was not found!\n") ;
479  (*status)++ ;
480  }
481  dval = iniparser_getdouble(sym, "badpix:badhireject", -1.) ;
482  if (dval!=-1.)
483  {
484  cfg -> badHiReject = dval ;
485  }
486  else
487  {
488  sinfo_msg_error(" badHiReject in the .ini file was not found!\n") ;
489  (*status)++ ;
490  }
491  ival = iniparser_getint(sym, "badpix:llx", -1) ;
492  if (ival!=-1)
493  {
494  cfg -> llx = ival ;
495  }
496  else
497  {
498  sinfo_msg_error(" factor in the .ini file was not found!\n") ;
499  (*status)++ ;
500  }
501  ival = iniparser_getint(sym, "badpix:lly", -1) ;
502  if (ival!=-1)
503  {
504  cfg -> lly = ival ;
505  }
506  else
507  {
508  sinfo_msg_error(" factor in the .ini file was not found!\n") ;
509  (*status)++ ;
510  }
511  ival = iniparser_getint(sym, "badpix:urx", -1) ;
512  if (ival!=-1)
513  {
514  cfg -> urx = ival ;
515  }
516  else
517  {
518  sinfo_msg_error(" factor in the .ini file was not found!\n") ;
519  (*status)++ ;
520  }
521  ival = iniparser_getint(sym, "badpix:ury", -1) ;
522  if (ival!=-1)
523  {
524  cfg -> ury = ival ;
525  }
526  else
527  {
528  sinfo_msg_error(" factor in the .ini file was not found!\n") ;
529  (*status)++ ;
530  }
531  return ;
532 }
533 
534 static void parse_section_thresh(
535  dictionary * sym,
536  flat_config * cfg,
537  int *status )
538 {
539  int ival ;
540  float dval ;
541 
542  ival = iniparser_getboolean(sym, "thresh:threshind", -1) ;
543  if (ival != -1)
544  {
545  cfg -> threshInd = ival ;
546  }
547  else
548  {
549  sinfo_msg_error(" ThreshInd in the .ini file was not found!\n") ;
550  (*status)++ ;
551  }
552  dval = iniparser_getdouble(sym, "thresh:meanfactor", -1.) ;
553  if (dval!=-1.)
554  {
555  cfg -> meanfactor = dval ;
556  }
557  else
558  {
559  sinfo_msg_error(" mean factor in the .ini file was not found!\n") ;
560  (*status)++ ;
561  }
562 }
563 
564 
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69
#define sinfo_msg_warning(...)
Print an warning message.
Definition: sinfo_msg.h:93