Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
File operations

Classes

struct  mhdf_EntDesc
struct  mhdf_TagDesc
struct  mhdf_ElemDesc
struct  mhdf_FileDesc

Typedefs

typedef void * mhdf_FileHandle
 Opaque handle to an open file.
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

Functions

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.
mhdf_FileHandle mhdf_openFile (const char *filename, int writable, unsigned long *max_id, hid_t id_type, mhdf_Status *status)
 Open an existing file.
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.
int mhdf_countOpenHandles (mhdf_FileHandle h)
 Get number of open HDF5 objects from file.
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.
void mhdf_fixFileDesc (struct mhdf_FileDesc *copy_ptr, const struct mhdf_FileDesc *orig_addr)
 Fix nested pointers for copied/moved FileDesc struct.
void mhdf_closeFile (mhdf_FileHandle handle, mhdf_Status *status)
 Close the file.

Variables

char struct_mhdf_Status::message [MHDF_MESSAGE_BUFFER_LEN]
long mhdf_EntDesc::start_id
long mhdf_EntDesc::count
int mhdf_EntDesc::vals_per_ent
int * mhdf_EntDesc::dense_tag_indices
int mhdf_EntDesc::num_dense_tags
const char * mhdf_TagDesc::name
enum mhdf_TagDataType mhdf_TagDesc::type
int mhdf_TagDesc::size
int mhdf_TagDesc::bytes
int mhdf_TagDesc::storage
int mhdf_TagDesc::have_sparse
void * mhdf_TagDesc::default_value
int mhdf_TagDesc::default_value_size
void * mhdf_TagDesc::global_value
int mhdf_TagDesc::global_value_size
int * mhdf_TagDesc::dense_elem_indices
int mhdf_TagDesc::num_dense_indices
const char * mhdf_ElemDesc::handle
const char * mhdf_ElemDesc::type
int mhdf_ElemDesc::have_adj
struct mhdf_EntDesc mhdf_ElemDesc::desc
struct mhdf_EntDesc mhdf_FileDesc::nodes
struct mhdf_EntDesc mhdf_FileDesc::sets
int mhdf_FileDesc::have_set_contents
int mhdf_FileDesc::have_set_children
int mhdf_FileDesc::have_set_parents
struct mhdf_ElemDescmhdf_FileDesc::elems
int mhdf_FileDesc::num_elem_desc
struct mhdf_TagDescmhdf_FileDesc::tags
int mhdf_FileDesc::num_tag_desc
int * mhdf_FileDesc::numEntSets
int ** mhdf_FileDesc::defTagsEntSets
int ** mhdf_FileDesc::defTagsVals
size_t mhdf_FileDesc::total_size
unsigned char * mhdf_FileDesc::offset

Typedef Documentation

typedef struct mhdf_ElemDesc MHDF_ElemDesc
typedef struct mhdf_EntDesc MHDF_EntDesc

Data common to sets, nodes, and each element type

typedef struct mhdf_FileDesc MHDF_FileDesc
typedef void* mhdf_FileHandle

Opaque handle to an open file.

Definition at line 87 of file mhdf_public.h.

Definition at line 89 of file mhdf_public.h.

typedef struct mhdf_TagDesc MHDF_TagDesc

Struct describing a tag


Function Documentation

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.

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().

{
    FileHandle* file_ptr;
    API_BEGIN;

    file_ptr = (FileHandle*)( handle );
    if( !mhdf_check_valid_file( file_ptr, status ) ) return;
    /*
      if (file_ptr->open_handle_count)
      {
        mhdf_setError( status, "Cannot close file with %d open data handles.",
          file_ptr->open_handle_count );
        return;
      }
    */

    /* Check for open handles.  HDF5 will not actually close the
       file until all handles are closed. */
    if( mhdf_checkOpenHandles( handle, status ) ) return;

    if( 0 > H5Fclose( file_ptr->hdf_handle ) )
    {
        mhdf_setFail( status, "H5FClose failed.  Invalid handle?" );
        return;
    }

    memset( file_ptr, 0, sizeof( FileHandle ) );
    free( file_ptr );
    mhdf_setOkay( status );
    API_END_H( -1 );
}

