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: 2008/01/17 07:54:04 $
00023  * $Revision: 1.6 $
00024  * $Name: sinfo-2_2_5 $
00025  * $Log: sinfo_dump.c,v $
00026  * Revision 1.6  2008/01/17 07:54:04  amodigli
00027  * shorten long lines
00028  *
00029  * Revision 1.5  2007/08/11 10:45:47  amodigli
00030  * upgrade to CPL4, fixed compil warnings
00031  *
00032  * Revision 1.4  2007/06/06 07:10:45  amodigli
00033  * replaced tab with 4 spaces
00034  *
00035  * Revision 1.3  2006/10/20 08:07:05  amodigli
00036  * using prefix sinfo_ in place of sinfoni_ for includes
00037  *
00038  * Revision 1.2  2006/10/16 07:26:23  amodigli
00039  * shortened line length
00040  *
00041  * Revision 1.1  2006/08/09 12:20:11  amodigli
00042  * added sinfo_dump.h sinfo_dump.c
00043  *
00044  * Revision 1.7  2006/05/12 15:02:05  jmlarsen
00045  * Support NULL tags
00046  *
00047  * Revision 1.6  2006/02/28 09:15:22  jmlarsen
00048  * Minor update
00049  *
00050  * Revision 1.5  2006/02/15 13:19:15  jmlarsen
00051  * Reduced source code max. line length
00052  *
00053  * Revision 1.4  2005/12/19 16:17:56  jmlarsen
00054  * Replaced bool -> int
00055  *
00056  */
00057 
00058 #ifdef HAVE_CONFIG_H
00059 #  include <config.h>
00060 #endif
00061 
00062 /*----------------------------------------------------------------------------*/
00069 /*----------------------------------------------------------------------------*/
00070 
00073 #include <sinfo_dump.h>
00074 #include <sinfo_utils.h>
00075 #include <sinfo_error.h>
00076 #include <sinfo_msg.h>
00077 #include <cpl.h>
00078 
00079 /*----------------------------------------------------------------*/
00091 /*----------------------------------------------------------------*/
00092 cpl_error_code
00093 sinfo_print_cpl_propertylist(const cpl_propertylist *pl, long low, long high)
00094 {
00095     cpl_property *prop;
00096     long i = 0;
00097     
00098     assure (0 <= low && high <= cpl_propertylist_get_size(pl) && low <= high,
00099         CPL_ERROR_ILLEGAL_INPUT, "Illegal range");
00100     /* Printing an empty range is allowed but only when low == high */
00101 
00102     if (pl == NULL){
00103     sinfo_msg("NULL");
00104     }
00105     else if (cpl_propertylist_is_empty(pl))  {
00106     sinfo_msg("[Empty property list]");
00107     }
00108     else    
00109     for (i = low; i < high; i++)
00110         {
00111         /* bug workaround: remove const cast when declaration 
00112            of cpl_propertylist_get() is changed */
00113         prop = cpl_propertylist_get((cpl_propertylist *)pl, i);
00114         check (sinfo_print_cpl_property(prop), 
00115                 "Error printing property");
00116         }
00117     
00118   cleanup:
00119     return cpl_error_get_code();
00120 }
00121 /*----------------------------------------------------------------*/
00129 /*----------------------------------------------------------------*/
00130 
00131 cpl_error_code
00132 sinfo_print_cpl_property(const cpl_property *prop)
00133 {
00134     cpl_type t;
00135 
00136     if (prop == NULL)
00137     {
00138         sinfo_msg("NULL");
00139     }
00140     else
00141     {   
00142         /* print property with this formatting
00143            NAME =
00144              VALUE
00145            COMMENT
00146         */
00147 
00148         /* print name */
00149         
00150         sinfo_msg("%s =", cpl_property_get_name(prop));
00151 
00152         /* print value */
00153         
00154         check( t = cpl_property_get_type(prop), 
00155                   "Could not read property type");
00156         
00157         switch(t & (~CPL_TYPE_FLAG_ARRAY))
00158         {
00159         case CPL_TYPE_CHAR:
00160             if (t & CPL_TYPE_FLAG_ARRAY)  /* if type is string */
00161             {
00162                 sinfo_msg("  '%s'", cpl_property_get_string(prop));
00163             }
00164             else                          /* an ordinary char */
00165             {
00166                 sinfo_msg("  %c", cpl_property_get_char(prop));
00167             }
00168             break;
00169         case CPL_TYPE_BOOL:    if (cpl_property_get_bool(prop))
00170             {sinfo_msg("  true");}
00171         else
00172             {sinfo_msg("  false");}
00173             break;
00174         case CPL_TYPE_UCHAR: 
00175       sinfo_msg("%c",cpl_property_get_char(prop)); 
00176           break;
00177         case CPL_TYPE_INT:   
00178       sinfo_msg("%d",cpl_property_get_int(prop)); 
00179           break;
00180         case CPL_TYPE_UINT:  
00181           sinfo_msg("%d",cpl_property_get_int(prop)); 
00182           break;
00183         case CPL_TYPE_LONG: 
00184           sinfo_msg("%ld",cpl_property_get_long(prop)); 
00185           break;
00186         case CPL_TYPE_ULONG: 
00187           sinfo_msg("%ld",cpl_property_get_long(prop)); 
00188           break;
00189         case CPL_TYPE_FLOAT: 
00190           sinfo_msg("%f",cpl_property_get_float(prop)); 
00191           break;
00192         case CPL_TYPE_DOUBLE: 
00193           sinfo_msg("%f",cpl_property_get_double(prop)); 
00194           break;
00195         case CPL_TYPE_POINTER: 
00196           sinfo_msg("POINTER");    
00197           break;
00198         case CPL_TYPE_INVALID: 
00199           sinfo_msg("INVALID");    
00200           break;
00201         default: 
00202           sinfo_msg("  unrecognized property");  
00203           break;
00204         }
00205         
00206         /* Is this property an array? */
00207         if (t & CPL_TYPE_FLAG_ARRAY){
00208         sinfo_msg("  (array size = %ld)", cpl_property_get_size(prop));
00209         }
00210 
00211         /* Print comment */
00212         if (cpl_property_get_comment(prop) != NULL){
00213         sinfo_msg("    %s", cpl_property_get_comment(prop));
00214         }
00215     }
00216 
00217   cleanup:
00218     return cpl_error_get_code();
00219 }
00220 
00221 /*----------------------------------------------------------------*/
00229 /*----------------------------------------------------------------*/
00230 cpl_error_code
00231 sinfo_print_cpl_frameset(const cpl_frameset *frames)
00232 {
00233     /* Two special cases: a NULL frame set and an empty frame set */
00234 
00235     if (frames == NULL)
00236     {
00237         sinfo_msg("NULL");
00238     }
00239     else
00240     {
00241         const cpl_frame *f = NULL;
00242         check( f = cpl_frameset_get_first_const(frames), 
00243                    "Error reading frameset");
00244         
00245         if (f == NULL)
00246         {
00247             sinfo_msg("[Empty frame set]");
00248         }
00249         else
00250         {
00251             while(f != NULL)
00252             {
00253                 check( sinfo_print_cpl_frame(f), 
00254                                   "Could not print frame");
00255                 check( f = cpl_frameset_get_next_const(frames), 
00256                                   "Error reading frameset");
00257             }
00258         }
00259     }
00260     
00261   cleanup:
00262     return cpl_error_get_code();
00263 }
00264 
00265 /*----------------------------------------------------------------*/
00273 /*----------------------------------------------------------------*/
00274 cpl_error_code
00275 sinfo_print_cpl_frame(const cpl_frame *f)
00276 {
00277     if (f == NULL)
00278     {
00279         sinfo_msg("NULL");
00280     }
00281     else
00282     {
00283         sinfo_msg("%-7s %-20s '%s'", 
00284              sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)),
00285              cpl_frame_get_tag(f) != NULL ? 
00286                      cpl_frame_get_tag(f) : "Null",
00287              cpl_frame_get_filename(f));
00288         
00289         sinfo_msg_debug("type \t= %s",   
00290             sinfo_tostring_cpl_frame_type (cpl_frame_get_type (f)));
00291         sinfo_msg_debug("group \t= %s",  
00292             sinfo_tostring_cpl_frame_group(cpl_frame_get_group(f)));
00293         sinfo_msg_debug("level \t= %s",  
00294             sinfo_tostring_cpl_frame_level(cpl_frame_get_level(f)));
00295     }
00296 
00297     return cpl_error_get_code();
00298 }
00299 
00300 /*----------------------------------------------------------------*/
00306 /*----------------------------------------------------------------*/
00307 const char *
00308 sinfo_tostring_cpl_frame_type(cpl_frame_type ft)
00309 {    
00310     switch(ft)
00311     {
00312     case CPL_FRAME_TYPE_NONE:   return "NONE";      break;
00313     case CPL_FRAME_TYPE_IMAGE:  return "IMAGE";     break;
00314     case CPL_FRAME_TYPE_MATRIX: return "MATRIX";    break;
00315     case CPL_FRAME_TYPE_TABLE:  return "TABLE";     break;
00316     default: return "unrecognized frame type";
00317     }
00318 }
00319 
00320 /*----------------------------------------------------------------*/
00326 /*----------------------------------------------------------------*/
00327 const char *
00328 sinfo_tostring_cpl_frame_group(cpl_frame_group fg)
00329 {
00330     switch(fg)
00331     {
00332     case CPL_FRAME_GROUP_NONE:    return "NONE";                    break;
00333     case CPL_FRAME_GROUP_RAW:     return CPL_FRAME_GROUP_RAW_ID;    break;
00334     case CPL_FRAME_GROUP_CALIB:   return CPL_FRAME_GROUP_CALIB_ID;  break;
00335     case CPL_FRAME_GROUP_PRODUCT: return CPL_FRAME_GROUP_PRODUCT_ID;break;
00336     default:
00337         return "unrecognized frame group";
00338     }
00339 }
00340 
00341 /*----------------------------------------------------------------*/
00347 /*----------------------------------------------------------------*/
00348 const char *
00349 sinfo_tostring_cpl_frame_level(cpl_frame_level fl)
00350 {
00351     
00352     switch(fl)
00353     {
00354     case CPL_FRAME_LEVEL_NONE:        return "NONE";        break;
00355     case CPL_FRAME_LEVEL_TEMPORARY:   return "TEMPORARY";   break;
00356     case CPL_FRAME_LEVEL_INTERMEDIATE:return "INTERMEDIATE";break;
00357     case CPL_FRAME_LEVEL_FINAL:       return "FINAL";       break;
00358     default: return "unrecognized frame level";
00359     }
00360 }
00361 
00362 
00363 /*----------------------------------------------------------------*/
00369 /*----------------------------------------------------------------*/
00370 const char *
00371 sinfo_tostring_cpl_type(cpl_type t)
00372 {
00373 
00374     /* Note that CPL_TYPE_STRING is shorthand
00375        for CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY . */
00376 
00377     if (!(t & CPL_TYPE_FLAG_ARRAY))
00378     switch(t & (~CPL_TYPE_FLAG_ARRAY))
00379         {
00380         case CPL_TYPE_CHAR:       return "char";    break;
00381         case CPL_TYPE_UCHAR:      return "uchar";   break;
00382         case CPL_TYPE_BOOL:       return "boolean"; break;
00383         case CPL_TYPE_INT:        return "int";     break;
00384         case CPL_TYPE_UINT:       return "uint";    break;
00385         case CPL_TYPE_LONG:       return "long";    break;
00386         case CPL_TYPE_ULONG:      return "ulong";   break;
00387         case CPL_TYPE_FLOAT:      return "float";   break;
00388         case CPL_TYPE_DOUBLE:     return "double";  break;
00389         case CPL_TYPE_POINTER:    return "pointer"; break;
00390 /* not in CPL3.0: case CPL_TYPE_COMPLEX:    return "complex"; break; */
00391         case CPL_TYPE_INVALID:    return "invalid"; break;
00392         default:
00393         return "unrecognized type";
00394         }
00395     else
00396     switch(t & (~CPL_TYPE_FLAG_ARRAY))
00397         {
00398         case CPL_TYPE_CHAR:       return "string (char array)"; break;
00399         case CPL_TYPE_UCHAR:      return "uchar array";         break;
00400         case CPL_TYPE_BOOL:       return "boolean array";       break;
00401         case CPL_TYPE_INT:        return "int array";           break;
00402         case CPL_TYPE_UINT:       return "uint array";          break;
00403         case CPL_TYPE_LONG:       return "long array";          break;
00404         case CPL_TYPE_ULONG:      return "ulong array";         break;
00405         case CPL_TYPE_FLOAT:      return "float array";         break;
00406         case CPL_TYPE_DOUBLE:     return "double array";        break;
00407         case CPL_TYPE_POINTER:    return "pointer array";       break;
00408 /* not in CPL3.0: case CPL_TYPE_COMPLEX:    return "complex array"; break; */
00409         case CPL_TYPE_INVALID:    return "invalid (array)";     break;
00410         default:
00411         return "unrecognized type";
00412         }
00413 }

Generated on 8 Mar 2011 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1