Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
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, 00047 const char* subname, 00048 struct mhdf_EntDesc* data, 00049 const char* vals_label, 00050 const char* extra_label, 00051 struct mhdf_FileDesc* all ) 00052 { 00053 int i, len = 10; 00054 00055 if( vals_label && (int)strlen( vals_label ) > len ) len = strlen( vals_label ); 00056 if( extra_label && (int)strlen( extra_label ) > len ) len = strlen( extra_label ); 00057 00058 if( subname ) 00059 printf( " %s (%s):\n", name, subname ); 00060 else 00061 printf( " %s:\n", name ); 00062 00063 if( vals_label ) printf( " %-*s: %d\n", len, vals_label, data->vals_per_ent ); 00064 00065 printf( " %-*s: %ld [%ld - %ld]\n", len, "entities", data->count, data->start_id, 00066 data->start_id + data->count - 1 ); 00067 00068 if( extra_label ) printf( " %-*s\n", len, extra_label ); 00069 00070 if( !data->num_dense_tags ) return; 00071 00072 printf( " %-*s: \"%s\"", len, "dense tags", all->tags[data->dense_tag_indices[0]].name ); 00073 for( i = 1; i < data->num_dense_tags; ++i ) 00074 printf( ", \"%s\"", all->tags[data->dense_tag_indices[i]].name ); 00075 printf( "\n" ); 00076 } 00077 00078 static void print_elem_desc( struct mhdf_ElemDesc* data, struct mhdf_FileDesc* all ) 00079 { 00080 const char* adj = data->have_adj ? "adjacencies" : "no adjencies"; 00081 print_ent_desc( data->handle, data->type, &data->desc, "nodes per element", adj, all ); 00082 } 00083 00084 static const char* tag_type_name( enum mhdf_TagDataType type ) 00085 { 00086 static const char opaque[] = "opaque"; 00087 static const char integer[] = "integer"; 00088 static const char real[] = "real"; 00089 static const char bits[] = "bit field"; 00090 static const char boolean[] = "boolean"; 00091 static const char id[] = "entity id"; 00092 static const char unknown[] = "(UNKNOWN TYPE ID)"; 00093 switch( type ) 00094 { 00095 case mhdf_OPAQUE: 00096 return opaque; 00097 case mhdf_INTEGER: 00098 return integer; 00099 case mhdf_FLOAT: 00100 return real; 00101 case mhdf_BITFIELD: 00102 return bits; 00103 case mhdf_BOOLEAN: 00104 return boolean; 00105 case mhdf_ENTITY_ID: 00106 return id; 00107 } 00108 return unknown; 00109 } 00110 00111 static const char* string_tag_value( const void* value, enum mhdf_TagDataType type, int size ) 00112 { 00113 static char buffer[1024]; 00114 const char* data = value; 00115 char* offset = buffer; 00116 int print, i; 00117 const int* intptr = value; 00118 const double* dblptr = value; 00119 const unsigned long* idptr = value; 00120 00121 if( size <= 0 ) 00122 { 00123 *buffer = '\0'; 00124 return buffer; 00125 } 00126 00127 switch( type ) 00128 { 00129 case mhdf_OPAQUE: 00130 print = 1; 00131 for( i = 0; i < size; ++i ) 00132 if( !isprint( data[i] ) ) print = 0; 00133 if( print ) 00134 { 00135 offset[0] = '"'; 00136 memcpy( offset + 1, data, size ); 00137 offset[size + 1] = '"'; 00138 offset[size + 2] = '\0'; 00139 offset += size + 2; 00140 } 00141 else 00142 { 00143 strcpy( offset, "0x" ); 00144 offset += 2; 00145 for( i = 0; i < size; ++i ) 00146 offset += sprintf( offset, "%02x", (unsigned int)data[i] ); 00147 } 00148 break; 00149 case mhdf_INTEGER: 00150 if( size == 1 ) 00151 { 00152 offset += sprintf( offset, "%d", intptr[0] ); 00153 } 00154 else 00155 { 00156 offset += sprintf( offset, "{%d", intptr[0] ); 00157 for( i = 1; i < size; ++i ) 00158 offset += sprintf( offset, ",%d", intptr[i] ); 00159 offset += sprintf( offset, "}" ); 00160 } 00161 break; 00162 case mhdf_FLOAT: 00163 if( size == 1 ) 00164 { 00165 offset += sprintf( offset, "%g", dblptr[0] ); 00166 } 00167 else 00168 { 00169 offset += sprintf( offset, "{%g", dblptr[0] ); 00170 for( i = 1; i < size; ++i ) 00171 offset += sprintf( offset, ",%g", dblptr[i] ); 00172 offset += sprintf( offset, "}" ); 00173 } 00174 break; 00175 case mhdf_BITFIELD: 00176 if( size > 8 ) 00177 offset += sprintf( offset, "(more than 8 bits)" ); 00178 else 00179 { 00180 for( i = size - 1; i >= 0; --i ) 00181 *( offset++ ) = (char)( *data & ( 1 << i ) ? '1' : '0' ); 00182 *offset = '\0'; 00183 } 00184 break; 00185 case mhdf_BOOLEAN: 00186 if( size == 1 ) 00187 { 00188 offset += sprintf( offset, "%s", data[0] ? "true" : "false" ); 00189 } 00190 else 00191 { 00192 offset += sprintf( offset, "{%s", data[0] ? "true" : "false" ); 00193 for( i = 1; i < size; ++i ) 00194 offset += sprintf( offset, ",%s", data[i] ? "true" : "false" ); 00195 offset += sprintf( offset, "}" ); 00196 } 00197 break; 00198 case mhdf_ENTITY_ID: 00199 if( size == 1 ) 00200 { 00201 offset += sprintf( offset, "%lu", idptr[0] ); 00202 } 00203 else 00204 { 00205 offset += sprintf( offset, "{%lu", idptr[0] ); 00206 for( i = 1; i < size; ++i ) 00207 offset += sprintf( offset, ",%lu", idptr[i] ); 00208 offset += sprintf( offset, "}" ); 00209 } 00210 break; 00211 default: 00212 strcpy( buffer, "(unknown data type)" ); 00213 break; 00214 } 00215 00216 return buffer; 00217 } 00218 00219 static const char* ent_desc_name( struct mhdf_FileDesc* all, int idx ) 00220 { 00221 static const char nodes[] = "Nodes"; 00222 static const char sets[] = "Sets"; 00223 static const char invalid[] = "<INVALID INDEX!>"; 00224 if( idx == -2 ) return sets; 00225 if( idx == -1 ) return nodes; 00226 if( idx >= all->num_elem_desc || idx < -2 ) return invalid; 00227 return all->elems[idx].handle; 00228 } 00229 00230 static void print_tag_desc( struct mhdf_TagDesc* data, struct mhdf_FileDesc* all ) 00231 { 00232 int i, width = 8; 00233 00234 printf( " \"%s\":\n", data->name ); 00235 printf( " %-*s: %s\n", width, "type", tag_type_name( data->type ) ); 00236 if( data->size < 0 ) 00237 printf( " %-*s: (variable)\n", width, "size" ); 00238 else 00239 printf( " %-*s: %d (%d bytes)\n", width, "size", data->size, data->bytes ); 00240 printf( " %-*s: %x\n", width, "flags", data->storage ); 00241 if( data->default_value ) 00242 printf( " %-*s: %s\n", width, "default", 00243 string_tag_value( data->default_value, data->type, data->default_value_size ) ); 00244 if( data->global_value ) 00245 printf( " %-*s: %s\n", width, "mesh val", 00246 string_tag_value( data->global_value, data->type, data->global_value_size ) ); 00247 if( data->have_sparse ) 00248 { 00249 printf( " %-*s: (sparse)", width, "tables" ); 00250 for( i = 0; i < data->num_dense_indices; ++i ) 00251 printf( ", %s", ent_desc_name( all, data->dense_elem_indices[i] ) ); 00252 } 00253 else if( data->num_dense_indices ) 00254 { 00255 printf( " %-*s: %s", width, "tables", ent_desc_name( all, data->dense_elem_indices[0] ) ); 00256 for( i = 1; i < data->num_dense_indices; ++i ) 00257 printf( ", %s", ent_desc_name( all, data->dense_elem_indices[i] ) ); 00258 } 00259 else 00260 { 00261 printf( " %-*s: (none)", width, "tables" ); 00262 } 00263 printf( "\n" ); 00264 } 00265 00266 static int print_file_summary( struct mhdf_FileDesc* data ) 00267 { 00268 int i; 00269 00270 printf( " Entities:\n" ); 00271 print_ent_desc( "Nodes", NULL, &data->nodes, "dimension", NULL, data ); 00272 for( i = 0; i < data->num_elem_desc; ++i ) 00273 print_elem_desc( data->elems + i, data ); 00274 print_ent_desc( "Sets", NULL, &data->sets, NULL, NULL, data ); 00275 00276 printf( " Tags:\n" ); 00277 for( i = 0; i < data->num_tag_desc; ++i ) 00278 print_tag_desc( data->tags + i, data ); 00279 00280 return 0; 00281 }