X-shooter Pipeline Reference Manual 3.8.15
xsh_dump.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 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-01-02 15:27:33 $
23 * $Revision: 1.12 $
24 * $Name: not supported by cvs2svn $
25 */
26
27#ifdef HAVE_CONFIG_H
28# include <config.h>
29#endif
30
31/*----------------------------------------------------------------------------*/
39/*----------------------------------------------------------------------------*/
40
43#include "xsh_dump.h"
44
45#include <xsh_error.h>
46#include <xsh_msg.h>
47
48#include <cpl.h>
49#include <xsh_cpl_size.h>
50
51/*----------------------------------------------------------------*/
63/*----------------------------------------------------------------*/
64cpl_error_code
65xsh_print_cpl_propertylist (const cpl_propertylist * pl, long low, long high)
66{
67 cpl_property *prop;
68 long i = 0;
69
70 assure (0 <= low && high <= cpl_propertylist_get_size (pl) && low <= high,
71 CPL_ERROR_ILLEGAL_INPUT, "Illegal range");
72 /* Printing an empty range is allowed but only when low == high */
73
74 if (pl == NULL) {
75 xsh_msg ("NULL");
76 }
77 else if (cpl_propertylist_is_empty (pl)) {
78 xsh_msg ("[Empty property list]");
79 }
80 else
81 for (i = low; i < high; i++) {
82 /* bug workaround: remove const cast when declaration
83 of cpl_propertylist_get() is changed */
84 prop = cpl_propertylist_get ((cpl_propertylist *) pl, i);
86 }
87
88cleanup:
89 return cpl_error_get_code ();
90}
91
92/*----------------------------------------------------------------*/
100/*----------------------------------------------------------------*/
101
102cpl_error_code
103xsh_print_cpl_property (const cpl_property * prop)
104{
105 cpl_type t;
106
107 if (prop == NULL) {
108 xsh_msg ("NULL");
109 }
110 else {
111 /* print property with this formatting
112 NAME =
113 VALUE
114 COMMENT
115 */
116
117 /* print name */
118
119 xsh_msg ("%s =", cpl_property_get_name (prop));
120
121 /* print value */
122
123 check (t = cpl_property_get_type (prop));
124
125 switch (t & (~CPL_TYPE_FLAG_ARRAY)) {
126 case CPL_TYPE_CHAR:
127 if (t & CPL_TYPE_FLAG_ARRAY) { /* if type is string */
128 xsh_msg (" '%s'", cpl_property_get_string (prop));
129 }
130 else { /* an ordinary char */
131
132 xsh_msg (" %c", cpl_property_get_char (prop));
133 }
134 break;
135 case CPL_TYPE_BOOL:
136 if (cpl_property_get_bool (prop)) {
137 xsh_msg (" true");
138 }
139 else {
140 xsh_msg (" false");
141 }
142 break;
143 case CPL_TYPE_UCHAR:
144 xsh_msg (" %c", cpl_property_get_char (prop));
145 break;
146 case CPL_TYPE_INT:
147 xsh_msg (" %d", cpl_property_get_int (prop));
148 break;
149 case CPL_TYPE_UINT:
150 xsh_msg (" %d", cpl_property_get_int (prop));
151 break;
152 case CPL_TYPE_LONG:
153 xsh_msg (" %ld", cpl_property_get_long (prop));
154 break;
155 case CPL_TYPE_ULONG:
156 xsh_msg (" %ld", cpl_property_get_long (prop));
157 break;
158 case CPL_TYPE_FLOAT:
159 xsh_msg (" %f", cpl_property_get_float (prop));
160 break;
161 case CPL_TYPE_DOUBLE:
162 xsh_msg (" %f", cpl_property_get_double (prop));
163 break;
164 case CPL_TYPE_POINTER:
165 xsh_msg (" POINTER");
166 break;
167 case CPL_TYPE_INVALID:
168 xsh_msg (" INVALID");
169 break;
170 default:
171 xsh_msg (" unrecognized property");
172 break;
173 }
174
175 /* Is this property an array? */
176 if (t & CPL_TYPE_FLAG_ARRAY) {
177 cpl_msg_info(cpl_func," (array size = %d" CPL_SIZE_FORMAT " )",
178 (int)cpl_property_get_size(prop));
179 }
180
181 /* Print comment */
182 if (cpl_property_get_comment (prop) != NULL) {
183 xsh_msg (" %s", cpl_property_get_comment (prop));
184 }
185 }
186
187cleanup:
188 return cpl_error_get_code ();
189}
190
191/*----------------------------------------------------------------*/
199/*----------------------------------------------------------------*/
200cpl_error_code
201xsh_print_cpl_frameset (cpl_frameset * frames)
202{
203 /* Two special cases: a NULL frame set and an empty frame set */
204
205 if (frames == NULL) {
206 xsh_msg ("NULL");
207 }
208 else {
209 const cpl_frame *f = NULL;
210 cpl_frameset_iterator* it = cpl_frameset_iterator_new(frames);
211 f = cpl_frameset_iterator_get(it);
212
213 if (f == NULL) {
214 xsh_msg ("[Empty frame set]");
215 }
216 else {
217 do {
219 cpl_frameset_iterator_advance(it, 1);
220 f = cpl_frameset_iterator_get_const(it);
221
222 }
223 while (f != NULL);
224 }
225 cpl_frameset_iterator_delete(it);
226 }
227
228cleanup:
229
230 return cpl_error_get_code ();
231}
232
233/*----------------------------------------------------------------*/
241/*----------------------------------------------------------------*/
242cpl_error_code
243xsh_print_cpl_frame (const cpl_frame * f)
244{
245 if (f == NULL) {
246 xsh_msg ("NULL");
247 }
248 else {
249 xsh_msg ("%-7s %-20s '%s'",
250 xsh_tostring_cpl_frame_group (cpl_frame_get_group (f)),
251 cpl_frame_get_tag (f) != NULL ? cpl_frame_get_tag (f) : "Null",
252 cpl_frame_get_filename (f));
253
254 xsh_msg_dbg_low ("type \t= %s",
255 xsh_tostring_cpl_frame_type (cpl_frame_get_type (f)));
256 xsh_msg_dbg_low ("group \t= %s",
257 xsh_tostring_cpl_frame_group (cpl_frame_get_group (f)));
258 xsh_msg_dbg_low ("level \t= %s",
259 xsh_tostring_cpl_frame_level (cpl_frame_get_level (f)));
260 }
261
262 return cpl_error_get_code ();
263}
264
265/*----------------------------------------------------------------*/
271/*----------------------------------------------------------------*/
272const char *
274{
275 switch (ft) {
276 case CPL_FRAME_TYPE_NONE:
277 return "NONE";
278 break;
279 case CPL_FRAME_TYPE_IMAGE:
280 return "IMAGE";
281 break;
282 case CPL_FRAME_TYPE_MATRIX:
283 return "MATRIX";
284 break;
285 case CPL_FRAME_TYPE_TABLE:
286 return "TABLE";
287 break;
288 default:
289 return "unrecognized frame type";
290 }
291}
292
293/*----------------------------------------------------------------*/
299/*----------------------------------------------------------------*/
300const char *
302{
303 switch (fg) {
304 case CPL_FRAME_GROUP_NONE:
305 return "NONE";
306 break;
307 case CPL_FRAME_GROUP_RAW:
308 return CPL_FRAME_GROUP_RAW_ID;
309 break;
310 case CPL_FRAME_GROUP_CALIB:
311 return CPL_FRAME_GROUP_CALIB_ID;
312 break;
313 case CPL_FRAME_GROUP_PRODUCT:
314 return CPL_FRAME_GROUP_PRODUCT_ID;
315 break;
316 default:
317 return "unrecognized frame group";
318 }
319}
320
321/*----------------------------------------------------------------*/
327/*----------------------------------------------------------------*/
328const char *
330{
331
332 switch (fl) {
333 case CPL_FRAME_LEVEL_NONE:
334 return "NONE";
335 break;
336 case CPL_FRAME_LEVEL_TEMPORARY:
337 return "TEMPORARY";
338 break;
339 case CPL_FRAME_LEVEL_INTERMEDIATE:
340 return "INTERMEDIATE";
341 break;
342 case CPL_FRAME_LEVEL_FINAL:
343 return "FINAL";
344 break;
345 default:
346 return "unrecognized frame level";
347 }
348}
349
350
351/*----------------------------------------------------------------*/
357/*----------------------------------------------------------------*/
358const char *
360{
361
362 /* Note that CPL_TYPE_STRING is shorthand
363 for CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY . */
364
365 if (!(t & CPL_TYPE_FLAG_ARRAY))
366 switch (t & (~CPL_TYPE_FLAG_ARRAY)) {
367 case CPL_TYPE_CHAR:
368 return "char";
369 break;
370 case CPL_TYPE_UCHAR:
371 return "uchar";
372 break;
373 case CPL_TYPE_BOOL:
374 return "boolean";
375 break;
376 case CPL_TYPE_INT:
377 return "int";
378 break;
379 case CPL_TYPE_UINT:
380 return "uint";
381 break;
382 case CPL_TYPE_LONG:
383 return "long";
384 break;
385 case CPL_TYPE_ULONG:
386 return "ulong";
387 break;
388 case CPL_TYPE_FLOAT:
389 return "float";
390 break;
391 case CPL_TYPE_DOUBLE:
392 return "double";
393 break;
394 case CPL_TYPE_POINTER:
395 return "pointer";
396 break;
397/* not in CPL3.0: case CPL_TYPE_COMPLEX: return "complex"; break; */
398 case CPL_TYPE_INVALID:
399 return "invalid";
400 break;
401 default:
402 return "unrecognized type";
403 }
404 else
405 switch (t & (~CPL_TYPE_FLAG_ARRAY)) {
406 case CPL_TYPE_CHAR:
407 return "string (char array)";
408 break;
409 case CPL_TYPE_UCHAR:
410 return "uchar array";
411 break;
412 case CPL_TYPE_BOOL:
413 return "boolean array";
414 break;
415 case CPL_TYPE_INT:
416 return "int array";
417 break;
418 case CPL_TYPE_UINT:
419 return "uint array";
420 break;
421 case CPL_TYPE_LONG:
422 return "long array";
423 break;
424 case CPL_TYPE_ULONG:
425 return "ulong array";
426 break;
427 case CPL_TYPE_FLOAT:
428 return "float array";
429 break;
430 case CPL_TYPE_DOUBLE:
431 return "double array";
432 break;
433 case CPL_TYPE_POINTER:
434 return "pointer array";
435 break;
436/* not in CPL3.0: case CPL_TYPE_COMPLEX: return "complex array"; break; */
437 case CPL_TYPE_INVALID:
438 return "invalid (array)";
439 break;
440 default:
441 return "unrecognized type";
442 }
443}
444
const char * xsh_tostring_cpl_frame_group(cpl_frame_group fg)
Convert a frame group to a string.
Definition: xsh_dump.c:301
cpl_error_code xsh_print_cpl_frameset(cpl_frameset *frames)
Print a frame set.
Definition: xsh_dump.c:201
const char * xsh_tostring_cpl_type(cpl_type t)
Convert a CPL type to a string.
Definition: xsh_dump.c:359
cpl_error_code xsh_print_cpl_property(const cpl_property *prop)
Print a property.
Definition: xsh_dump.c:103
cpl_error_code xsh_print_cpl_propertylist(const cpl_propertylist *pl, long low, long high)
Print a property list.
Definition: xsh_dump.c:65
const char * xsh_tostring_cpl_frame_level(cpl_frame_level fl)
Convert a frame level to a string.
Definition: xsh_dump.c:329
cpl_error_code xsh_print_cpl_frame(const cpl_frame *f)
Print a frame.
Definition: xsh_dump.c:243
const char * xsh_tostring_cpl_frame_type(cpl_frame_type ft)
Convert a frame type to a string.
Definition: xsh_dump.c:273
#define assure(CONDITION, ERROR_CODE,...)
Definition: xsh_error.h:54
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
#define xsh_msg_dbg_low(...)
Definition: xsh_msg.h:48