MOAB: Mesh Oriented datABase  (version 5.2.1)
info.c
Go to the documentation of this file.
00001 #include "mhdf.h"
00002 #include <stdlib.h>
00003 #include <stdio.h>
00004 #include <string.h>
00005 #include <ctype.h>
00006 #include <H5Tpublic.h>
00007 
00008 static int print_file_summary( struct mhdf_FileDesc* data );
00009 
00010 int main( int argc, char* argv[] )
00011 {
00012     int                   result;
00013     mhdf_FileHandle       file;
00014     mhdf_Status           status;
00015     unsigned long         max_id;
00016     struct mhdf_FileDesc* data;
00017 
00018     if( argc != 2 )
00019     {
00020         fprintf( stderr, "Usage: %s <filename>\n", argv[ 0 ] );
00021         return 1;
00022     }
00023 
00024     file = mhdf_openFile( argv[ 1 ], 0, &max_id, -1, &status );
00025     if( mhdf_isError( &status ) )
00026     {
00027         fprintf( stderr, "%s: %s\n", argv[ 1 ], mhdf_message( &status ) );
00028         return 1;
00029     }
00030 
00031     data = mhdf_getFileSummary( file, H5T_NATIVE_ULONG, &status, 0 ); /* no extra set info here*/
00032     if( mhdf_isError( &status ) )
00033     {
00034         fprintf( stderr, "%s: %s\n", argv[ 1 ], mhdf_message( &status ) );
00035         return 1;
00036     }
00037 
00038     mhdf_closeFile( file, &status );
00039 
00040     printf( "%s:\n", argv[ 1 ] );
00041     result = print_file_summary( data );
00042     free( data );
00043     return result;
00044 }
00045 
00046 static void print_ent_desc( const char* name, const char* subname, struct mhdf_EntDesc* data, const char* vals_label,
00047                             const char* extra_label, struct mhdf_FileDesc* all )
00048 {
00049     int i, len = 10;
00050 
00051     if( vals_label && (int)strlen( vals_label ) > len ) len = strlen( vals_label );
00052     if( extra_label && (int)strlen( extra_label ) > len ) len = strlen( extra_label );
00053 
00054     if( subname )
00055         printf( "    %s (%s):\n", name, subname );
00056     else
00057         printf( "    %s:\n", name );
00058 
00059     if( vals_label ) printf( "      %-*s: %d\n", len, vals_label, data->vals_per_ent );
00060 
00061     printf( "      %-*s: %ld [%ld - %ld]\n", len, "entities", data->count, data->start_id,
00062             data->start_id + data->count - 1 );
00063 
00064     if( extra_label ) printf( "      %-*s\n", len, extra_label );
00065 
00066     if( !data->num_dense_tags ) return;
00067 
00068     printf( "      %-*s: \"%s\"", len, "dense tags", all->tags[ data->dense_tag_indices[ 0 ] ].name );
00069     for( i = 1; i < data->num_dense_tags; ++i )
00070         printf( ", \"%s\"", all->tags[ data->dense_tag_indices[ i ] ].name );
00071     printf( "\n" );
00072 }
00073 
00074 static void print_elem_desc( struct mhdf_ElemDesc* data, struct mhdf_FileDesc* all )
00075 {
00076     const char* adj = data->have_adj ? "adjacencies" : "no adjencies";
00077     print_ent_desc( data->handle, data->type, &data->desc, "nodes per element", adj, all );
00078 }
00079 
00080 static const char* tag_type_name( enum mhdf_TagDataType type )
00081 {
00082     static const char opaque[] = "opaque";
00083     static const char integer[] = "integer";
00084     static const char real[] = "real";
00085     static const char bits[] = "bit field";
00086     static const char boolean[] = "boolean";
00087     static const char id[] = "entity id";
00088     static const char unknown[] = "(UNKNOWN TYPE ID)";
00089     switch( type )
00090     {
00091         case mhdf_OPAQUE:
00092             return opaque;
00093         case mhdf_INTEGER:
00094             return integer;
00095         case mhdf_FLOAT:
00096             return real;
00097         case mhdf_BITFIELD:
00098             return bits;
00099         case mhdf_BOOLEAN:
00100             return boolean;
00101         case mhdf_ENTITY_ID:
00102             return id;
00103     }
00104     return unknown;
00105 }
00106 
00107 static const char* string_tag_value( const void* value, enum mhdf_TagDataType type, int size )
00108 {
00109     static char          buffer[ 1024 ];
00110     const char*          data = value;
00111     char*                offset = buffer;
00112     int                  print, i;
00113     const int*           intptr = value;
00114     const double*        dblptr = value;
00115     const unsigned long* idptr = value;
00116 
00117     if( size <= 0 )
00118     {
00119         *buffer = '\0';
00120         return buffer;
00121     }
00122 
00123     switch( type )
00124     {
00125         case mhdf_OPAQUE:
00126             print = 1;
00127             for( i = 0; i < size; ++i )
00128                 if( !isprint( data[ i ] ) ) print = 0;
00129             if( print )
00130             {
00131                 offset[ 0 ] = '"';
00132                 memcpy( offset + 1, data, size );
00133                 offset[ size + 1 ] = '"';
00134                 offset[ size + 2 ] = '\0';
00135                 offset += size + 2;
00136             }
00137             else
00138             {
00139                 strcpy( offset, "0x" );
00140                 offset += 2;
00141                 for( i = 0; i < size; ++i )
00142                     offset += sprintf( offset, "%02x", (unsigned int)data[ i ] );
00143             }
00144             break;
00145         case mhdf_INTEGER:
00146             if( size == 1 ) { offset += sprintf( offset, "%d", intptr[ 0 ] ); }
00147             else
00148             {
00149                 offset += sprintf( offset, "{%d", intptr[ 0 ] );
00150                 for( i = 1; i < size; ++i )
00151                     offset += sprintf( offset, ",%d", intptr[ i ] );
00152                 offset += sprintf( offset, "}" );
00153             }
00154             break;
00155         case mhdf_FLOAT:
00156             if( size == 1 ) { offset += sprintf( offset, "%g", dblptr[ 0 ] ); }
00157             else
00158             {
00159                 offset += sprintf( offset, "{%g", dblptr[ 0 ] );
00160                 for( i = 1; i < size; ++i )
00161                     offset += sprintf( offset, ",%g", dblptr[ i ] );
00162                 offset += sprintf( offset, "}" );
00163             }
00164             break;
00165         case mhdf_BITFIELD:
00166             if( size > 8 )
00167                 offset += sprintf( offset, "(more than 8 bits)" );
00168             else
00169             {
00170                 for( i = size - 1; i >= 0; --i )
00171                     *( offset++ ) = (char)( *data & ( 1 << i ) ? '1' : '0' );
00172                 *offset = '\0';
00173             }
00174             break;
00175         case mhdf_BOOLEAN:
00176             if( size == 1 ) { offset += sprintf( offset, "%s", data[ 0 ] ? "true" : "false" ); }
00177             else
00178             {
00179                 offset += sprintf( offset, "{%s", data[ 0 ] ? "true" : "false" );
00180                 for( i = 1; i < size; ++i )
00181                     offset += sprintf( offset, ",%s", data[ i ] ? "true" : "false" );
00182                 offset += sprintf( offset, "}" );
00183             }
00184             break;
00185         case mhdf_ENTITY_ID:
00186             if( size == 1 ) { offset += sprintf( offset, "%lu", idptr[ 0 ] ); }
00187             else
00188             {
00189                 offset += sprintf( offset, "{%lu", idptr[ 0 ] );
00190                 for( i = 1; i < size; ++i )
00191                     offset += sprintf( offset, ",%lu", idptr[ i ] );
00192                 offset += sprintf( offset, "}" );
00193             }
00194             break;
00195         default:
00196             strcpy( buffer, "(unknown data type)" );
00197             break;
00198     }
00199 
00200     return buffer;
00201 }
00202 
00203 static const char* ent_desc_name( struct mhdf_FileDesc* all, int idx )
00204 {
00205     static const char nodes[] = "Nodes";
00206     static const char sets[] = "Sets";
00207     static const char invalid[] = "<INVALID INDEX!>";
00208     if( idx == -2 ) return sets;
00209     if( idx == -1 ) return nodes;
00210     if( idx >= all->num_elem_desc || idx < -2 ) return invalid;
00211     return all->elems[ idx ].handle;
00212 }
00213 
00214 static void print_tag_desc( struct mhdf_TagDesc* data, struct mhdf_FileDesc* all )
00215 {
00216     int i, width = 8;
00217 
00218     printf( "    \"%s\":\n", data->name );
00219     printf( "      %-*s: %s\n", width, "type", tag_type_name( data->type ) );
00220     if( data->size < 0 )
00221         printf( "      %-*s: (variable)\n", width, "size" );
00222     else
00223         printf( "      %-*s: %d (%d bytes)\n", width, "size", data->size, data->bytes );
00224     printf( "      %-*s: %x\n", width, "flags", data->storage );
00225     if( data->default_value )
00226         printf( "      %-*s: %s\n", width, "default",
00227                 string_tag_value( data->default_value, data->type, data->default_value_size ) );
00228     if( data->global_value )
00229         printf( "      %-*s: %s\n", width, "mesh val",
00230                 string_tag_value( data->global_value, data->type, data->global_value_size ) );
00231     if( data->have_sparse )
00232     {
00233         printf( "      %-*s: (sparse)", width, "tables" );
00234         for( i = 0; i < data->num_dense_indices; ++i )
00235             printf( ", %s", ent_desc_name( all, data->dense_elem_indices[ i ] ) );
00236     }
00237     else if( data->num_dense_indices )
00238     {
00239         printf( "      %-*s: %s", width, "tables", ent_desc_name( all, data->dense_elem_indices[ 0 ] ) );
00240         for( i = 1; i < data->num_dense_indices; ++i )
00241             printf( ", %s", ent_desc_name( all, data->dense_elem_indices[ i ] ) );
00242     }
00243     else
00244     {
00245         printf( "      %-*s: (none)", width, "tables" );
00246     }
00247     printf( "\n" );
00248 }
00249 
00250 static int print_file_summary( struct mhdf_FileDesc* data )
00251 {
00252     int i;
00253 
00254     printf( "  Entities:\n" );
00255     print_ent_desc( "Nodes", NULL, &data->nodes, "dimension", NULL, data );
00256     for( i = 0; i < data->num_elem_desc; ++i )
00257         print_elem_desc( data->elems + i, data );
00258     print_ent_desc( "Sets", NULL, &data->sets, NULL, NULL, data );
00259 
00260     printf( "  Tags:\n" );
00261     for( i = 0; i < data->num_tag_desc; ++i )
00262         print_tag_desc( data->tags + i, data );
00263 
00264     return 0;
00265 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines