UVES Pipeline Reference Manual  5.4.0
uves_dump.c
1 /* *
2  * This file is part of the X-SHOOTER Pipeline *
3  * Copyright (C) 2002,2003 European Southern Observatory *
4  * *
5  * This library 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  * $Author: amodigli $
22  * $Date: 2011-12-08 13:59:20 $
23  * $Revision: 1.23 $
24  * $Name: not supported by cvs2svn $
25  * $Log: not supported by cvs2svn $
26  * Revision 1.22 2010/09/24 09:32:03 amodigli
27  * put back QFITS dependency to fix problem spot by NRI on FIBER mode (with MIDAS calibs) data
28  *
29  * Revision 1.20 2007/08/21 13:08:26 jmlarsen
30  * Removed irplib_access module, largely deprecated by CPL-4
31  *
32  * Revision 1.19 2007/06/06 08:17:33 amodigli
33  * replace tab with 4 spaces
34  *
35  * Revision 1.18 2007/04/24 12:50:29 jmlarsen
36  * Replaced cpl_propertylist -> uves_propertylist which is much faster
37  *
38  * Revision 1.17 2007/04/24 09:26:11 jmlarsen
39  * Do not crash on NULL strings
40  *
41  * Revision 1.16 2006/11/24 09:36:07 jmlarsen
42  * Removed obsolete comment
43  *
44  * Revision 1.15 2006/11/16 14:12:21 jmlarsen
45  * Changed undefined trace number from 0 to -1, to support zero as an actual trace number
46  *
47  * Revision 1.14 2006/11/15 15:02:14 jmlarsen
48  * Implemented const safe workarounds for CPL functions
49  *
50  * Revision 1.12 2006/11/15 14:04:08 jmlarsen
51  * Removed non-const version of parameterlist_get_first/last/next which is already
52  * in CPL, added const-safe wrapper, unwrapper and deallocator functions
53  *
54  * Revision 1.11 2006/11/13 14:23:55 jmlarsen
55  * Removed workarounds for CPL const bugs
56  *
57  * Revision 1.10 2006/11/06 15:19:41 jmlarsen
58  * Removed unused include directives
59  *
60  * Revision 1.9 2006/08/17 13:56:52 jmlarsen
61  * Reduced max line length
62  *
63  * Revision 1.8 2006/08/16 11:46:30 jmlarsen
64  * Support printing NULL frame filename
65  *
66  * Revision 1.7 2006/05/12 15:02:05 jmlarsen
67  * Support NULL tags
68  *
69  * Revision 1.6 2006/02/28 09:15:22 jmlarsen
70  * Minor update
71  *
72  * Revision 1.5 2006/02/15 13:19:15 jmlarsen
73  * Reduced source code max. line length
74  *
75  * Revision 1.4 2005/12/19 16:17:56 jmlarsen
76  * Replaced bool -> int
77  *
78  */
79 
80 #ifdef HAVE_CONFIG_H
81 # include <config.h>
82 #endif
83 
84 #include <uves_cpl_size.h>
85 /*----------------------------------------------------------------------------*/
92 /*----------------------------------------------------------------------------*/
93 
96 #include <uves_dump.h>
97 
98 #include <uves_msg.h>
99 #include <uves_error.h>
100 
101 #include <cpl.h>
102 
103 /*----------------------------------------------------------------*/
115 /*----------------------------------------------------------------*/
116 cpl_error_code
117 uves_print_uves_propertylist(const uves_propertylist *pl, long low, long high)
118 {
119  const cpl_property *prop;
120  long i = 0;
121 
122  assure (0 <= low && high <= uves_propertylist_get_size(pl) && low <= high,
123  CPL_ERROR_ILLEGAL_INPUT, "Illegal range");
124  /* Printing an empty range is allowed but only when low == high */
125 
126  if (pl == NULL){
127  uves_msg("NULL");
128  }
129  else if (uves_propertylist_is_empty(pl)) {
130  uves_msg("[Empty property list]");
131  }
132  else
133  for (i = low; i < high; i++)
134  {
135  prop = uves_propertylist_get_const(pl, i);
136  check (uves_print_cpl_property(prop), "Error printing property");
137  }
138 
139  cleanup:
140  return cpl_error_get_code();
141 }
142 /*----------------------------------------------------------------*/
150 /*----------------------------------------------------------------*/
151 
152 cpl_error_code
153 uves_print_cpl_property(const cpl_property *prop)
154 {
155  cpl_type t;
156 
157  if (prop == NULL)
158  {
159  uves_msg("NULL");
160  }
161  else
162  {
163  /* print property with this formatting
164  NAME =
165  VALUE
166  COMMENT
167  */
168 
169  /* print name */
170 
171  uves_msg("%s =", cpl_property_get_name(prop) != NULL ?
172  cpl_property_get_name(prop) : "NULL");
173 
174  /* print value */
175 
176  check( t = cpl_property_get_type(prop), "Could not read property type");
177 
178  switch(t & (~CPL_TYPE_FLAG_ARRAY))
179  {
180  case CPL_TYPE_CHAR:
181  if (t & CPL_TYPE_FLAG_ARRAY) /* if type is string */
182  {
183  uves_msg(" '%s'", cpl_property_get_string(prop) != NULL ?
184  cpl_property_get_string(prop) : "NULL");
185  }
186  else /* an ordinary char */
187  {
188  uves_msg(" %c", cpl_property_get_char(prop));
189  }
190  break;
191  case CPL_TYPE_BOOL: if (cpl_property_get_bool(prop))
192  {uves_msg(" true");}
193  else
194  {uves_msg(" false");}
195  break;
196  case CPL_TYPE_UCHAR: uves_msg(" %c", cpl_property_get_char(prop)); break;
197  case CPL_TYPE_INT: uves_msg(" %d", cpl_property_get_int(prop)); break;
198  case CPL_TYPE_UINT: uves_msg(" %d", cpl_property_get_int(prop)); break;
199  case CPL_TYPE_LONG: uves_msg(" %ld", cpl_property_get_long(prop)); break;
200  case CPL_TYPE_ULONG: uves_msg(" %ld", cpl_property_get_long(prop)); break;
201  case CPL_TYPE_FLOAT: uves_msg(" %f", cpl_property_get_float(prop)); break;
202  case CPL_TYPE_DOUBLE: uves_msg(" %f", cpl_property_get_double(prop));break;
203  case CPL_TYPE_POINTER: uves_msg(" POINTER"); break;
204  case CPL_TYPE_INVALID: uves_msg(" INVALID"); break;
205  default: uves_msg(" unrecognized property"); break;
206  }
207 
208  /* Is this property an array? */
209  if (t & CPL_TYPE_FLAG_ARRAY){
210  cpl_msg_info(cpl_func," (array size = %" CPL_SIZE_FORMAT " )",
211  cpl_property_get_size(prop));
212  }
213 
214  /* Print comment */
215  if (cpl_property_get_comment(prop) != NULL){
216  uves_msg(" %s", cpl_property_get_comment(prop) != NULL ?
217  cpl_property_get_comment(prop) : "NULL");
218  }
219  }
220 
221  cleanup:
222  return cpl_error_get_code();
223 }
224 
225 /*----------------------------------------------------------------*/
233 /*----------------------------------------------------------------*/
234 cpl_error_code
235 uves_print_cpl_frameset(const cpl_frameset *frames)
236 {
237  /* Two special cases: a NULL frame set and an empty frame set */
238 
239  if (frames == NULL)
240  {
241  uves_msg("NULL");
242  }
243  else
244  {
245  const cpl_frame *f = NULL;
246  check( f = cpl_frameset_get_first_const(frames), "Error reading frameset");
247 
248  if (f == NULL)
249  {
250  uves_msg("[Empty frame set]");
251  }
252  else
253  {
254  while(f != NULL)
255  {
256  check( uves_print_cpl_frame(f), "Could not print frame");
257  check( f = cpl_frameset_get_next_const(frames),
258  "Error reading frameset");
259  }
260  }
261  }
262 
263  cleanup:
264  return cpl_error_get_code();
265 }
266 
267 /*----------------------------------------------------------------*/
275 /*----------------------------------------------------------------*/
276 cpl_error_code
277 uves_print_cpl_frame(const cpl_frame *f)
278 {
279  if (f == NULL)
280  {
281  uves_msg("NULL");
282  }
283  else
284  {
285  const char *filename = cpl_frame_get_filename(f);
286 
287  if (filename == NULL)
288  {
289  cpl_error_reset();
290  filename = "Null";
291  }
292 
293  uves_msg("%-7s %-20s '%s'",
294  uves_tostring_cpl_frame_group(cpl_frame_get_group(f)),
295  cpl_frame_get_tag(f) != NULL ? cpl_frame_get_tag(f) : "Null",
296  filename);
297 
298  uves_msg_debug("type \t= %s", uves_tostring_cpl_frame_type (cpl_frame_get_type (f)));
299  uves_msg_debug("group \t= %s", uves_tostring_cpl_frame_group(cpl_frame_get_group(f)));
300  uves_msg_debug("level \t= %s", uves_tostring_cpl_frame_level(cpl_frame_get_level(f)));
301  }
302 
303  return cpl_error_get_code();
304 }
305 
306 /*----------------------------------------------------------------*/
312 /*----------------------------------------------------------------*/
313 const char *
315 {
316  switch(ft)
317  {
318  case CPL_FRAME_TYPE_NONE: return "NONE"; break;
319  case CPL_FRAME_TYPE_IMAGE: return "IMAGE"; break;
320  case CPL_FRAME_TYPE_MATRIX: return "MATRIX"; break;
321  case CPL_FRAME_TYPE_TABLE: return "TABLE"; break;
322  default: return "unrecognized frame type";
323  }
324 }
325 
326 /*----------------------------------------------------------------*/
332 /*----------------------------------------------------------------*/
333 const char *
334 uves_tostring_cpl_frame_group(cpl_frame_group fg)
335 {
336  switch(fg)
337  {
338  case CPL_FRAME_GROUP_NONE: return "NONE"; break;
339  case CPL_FRAME_GROUP_RAW: return CPL_FRAME_GROUP_RAW_ID; break;
340  case CPL_FRAME_GROUP_CALIB: return CPL_FRAME_GROUP_CALIB_ID; break;
341  case CPL_FRAME_GROUP_PRODUCT: return CPL_FRAME_GROUP_PRODUCT_ID; break;
342  default:
343  return "unrecognized frame group";
344  }
345 }
346 
347 /*----------------------------------------------------------------*/
353 /*----------------------------------------------------------------*/
354 const char *
355 uves_tostring_cpl_frame_level(cpl_frame_level fl)
356 {
357 
358  switch(fl)
359  {
360  case CPL_FRAME_LEVEL_NONE: return "NONE"; break;
361  case CPL_FRAME_LEVEL_TEMPORARY: return "TEMPORARY"; break;
362  case CPL_FRAME_LEVEL_INTERMEDIATE:return "INTERMEDIATE";break;
363  case CPL_FRAME_LEVEL_FINAL: return "FINAL"; break;
364  default: return "unrecognized frame level";
365  }
366 }
367 
368 
369 /*----------------------------------------------------------------*/
375 /*----------------------------------------------------------------*/
376 const char *
378 {
379 
380  /* Note that CPL_TYPE_STRING is shorthand
381  for CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY . */
382 
383  if (!(t & CPL_TYPE_FLAG_ARRAY))
384  switch(t & (~CPL_TYPE_FLAG_ARRAY))
385  {
386  case CPL_TYPE_CHAR: return "char"; break;
387  case CPL_TYPE_UCHAR: return "uchar"; break;
388  case CPL_TYPE_BOOL: return "boolean"; break;
389  case CPL_TYPE_INT: return "int"; break;
390  case CPL_TYPE_UINT: return "uint"; break;
391  case CPL_TYPE_LONG: return "long"; break;
392  case CPL_TYPE_ULONG: return "ulong"; break;
393  case CPL_TYPE_FLOAT: return "float"; break;
394  case CPL_TYPE_DOUBLE: return "double"; break;
395  case CPL_TYPE_POINTER: return "pointer"; break;
396 /* not in CPL3.0: case CPL_TYPE_COMPLEX: return "complex"; break; */
397  case CPL_TYPE_INVALID: return "invalid"; break;
398  default:
399  return "unrecognized type";
400  }
401  else
402  switch(t & (~CPL_TYPE_FLAG_ARRAY))
403  {
404  case CPL_TYPE_CHAR: return "string (char array)"; break;
405  case CPL_TYPE_UCHAR: return "uchar array"; break;
406  case CPL_TYPE_BOOL: return "boolean array"; break;
407  case CPL_TYPE_INT: return "int array"; break;
408  case CPL_TYPE_UINT: return "uint array"; break;
409  case CPL_TYPE_LONG: return "long array"; break;
410  case CPL_TYPE_ULONG: return "ulong array"; break;
411  case CPL_TYPE_FLOAT: return "float array"; break;
412  case CPL_TYPE_DOUBLE: return "double array"; break;
413  case CPL_TYPE_POINTER: return "pointer array"; break;
414 /* not in CPL3.0: case CPL_TYPE_COMPLEX: return "complex array"; break; */
415  case CPL_TYPE_INVALID: return "invalid (array)"; break;
416  default:
417  return "unrecognized type";
418  }
419 }