MOAB: Mesh Oriented datABase  (version 5.5.0)
mhdf_public_test.cpp File Reference
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include "moab/mhdf_public.h"
+ Include dependency graph for mhdf_public_test.cpp:

Go to the source code of this file.

Functions

static int print_file_summary (MHDF_FileDesc *data)
 
int main (int argc, char *argv[])
 
static void print_ent_desc (const char *name, const char *subname, MHDF_EntDesc *data, const char *vals_label, const char *extra_label, MHDF_FileDesc *all)
 
static void print_elem_desc (MHDF_ElemDesc *data, MHDF_FileDesc *all)
 
static const char * tag_type_name (MHDF_TagDataType type)
 
static const char * string_tag_value (const void *value, MHDF_TagDataType type, int size)
 
static const char * ent_desc_name (MHDF_FileDesc *all, int idx)
 
static void print_tag_desc (MHDF_TagDesc *data, MHDF_FileDesc *all)
 

Function Documentation

◆ ent_desc_name()

static const char* ent_desc_name ( MHDF_FileDesc all,
int  idx 
)
static

Definition at line 218 of file mhdf_public_test.cpp.

219 {
220  static const char nodes[] = "Nodes";
221  static const char sets[] = "Sets";
222  static const char invalid[] = "<INVALID INDEX!>";
223  if( idx == -2 ) return sets;
224  if( idx == -1 ) return nodes;
225  if( idx >= all->num_elem_desc || idx < -2 ) return invalid;
226  return all->elems[idx].handle;
227 }

References mhdf_FileDesc::elems, mhdf_ElemDesc::handle, and mhdf_FileDesc::num_elem_desc.

Referenced by print_tag_desc().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 9 of file mhdf_public_test.cpp.

10 {
11  int result;
12  MHDF_FileHandle file;
13  MHDF_Status status;
14  unsigned long max_id;
15  MHDF_FileDesc* data;
16 
17  if( argc != 2 )
18  {
19  fprintf( stderr, "Usage: %s <filename>\n", argv[0] );
20  return 0;
21  }
22 
23  file = mhdf_openFile( argv[1], 0, &max_id, -1, &status );
24  if( mhdf_isError( &status ) )
25  {
26  fprintf( stderr, "%s: %s\n", argv[1], mhdf_message( &status ) );
27  return 1;
28  }
29 
30  data = mhdf_getFileSummary( file, H5T_NATIVE_ULONG, &status, 1 );
31  if( mhdf_isError( &status ) )
32  {
33  fprintf( stderr, "%s: %s\n", argv[1], mhdf_message( &status ) );
34  return 1;
35  }
36 
37  mhdf_closeFile( file, &status );
38 
39  printf( "%s:\n", argv[1] );
40  result = print_file_summary( data );
41  free( data );
42  return result;
43 }

References mhdf_closeFile(), mhdf_getFileSummary(), mhdf_isError(), mhdf_message(), mhdf_openFile(), and print_file_summary().

◆ print_elem_desc()

static void print_elem_desc ( MHDF_ElemDesc data,
MHDF_FileDesc all 
)
static

Definition at line 77 of file mhdf_public_test.cpp.

78 {
79  const char* adj = data->have_adj ? "adjacencies" : "no adjencies";
80  print_ent_desc( data->handle, data->type, &data->desc, "nodes per element", adj, all );
81 }

References mhdf_ElemDesc::desc, mhdf_ElemDesc::handle, mhdf_ElemDesc::have_adj, print_ent_desc(), and mhdf_ElemDesc::type.

Referenced by print_file_summary().

◆ print_ent_desc()

static void print_ent_desc ( const char *  name,
const char *  subname,
MHDF_EntDesc data,
const char *  vals_label,
const char *  extra_label,
MHDF_FileDesc all 
)
static

Definition at line 45 of file mhdf_public_test.cpp.

51 {
52  int i, len = 10;
53 
54  if( vals_label && (int)strlen( vals_label ) > len ) len = strlen( vals_label );
55  if( extra_label && (int)strlen( extra_label ) > len ) len = strlen( extra_label );
56 
57  if( subname )
58  printf( " %s (%s):\n", name, subname );
59  else
60  printf( " %s:\n", name );
61 
62  if( vals_label ) printf( " %-*s: %d\n", len, vals_label, data->vals_per_ent );
63 
64  printf( " %-*s: %ld [%ld - %ld]\n", len, "entities", data->count, data->start_id,
65  data->start_id + data->count - 1 );
66 
67  if( extra_label ) printf( " %-*s\n", len, extra_label );
68 
69  if( !data->num_dense_tags ) return;
70 
71  printf( " %-*s: \"%s\"", len, "dense tags", all->tags[data->dense_tag_indices[0]].name );
72  for( i = 1; i < data->num_dense_tags; ++i )
73  printf( ", \"%s\"", all->tags[data->dense_tag_indices[i]].name );
74  printf( "\n" );
75 }

