SINFONI Pipeline Reference Manual  2.5.2
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  const cpl_frame *f = NULL;
206  check(f = cpl_frameset_get_first_const(frames),
207  "Error reading frameset");
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  check(f = cpl_frameset_get_next_const(frames),
216  "Error reading frameset");
217  }
218  }
219  }
220 
221  cleanup: return cpl_error_get_code();
222 }
223 
224 /*----------------------------------------------------------------*/
232 /*----------------------------------------------------------------*/
233 cpl_error_code
234 sinfo_print_cpl_frame(const cpl_frame *f)
235 {
236  if (f == NULL ) {
237  sinfo_msg("NULL");
238  }
239  else {
240  sinfo_msg("%-7s %-20s '%s'",
241  sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)),
242  cpl_frame_get_tag(f) != NULL ? cpl_frame_get_tag(f) : "Null",
243  cpl_frame_get_filename(f));
244 
245  sinfo_msg_debug("type \t= %s",
246  sinfo_tostring_cpl_frame_type(cpl_frame_get_type(f)));
247  sinfo_msg_debug("group \t= %s",
248  sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)));
249  sinfo_msg_debug("level \t= %s",
250  sinfo_tostring_cpl_frame_level(cpl_frame_get_level(f)));
251  }
252 
253  return cpl_error_get_code();
254 }
255 
256 /*----------------------------------------------------------------*/
262 /*----------------------------------------------------------------*/
263 const char *
264 sinfo_tostring_cpl_frame_type(cpl_frame_type ft)
265 {
266  switch (ft)
267  {
268  case CPL_FRAME_TYPE_NONE:
269  return "NONE";
270  case CPL_FRAME_TYPE_IMAGE:
271  return "IMAGE";
272  case CPL_FRAME_TYPE_MATRIX:
273  return "MATRIX";
274  case CPL_FRAME_TYPE_TABLE:
275  return "TABLE";
276  default:
277  return "unrecognized frame type";
278  }
279 }
280 
281 /*----------------------------------------------------------------*/
287 /*----------------------------------------------------------------*/
288 const char *
289 sinfo_tostring_cpl_frame_group(cpl_frame_group fg)
290 {
291  switch (fg)
292  {
293  case CPL_FRAME_GROUP_NONE:
294  return "NONE";
295  case CPL_FRAME_GROUP_RAW:
296  return CPL_FRAME_GROUP_RAW_ID;
297  case CPL_FRAME_GROUP_CALIB:
298  return CPL_FRAME_GROUP_CALIB_ID;
299  case CPL_FRAME_GROUP_PRODUCT:
300  return CPL_FRAME_GROUP_PRODUCT_ID;
301  default:
302  return "unrecognized frame group";
303  }
304 }
305 
306 /*----------------------------------------------------------------*/
312 /*----------------------------------------------------------------*/
313 const char *
314 sinfo_tostring_cpl_frame_level(cpl_frame_level fl)
315 {
316 
317  switch (fl)
318  {
319  case CPL_FRAME_LEVEL_NONE:
320  return "NONE";
321  case CPL_FRAME_LEVEL_TEMPORARY:
322  return "TEMPORARY";
323  case CPL_FRAME_LEVEL_INTERMEDIATE:
324  return "INTERMEDIATE";
325  case CPL_FRAME_LEVEL_FINAL:
326  return "FINAL";
327  default:
328  return "unrecognized frame level";
329  }
330 }
331 
332 /*----------------------------------------------------------------*/
338 /*----------------------------------------------------------------*/
339 const char *
340 sinfo_tostring_cpl_type(cpl_type t)
341 {
342 
343  /* Note that CPL_TYPE_STRING is shorthand
344  for CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY . */
345 
346  if (!(t & CPL_TYPE_FLAG_ARRAY))
347  switch (t & (~CPL_TYPE_FLAG_ARRAY))
348  {
349  case CPL_TYPE_CHAR:
350  return "char";
351  case CPL_TYPE_UCHAR:
352  return "uchar";
353  case CPL_TYPE_BOOL:
354  return "boolean";
355  case CPL_TYPE_INT:
356  return "int";
357  case CPL_TYPE_UINT:
358  return "uint";
359  case CPL_TYPE_LONG:
360  return "long";
361  case CPL_TYPE_ULONG:
362  return "ulong";
363  case CPL_TYPE_FLOAT:
364  return "float";
365  case CPL_TYPE_DOUBLE:
366  return "double";
367  case CPL_TYPE_POINTER:
368  return "pointer";
369  /* not in CPL3.0: case CPL_TYPE_COMPLEX: return "complex"; */
370  case CPL_TYPE_INVALID:
371  return "invalid";
372  default:
373  return "unrecognized type";
374  }
375  else
376  switch (t & (~CPL_TYPE_FLAG_ARRAY))
377  {
378  case CPL_TYPE_CHAR:
379  return "string (char array)";
380  case CPL_TYPE_UCHAR:
381  return "uchar array";
382  case CPL_TYPE_BOOL:
383  return "boolean array";
384  case CPL_TYPE_INT:
385  return "int array";
386  case CPL_TYPE_UINT:
387  return "uint array";
388  case CPL_TYPE_LONG:
389  return "long array";
390  case CPL_TYPE_ULONG:
391  return "ulong array";
392  case CPL_TYPE_FLOAT:
393  return "float array";
394  case CPL_TYPE_DOUBLE:
395  return "double array";
396  case CPL_TYPE_POINTER:
397  return "pointer array";
398  /* not in CPL3.0: case CPL_TYPE_COMPLEX: return "complex array"; */
399  case CPL_TYPE_INVALID:
400  return "invalid (array)";
401  default:
402  return "unrecognized type";
403  }
404 }