sinfo_dump.c

00001 /*                                                                           *
00002  *   This file is part of the SINFONI   Pipeline                             *
00003  *   Copyright (C) 2002,2003 European Southern Observatory                   *
00004  *                                                                           *
00005  *   This library is free software; you can redistribute it and/or modify    *
00006  *   it under the terms of the GNU General Public License as published by    *
00007  *   the Free Software Foundation; either version 2 of the License, or       *
00008  *   (at your option) any later version.                                     *
00009  *                                                                           *
00010  *   This program is distributed in the hope that it will be useful,         *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
00013  *   GNU General Public License for more details.                            *
00014  *                                                                           *
00015  *   You should have received a copy of the GNU General Public License       *
00016  *   along with this program; if not, write to the Free Software             *
00017  *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA    *
00018  *                                                                           */
00019 
00020 /*
00021  * $Author: amodigli $
00022  * $Date: 2012/09/21 10:55:19 $
00023  * $Revision: 1.9 $
00024  * $Name: HEAD $
00025  * $Log: sinfo_dump.c,v $
00026  * Revision 1.9  2012/09/21 10:55:19  amodigli
00027  * removed warning from clang
00028  *
00029  * Revision 1.8  2012/03/02 08:42:20  amodigli
00030  * fixed some typos on doxygen
00031  *
00032  * Revision 1.7  2011/11/23 17:29:19  amodigli
00033  * fix warning with cpl6
00034  *
00035  * Revision 1.6  2008/01/17 07:54:04  amodigli
00036  * shorten long lines
00037  *
00038  * Revision 1.5  2007/08/11 10:45:47  amodigli
00039  * upgrade to CPL4, fixed compil warnings
00040  *
00041  * Revision 1.4  2007/06/06 07:10:45  amodigli
00042  * replaced tab with 4 spaces
00043  *
00044  * Revision 1.3  2006/10/20 08:07:05  amodigli
00045  * using prefix sinfo_ in place of sinfoni_ for includes
00046  *
00047  * Revision 1.2  2006/10/16 07:26:23  amodigli
00048  * shortened line length
00049  *
00050  * Revision 1.1  2006/08/09 12:20:11  amodigli
00051  * added sinfo_dump.h sinfo_dump.c
00052  *
00053  * Revision 1.7  2006/05/12 15:02:05  jmlarsen
00054  * Support NULL tags
00055  *
00056  * Revision 1.6  2006/02/28 09:15:22  jmlarsen
00057  * Minor update
00058  *
00059  * Revision 1.5  2006/02/15 13:19:15  jmlarsen
00060  * Reduced source code max. line length
00061  *
00062  * Revision 1.4  2005/12/19 16:17:56  jmlarsen
00063  * Replaced bool -> int
00064  *
00065  */
00066 
00067 #ifdef HAVE_CONFIG_H
00068 #  include <config.h>
00069 #endif
00070 
00073 /*----------------------------------------------------------------------------*/
00080 /*----------------------------------------------------------------------------*/
00081 
00082 
00083 #include <sinfo_dump.h>
00084 #include <sinfo_utils.h>
00085 #include <sinfo_error.h>
00086 #include <sinfo_msg.h>
00087 #include <cpl.h>
00088 
00089 /*----------------------------------------------------------------*/
00101 /*----------------------------------------------------------------*/
00102 cpl_error_code
00103 sinfo_print_cpl_propertylist(const cpl_propertylist *pl, long low, long high)
00104 {
00105     cpl_property *prop;
00106     long i = 0;
00107     
00108     assure (0 <= low && high <= cpl_propertylist_get_size(pl) && low <= high,
00109         CPL_ERROR_ILLEGAL_INPUT, "Illegal range");
00110     /* Printing an empty range is allowed but only when low == high */
00111 
00112     if (pl == NULL){
00113     sinfo_msg("NULL");
00114     }
00115     else if (cpl_propertylist_is_empty(pl))  {
00116     sinfo_msg("[Empty property list]");
00117     }
00118     else    
00119     for (i = low; i < high; i++)
00120         {
00121         /* bug workaround: remove const cast when declaration 
00122            of cpl_propertylist_get() is changed */
00123         prop = cpl_propertylist_get((cpl_propertylist *)pl, i);
00124         check (sinfo_print_cpl_property(prop), 
00125                 "Error printing property");
00126         }
00127     
00128   cleanup:
00129     return cpl_error_get_code();
00130 }
00131 /*----------------------------------------------------------------*/
00139 /*----------------------------------------------------------------*/
00140 
00141 cpl_error_code
00142 sinfo_print_cpl_property(const cpl_property *prop)
00143 {
00144     cpl_type t;
00145 
00146     if (prop == NULL)
00147     {
00148         sinfo_msg("NULL");
00149     }
00150     else
00151     {   
00152         /* print property with this formatting
00153            NAME =
00154              VALUE
00155            COMMENT
00156         */
00157 
00158         /* print name */
00159         
00160         sinfo_msg("%s =", cpl_property_get_name(prop));
00161 
00162         /* print value */
00163         
00164         check( t = cpl_property_get_type(prop), 
00165                   "Could not read property type");
00166         
00167         switch(t & (~CPL_TYPE_FLAG_ARRAY))
00168         {
00169         case CPL_TYPE_CHAR:
00170             if (t & CPL_TYPE_FLAG_ARRAY)  /* if type is string */
00171             {
00172                 sinfo_msg("  '%s'", cpl_property_get_string(prop));
00173             }
00174             else                          /* an ordinary char */
00175             {
00176                 sinfo_msg("  %c", cpl_property_get_char(prop));
00177             }
00178             break;
00179         case CPL_TYPE_BOOL:    if (cpl_property_get_bool(prop))
00180             {sinfo_msg("  true");}
00181         else
00182             {sinfo_msg("  false");}
00183             break;
00184         case CPL_TYPE_UCHAR: 
00185       sinfo_msg("%c",cpl_property_get_char(prop)); 
00186           break;
00187         case CPL_TYPE_INT:   
00188       sinfo_msg("%d",cpl_property_get_int(prop)); 
00189           break;
00190         case CPL_TYPE_UINT:  
00191           sinfo_msg("%d",cpl_property_get_int(prop)); 
00192           break;
00193         case CPL_TYPE_LONG: 
00194           sinfo_msg("%ld",cpl_property_get_long(prop)); 
00195           break;
00196         case CPL_TYPE_ULONG: 
00197           sinfo_msg("%ld",cpl_property_get_long(prop)); 
00198           break;
00199         case CPL_TYPE_FLOAT: 
00200           sinfo_msg("%f",cpl_property_get_float(prop)); 
00201           break;
00202         case CPL_TYPE_DOUBLE: 
00203           sinfo_msg("%f",cpl_property_get_double(prop)); 
00204           break;
00205         case CPL_TYPE_POINTER: 
00206           sinfo_msg("POINTER");    
00207           break;
00208         case CPL_TYPE_INVALID: 
00209           sinfo_msg("INVALID");    
00210           break;
00211         default: 
00212           sinfo_msg("  unrecognized property");  
00213           break;
00214         }
00215         
00216         /* Is this property an array? */
00217         if (t & CPL_TYPE_FLAG_ARRAY){
00218            cpl_msg_info(cpl_func,"  (array size = %" CPL_SIZE_FORMAT " )", 
00219               cpl_property_get_size(prop));
00220         }
00221 
00222         /* Print comment */
00223         if (cpl_property_get_comment(prop) != NULL){
00224         sinfo_msg("    %s", cpl_property_get_comment(prop));
00225         }
00226     }
00227 
00228   cleanup:
00229     return cpl_error_get_code();
00230 }
00231 
00232 /*----------------------------------------------------------------*/
00240 /*----------------------------------------------------------------*/
00241 cpl_error_code
00242 sinfo_print_cpl_frameset(const cpl_frameset *frames)
00243 {
00244     /* Two special cases: a NULL frame set and an empty frame set */
00245 
00246     if (frames == NULL)
00247     {
00248         sinfo_msg("NULL");
00249     }
00250     else
00251     {
00252         const cpl_frame *f = NULL;
00253         check( f = cpl_frameset_get_first_const(frames), 
00254                    "Error reading frameset");
00255         
00256         if (f == NULL)
00257         {
00258             sinfo_msg("[Empty frame set]");
00259         }
00260         else
00261         {
00262             while(f != NULL)
00263             {
00264                 check( sinfo_print_cpl_frame(f), 
00265                                   "Could not print frame");
00266                 check( f = cpl_frameset_get_next_const(frames), 
00267                                   "Error reading frameset");
00268             }
00269         }
00270     }
00271     
00272   cleanup:
00273     return cpl_error_get_code();
00274 }
00275 
00276 /*----------------------------------------------------------------*/
00284 /*----------------------------------------------------------------*/
00285 cpl_error_code
00286 sinfo_print_cpl_frame(const cpl_frame *f)
00287 {
00288     if (f == NULL)
00289     {
00290         sinfo_msg("NULL");
00291     }
00292     else
00293     {
00294         sinfo_msg("%-7s %-20s '%s'", 
00295              sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)),
00296              cpl_frame_get_tag(f) != NULL ? 
00297                      cpl_frame_get_tag(f) : "Null",
00298              cpl_frame_get_filename(f));
00299         
00300         sinfo_msg_debug("type \t= %s",   
00301             sinfo_tostring_cpl_frame_type (cpl_frame_get_type (f)));
00302         sinfo_msg_debug("group \t= %s",  
00303             sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)));
00304         sinfo_msg_debug("level \t= %s",  
00305             sinfo_tostring_cpl_frame_level(cpl_frame_get_level(f)));
00306     }
00307 
00308     return cpl_error_get_code();
00309 }
00310 
00311 /*----------------------------------------------------------------*/
00317 /*----------------------------------------------------------------*/
00318 const char *
00319 sinfo_tostring_cpl_frame_type(cpl_frame_type ft)
00320 {    
00321     switch(ft)
00322     {
00323     case CPL_FRAME_TYPE_NONE:   return "NONE";
00324     case CPL_FRAME_TYPE_IMAGE:  return "IMAGE";
00325     case CPL_FRAME_TYPE_MATRIX: return "MATRIX";
00326     case CPL_FRAME_TYPE_TABLE:  return "TABLE";
00327     default: return "unrecognized frame type";
00328     }
00329 }
00330 
00331 /*----------------------------------------------------------------*/
00337 /*----------------------------------------------------------------*/
00338 const char *
00339 sinfo_tostring_cpl_frame_group(cpl_frame_group fg)
00340 {
00341     switch(fg)
00342     {
00343     case CPL_FRAME_GROUP_NONE:    return "NONE";
00344     case CPL_FRAME_GROUP_RAW:     return CPL_FRAME_GROUP_RAW_ID;
00345     case CPL_FRAME_GROUP_CALIB:   return CPL_FRAME_GROUP_CALIB_ID;
00346     case CPL_FRAME_GROUP_PRODUCT: return CPL_FRAME_GROUP_PRODUCT_ID;
00347     default:
00348         return "unrecognized frame group";
00349     }
00350 }
00351 
00352 /*----------------------------------------------------------------*/
00358 /*----------------------------------------------------------------*/
00359 const char *
00360 sinfo_tostring_cpl_frame_level(cpl_frame_level fl)
00361 {
00362     
00363     switch(fl)
00364     {
00365     case CPL_FRAME_LEVEL_NONE:        return "NONE";
00366     case CPL_FRAME_LEVEL_TEMPORARY:   return "TEMPORARY";
00367     case CPL_FRAME_LEVEL_INTERMEDIATE:return "INTERMEDIATE";
00368     case CPL_FRAME_LEVEL_FINAL:       return "FINAL";
00369     default: return "unrecognized frame level";
00370     }
00371 }
00372 
00373 
00374 /*----------------------------------------------------------------*/
00380 /*----------------------------------------------------------------*/
00381 const char *
00382 sinfo_tostring_cpl_type(cpl_type t)
00383 {
00384 
00385     /* Note that CPL_TYPE_STRING is shorthand
00386        for CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY . */
00387 
00388     if (!(t & CPL_TYPE_FLAG_ARRAY))
00389     switch(t & (~CPL_TYPE_FLAG_ARRAY))
00390         {
00391         case CPL_TYPE_CHAR:       return "char";
00392         case CPL_TYPE_UCHAR:      return "uchar";
00393         case CPL_TYPE_BOOL:       return "boolean";
00394         case CPL_TYPE_INT:        return "int";
00395         case CPL_TYPE_UINT:       return "uint";
00396         case CPL_TYPE_LONG:       return "long";
00397         case CPL_TYPE_ULONG:      return "ulong";
00398         case CPL_TYPE_FLOAT:      return "float";
00399         case CPL_TYPE_DOUBLE:     return "double";
00400         case CPL_TYPE_POINTER:    return "pointer";
00401 /* not in CPL3.0: case CPL_TYPE_COMPLEX:    return "complex"; */
00402         case CPL_TYPE_INVALID:    return "invalid";
00403         default:
00404         return "unrecognized type";
00405         }
00406     else
00407     switch(t & (~CPL_TYPE_FLAG_ARRAY))
00408         {
00409         case CPL_TYPE_CHAR:       return "string (char array)";
00410         case CPL_TYPE_UCHAR:      return "uchar array";
00411         case CPL_TYPE_BOOL:       return "boolean array";
00412         case CPL_TYPE_INT:        return "int array";
00413         case CPL_TYPE_UINT:       return "uint array";
00414         case CPL_TYPE_LONG:       return "long array";
00415         case CPL_TYPE_ULONG:      return "ulong array";
00416         case CPL_TYPE_FLOAT:      return "float array";
00417         case CPL_TYPE_DOUBLE:     return "double array";
00418         case CPL_TYPE_POINTER:    return "pointer array";
00419 /* not in CPL3.0: case CPL_TYPE_COMPLEX:    return "complex array"; */
00420         case CPL_TYPE_INVALID:    return "invalid (array)";
00421         default:
00422         return "unrecognized type";
00423         }
00424 }

Generated on 3 Mar 2013 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1