References mhdf_EntDesc::count, mhdf_EntDesc::dense_tag_indices, mhdf_TagDesc::name, mhdf_EntDesc::num_dense_tags, mhdf_EntDesc::start_id, mhdf_FileDesc::tags, and mhdf_EntDesc::vals_per_ent.

Referenced by print_elem_desc(), and print_file_summary().

◆ print_file_summary()

static int print_file_summary ( MHDF_FileDesc data)
static

Definition at line 265 of file mhdf_public_test.cpp.

266 {
267  int i;
268 
269  printf( " Entities:\n" );
270  print_ent_desc( "Nodes", NULL, &data->nodes, "dimension", NULL, data );
271  for( i = 0; i < data->num_elem_desc; ++i )
272  print_elem_desc( data->elems + i, data );
273  print_ent_desc( "Sets", NULL, &data->sets, NULL, NULL, data );
274 
275  printf( " Tags:\n" );
276  for( i = 0; i < data->num_tag_desc; ++i )
277  print_tag_desc( data->tags + i, data );
278 
279  printf( " Number partitions: %d\n", data->numEntSets[0] );
280  for( i = 0; i < data->numEntSets[0]; i++ )
281  printf( " set id %d value %d \n", data->defTagsEntSets[0][i], data->defTagsVals[0][i] );
282  printf( "\n Number material sets: %d\n", data->numEntSets[1] );
283  for( i = 0; i < data->numEntSets[1]; i++ )
284  printf( " set id %d value %d \n", data->defTagsEntSets[1][i], data->defTagsVals[1][i] );
285  printf( "\n Number neumann sets: %d\n", data->numEntSets[2] );
286  for( i = 0; i < data->numEntSets[2]; i++ )
287  printf( " set id %d value %d \n", data->defTagsEntSets[2][i], data->defTagsVals[2][i] );
288  printf( "\n Number dirichlet sets: %d\n", data->numEntSets[3] );
289  for( i = 0; i < data->numEntSets[3]; i++ )
290  printf( " set id %d value %d \n", data->defTagsEntSets[3][i], data->defTagsVals[3][i] );
291  printf( "\n Number geometry sets: %d\n", data->numEntSets[4] );
292  for( i = 0; i < data->numEntSets[4]; i++ )
293  printf( " set id %d value %d \n", data->defTagsEntSets[4][i], data->defTagsVals[4][i] );
294 
295  return 0;
296 }

References mhdf_FileDesc::defTagsEntSets, mhdf_FileDesc::defTagsVals, mhdf_FileDesc::elems, mhdf_FileDesc::nodes, mhdf_FileDesc::num_elem_desc, mhdf_FileDesc::num_tag_desc, mhdf_FileDesc::numEntSets, print_elem_desc(), print_ent_desc(), print_tag_desc(), mhdf_FileDesc::sets, and mhdf_FileDesc::tags.

Referenced by main().

◆ print_tag_desc()

static void print_tag_desc ( MHDF_TagDesc data,
MHDF_FileDesc all 
)
static

Definition at line 229 of file mhdf_public_test.cpp.

230 {
231  int i, width = 8;
232 
233  printf( " \"%s\":\n", data->name );
234  printf( " %-*s: %s\n", width, "type", tag_type_name( data->type ) );
235  if( data->size < 0 )
236  printf( " %-*s: (variable)\n", width, "size" );
237  else
238  printf( " %-*s: %d (%d bytes)\n", width, "size", data->size, data->bytes );
239  printf( " %-*s: %x\n", width, "flags", data->storage );
240  if( data->default_value )
241  printf( " %-*s: %s\n", width, "default",
242  string_tag_value( data->default_value, data->type, data->default_value_size ) );
243  if( data->global_value )
244  printf( " %-*s: %s\n", width, "mesh val",
245  string_tag_value( data->global_value, data->type, data->global_value_size ) );
246  if( data->have_sparse )
247  {
248  printf( " %-*s: (sparse)", width, "tables" );
249  for( i = 0; i < data->num_dense_indices; ++i )
250  printf( ", %s", ent_desc_name( all, data->dense_elem_indices[i] ) );
251  }
252  else if( data->num_dense_indices )
253  {
254  printf( " %-*s: %s", width, "tables", ent_desc_name( all, data->dense_elem_indices[0] ) );
255  for( i = 1; i < data->num_dense_indices; ++i )
256  printf( ", %s", ent_desc_name( all, data->dense_elem_indices[i] ) );
257  }
258  else
259  {
260  printf( " %-*s: (none)", width, "tables" );
261  }
262  printf( "\n" );
263 }

References mhdf_TagDesc::bytes, mhdf_TagDesc::default_value, mhdf_TagDesc::default_value_size, mhdf_TagDesc::dense_elem_indices, ent_desc_name(), mhdf_TagDesc::global_value, mhdf_TagDesc::global_value_size, mhdf_TagDesc::have_sparse, mhdf_TagDesc::name, mhdf_TagDesc::num_dense_indices, mhdf_TagDesc::size, mhdf_TagDesc::storage, string_tag_value(), tag_type_name(), and mhdf_TagDesc::type.

Referenced by print_file_summary().

◆ string_tag_value()

static const char* string_tag_value ( const void *  value,
MHDF_TagDataType  type,
int  size 
)
static

Definition at line 110 of file mhdf_public_test.cpp.

111 {
112  static char buffer[1024];
113  const char* data = (const char*)value;
114  char* offset = buffer;
115  int print, i;
116  const int* intptr = (const int*)value;
117  const double* dblptr = (const double*)value;
118  const unsigned long* idptr = (const unsigned long*)value;
119 
120  if( size <= 0 )
121  {
122  *buffer = '\0';
123  return buffer;
124  }
125 
126  switch( type )
127  {
128  case mhdf_OPAQUE:
129  print = 1;
130  for( i = 0; i < size; ++i )
131  if( !isprint( data[i] ) ) print = 0;
132  if( print )
133  {
134  offset[0] = '"';
135  memcpy( offset + 1, data, size );
136  offset[size + 1] = '"';
137  offset[size + 2] = '\0';
138  offset += size + 2;
139  }
140  else
141  {
142  strcpy( offset, "0x" );
143  offset += 2;
144  for( i = 0; i < size; ++i )
145  offset += sprintf( offset, "%02x", (unsigned int)data[i] );
146  }
147  break;
148  case mhdf_INTEGER:
149  if( size == 1 )
150  {
151  offset += sprintf( offset, "%d", intptr[0] );
152  }
153  else
154  {
155  offset += sprintf( offset, "{%d", intptr[0] );
156  for( i = 1; i < size; ++i )
157  offset += sprintf( offset, ",%d", intptr[i] );
158  offset += sprintf( offset, "}" );
159  }
160  break;
161  case mhdf_FLOAT:
162  if( size == 1 )
163  {
164  offset += sprintf( offset, "%g", dblptr[0] );
165  }
166  else
167  {
168  offset += sprintf( offset, "{%g", dblptr[0] );
169  for( i = 1; i < size; ++i )
170  offset += sprintf( offset, ",%g", dblptr[i] );
171  offset += sprintf( offset, "}" );
172  }
173  break;
174  case mhdf_BITFIELD:
175  if( size > 8 )
176  offset += sprintf( offset, "(more than 8 bits)" );
177  else
178  {
179  for( i = size - 1; i >= 0; --i )
180  *( offset++ ) = (char)( *data & ( 1 << i ) ? '1' : '0' );
181  *offset = '\0';
182  }
183  break;
184  case mhdf_BOOLEAN:
185  if( size == 1 )
186  {
187  offset += sprintf( offset, "%s", data[0] ? "true" : "false" );
188  }
189  else
190  {
191  offset += sprintf( offset, "{%s", data[0] ? "true" : "false" );
192  for( i = 1; i < size; ++i )
193  offset += sprintf( offset, ",%s", data[i] ? "true" : "false" );
194  offset += sprintf( offset, "}" );
195  }
196  break;
197  case mhdf_ENTITY_ID:
198  if( size == 1 )
199  {
200  offset += sprintf( offset, "%lu", idptr[0] );
201  }
202  else
203  {
204  offset += sprintf( offset, "{%lu", idptr[0] );
205  for( i = 1; i < size; ++i )
206  offset += sprintf( offset, ",%lu", idptr[i] );
207  offset += sprintf( offset, "}" );
208  }
209  break;
210  default:
211  strcpy( buffer, "(unknown data type)" );
212  break;
213  }
214 
215  return buffer;
216 }

References buffer, mhdf_BITFIELD, mhdf_BOOLEAN, mhdf_ENTITY_ID, mhdf_FLOAT, mhdf_INTEGER, mhdf_OPAQUE, and size.

Referenced by print_tag_desc().

◆ tag_type_name()

static const char* tag_type_name ( MHDF_TagDataType  type)
static

Definition at line 83 of file mhdf_public_test.cpp.

84 {
85  static const char opaque[] = "opaque";
86  static const char integer[] = "integer";
87  static const char real[] = "real";
88  static const char bits[] = "bit field";
89  static const char boolean[] = "boolean";
90  static const char id[] = "entity id";
91  static const char unknown[] = "(UNKNOWN TYPE ID)";
92  switch( type )
93  {
94  case mhdf_OPAQUE:
95  return opaque;
96  case mhdf_INTEGER:
97  return integer;
98  case mhdf_FLOAT:
99  return real;
100  case mhdf_BITFIELD:
101  return bits;
102  case mhdf_BOOLEAN:
103  return boolean;
104  case mhdf_ENTITY_ID:
105  return id;
106  }
107  return unknown;
108 }

References mhdf_BITFIELD, mhdf_BOOLEAN, mhdf_ENTITY_ID, mhdf_FLOAT, mhdf_INTEGER, and mhdf_OPAQUE.

Referenced by print_tag_desc().