uves_dump.c

00001 /*                                                                              *
00002  *   This file is part of the X-SHOOTER 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: 2010/09/24 09:32:03 $
00023  * $Revision: 1.22 $
00024  * $Name: uves-4_9_1 $
00025  * $Log: uves_dump.c,v $
00026  * Revision 1.22  2010/09/24 09:32:03  amodigli
00027  * put back QFITS dependency to fix problem spot by NRI on FIBER mode (with MIDAS calibs) data
00028  *
00029  * Revision 1.20  2007/08/21 13:08:26  jmlarsen
00030  * Removed irplib_access module, largely deprecated by CPL-4
00031  *
00032  * Revision 1.19  2007/06/06 08:17:33  amodigli
00033  * replace tab with 4 spaces
00034  *
00035  * Revision 1.18  2007/04/24 12:50:29  jmlarsen
00036  * Replaced cpl_propertylist -> uves_propertylist which is much faster
00037  *
00038  * Revision 1.17  2007/04/24 09:26:11  jmlarsen
00039  * Do not crash on NULL strings
00040  *
00041  * Revision 1.16  2006/11/24 09:36:07  jmlarsen
00042  * Removed obsolete comment
00043  *
00044  * Revision 1.15  2006/11/16 14:12:21  jmlarsen
00045  * Changed undefined trace number from 0 to -1, to support zero as an actual trace number
00046  *
00047  * Revision 1.14  2006/11/15 15:02:14  jmlarsen
00048  * Implemented const safe workarounds for CPL functions
00049  *
00050  * Revision 1.12  2006/11/15 14:04:08  jmlarsen
00051  * Removed non-const version of parameterlist_get_first/last/next which is already
00052  * in CPL, added const-safe wrapper, unwrapper and deallocator functions
00053  *
00054  * Revision 1.11  2006/11/13 14:23:55  jmlarsen
00055  * Removed workarounds for CPL const bugs
00056  *
00057  * Revision 1.10  2006/11/06 15:19:41  jmlarsen
00058  * Removed unused include directives
00059  *
00060  * Revision 1.9  2006/08/17 13:56:52  jmlarsen
00061  * Reduced max line length
00062  *
00063  * Revision 1.8  2006/08/16 11:46:30  jmlarsen
00064  * Support printing NULL frame filename
00065  *
00066  * Revision 1.7  2006/05/12 15:02:05  jmlarsen
00067  * Support NULL tags
00068  *
00069  * Revision 1.6  2006/02/28 09:15:22  jmlarsen
00070  * Minor update
00071  *
00072  * Revision 1.5  2006/02/15 13:19:15  jmlarsen
00073  * Reduced source code max. line length
00074  *
00075  * Revision 1.4  2005/12/19 16:17:56  jmlarsen
00076  * Replaced bool -> int
00077  *
00078  */
00079 
00080 #ifdef HAVE_CONFIG_H
00081 #  include <config.h>
00082 #endif
00083 
00084 /*----------------------------------------------------------------------------*/
00091 /*----------------------------------------------------------------------------*/
00092 
00095 #include <uves_dump.h>
00096 
00097 #include <uves_msg.h>
00098 #include <uves_error.h>
00099 
00100 #include <cpl.h>
00101 
00102 /*----------------------------------------------------------------*/
00114 /*----------------------------------------------------------------*/
00115 cpl_error_code
00116 uves_print_uves_propertylist(const uves_propertylist *pl, long low, long high)
00117 {
00118     const cpl_property *prop;
00119     long i = 0;
00120     
00121     assure (0 <= low && high <= uves_propertylist_get_size(pl) && low <= high,
00122         CPL_ERROR_ILLEGAL_INPUT, "Illegal range");
00123     /* Printing an empty range is allowed but only when low == high */
00124 
00125     if (pl == NULL){
00126     uves_msg("NULL");
00127     }
00128     else if (uves_propertylist_is_empty(pl))  {
00129     uves_msg("[Empty property list]");
00130     }
00131     else    
00132     for (i = low; i < high; i++)
00133         {
00134         prop = uves_propertylist_get_const(pl, i);
00135         check (uves_print_cpl_property(prop), "Error printing property");
00136         }
00137     
00138   cleanup:
00139     return cpl_error_get_code();
00140 }
00141 /*----------------------------------------------------------------*/
00149 /*----------------------------------------------------------------*/
00150 
00151 cpl_error_code
00152 uves_print_cpl_property(const cpl_property *prop)
00153 {
00154     cpl_type t;
00155 
00156     if (prop == NULL)
00157     {
00158         uves_msg("NULL");
00159     }
00160     else
00161     {   
00162         /* print property with this formatting
00163            NAME =
00164              VALUE
00165            COMMENT
00166         */
00167 
00168         /* print name */
00169         
00170         uves_msg("%s =", cpl_property_get_name(prop) != NULL ?
00171                      cpl_property_get_name(prop) : "NULL");
00172             
00173         /* print value */
00174         
00175         check( t = cpl_property_get_type(prop), "Could not read property type");
00176         
00177         switch(t & (~CPL_TYPE_FLAG_ARRAY))
00178         {
00179         case CPL_TYPE_CHAR:
00180             if (t & CPL_TYPE_FLAG_ARRAY)  /* if type is string */
00181             {
00182                 uves_msg("  '%s'", cpl_property_get_string(prop) != NULL ?
00183                                 cpl_property_get_string(prop) : "NULL");
00184             }
00185             else                          /* an ordinary char */
00186             {
00187                 uves_msg("  %c", cpl_property_get_char(prop));
00188             }
00189             break;
00190         case CPL_TYPE_BOOL:    if (cpl_property_get_bool(prop))
00191             {uves_msg("  true");}
00192         else
00193             {uves_msg("  false");}
00194             break;
00195         case CPL_TYPE_UCHAR:   uves_msg("  %c", cpl_property_get_char(prop));  break;
00196         case CPL_TYPE_INT:     uves_msg("  %d", cpl_property_get_int(prop));   break;
00197         case CPL_TYPE_UINT:    uves_msg("  %d", cpl_property_get_int(prop));   break;
00198         case CPL_TYPE_LONG:    uves_msg("  %ld", cpl_property_get_long(prop)); break;
00199         case CPL_TYPE_ULONG:   uves_msg("  %ld", cpl_property_get_long(prop)); break;
00200         case CPL_TYPE_FLOAT:   uves_msg("  %f", cpl_property_get_float(prop)); break;
00201         case CPL_TYPE_DOUBLE:  uves_msg("  %f", cpl_property_get_double(prop));break;
00202         case CPL_TYPE_POINTER: uves_msg("  POINTER");                          break;
00203         case CPL_TYPE_INVALID: uves_msg("  INVALID");                          break;
00204         default: uves_msg("  unrecognized property");                          break;
00205         }
00206         
00207         /* Is this property an array? */
00208         if (t & CPL_TYPE_FLAG_ARRAY){
00209         uves_msg("  (array size = %ld)", cpl_property_get_size(prop));
00210         }
00211 
00212         /* Print comment */
00213         if (cpl_property_get_comment(prop) != NULL){
00214         uves_msg("    %s", cpl_property_get_comment(prop) != NULL ? 
00215                     cpl_property_get_comment(prop) : "NULL");
00216         }
00217     }
00218 
00219   cleanup:
00220     return cpl_error_get_code();
00221 }
00222 
00223 /*----------------------------------------------------------------*/
00231 /*----------------------------------------------------------------*/
00232 cpl_error_code
00233 uves_print_cpl_frameset(const cpl_frameset *frames)
00234 {
00235     /* Two special cases: a NULL frame set and an empty frame set */
00236 
00237     if (frames == NULL)
00238     {
00239         uves_msg("NULL");
00240     }
00241     else
00242     {
00243         const cpl_frame *f = NULL;
00244         check( f = cpl_frameset_get_first_const(frames), "Error reading frameset");
00245         
00246         if (f == NULL)
00247         {
00248             uves_msg("[Empty frame set]");
00249         }
00250         else
00251         {
00252             while(f != NULL)
00253             {
00254                 check( uves_print_cpl_frame(f), "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 uves_print_cpl_frame(const cpl_frame *f)
00276 {
00277     if (f == NULL)
00278     {
00279         uves_msg("NULL");
00280     }
00281     else
00282     {
00283         const char *filename = cpl_frame_get_filename(f);
00284 
00285         if (filename == NULL)
00286         {
00287             cpl_error_reset();
00288             filename = "Null";
00289         }
00290 
00291         uves_msg("%-7s %-20s '%s'", 
00292              uves_tostring_cpl_frame_group(cpl_frame_get_group(f)),
00293              cpl_frame_get_tag(f)      != NULL ? cpl_frame_get_tag(f) : "Null",
00294              filename);
00295         
00296         uves_msg_debug("type \t= %s",   uves_tostring_cpl_frame_type (cpl_frame_get_type (f)));
00297         uves_msg_debug("group \t= %s",  uves_tostring_cpl_frame_group(cpl_frame_get_group(f)));
00298         uves_msg_debug("level \t= %s",  uves_tostring_cpl_frame_level(cpl_frame_get_level(f)));
00299     }
00300 
00301     return cpl_error_get_code();
00302 }
00303 
00304 /*----------------------------------------------------------------*/
00310 /*----------------------------------------------------------------*/
00311 const char *
00312 uves_tostring_cpl_frame_type(cpl_frame_type ft)
00313 {    
00314     switch(ft)
00315     {
00316     case CPL_FRAME_TYPE_NONE:   return "NONE";      break;
00317     case CPL_FRAME_TYPE_IMAGE:  return "IMAGE";     break;
00318     case CPL_FRAME_TYPE_MATRIX: return "MATRIX";    break;
00319     case CPL_FRAME_TYPE_TABLE:  return "TABLE";     break;
00320     default: return "unrecognized frame type";
00321     }
00322 }
00323 
00324 /*----------------------------------------------------------------*/
00330 /*----------------------------------------------------------------*/
00331 const char *
00332 uves_tostring_cpl_frame_group(cpl_frame_group fg)
00333 {
00334     switch(fg)
00335     {
00336     case CPL_FRAME_GROUP_NONE:    return "NONE";                       break;
00337     case CPL_FRAME_GROUP_RAW:     return CPL_FRAME_GROUP_RAW_ID;       break;
00338     case CPL_FRAME_GROUP_CALIB:   return CPL_FRAME_GROUP_CALIB_ID;     break;
00339     case CPL_FRAME_GROUP_PRODUCT: return CPL_FRAME_GROUP_PRODUCT_ID;   break;
00340     default:
00341         return "unrecognized frame group";
00342     }
00343 }
00344 
00345 /*----------------------------------------------------------------*/
00351 /*----------------------------------------------------------------*/
00352 const char *
00353 uves_tostring_cpl_frame_level(cpl_frame_level fl)
00354 {
00355     
00356     switch(fl)
00357     {
00358     case CPL_FRAME_LEVEL_NONE:        return "NONE";        break;
00359     case CPL_FRAME_LEVEL_TEMPORARY:   return "TEMPORARY";   break;
00360     case CPL_FRAME_LEVEL_INTERMEDIATE:return "INTERMEDIATE";break;
00361     case CPL_FRAME_LEVEL_FINAL:       return "FINAL";       break;
00362     default: return "unrecognized frame level";
00363     }
00364 }
00365 
00366 
00367 /*----------------------------------------------------------------*/
00373 /*----------------------------------------------------------------*/
00374 const char *
00375 uves_tostring_cpl_type(cpl_type t)
00376 {
00377 
00378     /* Note that CPL_TYPE_STRING is shorthand
00379        for CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY . */
00380 
00381     if (!(t & CPL_TYPE_FLAG_ARRAY))
00382     switch(t & (~CPL_TYPE_FLAG_ARRAY))
00383         {
00384         case CPL_TYPE_CHAR:       return "char";    break;
00385         case CPL_TYPE_UCHAR:      return "uchar";   break;
00386         case CPL_TYPE_BOOL:       return "boolean"; break;
00387         case CPL_TYPE_INT:        return "int";     break;
00388         case CPL_TYPE_UINT:       return "uint";    break;
00389         case CPL_TYPE_LONG:       return "long";    break;
00390         case CPL_TYPE_ULONG:      return "ulong";   break;
00391         case CPL_TYPE_FLOAT:      return "float";   break;
00392         case CPL_TYPE_DOUBLE:     return "double";  break;
00393         case CPL_TYPE_POINTER:    return "pointer"; break;
00394 /* not in CPL3.0: case CPL_TYPE_COMPLEX:    return "complex"; break; */
00395         case CPL_TYPE_INVALID:    return "invalid"; break;
00396         default:
00397         return "unrecognized type";
00398         }
00399     else
00400     switch(t & (~CPL_TYPE_FLAG_ARRAY))
00401         {
00402         case CPL_TYPE_CHAR:       return "string (char array)"; break;
00403         case CPL_TYPE_UCHAR:      return "uchar array";         break;
00404         case CPL_TYPE_BOOL:       return "boolean array";       break;
00405         case CPL_TYPE_INT:        return "int array";           break;
00406         case CPL_TYPE_UINT:       return "uint array";          break;
00407         case CPL_TYPE_LONG:       return "long array";          break;
00408         case CPL_TYPE_ULONG:      return "ulong array";         break;
00409         case CPL_TYPE_FLOAT:      return "float array";         break;
00410         case CPL_TYPE_DOUBLE:     return "double array";        break;
00411         case CPL_TYPE_POINTER:    return "pointer array";       break;
00412 /* not in CPL3.0: case CPL_TYPE_COMPLEX:    return "complex array"; break; */
00413         case CPL_TYPE_INVALID:    return "invalid (array)";     break;
00414         default:
00415         return "unrecognized type";
00416         }
00417 }

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