UVES Pipeline Reference Manual  5.4.6
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  cpl_frameset_iterator* it = cpl_frameset_iterator_new(frames);
246  const cpl_frame *f = cpl_frameset_iterator_get_const(it);
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  cpl_frameset_iterator_advance(it, 1);
258  f = cpl_frameset_iterator_get_const(it);
259  }
260  }
261  cpl_frameset_iterator_delete(it);
262  }
263 
264  cleanup:
265  return cpl_error_get_code();
266 }
267 
268 /*----------------------------------------------------------------*/
276 /*----------------------------------------------------------------*/
277 cpl_error_code
278 uves_print_cpl_frame(const cpl_frame *f)
279 {
280  if (f == NULL)
281  {
282  uves_msg("NULL");
283  }
284  else
285  {
286  const char *filename = cpl_frame_get_filename(f);
287 
288  if (filename == NULL)
289  {
290  cpl_error_reset();
291  filename = "Null";
292  }
293 
294  uves_msg("%-7s %-20s '%s'",
295  uves_tostring_cpl_frame_group(cpl_frame_get_group(f)),
296  cpl_frame_get_tag(f) != NULL ? cpl_frame_get_tag(f) : "Null",
297  filename);
298 
299  uves_msg_debug("type \t= %s", uves_tostring_cpl_frame_type (cpl_frame_get_type (f)));
300  uves_msg_debug("group \t= %s", uves_tostring_cpl_frame_group(cpl_frame_get_group(f)));
301  uves_msg_debug("level \t= %s", uves_tostring_cpl_frame_level(cpl_frame_get_level(f)));
302  }
303 
304  return cpl_error_get_code();
305 }
306 
307 /*----------------------------------------------------------------*/
313 /*----------------------------------------------------------------*/
314 const char *
316 {
317  switch(ft)
318  {
319  case CPL_FRAME_TYPE_NONE: return "NONE"; break;
320  case CPL_FRAME_TYPE_IMAGE: return "IMAGE"; break;
321  case CPL_FRAME_TYPE_MATRIX: return "MATRIX"; break;
322  case CPL_FRAME_TYPE_TABLE: return "TABLE"; break;
323  default: return "unrecognized frame type";
324  }
325 }
326 
327 /*----------------------------------------------------------------*/
333 /*----------------------------------------------------------------*/
334 const char *
335 uves_tostring_cpl_frame_group(cpl_frame_group fg)
336 {
337  switch(fg)
338  {
339  case CPL_FRAME_GROUP_NONE: return "NONE"; break;
340  case CPL_FRAME_GROUP_RAW: return CPL_FRAME_GROUP_RAW_ID; break;
341  case CPL_FRAME_GROUP_CALIB: return CPL_FRAME_GROUP_CALIB_ID; break;
342  case CPL_FRAME_GROUP_PRODUCT: return CPL_FRAME_GROUP_PRODUCT_ID; break;
343  default:
344  return "unrecognized frame group";
345  }
346 }
347 
348 /*----------------------------------------------------------------*/
354 /*----------------------------------------------------------------*/
355 const char *
356 uves_tostring_cpl_frame_level(cpl_frame_level fl)
357 {
358 
359  switch(fl)
360  {
361  case CPL_FRAME_LEVEL_NONE: return "NONE"; break;
362  case CPL_FRAME_LEVEL_TEMPORARY: return "TEMPORARY"; break;
363  case CPL_FRAME_LEVEL_INTERMEDIATE:return "INTERMEDIATE";break;
364  case CPL_FRAME_LEVEL_FINAL: return "FINAL"; break;
365  default: return "unrecognized frame level";
366  }
367 }
368 
369 
370 /*----------------------------------------------------------------*/
376 /*----------------------------------------------------------------*/
377 const char *
379 {
380 
381  /* Note that CPL_TYPE_STRING is shorthand
382  for CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY . */
383 
384  if (!(t & CPL_TYPE_FLAG_ARRAY))
385  switch(t & (~CPL_TYPE_FLAG_ARRAY))
386  {
387  case CPL_TYPE_CHAR: return "char"; break;
388  case CPL_TYPE_UCHAR: return "uchar"; break;
389  case CPL_TYPE_BOOL: return "boolean"; break;
390  case CPL_TYPE_INT: return "int"; break;
391  case CPL_TYPE_UINT: return "uint"; break;
392  case CPL_TYPE_LONG: return "long"; break;
393  case CPL_TYPE_ULONG: return "ulong"; break;
394  case CPL_TYPE_FLOAT: return "float"; break;
395  case CPL_TYPE_DOUBLE: return "double"; break;
396  case CPL_TYPE_POINTER: return "pointer"; break;
397 /* not in CPL3.0: case CPL_TYPE_COMPLEX: return "complex"; break; */
398  case CPL_TYPE_INVALID: return "invalid"; break;
399  default:
400  return "unrecognized type";
401  }
402  else
403  switch(t & (~CPL_TYPE_FLAG_ARRAY))
404  {
405  case CPL_TYPE_CHAR: return "string (char array)"; break;
406  case CPL_TYPE_UCHAR: return "uchar array"; break;
407  case CPL_TYPE_BOOL: return "boolean array"; break;
408  case CPL_TYPE_INT: return "int array"; break;
409  case CPL_TYPE_UINT: return "uint array"; break;
410  case CPL_TYPE_LONG: return "long array"; break;
411  case CPL_TYPE_ULONG: return "ulong array"; break;
412  case CPL_TYPE_FLOAT: return "float array"; break;
413  case CPL_TYPE_DOUBLE: return "double array"; break;
414  case CPL_TYPE_POINTER: return "pointer array"; break;
415 /* not in CPL3.0: case CPL_TYPE_COMPLEX: return "complex array"; break; */
416  case CPL_TYPE_INVALID: return "invalid (array)"; break;
417  default:
418  return "unrecognized type";
419  }
420 }
const cpl_property * uves_propertylist_get_const(const uves_propertylist *self, long position)
Access property list elements by index.
cpl_error_code uves_print_cpl_frame(const cpl_frame *f)
Print a frame.
Definition: uves_dump.c:278
const char * uves_tostring_cpl_frame_level(cpl_frame_level fl)
Convert a frame level to a string.
Definition: uves_dump.c:356
int uves_propertylist_is_empty(const uves_propertylist *self)
Check whether a property list is empty.
const char * uves_tostring_cpl_frame_type(cpl_frame_type ft)
Convert a frame type to a string.
Definition: uves_dump.c:315
cpl_error_code uves_print_cpl_property(const cpl_property *prop)
Print a property.
Definition: uves_dump.c:153
long uves_propertylist_get_size(const uves_propertylist *self)
Get the current size of a property list.
#define uves_msg(...)
Print a message on 'info' or 'debug' level.
Definition: uves_msg.h:119
const char * uves_tostring_cpl_type(cpl_type t)
Convert a CPL type to a string.
Definition: uves_dump.c:378
const char * uves_tostring_cpl_frame_group(cpl_frame_group fg)
Convert a frame group to a string.
Definition: uves_dump.c:335
#define uves_msg_debug(...)
Print a debug message.
Definition: uves_msg.h:97
#define check(CMD,...)
Definition: uves_error.h:198
cpl_error_code uves_print_uves_propertylist(const uves_propertylist *pl, long low, long high)
Print a property list.
Definition: uves_dump.c:117
cpl_error_code uves_print_cpl_frameset(const cpl_frameset *frames)
Print a frame set.
Definition: uves_dump.c:235