Get number of open HDF5 objects from file.

Definition at line 150 of file file.c.

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

{
    return H5Fget_obj_count( ( (FileHandle*)file_handle )->hdf_handle, H5F_OBJ_ALL );
}
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 (Common element type names.), 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.

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().

{
    FileHandle* file_ptr;
    unsigned int flags;
    unsigned char idx;
    size_t i;
    hid_t enum_id, group_id;
    int rval;
    API_BEGIN;

    if( elem_list_len > 255 )
    {
        mhdf_setFail( status, "Element type list too long." );
        return NULL;
    }
    mhdf_setOkay( status );

    /* Create struct to hold working data */
    file_ptr = mhdf_alloc_FileHandle( 0, id_type, status );
    if( !file_ptr ) return NULL;

    /* Create the file */
    flags                = overwrite ? H5F_ACC_TRUNC : H5F_ACC_EXCL;
    file_ptr->hdf_handle = H5Fcreate( filename, flags, H5P_DEFAULT, H5P_DEFAULT );
    if( file_ptr->hdf_handle < 0 )
    {
        mhdf_setFail( status, "Failed to create file \"%s\"", filename );
        free( file_ptr );
        return NULL;
    }

    /* Create file structure */
    if( !make_hdf_group( ROOT_GROUP, file_ptr->hdf_handle, 6, status ) ||
        !make_hdf_group( TAG_GROUP, file_ptr->hdf_handle, 0, status ) ||
        !make_hdf_group( ELEMENT_GROUP, file_ptr->hdf_handle, 8, status ) ||
        !make_hdf_group( NODE_GROUP, file_ptr->hdf_handle, 3, status ) ||
        !make_hdf_group( SET_GROUP, file_ptr->hdf_handle, 5, status ) ||
        !make_hdf_group( NODE_TAG_GROUP, file_ptr->hdf_handle, 0, status ) ||
        !make_hdf_group( SET_TAG_GROUP, file_ptr->hdf_handle, 0, status ) )
    {
        H5Fclose( file_ptr->hdf_handle );
        free( file_ptr );
        return NULL;
    }

    /* Store the max ID as an attribite on the /tstt/ group */
#if defined( H5Gopen_vers ) && H5Gopen_vers > 1
    group_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT );
#else
    group_id = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP );
#endif
    rval = mhdf_create_scalar_attrib( group_id, MAX_ID_ATTRIB, H5T_NATIVE_ULONG, &file_ptr->max_id, status );
    H5Gclose( group_id );
    if( !rval )
    {
        H5Fclose( file_ptr->hdf_handle );
        free( file_ptr );
        return NULL;
    }

    /* Create the type name list in file */
    enum_id = H5Tenum_create( H5T_NATIVE_UCHAR );
    if( enum_id < 0 )
    {
        mhdf_setFail( status, "Failed to store elem type list." );
        H5Fclose( file_ptr->hdf_handle );
        free( file_ptr );
        return NULL;
    }
    for( i = 0; i < elem_list_len; ++i )
    {
        if( !elem_type_list[i] || !*elem_type_list[i] ) continue;

        idx = (unsigned char)i;
        if( H5Tenum_insert( enum_id, elem_type_list[i], &idx ) < 0 )
        {
            mhdf_setFail( status, "Failed to store elem type list." );
            H5Fclose( file_ptr->hdf_handle );
            free( file_ptr );
            return NULL;
        }
    }
#if defined( H5Tcommit_vers ) && H5Tcommit_vers > 1
    if( H5Tcommit2( file_ptr->hdf_handle, TYPE_ENUM_PATH, enum_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT ) < 0 )
#else
    if( H5Tcommit( file_ptr->hdf_handle, TYPE_ENUM_PATH, enum_id ) < 0 )
#endif
    {
        mhdf_setFail( status, "Failed to store elem type list." );
        H5Fclose( file_ptr->hdf_handle );
        free( file_ptr );
        return NULL;
    }
    H5Tclose( enum_id );

    API_END_H( 1 );
    return file_ptr;
}
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.

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().

