Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
mhdf_public.h File Reference
#include <H5Tpublic.h>
+ Include dependency graph for mhdf_public.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  struct_mhdf_Status
 Struct used to return error status. More...
 
struct  mhdf_EntDesc
 
struct  mhdf_TagDesc
 
struct  mhdf_ElemDesc
 
struct  mhdf_FileDesc
 

Macros

#define MHDF_MESSAGE_BUFFER_LEN   160
 
#define mhdf_EDGE_TYPE_NAME   "Edge"
 Name to use for edge element. More...
 
#define mhdf_TRI_TYPE_NAME   "Tri"
 Name to use for triangle element. More...
 
#define mhdf_QUAD_TYPE_NAME   "Quad"
 Name to use for quadrilateral element. More...
 
#define mhdf_POLYGON_TYPE_NAME   "Polygon"
 Name to use for general polygon element. More...
 
#define mhdf_TET_TYPE_NAME   "Tet"
 Name to use for tetrahedral element. More...
 
#define mhdf_PYRAMID_TYPE_NAME   "Pyramid"
 Name to use for quad-based pyramid element. More...
 
#define mhdf_PRISM_TYPE_NAME   "Prism"
 Name to use for triangular prism element. More...
 
#define mdhf_KNIFE_TYPE_NAME   "Knife"
 Name to use for knife element. More...
 
#define mdhf_HEX_TYPE_NAME   "Hex"
 Name to use for quad-sided hexahedral element. More...
 
#define mhdf_POLYHEDRON_TYPE_NAME   "Polyhedron"
 Name to use for general polyhedron specified as a arbitrary-length list of faces. More...
 
#define mhdf_SEPTAHEDRON_TYPE_NAME   "Septahedron"
 Name to use for hexagonal-based pyramid. More...
 

Typedefs

typedef struct struct_mhdf_Status mhdf_Status
 Struct used to return error status. More...
 
typedef mhdf_Status MHDF_Status
 
typedef enum mhdf_TagDataType MHDF_TagDataType
 Enum for tag data type class. More...
 
typedef long mhdf_index_t
 Type used when creating index tables. More...
 
typedef void * mhdf_FileHandle
 Opaque handle to an open file. More...
 
typedef mhdf_FileHandle MHDF_FileHandle
 
typedef struct mhdf_EntDesc MHDF_EntDesc
 
typedef struct mhdf_TagDesc MHDF_TagDesc
 
typedef struct mhdf_ElemDesc MHDF_ElemDesc
 
typedef struct mhdf_FileDesc MHDF_FileDesc
 

Enumerations

enum  mhdf_TagDataType {
  mhdf_OPAQUE = 0 , mhdf_INTEGER , mhdf_FLOAT , mhdf_BITFIELD ,
  mhdf_BOOLEAN , mhdf_ENTITY_ID
}
 Enum for tag data type class. More...
 

Functions

int mhdf_isError (mhdf_Status const *)
 Return 1 if passed status object indicates an error. Zero otherwise. More...
 
const char * mhdf_message (mhdf_Status const *)
 Get the error message given a status object.
More...
 
mhdf_FileHandle mhdf_createFile (const char *filename, int overwrite, const char **elem_type_list, size_t elem_type_list_len, hid_t id_type, mhdf_Status *status)
 Create a new file. More...
 
mhdf_FileHandle mhdf_openFile (const char *filename, int writable, unsigned long *max_id, hid_t id_type, mhdf_Status *status)
 Open an existing file. More...
 
mhdf_FileHandle mhdf_openFileWithOpt (const char *filename, int writable, unsigned long *max_id, hid_t id_type, hid_t options, mhdf_Status *status)
 Open an existing file with options. More...
 
int mhdf_countOpenHandles (mhdf_FileHandle h)
 Get number of open HDF5 objects from file. More...
 
MHDF_FileDescmhdf_getFileSummary (mhdf_FileHandle file_handle, hid_t file_id_type, mhdf_Status *status, int extraSetInfo)
 Get summary of data tables contained within file. More...
 
void mhdf_fixFileDesc (struct mhdf_FileDesc *copy_ptr, const struct mhdf_FileDesc *orig_addr)
 Fix nested pointers for copied/moved FileDesc struct. More...
 
void mhdf_closeFile (mhdf_FileHandle handle, mhdf_Status *status)
 Close the file. More...
 

Macro Definition Documentation

◆ mdhf_HEX_TYPE_NAME

#define mdhf_HEX_TYPE_NAME   "Hex"

Name to use for quad-sided hexahedral element.

Definition at line 44 of file mhdf_public.h.

◆ mdhf_KNIFE_TYPE_NAME

#define mdhf_KNIFE_TYPE_NAME   "Knife"

Name to use for knife element.

Definition at line 42 of file mhdf_public.h.

◆ mhdf_EDGE_TYPE_NAME

#define mhdf_EDGE_TYPE_NAME   "Edge"

Name to use for edge element.

Definition at line 28 of file mhdf_public.h.

◆ MHDF_MESSAGE_BUFFER_LEN

#define MHDF_MESSAGE_BUFFER_LEN   160

Definition at line 10 of file mhdf_public.h.

◆ mhdf_POLYGON_TYPE_NAME

#define mhdf_POLYGON_TYPE_NAME   "Polygon"

Name to use for general polygon element.

Definition at line 34 of file mhdf_public.h.

◆ mhdf_POLYHEDRON_TYPE_NAME

#define mhdf_POLYHEDRON_TYPE_NAME   "Polyhedron"

Name to use for general polyhedron specified as a arbitrary-length list of faces.

Definition at line 46 of file mhdf_public.h.

◆ mhdf_PRISM_TYPE_NAME

#define mhdf_PRISM_TYPE_NAME   "Prism"

Name to use for triangular prism element.

Definition at line 40 of file mhdf_public.h.

◆ mhdf_PYRAMID_TYPE_NAME

#define mhdf_PYRAMID_TYPE_NAME   "Pyramid"

Name to use for quad-based pyramid element.

Definition at line 38 of file mhdf_public.h.

◆ mhdf_QUAD_TYPE_NAME

#define mhdf_QUAD_TYPE_NAME   "Quad"

Name to use for quadrilateral element.

Definition at line 32 of file mhdf_public.h.

◆ mhdf_SEPTAHEDRON_TYPE_NAME

#define mhdf_SEPTAHEDRON_TYPE_NAME   "Septahedron"

Name to use for hexagonal-based pyramid.

Definition at line 48 of file mhdf_public.h.

◆ mhdf_TET_TYPE_NAME

#define mhdf_TET_TYPE_NAME   "Tet"

Name to use for tetrahedral element.

Definition at line 36 of file mhdf_public.h.

◆ mhdf_TRI_TYPE_NAME

#define mhdf_TRI_TYPE_NAME   "Tri"

Name to use for triangle element.

Definition at line 30 of file mhdf_public.h.

Typedef Documentation

◆ MHDF_ElemDesc

typedef struct mhdf_ElemDesc MHDF_ElemDesc

◆ MHDF_EntDesc

typedef struct mhdf_EntDesc MHDF_EntDesc

Data common to sets, nodes, and each element type

◆ MHDF_FileDesc

typedef struct mhdf_FileDesc MHDF_FileDesc

◆ mhdf_FileHandle

typedef void* mhdf_FileHandle

Opaque handle to an open file.

Definition at line 73 of file mhdf_public.h.

◆ MHDF_FileHandle

Definition at line 75 of file mhdf_public.h.

◆ mhdf_index_t

typedef long mhdf_index_t

Type used when creating index tables.

The data type used by mhdf_create* functions that create tables if indices (e.g. mhdf_createSetMeta, mhdf_createVarLenTag, etc.).

Definition at line 70 of file mhdf_public.h.

◆ mhdf_Status

Struct used to return error status.

◆ MHDF_Status

Definition at line 18 of file mhdf_public.h.

◆ MHDF_TagDataType

Enum for tag data type class.

Enumerates known types for tag data

◆ MHDF_TagDesc

typedef struct mhdf_TagDesc MHDF_TagDesc

Struct describing a tag

Enumeration Type Documentation

◆ mhdf_TagDataType

Enum for tag data type class.

Enumerates known types for tag data

Enumerator
mhdf_OPAQUE 

Opaque/unknown type

mhdf_INTEGER 

Integer type

mhdf_FLOAT 

Floating point value

mhdf_BITFIELD 

Bit field

mhdf_BOOLEAN 

Boolean values stored as one byte each

mhdf_ENTITY_ID 

Global ID referencing another entity in file

Definition at line 55 of file mhdf_public.h.

