Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
info.c File Reference
#include "mhdf.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <H5Tpublic.h>
+ Include dependency graph for info.c:

Go to the source code of this file.

Functions

static int print_file_summary (struct mhdf_FileDesc *data)
 
int main (int argc, char *argv[])
 
static void print_ent_desc (const char *name, const char *subname, struct mhdf_EntDesc *data, const char *vals_label, const char *extra_label, struct mhdf_FileDesc *all)
 
static void print_elem_desc (struct mhdf_ElemDesc *data, struct mhdf_FileDesc *all)
 
static const char * tag_type_name (enum mhdf_TagDataType type)
 
static const char * string_tag_value (const void *value, enum mhdf_TagDataType type, int size)
 
static const char * ent_desc_name (struct mhdf_FileDesc *all, int idx)
 
static void print_tag_desc (struct mhdf_TagDesc *data, struct mhdf_FileDesc *all)
 

Function Documentation

◆ ent_desc_name()

static const char* ent_desc_name ( struct mhdf_FileDesc all,
int  idx 
)
static

Definition at line 219 of file info.c.

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

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

Referenced by print_tag_desc().

◆ main()

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

Definition at line 10 of file info.c.

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

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

◆ print_elem_desc()

static void print_elem_desc ( struct mhdf_ElemDesc data,
struct mhdf_FileDesc all 
)
static

Definition at line 78 of file info.c.

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

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,
struct mhdf_EntDesc data,
const char *  vals_label,
const char *  extra_label,
struct mhdf_FileDesc all 
)
static

Definition at line 46 of file info.c.

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

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 ( struct mhdf_FileDesc data)
static

Definition at line 266 of file info.c.

267 {
268  int i;
269 
270  printf( " Entities:\n" );
271  print_ent_desc( "Nodes", NULL, &data->nodes, "dimension", NULL, data );
272  for( i = 0; i < data->num_elem_desc; ++i )
273  print_elem_desc( data->elems + i, data );
274  print_ent_desc( "Sets", NULL, &data->sets, NULL, NULL, data );
275 
276  printf( " Tags:\n" );
277  for( i = 0; i < data->num_tag_desc; ++i )
278  print_tag_desc( data->tags + i, data );
279 
280  return 0;
281 }

References mhdf_FileDesc::elems, mhdf_FileDesc::nodes, mhdf_FileDesc::num_elem_desc, mhdf_FileDesc::num_tag_desc, 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 ( struct mhdf_TagDesc data,
struct mhdf_FileDesc all 
)
static

Definition at line 230 of file info.c.

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

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,
enum mhdf_TagDataType  type,
int  size 
)
static

Definition at line 111 of file info.c.

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

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

Referenced by print_tag_desc().

◆ tag_type_name()

static const char* tag_type_name ( enum mhdf_TagDataType  type)
static

Definition at line 84 of file info.c.

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

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

Referenced by moab::ReadHDF5::create_tag(), moab::WriteHDF5::get_tag_size(), and print_tag_desc().