{
    int i;

    API_BEGIN;
    FIX_OFFSET( int*, nodes.dense_tag_indices );
    FIX_OFFSET( int*, sets.dense_tag_indices );
    FIX_OFFSET( struct mhdf_ElemDesc*, elems );
    FIX_OFFSET( struct mhdf_TagDesc*, tags );

    FIX_OFFSET( int*, numEntSets );
    FIX_OFFSET( int**, defTagsEntSets );
    FIX_OFFSET( int**, defTagsVals );

    for( i = 0; i < 5; i++ )
    {
        if( copy_ptr->defTagsEntSets ) FIX_OFFSET( int*, defTagsEntSets[i] );
        if( copy_ptr->defTagsVals ) FIX_OFFSET( int*, defTagsVals[i] );
    }

    if( copy_ptr->elems != NULL )
    {
        for( i = 0; i < copy_ptr->num_elem_desc; ++i )
        {
            FIX_OFFSET( const char*, elems[i].handle );
            FIX_OFFSET( const char*, elems[i].type );
            FIX_OFFSET( int*, elems[i].desc.dense_tag_indices );
        }
    }

    if( copy_ptr->tags != NULL )
    {
        for( i = 0; i < copy_ptr->num_tag_desc; ++i )
        {
            FIX_OFFSET( const char*, tags[i].name );
            FIX_OFFSET( void*, tags[i].default_value );
            FIX_OFFSET( void*, tags[i].global_value );
            FIX_OFFSET( int*, tags[i].dense_elem_indices );
        }
    }
    API_END;
}
MHDF_FileDesc* mhdf_getFileSummary ( mhdf_FileHandle  file_handle,
hid_t  file_id_type,
mhdf_Status status,
int  extraSetInfo 
) [read]

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.

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().