56 {
57  mhdf_OPAQUE = 0, /**< Opaque/unknown type */
58  mhdf_INTEGER, /**< Integer type */
59  mhdf_FLOAT, /**< Floating point value */
60  mhdf_BITFIELD, /**< Bit field */
61  mhdf_BOOLEAN, /**< Boolean values stored as one byte each */
62  mhdf_ENTITY_ID /**< Global ID referencing another entity in file */

Function Documentation

◆ mhdf_closeFile()

void mhdf_closeFile ( mhdf_FileHandle  handle,
mhdf_Status status 
)

Close the file.

Parameters
handleThe file to close.
statusPassed back status of API call.

Definition at line 438 of file file.c.

439 {
440  FileHandle* file_ptr;
441  API_BEGIN;
442 
443  file_ptr = (FileHandle*)( handle );
444  if( !mhdf_check_valid_file( file_ptr, status ) ) return;
445  /*
446  if (file_ptr->open_handle_count)
447  {
448  mhdf_setError( status, "Cannot close file with %d open data handles.",
449  file_ptr->open_handle_count );
450  return;
451  }
452  */
453 
454  /* Check for open handles. HDF5 will not actually close the
455  file until all handles are closed. */
456  if( mhdf_checkOpenHandles( handle, status ) ) return;
457 
458  if( 0 > H5Fclose( file_ptr->hdf_handle ) )
459  {
460  mhdf_setFail( status, "H5FClose failed. Invalid handle?" );
461  return;
462  }
463 
464  memset( file_ptr, 0, sizeof( FileHandle ) );
465  free( file_ptr );
466  mhdf_setOkay( status );
467  API_END_H( -1 );
468 }

References API_BEGIN, API_END_H, struct_FileHandle::hdf_handle, mhdf_check_valid_file(), mhdf_checkOpenHandles(), mhdf_setFail(), and mhdf_setOkay().

Referenced by moab::ReadHDF5::clean_up_read(), iMOAB_ReadHeaderInfo(), main(), moab::WriteHDF5Parallel::parallel_create_file(), moab::ReadHDF5::set_up_read(), and moab::WriteHDF5::write_file().

◆ mhdf_countOpenHandles()

int mhdf_countOpenHandles ( mhdf_FileHandle  h)

Get number of open HDF5 objects from file.

Definition at line 150 of file file.c.

151 {
152  return H5Fget_obj_count( ( (FileHandle*)file_handle )->hdf_handle, H5F_OBJ_ALL );
153 }

Referenced by moab::CheckOpenReadHDF5Handles::~CheckOpenReadHDF5Handles(), and moab::CheckOpenWriteHDF5Handles::~CheckOpenWriteHDF5Handles().

◆ mhdf_createFile()

mhdf_FileHandle mhdf_createFile ( const char *  filename,
int  overwrite,
const char **  elem_type_list,
size_t  elem_type_list_len,
hid_t  id_type,
mhdf_Status status 
)

Create a new file.

Create a new HDF mesh file. This handle must be closed with mhdf_closeFile to avoid resource loss.

Parameters
filenameThe path and name of the file to create
overwriteIf zero, will fail if the specified file already exists. If non-zero, will overwrite an existing file.
elem_type_listThe list of element types that will be stored in the file. If the element name exits as a pre- defined constant (mhdf_type), that constant should be used. If a constant does not exist for the type, a similar naming pattern should be used (accepted name for type, first character uppercase, subsequent characters lowercase.) The element type index passed to mhdf_addElement is then an index into this list. The array may contain null entries to allow the caller some control over the assigned indices without creating dummy types which may confuse readers.
elem_type_list_lenThe length of elem_type_list.
id_typeType to use when creating datasets containing file IDs
statusPassed back status of API call.
Returns
An opaque handle to the file.

Definition at line 37 of file file.c.

43 {
44  FileHandle* file_ptr;
45  unsigned int flags;
46  unsigned char idx;
47  size_t i;
48  hid_t enum_id, group_id;
49  int rval;
50  API_BEGIN;
51 
52  if( elem_list_len > 255 )
53  {
54  mhdf_setFail( status, "Element type list too long." );
55  return NULL;
56  }
57  mhdf_setOkay( status );
58 
59  /* Create struct to hold working data */
60  file_ptr = mhdf_alloc_FileHandle( 0, id_type, status );
61  if( !file_ptr ) return NULL;
62 
63  /* Create the file */
64  flags = overwrite ? H5F_ACC_TRUNC : H5F_ACC_EXCL;
65  file_ptr->hdf_handle = H5Fcreate( filename, flags, H5P_DEFAULT, H5P_DEFAULT );
66  if( file_ptr->hdf_handle < 0 )
67  {
68  mhdf_setFail( status, "Failed to create file \"%s\"", filename );
69  free( file_ptr );
70  return NULL;
71  }
72 
73  /* Create file structure */
74  if( !make_hdf_group( ROOT_GROUP, file_ptr->hdf_handle, 6, status ) ||
75  !make_hdf_group( TAG_GROUP, file_ptr->hdf_handle, 0, status ) ||
76  !make_hdf_group( ELEMENT_GROUP, file_ptr->hdf_handle, 8, status ) ||
77  !make_hdf_group( NODE_GROUP, file_ptr->hdf_handle, 3, status ) ||
78  !make_hdf_group( SET_GROUP, file_ptr->hdf_handle, 5, status ) ||
79  !make_hdf_group( NODE_TAG_GROUP, file_ptr->hdf_handle, 0, status ) ||
80  !make_hdf_group( SET_TAG_GROUP, file_ptr->hdf_handle, 0, status ) )
81  {
82  H5Fclose( file_ptr->hdf_handle );
83  free( file_ptr );
84  return NULL;
85  }
86 
87  /* Store the max ID as an attribite on the /tstt/ group */
88 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
89  group_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT );
90 #else
91  group_id = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP );
92 #endif
93  rval = mhdf_create_scalar_attrib( group_id, MAX_ID_ATTRIB, H5T_NATIVE_ULONG, &file_ptr->max_id, status );
94  H5Gclose( group_id );
95  if( !rval )
96  {
97  H5Fclose( file_ptr->hdf_handle );
98  free( file_ptr );
99  return NULL;
100  }
101 
102  /* Create the type name list in file */
103  enum_id = H5Tenum_create( H5T_NATIVE_UCHAR );
104  if( enum_id < 0 )
105  {
106  mhdf_setFail( status, "Failed to store elem type list." );
107  H5Fclose( file_ptr->hdf_handle );
108  free( file_ptr );
109  return NULL;
110  }
111  for( i = 0; i < elem_list_len; ++i )
112  {
113  if( !elem_type_list[i] || !*elem_type_list[i] ) continue;
114 
115  idx = (unsigned char)i;
116  if( H5Tenum_insert( enum_id, elem_type_list[i], &idx ) < 0 )
117  {
118  mhdf_setFail( status, "Failed to store elem type list." );
119  H5Fclose( file_ptr->hdf_handle );
120  free( file_ptr );
121  return NULL;
122  }
123  }
124 #if defined( H5Tcommit_vers ) && H5Tcommit_vers > 1
125  if( H5Tcommit2( file_ptr->hdf_handle, TYPE_ENUM_PATH, enum_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT ) < 0 )
126 #else
127  if( H5Tcommit( file_ptr->hdf_handle, TYPE_ENUM_PATH, enum_id ) < 0 )
128 #endif
129  {
130  mhdf_setFail( status, "Failed to store elem type list." );
131  H5Fclose( file_ptr->hdf_handle );
132  free( file_ptr );
133  return NULL;
134  }
135  H5Tclose( enum_id );
136 
137  API_END_H( 1 );
138  return file_ptr;
139 }

