SINFONI Pipeline Reference Manual  2.6.0
sinfo_dump.c
1 /* *
2  * This file is part of the SINFONI 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: 2012-09-21 10:55:19 $
23  * $Revision: 1.9 $
24  * $Name: not supported by cvs2svn $
25  */
26 
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30 
33 /*----------------------------------------------------------------------------*/
40 /*----------------------------------------------------------------------------*/
41 
42 #include <sinfo_dump.h>
43 #include <sinfo_utils.h>
44 #include <sinfo_error.h>
45 #include <sinfo_msg.h>
46 #include <cpl.h>
47 
48 /*----------------------------------------------------------------*/
60 /*----------------------------------------------------------------*/
61 cpl_error_code
62 sinfo_print_cpl_propertylist(const cpl_propertylist *pl, long low, long high)
63 {
64  cpl_property *prop;
65  long i = 0;
66 
67  assure(0 <= low && high <= cpl_propertylist_get_size(pl) && low <= high,
68  CPL_ERROR_ILLEGAL_INPUT, "Illegal range");
69  /* Printing an empty range is allowed but only when low == high */
70 
71  if (pl == NULL ) {
72  sinfo_msg("NULL");
73  }
74  else if (cpl_propertylist_is_empty(pl)) {
75  sinfo_msg("[Empty property list]");
76  }
77  else
78  for (i = low; i < high; i++) {
79  /* bug workaround: remove const cast when declaration
80  of cpl_propertylist_get() is changed */
81  prop = cpl_propertylist_get((cpl_propertylist *) pl, i);
82  check(sinfo_print_cpl_property(prop), "Error printing property");
83  }
84 
85  cleanup: return cpl_error_get_code();
86 }
87 /*----------------------------------------------------------------*/
95 /*----------------------------------------------------------------*/
96 
97 cpl_error_code
98 sinfo_print_cpl_property(const cpl_property *prop)
99 {
100  cpl_type t;
101 
102  if (prop == NULL ) {
103  sinfo_msg("NULL");
104  }
105  else {
106  /* print property with this formatting
107  NAME =
108  VALUE
109  COMMENT
110  */
111 
112  /* print name */
113 
114  sinfo_msg("%s =", cpl_property_get_name(prop));
115 
116  /* print value */
117 
118  check(t = cpl_property_get_type(prop), "Could not read property type");
119 
120  switch (t & (~CPL_TYPE_FLAG_ARRAY))
121  {
122  case CPL_TYPE_CHAR:
123  if (t & CPL_TYPE_FLAG_ARRAY) /* if type is string */
124  {
125  sinfo_msg(" '%s'", cpl_property_get_string(prop));
126  }
127  else /* an ordinary char */
128  {
129  sinfo_msg(" %c", cpl_property_get_char(prop));
130  }
131  break;
132  case CPL_TYPE_BOOL:
133  if (cpl_property_get_bool(prop)) {
134  sinfo_msg(" true");
135  }
136  else {
137  sinfo_msg(" false");
138  }
139  break;
140  case CPL_TYPE_UCHAR:
141  sinfo_msg("%c", cpl_property_get_char(prop));
142  break;
143  case CPL_TYPE_INT:
144  sinfo_msg("%d", cpl_property_get_int(prop));
145  break;
146  case CPL_TYPE_UINT:
147  sinfo_msg("%d", cpl_property_get_int(prop));
148  break;
149  case CPL_TYPE_LONG:
150  sinfo_msg("%ld", cpl_property_get_long(prop));
151  break;
152  case CPL_TYPE_ULONG:
153  sinfo_msg("%ld", cpl_property_get_long(prop));
154  break;
155  case CPL_TYPE_FLOAT:
156  sinfo_msg("%f", cpl_property_get_float(prop));
157  break;
158  case CPL_TYPE_DOUBLE:
159  sinfo_msg("%f", cpl_property_get_double(prop));
160  break;
161  case CPL_TYPE_POINTER:
162  sinfo_msg("POINTER");
163  break;
164  case CPL_TYPE_INVALID:
165  sinfo_msg("INVALID");
166  break;
167  default:
168  sinfo_msg(" unrecognized property");
169  break;
170  }
171 
172  /* Is this property an array? */
173  if (t & CPL_TYPE_FLAG_ARRAY) {
174  cpl_msg_info(cpl_func, " (array size = %" CPL_SIZE_FORMAT " )",
175  cpl_property_get_size(prop));
176  }
177 
178  /* Print comment */
179  if (cpl_property_get_comment(prop) != NULL ) {
180  sinfo_msg(" %s", cpl_property_get_comment(prop));
181  }
182  }
183 
184  cleanup: return cpl_error_get_code();
185 }
186 
187 /*----------------------------------------------------------------*/
195 /*----------------------------------------------------------------*/
196 cpl_error_code
197 sinfo_print_cpl_frameset(const cpl_frameset *frames)
198 {
199  /* Two special cases: a NULL frame set and an empty frame set */
200 
201  if (frames == NULL ) {
202  sinfo_msg("NULL");
203  }
204  else {
205 
206  cpl_frameset_iterator* it = cpl_frameset_iterator_new(frames);
207  const cpl_frame *f = cpl_frameset_iterator_get_const(it);
208 
209  if (f == NULL ) {
210  sinfo_msg("[Empty frame set]");
211  }
212  else {
213  while (f != NULL ) {
214  check(sinfo_print_cpl_frame(f), "Could not print frame");
215 
216  cpl_frameset_iterator_advance(it, 1);
217  f = cpl_frameset_iterator_get_const(it);
218 
219  }
220  }
221  cpl_frameset_iterator_delete(it);
222  }
223 
224  cleanup: return cpl_error_get_code();
225 }
226 
227 /*----------------------------------------------------------------*/
235 /*----------------------------------------------------------------*/
236 cpl_error_code
237 sinfo_print_cpl_frame(const cpl_frame *f)
238 {
239  if (f == NULL ) {
240  sinfo_msg("NULL");
241  }
242  else {
243  sinfo_msg("%-7s %-20s '%s'",
244  sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)),
245  cpl_frame_get_tag(f) != NULL ? cpl_frame_get_tag(f) : "Null",
246  cpl_frame_get_filename(f));
247 
248  sinfo_msg_debug("type \t= %s",
249  sinfo_tostring_cpl_frame_type(cpl_frame_get_type(f)));
250  sinfo_msg_debug("group \t= %s",
251  sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)));
252  sinfo_msg_debug("level \t= %s",
253  sinfo_tostring_cpl_frame_level(cpl_frame_get_level(f)));
254  }
255 
256  return cpl_error_get_code();
257 }
258 
259 /*----------------------------------------------------------------*/
265 /*----------------------------------------------------------------*/
266 const char *
267 sinfo_tostring_cpl_frame_type(cpl_frame_type ft)
268 {
269  switch (ft)
270  {
271  case CPL_FRAME_TYPE_NONE:
272  return "NONE";
273  case CPL_FRAME_TYPE_IMAGE:
274  return "IMAGE";
275  case CPL_FRAME_TYPE_MATRIX:
276  return "MATRIX";
277  case CPL_FRAME_TYPE_TABLE:
278  return "TABLE";
279  default:
280  return "unrecognized frame type";
281  }
282 }
283 
284 /*----------------------------------------------------------------*/
290 /*----------------------------------------------------------------*/
291 const char *
292 sinfo_tostring_cpl_frame_group(cpl_frame_group fg)
293 {
294  switch (fg)
295  {
296  case CPL_FRAME_GROUP_NONE:
297  return "NONE";
298  case CPL_FRAME_GROUP_RAW:
299  return CPL_FRAME_GROUP_RAW_ID;
300  case CPL_FRAME_GROUP_CALIB:
301  return CPL_FRAME_GROUP_CALIB_ID;
302  case CPL_FRAME_GROUP_PRODUCT:
303  return CPL_FRAME_GROUP_PRODUCT_ID;
304  default:
305  return "unrecognized frame group";
306  }
307 }
308 
309 /*----------------------------------------------------------------*/
315 /*----------------------------------------------------------------*/
316 const char *
317 sinfo_tostring_cpl_frame_level(cpl_frame_level fl)
318 {
319 
320  switch (fl)
321  {
322  case CPL_FRAME_LEVEL_NONE:
323  return "NONE";
324  case CPL_FRAME_LEVEL_TEMPORARY:
325  return "TEMPORARY";
326  case CPL_FRAME_LEVEL_INTERMEDIATE:
327  return "INTERMEDIATE";
328  case CPL_FRAME_LEVEL_FINAL:
329  return "FINAL";
330  default:
331  return "unrecognized frame level";
332  }
333 }
334 
335 /*----------------------------------------------------------------*/
341 /*----------------------------------------------------------------*/
342 const char *
343 sinfo_tostring_cpl_type(cpl_type t)
344 {
345 
346  /* Note that CPL_TYPE_STRING is shorthand
347  for CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY . */
348 
349  if (!(t & CPL_TYPE_FLAG_ARRAY))
350  switch (t & (~CPL_TYPE_FLAG_ARRAY))
351  {
352  case CPL_TYPE_CHAR:
353  return "char";
354  case CPL_TYPE_UCHAR:
355  return "uchar";
356  case CPL_TYPE_BOOL:
357  return "boolean";
358  case CPL_TYPE_INT:
359  return "int";
360  case CPL_TYPE_UINT:
361  return "uint";
362  case CPL_TYPE_LONG:
363  return "long";
364  case CPL_TYPE_ULONG:
365  return "ulong";
366  case CPL_TYPE_FLOAT:
367  return "float";
368  case CPL_TYPE_DOUBLE:
369  return "double";
370  case CPL_TYPE_POINTER:
371  return "pointer";
372  /* not in CPL3.0: case CPL_TYPE_COMPLEX: return "complex"; */
373  case CPL_TYPE_INVALID:
374  return "invalid";
375  default:
376  return "unrecognized type";
377  }
378  else
379  switch (t & (~CPL_TYPE_FLAG_ARRAY))
380  {
381  case CPL_TYPE_CHAR:
382  return "string (char array)";
383  case CPL_TYPE_UCHAR:
384  return "uchar array";
385  case CPL_TYPE_BOOL:
386  return "boolean array";
387  case CPL_TYPE_INT:
388  return "int array";
389  case CPL_TYPE_UINT:
390  return "uint array";
391  case CPL_TYPE_LONG:
392  return "long array";
393  case CPL_TYPE_ULONG:
394  return "ulong array";
395  case CPL_TYPE_FLOAT:
396  return "float array";
397  case CPL_TYPE_DOUBLE:
398  return "double array";
399  case CPL_TYPE_POINTER:
400  return "pointer array";
401  /* not in CPL3.0: case CPL_TYPE_COMPLEX: return "complex array"; */
402  case CPL_TYPE_INVALID:
403  return "invalid (array)";
404  default:
405  return "unrecognized type";
406  }
407 }
#define sinfo_msg_debug(...)
Print a debug message.
Definition: sinfo_msg.h:103