{
    struct mhdf_FileDesc* result;
    hid_t table_id;
    int i, i1, numtags, j, k, size, *indices, have, num_tag_names = 0;
    unsigned int ui;
    void* ptr;
    char **elem_handles = 0, **tag_names = 0;
    unsigned char *array, *matrix;
    const char* pname[5] = { "PARALLEL_PARTITION", "MATERIAL_SET", "NEUMANN_SET", "DIRICHLET_SET", "GEOM_DIMENSION" };

    long* id_list;
    struct mhdf_TagDesc* tag_desc;
    long int nval, junk;
    hid_t table[3];
    hid_t data_type;

    API_BEGIN;

    mhdf_setOkay( status );
    result = alloc_file_desc( status );
    if( NULL == result ) return NULL;

    /* get node info */
    have = mhdf_haveNodes( file_handle, status );
    if( mhdf_isError( status ) )
    {
        free( result );
        return NULL;
    }
    if( have )
    {
        table_id = mhdf_openNodeCoords( file_handle, &result->nodes.count, &result->nodes.vals_per_ent,
                                        &result->nodes.start_id, status );
        if( table_id < 0 )
        {
            free( result );
            return NULL;
        }
        mhdf_closeData( file_handle, table_id, status );
    }
    else
    {
        result->nodes.count        = 0;
        result->nodes.vals_per_ent = 0;
        result->nodes.start_id     = 0;
    }

    /* get set info */
    result->sets.vals_per_ent = -1;
    have                      = mhdf_haveSets( file_handle, &result->have_set_contents, &result->have_set_children,
                                               &result->have_set_parents, status );
    if( mhdf_isError( status ) )
    {
        free( result );
        return NULL;
    }
    if( have )
    {
        table_id = mhdf_openSetMeta( file_handle, &result->sets.count, &result->sets.start_id, status );
        if( table_id < 0 )
        {
            free( result );
            return NULL;
        }
        mhdf_closeData( file_handle, table_id, status );
    }
    else
    {
        result->sets.count    = 0;
        result->sets.start_id = 0;
    }

    /* get element list */
    elem_handles = mhdf_getElemHandles( file_handle, &ui, status );
    if( elem_handles == NULL )
    {
        free( result );
        return NULL;
    }
    result->num_elem_desc = ui;

    /* allocate array of element descriptors */
    size = result->num_elem_desc * sizeof( struct mhdf_ElemDesc );
    ptr  = realloc_data( &result, size, status, sizeof( char* ) );
    if( NULL == ptr )
    {
        free( elem_handles );
        return NULL;
    }
    memset( ptr, 0, size );
    result->elems = ptr;

    /* Initialize each element descriptor */
    for( i = 0; i < result->num_elem_desc; ++i )
    {
        result = get_elem_desc( file_handle, result, elem_handles[i], i, status );
        if( NULL == result )
        {
            free( elem_handles );
            return NULL;
        }
    }

    /* get tag list */
    tag_names = mhdf_getTagNames( file_handle, &num_tag_names, status );
    if( mhdf_isError( status ) )
    {
        free( elem_handles );
        free( result );
        return NULL;
    }

    /* allocate array of tag descriptors */
    size = num_tag_names * sizeof( struct mhdf_TagDesc );
    ptr  = realloc_data( &result, size, status, sizeof( char* ) );
    if( NULL == ptr )
    {
        free( elem_handles );
        free_string_list( tag_names, result->num_tag_desc );
        return NULL;
    }
    memset( ptr, 0, size );
    result->tags         = ptr;
    result->num_tag_desc = num_tag_names;
    memset( result->tags, 0, size );

    /* Initialize each tag descriptor */
    for( i = 0; i < result->num_tag_desc; ++i )
    {
        result = get_tag_desc( file_handle, result, tag_names[i], i, file_id_type, status );
        if( NULL == result )
        {
            free( elem_handles );
            free_string_list( tag_names, num_tag_names );
            return NULL;
        }
    }

    /* Determine which dense tags are present */

    size  = ( 2 + result->num_elem_desc ) * result->num_tag_desc;
    array = mhdf_malloc( size, status );
    if( NULL == array )
    {
        free( elem_handles );
        free_string_list( tag_names, num_tag_names );
        free( result );
        return NULL;
    }
    memset( array, 0, size );
    matrix = array + ( 2 * result->num_tag_desc );

    for( j = 0; j < result->num_tag_desc; ++j )
    {
        if( mhdf_haveDenseTag( file_handle, tag_names[j], mhdf_node_type_handle(), status ) )
            matrix[-1 * result->num_tag_desc + j] = 1;
        if( mhdf_haveDenseTag( file_handle, tag_names[j], mhdf_set_type_handle(), status ) )
            matrix[-2 * result->num_tag_desc + j] = 1;
        for( i = 0; i < result->num_elem_desc; ++i )
            if( mhdf_haveDenseTag( file_handle, tag_names[j], elem_handles[i], status ) )
                matrix[i * result->num_tag_desc + j] = 1;
    }
    free( elem_handles );
    free_string_list( tag_names, result->num_tag_desc );

    /* Populate dense tag lists for element types */
    for( i = -2; i < result->num_elem_desc; ++i )
    {
        size = 0;
        for( j = 0; j < result->num_tag_desc; ++j )
            size += matrix[i * result->num_tag_desc + j];
        if( !size )
        {
            indices = NULL;
        }
        else
        {
            indices = realloc_data( &result, size * sizeof( int ), status, sizeof( int ) );
            if( NULL == indices )
            {
                free( array );
                return NULL;
            }

            k = 0;
            for( j = 0; j < result->num_tag_desc; ++j )
                if( matrix[i * result->num_tag_desc + j] ) indices[k++] = j;
            assert( k == size );
        }

        if( i == -2 )
        {
            result->sets.dense_tag_indices = indices;
            result->sets.num_dense_tags    = size;
        }
        else if( i == -1 )
        {
            result->nodes.dense_tag_indices = indices;
            result->nodes.num_dense_tags    = size;
        }
        else
        {
            result->elems[i].desc.dense_tag_indices = indices;
            result->elems[i].desc.num_dense_tags    = size;
        }
    }

    /* Populate dense tag lists for each tag */
    for( j = 0; j < result->num_tag_desc; ++j )
    {
        size = 0;
        for( i = -2; i < result->num_elem_desc; ++i )
            size += matrix[i * result->num_tag_desc + j];
        if( !size )
        {
            indices = 0;
        }
        else
        {
            indices = realloc_data( &result, size * sizeof( int ), status, sizeof( int ) );
            if( NULL == ptr )
            {
                free( array );
                return NULL;
            }

            k = 0;
            for( i = -2; i < result->num_elem_desc; ++i )
                if( matrix[i * result->num_tag_desc + j] ) indices[k++] = i;
            assert( k == size );
        }

        result->tags[j].num_dense_indices  = size;
        result->tags[j].dense_elem_indices = indices;
    }

    if( extraSetInfo )
    {
        /* open the table for parallel partitions, material sets, neumann sets,
         * dirichlet sets
         *  to determine number of parts, etc
         *   this is needed for iMOAB and VisIt plugin */
        const int NPRIMARY_SETS = 5;
        ptr                     = realloc_data( &result, NPRIMARY_SETS * sizeof( int ), status, sizeof( int ) );
        if( NULL == ptr || mhdf_isError( status ) )
        {
            free( array );
            return NULL;
        }
        result->numEntSets = ptr;
        for( i = 0; i < NPRIMARY_SETS; ++i )
            result->numEntSets[i] = 0;

        ptr = realloc_data( &result, NPRIMARY_SETS * sizeof( int* ), status, sizeof( int* ) );
        if( NULL == ptr || mhdf_isError( status ) )
        {
            free( array );
            return NULL;
        }
        result->defTagsEntSets = ptr;

        ptr = realloc_data( &result, NPRIMARY_SETS * sizeof( int* ), status, sizeof( int* ) );
        if( NULL == ptr || mhdf_isError( status ) )
        {
            free( array );
            return NULL;
        }
        result->defTagsVals = ptr;
        numtags             = result->num_tag_desc;

        for( i = 0; i < numtags; i++ )
        {
            tag_desc = &( result->tags[i] );
            for( k = 0; k < NPRIMARY_SETS; k++ ) /* number of default tags to consider */
            {
                if( strcmp( pname[k], tag_desc->name ) == 0 )
                {
                    if( tag_desc->have_sparse )
                    {
                        mhdf_openSparseTagData( file_handle, pname[k], &nval, &junk, table, status );
                        if( mhdf_isError( status ) )
                        {
                            free( array );
                            return NULL;
                        }
                        /* for sparse tags, read */
                        result->numEntSets[k] = nval;
                        if( nval <= 0 ) continue; /* do not do anything */

                        ptr = realloc_data( &result, nval * sizeof( int ), status, sizeof( int ) );
                        if( NULL == ptr || mhdf_isError( status ) )
                        {
                            free( array );
                            return NULL;
                        }
                        memset( ptr, 0, nval * sizeof( int ) );
                        result->defTagsEntSets[k] = ptr;
                        tag_desc                  = &( result->tags[i] );

                        ptr = realloc_data( &result, nval * sizeof( int ), status, sizeof( int ) );
                        if( NULL == ptr || mhdf_isError( status ) )
                        {
                            free( array );
                            return NULL;
                        }
                        memset( ptr, 0, nval * sizeof( int ) );
                        result->defTagsVals[k] = ptr;
                        tag_desc               = &( result->tags[i] ); /* this is because the tag might point to
                                                              something else*/

                        /* make room for the long array type
                          is it long or something else? */
                        id_list = mhdf_malloc( nval * sizeof( long ), status );
                        /* fill the id with values, then convert to int type (-set start)

                         mhdf_read_data( table_id, offset, count, int_type, id_list, H5P_DEFAULT,
                         status );*/

                        data_type = H5Dget_type( table[0] );

                        mhdf_read_data( table[0], 0, nval, data_type, id_list, H5P_DEFAULT, status );
                        if( mhdf_isError( status ) )
                        {
                            free( array );
                            return NULL;
                        }
                        H5Tclose( data_type );

                        for( i1 = 0; i1 < nval; i1++ )
                            result->defTagsEntSets[k][i1] = (int)( id_list[i1] - result->sets.start_id + 1 );
                        /* now read values, integer type */
                        data_type = H5Dget_type( table[1] );
                        mhdf_read_data( table[1], 0, nval, data_type, result->defTagsVals[k], H5P_DEFAULT, status );
                        if( mhdf_isError( status ) )
                        {
                            free( array );
                            return NULL;
                        }
                        H5Tclose( data_type );
                        mhdf_closeData( file_handle, table[0], status );
                        if( mhdf_isError( status ) )
                        {
                            free( array );
                            return NULL;
                        }
                        mhdf_closeData( file_handle, table[1], status );
                        if( mhdf_isError( status ) )
                        {
                            free( array );
                            return NULL;
                        }
                        free( id_list );
                    }
                    else if( 0 == k || 1 == k )
                    { /* parallel partition or material sets should still work if dense
 could be dense tags on sets */
                        if( !mhdf_haveDenseTag( file_handle, pname[k], mhdf_set_type_handle(), status ) ) continue;
                        table[0] =
                            mhdf_openDenseTagData( file_handle, pname[k], mhdf_set_type_handle(), &nval, status );
                        if( mhdf_isError( status ) )
                        {
                            continue; /* do not error out if not a dense tag either */
                        }
                        result->numEntSets[k] = nval;
                        if( nval <= 0 ) continue; /* do not do anything */

                        /*
                         * if dense parallel partition or material set, we know what to expect
                         */
                        result->numEntSets[k] = nval; /* k could be 0 or 1 */
                        if( nval <= 0 ) continue;     /* do not do anything */

                        ptr = realloc_data( &result, nval * sizeof( int ), status, sizeof( int ) );
                        if( NULL == ptr || mhdf_isError( status ) )
                        {
                            free( array );
                            return NULL;
                        }
                        memset( ptr, 0, nval * sizeof( int ) );
                        result->defTagsEntSets[k] = ptr;
                        tag_desc                  = &( result->tags[i] );

                        ptr = realloc_data( &result, nval * sizeof( int ), status, sizeof( int ) );
                        if( NULL == ptr || mhdf_isError( status ) )
                        {
                            free( array );
                            return NULL;
                        }
                        memset( ptr, 0, nval * sizeof( int ) );
                        result->defTagsVals[k] = ptr;
                        tag_desc               = &( result->tags[i] ); /* this is because the tag might point to
                                                              something else*/

                        for( i1 = 0; i1 < nval; i1++ )
                        {
                            result->defTagsEntSets[k][i1] = i1 + 1;
                            /*result -> defTagsVals[k][i1] = i1; we know how the partition looks
                             * like  */
                        }
                        /* fill in the data with the dense tag values
                          because dense, sets will be in order

                          we know it has to be integer */
                        mhdf_readTagValues( table[0], 0, nval, H5T_NATIVE_INT, result->defTagsVals[k], status );
                        if( mhdf_isError( status ) )
                        {
                            free( array );
                            return NULL;
                        }
                        mhdf_closeData( file_handle, table[0], status );
                        if( mhdf_isError( status ) )
                        {
                            free( array );
                            return NULL;
                        }
                    }
                }
            }
        }
    }
    /* Compact memory and return */
    free( array );
    result->total_size = result->offset - (unsigned char*)result;

    API_END;
    return result;
}
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.