References API_BEGIN, API_END_H, ELEMENT_GROUP, struct_FileHandle::hdf_handle, make_hdf_group(), struct_FileHandle::max_id, MAX_ID_ATTRIB, mhdf_alloc_FileHandle(), mhdf_create_scalar_attrib(), mhdf_setFail(), mhdf_setOkay(), NODE_GROUP, NODE_TAG_GROUP, ROOT_GROUP, SET_GROUP, SET_TAG_GROUP, TAG_GROUP, and TYPE_ENUM_PATH.

Referenced by moab::WriteHDF5Parallel::parallel_create_file(), and moab::WriteHDF5::serial_create_file().

◆ mhdf_fixFileDesc()

void mhdf_fixFileDesc ( struct mhdf_FileDesc copy_ptr,
const struct mhdf_FileDesc orig_addr 
)

Fix nested pointers for copied/moved FileDesc struct.

This is a utility method to facility copying/moving/communicating struct FileDesc instances. The structure and all data it references are allocated in a single contiguous block of memory of size FileDesc::total_size. As such, the struct can be copied with a single memcpy, packed into a single network packet, communicated with a single MPI call, etc. However, the pointers contained within the struct will not be valid in the copied instance (they will still point into the original instance.) Given a pointer to the copied struct and the address of the original struct, this function will updated all contained pointers.

Definition at line 77 of file file-desc.c.

78 {
79  int i;
80 
81  API_BEGIN;
82  FIX_OFFSET( int*, nodes.dense_tag_indices );
83  FIX_OFFSET( int*, sets.dense_tag_indices );
84  FIX_OFFSET( struct mhdf_ElemDesc*, elems );
85  FIX_OFFSET( struct mhdf_TagDesc*, tags );
86 
87  FIX_OFFSET( int*, numEntSets );
88  FIX_OFFSET( int**, defTagsEntSets );
89  FIX_OFFSET( int**, defTagsVals );
90 
91  for( i = 0; i < 5; i++ )
92  {
93  if( copy_ptr->defTagsEntSets ) FIX_OFFSET( int*, defTagsEntSets[i] );
94  if( copy_ptr->defTagsVals ) FIX_OFFSET( int*, defTagsVals[i] );
95  }
96 
97  if( copy_ptr->elems != NULL )
98  {
99  for( i = 0; i < copy_ptr->num_elem_desc; ++i )
100  {
101  FIX_OFFSET( const char*, elems[i].handle );
102  FIX_OFFSET( const char*, elems[i].type );
103  FIX_OFFSET( int*, elems[i].desc.dense_tag_indices );
104  }
105  }
106 
107  if( copy_ptr->tags != NULL )
108  {
109  for( i = 0; i < copy_ptr->num_tag_desc; ++i )
110  {
111  FIX_OFFSET( const char*, tags[i].name );
112  FIX_OFFSET( void*, tags[i].default_value );
113  FIX_OFFSET( void*, tags[i].global_value );
114  FIX_OFFSET( int*, tags[i].dense_elem_indices );
115  }
116  }
117  API_END;
118 }

References API_BEGIN, API_END, mhdf_FileDesc::defTagsEntSets, mhdf_FileDesc::defTagsVals, mhdf_EntDesc::dense_tag_indices, mhdf_FileDesc::elems, FIX_OFFSET, mhdf_FileDesc::nodes, mhdf_FileDesc::num_elem_desc, mhdf_FileDesc::num_tag_desc, mhdf_FileDesc::numEntSets, mhdf_FileDesc::sets, and mhdf_FileDesc::tags.

Referenced by realloc_data(), and moab::ReadHDF5::set_up_read().

◆ mhdf_getFileSummary()

MHDF_FileDesc* mhdf_getFileSummary ( mhdf_FileHandle  file_handle,
hid_t  file_id_type,
mhdf_Status status,
int  extraSetInfo 
)

Get summary of data tables contained within file.

Returned struct, including all pointed-to data, is allocated in a single contiguous block of memory with a size equal to 'total_size'. Caller is responsible for freeing the returned struct FileDesc pointer (and only that pointer, not pointers nexted within the struct!). Caller may copy (e.g. MPI_BCast) entire struct as one contiguous block, assuming all nested pointers in the copy are updated to the correct relative offset from the beginning of the struct.

Definition at line 385 of file file-desc.c.

389 {
390  struct mhdf_FileDesc* result;
391  hid_t table_id;
392  int i, i1, numtags, j, k, size, *indices, have, num_tag_names = 0;
393  unsigned int ui;
394  void* ptr;
395  char **elem_handles = 0, **tag_names = 0;
396  unsigned char *array, *matrix;
397  const char* pname[5] = { "PARALLEL_PARTITION", "MATERIAL_SET", "NEUMANN_SET", "DIRICHLET_SET", "GEOM_DIMENSION" };
398 
399  long* id_list;
400  struct mhdf_TagDesc* tag_desc;
401  long int nval, junk;
402  hid_t table[3];
403  hid_t data_type;
404 
405  API_BEGIN;
406 
407  mhdf_setOkay( status );
408  result = alloc_file_desc( status );
409  if( NULL == result ) return NULL;
410 
411  /* get node info */
412  have = mhdf_haveNodes( file_handle, status );
413  if( mhdf_isError( status ) )
414  {
415  free( result );
416  return NULL;
417  }
418  if( have )
419  {
420  table_id = mhdf_openNodeCoords( file_handle, &result->nodes.count, &result->nodes.vals_per_ent,
421  &result->nodes.start_id, status );
422  if( table_id < 0 )
423  {
424  free( result );
425  return NULL;
426  }
427  mhdf_closeData( file_handle, table_id, status );
428  }
429  else
430  {
431  result->nodes.count = 0;
432  result->nodes.vals_per_ent = 0;
433  result->nodes.start_id = 0;
434  }
435 
436  /* get set info */
437  result->sets.vals_per_ent = -1;
438  have = mhdf_haveSets( file_handle, &result->have_set_contents, &result->have_set_children,
439  &result->have_set_parents, status );
440  if( mhdf_isError( status ) )
441  {
442  free( result );
443  return NULL;
444  }
445  if( have )
446  {
447  table_id = mhdf_openSetMeta( file_handle, &result->sets.count, &result->sets.start_id, status );
448  if( table_id < 0 )
449  {
450  free( result );
451  return NULL;
452  }
453  mhdf_closeData( file_handle, table_id, status );
454  }
455  else
456  {
457  result->sets.count = 0;
458  result->sets.start_id = 0;
459  }
460 
461  /* get element list */
462  elem_handles = mhdf_getElemHandles( file_handle, &ui, status );
463  if( elem_handles == NULL )
464  {
465  free( result );
466  return NULL;
467  }
468  result->num_elem_desc = ui;
469 
470  /* allocate array of element descriptors */
471  size = result->num_elem_desc * sizeof( struct mhdf_ElemDesc );
472  ptr = realloc_data( &result, size, status, sizeof( char* ) );
473  if( NULL == ptr )
474  {
475  free( elem_handles );
476  return NULL;
477  }
478  memset( ptr, 0, size );
479  result->elems = ptr;
480 
481  /* Initialize each element descriptor */
482  for( i = 0; i < result->num_elem_desc; ++i )
483  {
484  result = get_elem_desc( file_handle, result, elem_handles[i], i, status );
485  if( NULL == result )
486  {
487  free( elem_handles );
488  return NULL;
489  }
490  }
491 
492  /* get tag list */
493  tag_names = mhdf_getTagNames( file_handle, &num_tag_names, status );
494  if( mhdf_isError( status ) )
495  {
496  free( elem_handles );
497  free( result );
498  return NULL;
499  }
500 
501  /* allocate array of tag descriptors */
502  size = num_tag_names * sizeof( struct mhdf_TagDesc );
503  ptr = realloc_data( &result, size, status, sizeof( char* ) );
504  if( NULL == ptr )
505  {
506  free( elem_handles );
507  free_string_list( tag_names, result->num_tag_desc );
508  return NULL;
509  }
510  memset( ptr, 0, size );
511  result->tags = ptr;
512  result->num_tag_desc = num_tag_names;
513  memset( result->tags, 0, size );
514 
515  /* Initialize each tag descriptor */
516  for( i = 0; i < result->num_tag_desc; ++i )
517  {
518  result = get_tag_desc( file_handle, result, tag_names[i], i, file_id_type, status );
519  if( NULL == result )
520  {
521  free( elem_handles );
522  free_string_list( tag_names, num_tag_names );
523  return NULL;
524  }
525  }
526 
527  /* Determine which dense tags are present */
528 
529  size = ( 2 + result->num_elem_desc ) * result->num_tag_desc;
530  array = mhdf_malloc( size, status );
531  if( NULL == array )
532  {
533  free( elem_handles );
534  free_string_list( tag_names, num_tag_names );
535  free( result );
536  return NULL;
537  }
538  memset( array, 0, size );
539  matrix = array + ( 2 * result->num_tag_desc );
540 
541  for( j = 0; j < result->num_tag_desc; ++j )
542  {
543  if( mhdf_haveDenseTag( file_handle, tag_names[j], mhdf_node_type_handle(), status ) )
544  matrix[-1 * result->num_tag_desc + j] = 1;
545  if( mhdf_haveDenseTag( file_handle, tag_names[j], mhdf_set_type_handle(), status ) )
546  matrix[-2 * result->num_tag_desc + j] = 1;
547  for( i = 0; i < result->num_elem_desc; ++i )
548  if( mhdf_haveDenseTag( file_handle, tag_names[j], elem_handles[i], status ) )
549  matrix[i * result->num_tag_desc + j] = 1;
550  }
551  free( elem_handles );
552  free_string_list( tag_names, result->num_tag_desc );
553 
554  /* Populate dense tag lists for element types */
555  for( i = -2; i < result->num_elem_desc; ++i )
556  {
557  size = 0;
558  for( j = 0; j < result->num_tag_desc; ++j )
559  size += matrix[i * result->num_tag_desc + j];
560  if( !size )
561  {
562  indices = NULL;
563  }
564  else
565  {
566  indices = realloc_data( &result, size * sizeof( int ), status, sizeof( int ) );
567  if( NULL == indices )
568  {
569  free( array );
570  return NULL;
571  }
572 
573  k = 0;
574  for( j = 0; j < result->num_tag_desc; ++j )
575  if( matrix[i * result->num_tag_desc + j] ) indices[k++] = j;
576  assert( k == size );
577  }
578 
579  if( i == -2 )
580  {
581  result->sets.dense_tag_indices = indices;
582  result->sets.num_dense_tags = size;
583  }
584  else if( i == -1 )
585  {
586  result->nodes.dense_tag_indices = indices;
587  result->nodes.num_dense_tags = size;
588  }
589  else
590  {
591  result->elems[i].desc.dense_tag_indices = indices;
592  result->elems[i].desc.num_dense_tags = size;
593  }
594  }
595 
596  /* Populate dense tag lists for each tag */
597  for( j = 0; j < result->num_tag_desc; ++j )
598  {
599  size = 0;
600  for( i = -2; i < result->num_elem_desc; ++i )
601  size += matrix[i * result->num_tag_desc + j];
602  if( !size )
603  {
604  indices = 0;
605  }
606  else
607  {
608  indices = realloc_data( &result, size * sizeof( int ), status, sizeof( int ) );
609  if( NULL == ptr )
610  {
611  free( array );
612  return NULL;
613  }
614 
615  k = 0;
616  for( i = -2; i < result->num_elem_desc; ++i )
617  if( matrix[i * result->num_tag_desc + j] ) indices[k++] = i;
618  assert( k == size );
619  }
620 
621  result->tags[j].num_dense_indices = size;
622  result->tags[j].dense_elem_indices = indices;
623  }
624 
625  if( extraSetInfo )
626  {
627  /* open the table for parallel partitions, material sets, neumann sets,
628  * dirichlet sets
629  * to determine number of parts, etc
630  * this is needed for iMOAB and VisIt plugin */
631  const int NPRIMARY_SETS = 5;
632  ptr = realloc_data( &result, NPRIMARY_SETS * sizeof( int ), status, sizeof( int ) );
633  if( NULL == ptr || mhdf_isError( status ) )
634  {
635  free( array );
636  return NULL;
637  }
638  result->numEntSets = ptr;
639  for( i = 0; i < NPRIMARY_SETS; ++i )
640  result->numEntSets[i] = 0;
641 
642  ptr = realloc_data( &result, NPRIMARY_SETS * sizeof( int* ), status, sizeof( int* ) );
643  if( NULL == ptr || mhdf_isError( status ) )
644  {
645  free( array );
646  return NULL;
647  }
648  result->defTagsEntSets = ptr;
649 
650  ptr = realloc_data( &result, NPRIMARY_SETS * sizeof( int* ), status, sizeof( int* ) );
651  if( NULL == ptr || mhdf_isError( status ) )
652  {
653  free( array );
654  return NULL;
655  }
656  result->defTagsVals = ptr;
657  numtags = result->num_tag_desc;
658 
659  for( i = 0; i < numtags; i++ )
660  {
661  tag_desc = &( result->tags[i] );
662  for( k = 0; k < NPRIMARY_SETS; k++ ) /* number of default tags to consider */
663  {
664  if( strcmp( pname[k], tag_desc->name ) == 0 )
665  {
666  if( tag_desc->have_sparse )
667  {
668  mhdf_openSparseTagData( file_handle, pname[k], &nval, &junk, table, status );
669  if( mhdf_isError( status ) )
670  {
671  free( array );
672  return NULL;
673  }
674  /* for sparse tags, read */
675  result->numEntSets[k] = nval;
676  if( nval <= 0 ) continue; /* do not do anything */
677 
678  ptr = realloc_data( &result, nval * sizeof( int ), status, sizeof( int ) );
679  if( NULL == ptr || mhdf_isError( status ) )
680  {
681  free( array );
682  return NULL;
683  }
684  memset( ptr, 0, nval * sizeof( int ) );
685  result->defTagsEntSets[k] = ptr;
686  tag_desc = &( result->tags[i] );
687 
688  ptr = realloc_data( &result, nval * sizeof( int ), status, sizeof( int ) );
689  if( NULL == ptr || mhdf_isError( status ) )
690  {
691  free( array );
692  return NULL;
693  }
694  memset( ptr, 0, nval * sizeof( int ) );
695  result->defTagsVals[k] = ptr;
696  tag_desc = &( result->tags[i] ); /* this is because the tag might point to
697  something else*/
698 
699  /* make room for the long array type
700  is it long or something else? */
701  id_list = mhdf_malloc( nval * sizeof( long ), status );
702  /* fill the id with values, then convert to int type (-set start)
703 
704  mhdf_read_data( table_id, offset, count, int_type, id_list, H5P_DEFAULT,
705  status );*/
706 
707  data_type = H5Dget_type( table[0] );
708 
709  mhdf_read_data( table[0], 0, nval, data_type, id_list, H5P_DEFAULT, status );
710  if( mhdf_isError( status ) )
711  {
712  free( array );
713  return NULL;
714  }
715  H5Tclose( data_type );
716 
717  for( i1 = 0; i1 < nval; i1++ )
718  result->defTagsEntSets[k][i1] = (int)( id_list[i1] - result->sets.start_id + 1 );
719  /* now read values, integer type */
720  data_type = H5Dget_type( table[1] );
721  mhdf_read_data( table[1], 0, nval, data_type, result->defTagsVals[k], H5P_DEFAULT, status );
722  if( mhdf_isError( status ) )
723  {
724  free( array );
725  return NULL;
726  }
727  H5Tclose( data_type );
728  mhdf_closeData( file_handle, table[0], status );
729  if( mhdf_isError( status ) )
730  {
731  free( array );
732  return NULL;
733  }
734  mhdf_closeData( file_handle, table[1], status );
735  if( mhdf_isError( status ) )
736  {
737  free( array );
738  return NULL;
739  }
740  free( id_list );
741  }
742  else if( 0 == k || 1 == k )
743  { /* parallel partition or material sets should still work if dense
744  could be dense tags on sets */
745  if( !mhdf_haveDenseTag( file_handle, pname[k], mhdf_set_type_handle(), status ) ) continue;
746  table[0] =
747  mhdf_openDenseTagData( file_handle, pname[k], mhdf_set_type_handle(), &nval, status );
748  if( mhdf_isError( status ) )
749  {
750  continue; /* do not error out if not a dense tag either */
751  }
752  result->numEntSets[k] = nval;
753  if( nval <= 0 ) continue; /* do not do anything */
754 
755  /*
756  * if dense parallel partition or material set, we know what to expect
757  */
758  result->numEntSets[k] = nval; /* k could be 0 or 1 */
759  if( nval <= 0 ) continue; /* do not do anything */
760 
761  ptr = realloc_data( &result, nval * sizeof( int ), status, sizeof( int ) );
762  if( NULL == ptr || mhdf_isError( status ) )
763  {
764  free( array );
765  return NULL;
766  }
767  memset( ptr, 0, nval * sizeof( int ) );
768  result->defTagsEntSets[k] = ptr;
769  tag_desc = &( result->tags[i] );
770 
771  ptr = realloc_data( &result, nval * sizeof( int ), status, sizeof( int ) );
772  if( NULL == ptr || mhdf_isError( status ) )
773  {
774  free( array );
775  return NULL;
776  }
777  memset( ptr, 0, nval * sizeof( int ) );
778  result->defTagsVals[k] = ptr;
779  tag_desc = &( result->tags[i] ); /* this is because the tag might point to
780  something else*/
781 
782  for( i1 = 0; i1 < nval; i1++ )
783  {
784  result->defTagsEntSets[k][i1] = i1 + 1;
785  /*result -> defTagsVals[k][i1] = i1; we know how the partition looks
786  * like */
787  }
788  /* fill in the data with the dense tag values
789  because dense, sets will be in order
790 
791  we know it has to be integer */
792  mhdf_readTagValues( table[0], 0, nval, H5T_NATIVE_INT, result->defTagsVals[k], status );
793  if( mhdf_isError( status ) )
794  {
795  free( array );
796  return NULL;
797  }
798  mhdf_closeData( file_handle, table[0], status );
799  if( mhdf_isError( status ) )
800  {
801  free( array );
802  return NULL;
803  }
804  }
805  }
806  }
807  }
808  }
809  /* Compact memory and return */
810  free( array );
811  result->total_size = result->offset - (unsigned char*)result;
812 
813  API_END;
814  return result;
815 }

References alloc_file_desc(), API_BEGIN, API_END, mhdf_EntDesc::count, mhdf_FileDesc::defTagsEntSets, mhdf_FileDesc::defTagsVals, mhdf_TagDesc::dense_elem_indices, mhdf_EntDesc::dense_tag_indices, mhdf_ElemDesc::desc, mhdf_FileDesc::elems, free_string_list(), get_elem_desc(), get_tag_desc(), mhdf_FileDesc::have_set_children, mhdf_FileDesc::have_set_contents, mhdf_FileDesc::have_set_parents, mhdf_TagDesc::have_sparse, mhdf_closeData(), mhdf_getElemHandles(), mhdf_getTagNames(), mhdf_haveDenseTag(), mhdf_haveNodes(), mhdf_haveSets(), mhdf_isError(), mhdf_malloc(), mhdf_node_type_handle(), mhdf_openDenseTagData(), mhdf_openNodeCoords(), mhdf_openSetMeta(), mhdf_openSparseTagData(), mhdf_read_data(), mhdf_readTagValues(), mhdf_set_type_handle(), mhdf_setOkay(), mhdf_TagDesc::name, mhdf_FileDesc::nodes, mhdf_TagDesc::num_dense_indices, mhdf_EntDesc::num_dense_tags, mhdf_FileDesc::num_elem_desc, mhdf_FileDesc::num_tag_desc, mhdf_FileDesc::numEntSets, mhdf_FileDesc::offset, realloc_data(), mhdf_FileDesc::sets, size, mhdf_EntDesc::start_id, mhdf_FileDesc::tags, mhdf_FileDesc::total_size, and mhdf_EntDesc::vals_per_ent.

Referenced by iMOAB_ReadHeaderInfo(), main(), and moab::ReadHDF5::set_up_read().

◆ mhdf_isError()

int mhdf_isError ( mhdf_Status const *  status)

Return 1 if passed status object indicates an error. Zero otherwise.

MOAB, a Mesh-Oriented datABase, is a software component for creating, storing and accessing finite element mesh data.

Copyright 2004 Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

Definition at line 26 of file status.c.

27 {
28  return !!status->message[0];
29 }

References struct_mhdf_Status::message.

Referenced by alloc_file_desc(), check_valid_adjacencies(), check_valid_elem_conn(), check_valid_parents_children(), check_valid_poly_conn(), check_valid_set_contents(), check_valid_sets(), check_valid_tag(), check_valid_var_len_tag(), moab::ReadHDF5::create_tag(), get_elem_desc(), get_tag_desc(), iMOAB_ReadHeaderInfo(), moab::ReadHDF5::is_error(), main(), mhdf_getFileSummary(), moab::ReadHDF5::read_qa(), moab::ReadHDF5::read_tag_values_all(), moab::ReadHDF5::read_tag_values_partial(), realloc_data(), moab::ReadHDF5::set_up_read(), and moab::WriteHDF5::write_file().

◆ mhdf_message()

◆ mhdf_openFile()

mhdf_FileHandle mhdf_openFile ( const char *  filename,
int  writable,
unsigned long *  max_id,
hid_t  id_type,
mhdf_Status status 
)

Open an existing file.

Open an existing HDF mesh file. This handle must be closed with mhdf_closeFile to avoid resource loss.

Parameters
filenameThe path and name of the file to open
writableIf non-zero, open read-write. Otherwise read-only.
statusPassed back status of API call.
max_idUsed to pass back the maximum global ID used in the file. Provided as an indication to the caller of the size of the mesh. This parameter is optional. NULL may be passed.
id_typeType to use when creating datasets containing file IDs
Returns
An opaque handle to the file.

Definition at line 141 of file file.c.

146 {
147  return mhdf_openFileWithOpt( filename, writeable, max_id_out, id_type, H5P_DEFAULT, status );
148 }

References mhdf_openFileWithOpt().

Referenced by iMOAB_ReadHeaderInfo(), main(), and moab::ReadHDF5::set_up_read().

◆ mhdf_openFileWithOpt()

mhdf_FileHandle mhdf_openFileWithOpt ( const char *  filename,
int  writable,
unsigned long *  max_id,
hid_t  id_type,
hid_t  options,
mhdf_Status status 
)

Open an existing file with options.

Open an existing HDF mesh file. This handle must be closed with mhdf_closeFile to avoid resource loss. This function allows the calling application to specify the HDF5 access property list that is passed to the HDF5 H5Fopen API. If this is passed as H5P_DEFAULT, the behavior is the same as mhdf_openFile . This argument is typically used to specify a parallel context for for writing the file in parallel.

Parameters
filenameThe path and name of the file to open
writableIf non-zero, open read-write. Otherwise read-only.
statusPassed back status of API call.
max_idUsed to pass back the maximum global ID used in the file. Provided as an indication to the caller of the size of the mesh. This parameter is optional. NULL may be passed.
optionsThe HDF5 access property list to use when opening the file. See the HDF5 documentation for H5Fopen.
id_typeType to use when creating datasets containing file IDs
Returns
An opaque handle to the file.

Definition at line 277 of file file.c.

283 {
284  FileHandle* file_ptr;
285  unsigned int flags;
286  hid_t group_id;
287  int check_is_hdf5 = 1;
288 #ifdef MOAB_HAVE_HDF5_PARALLEL
289  herr_t err;
290  MPI_Comm comm;
291  MPI_Info info;
292 #endif
293  API_BEGIN;
294 
295  /* Check if file is HDF5 */
296  /* Don't do this because it can't handle MPI-IO driver code that
297  passes options via prefixes on the file name. */
298 #ifdef MOAB_HAVE_HDF5_PARALLEL
299  if( access_prop != H5P_DEFAULT )
300  {
301  err = H5Pget_fapl_mpio( access_prop, &comm, &info );
302  if( err >= 0 )
303  {
304  check_is_hdf5 = 0;
305  /* MPI Documentation is inconsistent with regards to whether
306  or not the above call dup's these, but my testing with 1.8.3
307  indicates that at least for that version they are not.
308  MPI_Comm_free(&comm);
309  MPI_Info_free(&info); */
310  }
311  }
312 #endif
313  if( check_is_hdf5 && H5Fis_hdf5( filename ) <= 0 )
314  {
315  mhdf_setFail( status, "%s: File is not HDF5", filename );
316  return NULL;
317  }
318 
319  /* Create struct to hold working data */
320  file_ptr = mhdf_alloc_FileHandle( 0, id_type, status );
321  if( !file_ptr )
322  {
323  mhdf_setFail( status, "Memory allocation failed" );
324  return NULL;
325  }
326 
327  /* Create the file */
328  flags = writable ? H5F_ACC_RDWR : H5F_ACC_RDONLY;
329  file_ptr->hdf_handle = H5Fopen( filename, flags, access_prop );
330  if( file_ptr->hdf_handle < 0 )
331  {
332  mhdf_setFail( status, "Failed to open file \"%s\"", filename );
333  free( file_ptr );
334  return NULL;
335  }
336 
337  /* Check for TSTT data in file */
338 #if defined( H5Gopen_vers ) && H5Gopen_vers > 1
339  group_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT );
340 #else
341  group_id = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP );
342 #endif
343  if( group_id < 0 )
344  {
345  mhdf_setFail( status, "Invalid file \"%s\"\n", filename );
346  H5Fclose( file_ptr->hdf_handle );
347  free( file_ptr );
348  return NULL;
349  }
350  H5Gclose( group_id );
351 
352  /* Get max id */
353  if( !scan_for_max_id( file_ptr, status ) )
354  {
355  H5Fclose( file_ptr->hdf_handle );
356  mhdf_setFail( status, "Internal error reading file" );
357  free( file_ptr );
358  return NULL;
359  }
360 
361  if( max_id_out ) *max_id_out = file_ptr->max_id;
362 
363  mhdf_setOkay( status );
364  API_END_H( 1 );
365  return file_ptr;
366 }

References API_BEGIN, API_END_H, struct_FileHandle::hdf_handle, struct_FileHandle::max_id, mhdf_alloc_FileHandle(), mhdf_setFail(), mhdf_setOkay(), ROOT_GROUP, and scan_for_max_id().

Referenced by mhdf_openFile(), moab::WriteHDF5Parallel::parallel_create_file(), and moab::ReadHDF5::set_up_read().