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

Generated on 9 Mar 2012 for UVES Pipeline Reference Manual by  doxygen 1.6.1