References mhdf_openFileWithOpt().

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

{
    return mhdf_openFileWithOpt( filename, writeable, max_id_out, id_type, H5P_DEFAULT, status );
}
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.

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().

{
    FileHandle* file_ptr;
    unsigned int flags;
    hid_t group_id;
    int check_is_hdf5 = 1;
#ifdef MOAB_HAVE_HDF5_PARALLEL
    herr_t err;
    MPI_Comm comm;
    MPI_Info info;
#endif
    API_BEGIN;

    /* Check if file is HDF5 */
    /* Don't do this because it can't handle MPI-IO driver code that
       passes options via prefixes on the file name. */
#ifdef MOAB_HAVE_HDF5_PARALLEL
    if( access_prop != H5P_DEFAULT )
    {
        err = H5Pget_fapl_mpio( access_prop, &comm, &info );
        if( err >= 0 )
        {
            check_is_hdf5 = 0;
            /* MPI Documentation is inconsistent with regards to whether
               or not the above call dup's these, but my testing with 1.8.3
               indicates that at least for that version they are not.
            MPI_Comm_free(&comm);
            MPI_Info_free(&info); */
        }
    }
#endif
    if( check_is_hdf5 && H5Fis_hdf5( filename ) <= 0 )
    {
        mhdf_setFail( status, "%s: File is not HDF5", filename );
        return NULL;
    }

    /* Create struct to hold working data */
    file_ptr = mhdf_alloc_FileHandle( 0, id_type, status );
    if( !file_ptr )
    {
        mhdf_setFail( status, "Memory allocation failed" );
        return NULL;
    }

    /* Create the file */
    flags                = writable ? H5F_ACC_RDWR : H5F_ACC_RDONLY;
    file_ptr->hdf_handle = H5Fopen( filename, flags, access_prop );
    if( file_ptr->hdf_handle < 0 )
    {
        mhdf_setFail( status, "Failed to open file \"%s\"", filename );
        free( file_ptr );
        return NULL;
    }

    /* Check for TSTT data in file */
#if defined( H5Gopen_vers ) && H5Gopen_vers > 1
    group_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT );
#else
    group_id     = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP );
#endif
    if( group_id < 0 )
    {
        mhdf_setFail( status, "Invalid file \"%s\"\n", filename );
        H5Fclose( file_ptr->hdf_handle );
        free( file_ptr );
        return NULL;
    }
    H5Gclose( group_id );

    /* Get max id */
    if( !scan_for_max_id( file_ptr, status ) )
    {
        H5Fclose( file_ptr->hdf_handle );
        mhdf_setFail( status, "Internal error reading file" );
        free( file_ptr );
        return NULL;
    }

    if( max_id_out ) *max_id_out = file_ptr->max_id;

    mhdf_setOkay( status );
    API_END_H( 1 );
    return file_ptr;
}

Variable Documentation

Tag size (number of bytes)

Definition at line 195 of file mhdf_public.h.

Referenced by get_tag_desc(), and print_tag_desc().

Definition at line 229 of file mhdf_public.h.

Referenced by mhdf_fixFileDesc(), and mhdf_getFileSummary().

Definition at line 230 of file mhdf_public.h.

Referenced by mhdf_fixFileDesc(), and mhdf_getFileSummary().

Indices into mhdf_FileDesc::tags for each tag for which dense data is present for these entities

Definition at line 186 of file mhdf_public.h.

Referenced by get_elem_desc(), mhdf_fixFileDesc(), mhdf_getFileSummary(), and print_ent_desc().

File contains adjacency data for this element group

Definition at line 210 of file mhdf_public.h.

Referenced by check_valid_adjacencies(), get_elem_desc(), moab::ReadHDF5::load_file_impl(), moab::ReadHDF5::load_file_partial(), and print_elem_desc().

Length of dense_tag_indices

Definition at line 187 of file mhdf_public.h.

Referenced by get_elem_desc(), mhdf_getFileSummary(), and print_ent_desc().

unsigned char* mhdf_FileDesc::offset

Unused, may be used by application

Definition at line 232 of file mhdf_public.h.

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

MOAB tag type (dense or sparse)

Definition at line 196 of file mhdf_public.h.

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

Size of memory block containing all struct data

Definition at line 231 of file mhdf_public.h.

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

Connectivity length for elems, dimension for verts, unused for sets, -1 for variable length poly* data

Definition at line 184 of file mhdf_public.h.

Referenced by check_valid_connectivity(), check_valid_elem_conn(), get_elem_desc(), iMOAB_ReadHeaderInfo(), mhdf_getFileSummary(), print_ent_desc(), moab::ReadHDF5::read_elems(), moab::ReadHDF5::read_node_adj_elems(), and moab::ReadHDF5::read_nodes().

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines