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: 2006/10/20 08:07:05 $
00023  * $Revision: 1.3 $
00024  * $Name:  $
00025  * $Log: sinfo_dump.c,v $
00026  * Revision 1.3  2006/10/20 08:07:05  amodigli
00027  * using prefix sinfo_ in place of sinfoni_ for includes
00028  *
00029  * Revision 1.2  2006/10/16 07:26:23  amodigli
00030  * shortened line length
00031  *
00032  * Revision 1.1  2006/08/09 12:20:11  amodigli
00033  * added sinfo_dump.h sinfo_dump.c
00034  *
00035  * Revision 1.7  2006/05/12 15:02:05  jmlarsen
00036  * Support NULL tags
00037  *
00038  * Revision 1.6  2006/02/28 09:15:22  jmlarsen
00039  * Minor update
00040  *
00041  * Revision 1.5  2006/02/15 13:19:15  jmlarsen
00042  * Reduced source code max. line length
00043  *
00044  * Revision 1.4  2005/12/19 16:17:56  jmlarsen
00045  * Replaced bool -> int
00046  *
00047  */
00048 
00049 #ifdef HAVE_CONFIG_H
00050 #  include <config.h>
00051 #endif
00052 
00053 /*----------------------------------------------------------------------------*/
00060 /*----------------------------------------------------------------------------*/
00061 
00064 #include <sinfo_dump.h>
00065 #include <sinfo_utils.h>
00066 #include <sinfo_error.h>
00067 #include <sinfo_msg.h>
00068 #include <cpl.h>
00069 
00070 /*----------------------------------------------------------------*/
00082 /*----------------------------------------------------------------*/
00083 cpl_error_code
00084 sinfo_print_cpl_propertylist(const cpl_propertylist *pl, long low, long high)
00085 {
00086     cpl_property *prop;
00087     long i = 0;
00088     
00089     assure (0 <= low && high <= cpl_propertylist_get_size(pl) && low <= high,
00090         CPL_ERROR_ILLEGAL_INPUT, "Illegal range");
00091     /* Printing an empty range is allowed but only when low == high */
00092 
00093     if (pl == NULL){
00094     sinfo_msg("NULL");
00095     }
00096     else if (cpl_propertylist_is_empty(pl))  {
00097     sinfo_msg("[Empty property list]");
00098     }
00099     else    
00100     for (i = low; i < high; i++)
00101         {
00102         /* bug workaround: remove const cast when declaration 
00103            of cpl_propertylist_get() is changed */
00104         prop = cpl_propertylist_get((cpl_propertylist *)pl, i);
00105         check (sinfo_print_cpl_property(prop), 
00106                 "Error printing property");
00107         }
00108     
00109   cleanup:
00110     return cpl_error_get_code();
00111 }
00112 /*----------------------------------------------------------------*/
00120 /*----------------------------------------------------------------*/
00121 
00122 cpl_error_code
00123 sinfo_print_cpl_property(const cpl_property *prop)
00124 {
00125     cpl_type t;
00126 
00127     if (prop == NULL)
00128     {
00129         sinfo_msg("NULL");
00130     }
00131     else
00132     {   
00133         /* print property with this formatting
00134            NAME =
00135              VALUE
00136            COMMENT
00137         */
00138 
00139         /* print name */
00140         
00141         sinfo_msg("%s =", cpl_property_get_name(prop));
00142 
00143         /* print value */
00144         
00145         check( t = cpl_property_get_type(prop), 
00146                   "Could not read property type");
00147         
00148         switch(t & (~CPL_TYPE_FLAG_ARRAY))
00149         {
00150         case CPL_TYPE_CHAR:
00151             if (t & CPL_TYPE_FLAG_ARRAY)  /* if type is string */
00152             {
00153                 sinfo_msg("  '%s'", cpl_property_get_string(prop));
00154             }
00155             else                          /* an ordinary char */
00156             {
00157                 sinfo_msg("  %c", cpl_property_get_char(prop));
00158             }
00159             break;
00160         case CPL_TYPE_BOOL:    if (cpl_property_get_bool(prop))
00161             {sinfo_msg("  true");}
00162         else
00163             {sinfo_msg("  false");}
00164             break;
00165         case CPL_TYPE_UCHAR: sinfo_msg("%c",cpl_property_get_char(prop));  break;
00166         case CPL_TYPE_INT:   sinfo_msg("%d",cpl_property_get_int(prop));  break;
00167         case CPL_TYPE_UINT:  sinfo_msg("%d",cpl_property_get_int(prop));  break;
00168         case CPL_TYPE_LONG:  sinfo_msg("%ld",cpl_property_get_long(prop));  break;
00169         case CPL_TYPE_ULONG: sinfo_msg("%ld",cpl_property_get_long(prop));  break;
00170         case CPL_TYPE_FLOAT: sinfo_msg("%f",cpl_property_get_float(prop));  break;
00171         case CPL_TYPE_DOUBLE: sinfo_msg("%f",cpl_property_get_double(prop)); break;
00172         case CPL_TYPE_POINTER: sinfo_msg("POINTER");    break;
00173         case CPL_TYPE_INVALID: sinfo_msg("INVALID");    break;
00174         default: sinfo_msg("  unrecognized property");  break;
00175         }
00176         
00177         /* Is this property an array? */
00178         if (t & CPL_TYPE_FLAG_ARRAY){
00179         sinfo_msg("  (array size = %ld)", cpl_property_get_size(prop));
00180         }
00181 
00182         /* Print comment */
00183         if (cpl_property_get_comment(prop) != NULL){
00184         sinfo_msg("    %s", cpl_property_get_comment(prop));
00185         }
00186     }
00187 
00188   cleanup:
00189     return cpl_error_get_code();
00190 }
00191 
00192 /*----------------------------------------------------------------*/
00200 /*----------------------------------------------------------------*/
00201 cpl_error_code
00202 sinfo_print_cpl_frameset(const cpl_frameset *frames)
00203 {
00204     /* Two special cases: a NULL frame set and an empty frame set */
00205 
00206     if (frames == NULL)
00207     {
00208         sinfo_msg("NULL");
00209     }
00210     else
00211     {
00212         cpl_frame *f = NULL;
00213         check( f = cpl_frameset_get_first(frames), 
00214                    "Error reading frameset");
00215         
00216         if (f == NULL)
00217         {
00218             sinfo_msg("[Empty frame set]");
00219         }
00220         else
00221         {
00222             while(f != NULL)
00223             {
00224                 check( sinfo_print_cpl_frame(f), 
00225                                   "Could not print frame");
00226                 check( f = cpl_frameset_get_next(frames), 
00227                                   "Error reading frameset");
00228             }
00229         }
00230     }
00231     
00232   cleanup:
00233     return cpl_error_get_code();
00234 }
00235 
00236 /*----------------------------------------------------------------*/
00244 /*----------------------------------------------------------------*/
00245 cpl_error_code
00246 sinfo_print_cpl_frame(const cpl_frame *f)
00247 {
00248     if (f == NULL)
00249     {
00250         sinfo_msg("NULL");
00251     }
00252     else
00253     {
00254         sinfo_msg("%-7s %-20s '%s'", 
00255              sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)),
00256              cpl_frame_get_tag(f) != NULL ? 
00257                      cpl_frame_get_tag(f) : "Null",
00258              cpl_frame_get_filename(f));
00259         
00260         sinfo_msg_debug("type \t= %s",   
00261             sinfo_tostring_cpl_frame_type (cpl_frame_get_type (f)));
00262         sinfo_msg_debug("group \t= %s",  
00263             sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)));
00264         sinfo_msg_debug("level \t= %s",  
00265             sinfo_tostring_cpl_frame_level(cpl_frame_get_level(f)));
00266     }
00267 
00268     return cpl_error_get_code();
00269 }
00270 
00271 /*----------------------------------------------------------------*/
00277 /*----------------------------------------------------------------*/
00278 const char *
00279 sinfo_tostring_cpl_frame_type(cpl_frame_type ft)
00280 {    
00281     switch(ft)
00282     {
00283     case CPL_FRAME_TYPE_NONE:   return "NONE";      break;
00284     case CPL_FRAME_TYPE_IMAGE:  return "IMAGE";     break;
00285     case CPL_FRAME_TYPE_MATRIX: return "MATRIX";    break;
00286     case CPL_FRAME_TYPE_TABLE:  return "TABLE";     break;
00287     default: return "unrecognized frame type";
00288     }
00289 }
00290 
00291 /*----------------------------------------------------------------*/
00297 /*----------------------------------------------------------------*/
00298 const char *
00299 sinfo_tostring_cpl_frame_group(cpl_frame_group fg)
00300 {
00301     switch(fg)
00302     {
00303     case CPL_FRAME_GROUP_NONE:    return "NONE";                    break;
00304     case CPL_FRAME_GROUP_RAW:     return CPL_FRAME_GROUP_RAW_ID;    break;
00305     case CPL_FRAME_GROUP_CALIB:   return CPL_FRAME_GROUP_CALIB_ID;  break;
00306     case CPL_FRAME_GROUP_PRODUCT: return CPL_FRAME_GROUP_PRODUCT_ID;break;
00307     default:
00308         return "unrecognized frame group";
00309     }
00310 }
00311 
00312 /*----------------------------------------------------------------*/
00318 /*----------------------------------------------------------------*/
00319 const char *
00320 sinfo_tostring_cpl_frame_level(cpl_frame_level fl)
00321 {
00322     
00323     switch(fl)
00324     {
00325     case CPL_FRAME_LEVEL_NONE:        return "NONE";        break;
00326     case CPL_FRAME_LEVEL_TEMPORARY:   return "TEMPORARY";   break;
00327     case CPL_FRAME_LEVEL_INTERMEDIATE:return "INTERMEDIATE";break;
00328     case CPL_FRAME_LEVEL_FINAL:       return "FINAL";       break;
00329     default: return "unrecognized frame level";
00330     }
00331 }
00332 
00333 
00334 /*----------------------------------------------------------------*/
00340 /*----------------------------------------------------------------*/
00341 const char *
00342 sinfo_tostring_cpl_type(cpl_type t)
00343 {
00344 
00345     /* Note that CPL_TYPE_STRING is shorthand
00346        for CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY . */
00347 
00348     if (!(t & CPL_TYPE_FLAG_ARRAY))
00349     switch(t & (~CPL_TYPE_FLAG_ARRAY))
00350         {
00351         case CPL_TYPE_CHAR:       return "char";    break;
00352         case CPL_TYPE_UCHAR:      return "uchar";   break;
00353         case CPL_TYPE_BOOL:       return "boolean"; break;
00354         case CPL_TYPE_INT:        return "int";     break;
00355         case CPL_TYPE_UINT:       return "uint";    break;
00356         case CPL_TYPE_LONG:       return "long";    break;
00357         case CPL_TYPE_ULONG:      return "ulong";   break;
00358         case CPL_TYPE_FLOAT:      return "float";   break;
00359         case CPL_TYPE_DOUBLE:     return "double";  break;
00360         case CPL_TYPE_POINTER:    return "pointer"; break;
00361 /* not in CPL3.0: case CPL_TYPE_COMPLEX:    return "complex"; break; */
00362         case CPL_TYPE_INVALID:    return "invalid"; break;
00363         default:
00364         return "unrecognized type";
00365         }
00366     else
00367     switch(t & (~CPL_TYPE_FLAG_ARRAY))
00368         {
00369         case CPL_TYPE_CHAR:       return "string (char array)"; break;
00370         case CPL_TYPE_UCHAR:      return "uchar array";         break;
00371         case CPL_TYPE_BOOL:       return "boolean array";       break;
00372         case CPL_TYPE_INT:        return "int array";           break;
00373         case CPL_TYPE_UINT:       return "uint array";          break;
00374         case CPL_TYPE_LONG:       return "long array";          break;
00375         case CPL_TYPE_ULONG:      return "ulong array";         break;
00376         case CPL_TYPE_FLOAT:      return "float array";         break;
00377         case CPL_TYPE_DOUBLE:     return "double array";        break;
00378         case CPL_TYPE_POINTER:    return "pointer array";       break;
00379 /* not in CPL3.0: case CPL_TYPE_COMPLEX:    return "complex array"; break; */
00380         case CPL_TYPE_INVALID:    return "invalid (array)";     break;
00381         default:
00382         return "unrecognized type";
00383         }
00384 }

Generated on Wed Jan 17 08:33:42 2007 for SINFONI Pipeline Reference Manual by  doxygen 1.4.4