MOAB: Mesh Oriented datABase  (version 5.4.1)
util.h File Reference
#include <sys/types.h>
#include <H5Ipublic.h>
#include "status.h"
#include "file-handle.h"
+ Include dependency graph for util.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define API_BEGIN
#define API_END_H(n)
#define API_END   API_END_H( 0 )

Functions

void * mhdf_malloc (size_t size, mhdf_Status *status)
void * mhdf_realloc (void *ptr, size_t size, mhdf_Status *status)
size_t mhdf_name_to_path (const char *name, char *path, size_t path_len)
int mhdf_path_to_name (const char *path, char *name)
char * mhdf_name_to_path_copy (const char *name, mhdf_Status *status)
char * mhdf_name_to_path_cat (const char *prefix, const char *name, mhdf_Status *status)
hid_t mhdf_elem_group_from_handle (FileHandle *file_ptr, const char *elem_handle, mhdf_Status *status)
int mhdf_create_scalar_attrib (hid_t object, const char *name, hid_t type, const void *value, mhdf_Status *status)
int mhdf_read_scalar_attrib (hid_t object, const char *name, hid_t type, void *value, mhdf_Status *status)
int mhdf_find_attribute (hid_t object, const char *attrib_name, unsigned int *index_out, mhdf_Status *status)
int mhdf_is_in_group (hid_t group, const char *name, mhdf_Status *status)
int mhdf_read_data (hid_t data_table, long offset, long count, hid_t type, void *array, hid_t read_prop, mhdf_Status *status)
int mhdf_write_data (hid_t data_table, long offset, long count, hid_t type, const void *array, hid_t write_prop, mhdf_Status *status)
int mhdf_read_column (hid_t data_table, int column, long offset, long count, hid_t type, void *array, hid_t read_prop, mhdf_Status *status)
int mhdf_write_column (hid_t data_table, int column, long offset, long count, hid_t type, const void *array, hid_t write_prop, mhdf_Status *status)
hid_t mhdf_create_table (hid_t group, const char *path, hid_t type, int rank, hsize_t *dims, mhdf_Status *status)
hid_t mhdf_create_table_with_prop (hid_t group, const char *path, hid_t type, int rank, hsize_t *dims, hid_t dataset_creation_prop, mhdf_Status *status)
hid_t mhdf_open_table (hid_t group, const char *path, int columns, hsize_t *rows_out, mhdf_Status *status)
hid_t mhdf_open_table2 (hid_t group, const char *path, int rank, hsize_t *dims_out, long *start_id_out, mhdf_Status *status)
hid_t mhdf_open_table_simple (hid_t group, const char *path, mhdf_Status *status)
int mhdf_compact_to_ranges (int *length_in_out, int *ids_in, int ordered)
hid_t get_elem_type_enum (FileHandle *file_ptr, mhdf_Status *status)
void mhdf_api_begin_internal (void)
void mhdf_api_end_internal (int expected_diff, const char *filename, int linenumber)
int mhdf_write_max_id (FileHandle *file_ptr, mhdf_Status *status)

Define Documentation

#define API_BEGIN

Definition at line 122 of file util.h.

Referenced by mhdf_addElement(), mhdf_checkOpenHandles(), mhdf_closeFile(), mhdf_createAdjacency(), mhdf_createConnectivity(), mhdf_createDenseTagData(), mhdf_createFile(), mhdf_createNodeCoords(), mhdf_createPolyConnectivity(), mhdf_createSetChildren(), mhdf_createSetData(), mhdf_createSetMeta(), mhdf_createSetParents(), mhdf_createSparseTagData(), mhdf_createTag(), mhdf_createVarLenTag(), mhdf_createVarLenTagData(), mhdf_fixFileDesc(), mhdf_getElemName(), mhdf_getElemTypeName(), mhdf_getFileSummary(), mhdf_getNextStartId(), mhdf_getNumberTags(), mhdf_getTagDataType(), mhdf_getTagInfo(), mhdf_getTagNames(), mhdf_getTagValues(), mhdf_haveAdjacency(), mhdf_haveDenseTag(), mhdf_haveNodes(), mhdf_haveSets(), mhdf_isPolyElement(), mhdf_openAdjacency(), mhdf_openConnectivity(), mhdf_openConnectivitySimple(), mhdf_openDenseTagData(), mhdf_openFileWithOpt(), mhdf_openNodeCoords(), mhdf_openNodeCoordsSimple(), mhdf_openPolyConnectivity(), mhdf_openSetChildren(), mhdf_openSetData(), mhdf_openSetMeta(), mhdf_openSetMetaSimple(), mhdf_openSetParents(), mhdf_openSparseTagData(), mhdf_readAdjacency(), mhdf_readAdjacencyWithOpt(), mhdf_readConnectivity(), mhdf_readConnectivityWithOpt(), mhdf_readHistory(), mhdf_readNodeCoord(), mhdf_readNodeCoords(), mhdf_readNodeCoordsWithOpt(), mhdf_readNodeCoordWithOpt(), mhdf_readPolyConnIDs(), mhdf_readPolyConnIDsWithOpt(), mhdf_readPolyConnIndices(), mhdf_readPolyConnIndicesWithOpt(), mhdf_readSetChildEndIndices(), mhdf_readSetChildEndIndicesWithOpt(), mhdf_readSetContentEndIndices(), mhdf_readSetContentEndIndicesWithOpt(), mhdf_readSetData(), mhdf_readSetDataWithOpt(), mhdf_readSetFlags(), mhdf_readSetFlagsWithOpt(), mhdf_readSetMeta(), mhdf_readSetMetaWithOpt(), mhdf_readSetParentEndIndices(), mhdf_readSetParentEndIndicesWithOpt(), mhdf_readSetParentsChildren(), mhdf_readSetParentsChildrenWithOpt(), mhdf_readSparseTagEntities(), mhdf_readSparseTagEntitiesWithOpt(), mhdf_readSparseTagIndices(), mhdf_readSparseTagIndicesWithOpt(), mhdf_readTagValuesWithOpt(), mhdf_writeAdjacency(), mhdf_writeAdjacencyWithOpt(), mhdf_writeConnectivity(), mhdf_writeConnectivityWithOpt(), mhdf_writeHistory(), mhdf_writeNodeCoord(), mhdf_writeNodeCoords(), mhdf_writeNodeCoordsWithOpt(), mhdf_writeNodeCoordWithOpt(), mhdf_writePolyConnIDs(), mhdf_writePolyConnIDsWithOpt(), mhdf_writePolyConnIndices(), mhdf_writePolyConnIndicesWithOpt(), mhdf_writeSetData(), mhdf_writeSetDataWithOpt(), mhdf_writeSetMeta(), mhdf_writeSetMetaWithOpt(), mhdf_writeSetParentsChildren(), mhdf_writeSetParentsChildrenWithOpt(), mhdf_writeSparseTagEntities(), mhdf_writeSparseTagEntitiesWithOpt(), mhdf_writeSparseTagIndices(), mhdf_writeSparseTagIndicesWithOpt(), and mhdf_writeTagValuesWithOpt().

#define API_END   API_END_H( 0 )

Definition at line 128 of file util.h.

Referenced by mhdf_addElement(), mhdf_createTag(), mhdf_createVarLenTag(), mhdf_fixFileDesc(), mhdf_getElemName(), mhdf_getElemTypeName(), mhdf_getFileSummary(), mhdf_getNextStartId(), mhdf_getNumberTags(), mhdf_getTagDataType(), mhdf_getTagInfo(), mhdf_getTagNames(), mhdf_getTagValues(), mhdf_haveAdjacency(), mhdf_haveDenseTag(), mhdf_haveNodes(), mhdf_haveSets(), mhdf_isPolyElement(), mhdf_readAdjacency(), mhdf_readAdjacencyWithOpt(), mhdf_readConnectivity(), mhdf_readConnectivityWithOpt(), mhdf_readHistory(), mhdf_readNodeCoord(), mhdf_readNodeCoords(), mhdf_readNodeCoordsWithOpt(), mhdf_readNodeCoordWithOpt(), mhdf_readPolyConnIDs(), mhdf_readPolyConnIDsWithOpt(), mhdf_readPolyConnIndices(), mhdf_readPolyConnIndicesWithOpt(), mhdf_readSetChildEndIndices(), mhdf_readSetChildEndIndicesWithOpt(), mhdf_readSetContentEndIndices(), mhdf_readSetContentEndIndicesWithOpt(), mhdf_readSetData(), mhdf_readSetDataWithOpt(), mhdf_readSetFlags(), mhdf_readSetFlagsWithOpt(), mhdf_readSetMeta(), mhdf_readSetMetaWithOpt(), mhdf_readSetParentEndIndices(), mhdf_readSetParentEndIndicesWithOpt(), mhdf_readSetParentsChildren(), mhdf_readSetParentsChildrenWithOpt(), mhdf_readSparseTagEntities(), mhdf_readSparseTagEntitiesWithOpt(), mhdf_readSparseTagIndices(), mhdf_readSparseTagIndicesWithOpt(), mhdf_readTagValuesWithOpt(), mhdf_writeAdjacency(), mhdf_writeAdjacencyWithOpt(), mhdf_writeConnectivity(), mhdf_writeConnectivityWithOpt(), mhdf_writeHistory(), mhdf_writeNodeCoord(), mhdf_writeNodeCoords(), mhdf_writeNodeCoordsWithOpt(), mhdf_writeNodeCoordWithOpt(), mhdf_writePolyConnIDs(), mhdf_writePolyConnIDsWithOpt(), mhdf_writePolyConnIndices(), mhdf_writePolyConnIndicesWithOpt(), mhdf_writeSetData(), mhdf_writeSetDataWithOpt(), mhdf_writeSetMeta(), mhdf_writeSetMetaWithOpt(), mhdf_writeSetParentsChildren(), mhdf_writeSetParentsChildrenWithOpt(), mhdf_writeSparseTagEntities(), mhdf_writeSparseTagEntitiesWithOpt(), mhdf_writeSparseTagIndices(), mhdf_writeSparseTagIndicesWithOpt(), and mhdf_writeTagValuesWithOpt().


Function Documentation

hid_t get_elem_type_enum ( FileHandle file_ptr,
mhdf_Status status 
)

Definition at line 786 of file util.c.

References struct_FileHandle::hdf_handle, mhdf_setFail(), and TYPE_ENUM_PATH.

Referenced by mhdf_addElement(), and mhdf_getElemName().

{
    hid_t result;
#if defined( H5Topen_vers ) && H5Topen_vers > 1
    result = H5Topen2( file_ptr->hdf_handle, TYPE_ENUM_PATH, H5P_DEFAULT );
#else
    result = H5Topen( file_ptr->hdf_handle, TYPE_ENUM_PATH );
#endif
    if( result < 0 ) mhdf_setFail( status, "Element type enum does not exist in file.  Invalid file." );
    return result;
}
void mhdf_api_begin_internal ( void  )

Definition at line 862 of file util.c.

References num_open().

{
    /* HDF5 docs are incorrect.  Passing H5F_OBJ_ALL as the first
       arg to H5Fget_obj_count returns the total number of open
       handles, not just those in files (i.e. temporary types and such.)
    mhdf_api_handle_count = H5Fget_obj_count( H5F_OBJ_ALL, H5F_OBJ_ALL );
       Need to loop to get actual file handles:
    */
    mhdf_api_handle_count = num_open();
}
void mhdf_api_end_internal ( int  expected_diff,
const char *  filename,
int  linenumber 
)

Definition at line 873 of file util.c.

References num_open().

{
    if( mhdf_api_handle_count + expected_diff != num_open() )
    {
        fprintf( stderr, "Unclosed handles at end of mhdf API call.\n" );
        fprintf( stderr, "Entered with %d, expected %d change, got %d.\n", mhdf_api_handle_count, expected_diff,
                 num_open() );
        fprintf( stderr, "%s:%d\n", filename, linenumber );
        abort();
    }

    mhdf_api_handle_count = 0;
}
int mhdf_compact_to_ranges ( int *  length_in_out,
int *  ids_in,
int  ordered 
)

Definition at line 733 of file util.c.

References length(), and qs_comp_int().

{
    int new_length = 0;
    int *iter, *end;
    int prev, count;
    int need_copy = 0;
    int *copy_ptr = 0, *w_iter;
    size_t blen;

    if( !ordered ) qsort( ids, *length, sizeof( int ), &qs_comp_int );

    iter = ids;
    end  = ids + *length;
    while( iter != end )
    {
        prev = *( iter++ );
        while( iter < end && *( iter++ ) == ++prev )
            ;
        new_length += 2;
        if( new_length > ( iter - ids ) ) need_copy = 1;
    }

    if( new_length > *length ) return 0;

    if( need_copy )
    {
        blen     = sizeof( int ) * *length;
        copy_ptr = (int*)malloc( blen );
        memcpy( copy_ptr, ids, blen );
        iter = copy_ptr;
    }
    else
    {
        iter = ids;
    }

    end    = iter + *length;
    w_iter = ids;
    while( iter != end )
    {
        prev  = *( iter++ );
        count = 1;
        while( iter < end && *( iter++ ) == ++prev )
            ;
        *( w_iter++ ) = prev - count;
        *( w_iter++ ) = count;
    }

    *length = new_length;
    if( need_copy ) free( copy_ptr );
    return 1;
}
int mhdf_create_scalar_attrib ( hid_t  object,
const char *  name,
hid_t  type,
const void *  value,
mhdf_Status status 
)

Definition at line 164 of file util.c.

References mhdf_setFail(), and VALGRIND_CHECK_MEM_IS_DEFINED.

Referenced by create_tag_common(), mhdf_addElement(), mhdf_createConnectivity(), mhdf_createFile(), mhdf_createNodeCoords(), mhdf_createPolyConnectivity(), mhdf_createSetMeta(), mhdf_createVarLenTag(), and store_tag_val_in_attrib().

{
    hid_t dspace_id, attr_id;
    herr_t rval;

    dspace_id = H5Screate( H5S_SCALAR );
    if( dspace_id < 0 )
    {
        mhdf_setFail( status, "Internal error calling H5Screate_simple." );
        return 0;
    }

#if defined( H5Acreate_vers ) && H5Acreate_vers > 1
    attr_id = H5Acreate2( object, name, type, dspace_id, H5P_DEFAULT, H5P_DEFAULT );
#else
    attr_id = H5Acreate( object, name, type, dspace_id, H5P_DEFAULT );
#endif
    H5Sclose( dspace_id );
    if( attr_id < 0 )
    {
        mhdf_setFail( status, "Failed to create \"%s\" attrib.", name );
        return 0;
    }

    VALGRIND_CHECK_MEM_IS_DEFINED( value, H5Tget_size( type ) );
    rval = H5Awrite( attr_id, type, value );
    H5Aclose( attr_id );
    if( rval < 0 )
    {
        mhdf_setFail( status, "Failed to write \"%s\" attrib.", name );
        return 0;
    }

    return 1;
}
hid_t mhdf_create_table ( hid_t  group,
const char *  path,
hid_t  type,
int  rank,
hsize_t *  dims,
mhdf_Status status 
)
hid_t mhdf_create_table_with_prop ( hid_t  group,
const char *  path,
hid_t  type,
int  rank,
hsize_t *  dims,
hid_t  dataset_creation_prop,
mhdf_Status status 
)

Definition at line 568 of file util.c.

References mhdf_setFail(), and mhdf_setOkay().

Referenced by mhdf_create_table().

{
    hid_t space_id, table_id;

    space_id = H5Screate_simple( rank, dims, NULL );
    if( space_id < 0 )
    {
        mhdf_setFail( status, "Internal error calling H5Screate_simple." );
        return -1;
    }

#if defined( H5Dcreate_vers ) && H5Dcreate_vers > 1
    table_id = H5Dcreate2( group_id, path, type, space_id, H5P_DEFAULT, create_prop, H5P_DEFAULT );
#else
    table_id = H5Dcreate( group_id, path, type, space_id, create_prop );
#endif
    H5Sclose( space_id );
    if( table_id < 0 )
    {
        mhdf_setFail( status, "HDF5 DataSet creation failed." );
        return -1;
    }

    mhdf_setOkay( status );
    return table_id;
}
hid_t mhdf_elem_group_from_handle ( FileHandle file_ptr,
const char *  elem_handle,
mhdf_Status status 
)

Definition at line 146 of file util.c.

References ELEMENT_GROUP, struct_FileHandle::hdf_handle, mhdf_name_to_path_cat(), and mhdf_setFail().

Referenced by mhdf_createAdjacency(), mhdf_createConnectivity(), mhdf_createDenseTagData(), mhdf_createPolyConnectivity(), mhdf_getElemTypeName(), mhdf_haveAdjacency(), mhdf_haveDenseTag(), mhdf_isPolyElement(), mhdf_openAdjacency(), mhdf_openConnectivity(), mhdf_openConnectivitySimple(), mhdf_openDenseTagData(), and mhdf_openPolyConnectivity().

{
    char* path;
    hid_t result;

    path = mhdf_name_to_path_cat( ELEMENT_GROUP, elem_handle, status );
    if( NULL == path ) return -1;

#if defined( H5Gopen_vers ) && H5Gopen_vers > 1
    result = H5Gopen2( file_ptr->hdf_handle, path, H5P_DEFAULT );
#else
    result  = H5Gopen( file_ptr->hdf_handle, path );
#endif
    free( path );
    if( result < 0 ) mhdf_setFail( status, "Failed to open element group: \"%s\"", elem_handle );
    return result;
}
int mhdf_find_attribute ( hid_t  object,
const char *  attrib_name,
unsigned int *  index_out,
mhdf_Status status 
)

Definition at line 256 of file util.c.

References find_attr_by_name(), and mhdf_setFail().

Referenced by mhdf_getTagInfo(), mhdf_getTagValues(), mhdf_openSparseTagData(), and read_tag_attrib_data().

{
    herr_t rval;
#if defined( H5Aiterate_vers ) && H5Aiterate_vers > 1
    hsize_t idx = 0;
    rval = H5Aiterate2( object, H5_INDEX_CRT_ORDER, H5_ITER_NATIVE, &idx, &find_attr_by_name, (void*)attrib_name );
    *index_out = (unsigned int)idx;
#else
    *index_out = 0;
    rval = H5Aiterate( object, index_out, &find_attr_by_name, (void*)attrib_name );
#endif
    if( rval < 0 ) mhdf_setFail( status, "Internal error calling H5Aiterate." );
    return (int)rval;
}
int mhdf_is_in_group ( hid_t  group,
const char *  name,
mhdf_Status status 
)

Definition at line 280 of file util.c.

References find_link_by_name(), and mhdf_setFail().

Referenced by mhdf_getTagInfo(), mhdf_haveAdjacency(), mhdf_haveDenseTag(), mhdf_haveNodes(), mhdf_haveSets(), mhdf_isPolyElement(), mhdf_readHistory(), and scan_for_max_id().

{
    int rval;
    rval = H5Giterate( group, ".", NULL, &find_link_by_name, (void*)name );
    if( rval < 0 ) mhdf_setFail( status, "Internal error in H5Giterate." );
    return rval;
}
void* mhdf_malloc ( size_t  size,
mhdf_Status status 
)

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 32 of file util.c.

References mhdf_setFail().

Referenced by alloc_file_desc(), mhdf_addElement(), mhdf_alloc_FileHandle(), mhdf_createDenseTagData(), mhdf_getElemHandles(), mhdf_getFileSummary(), mhdf_getTagNames(), mhdf_name_to_path_cat(), mhdf_name_to_path_copy(), mhdf_openDenseTagData(), and mhdf_readHistory().

{
    void* result;
    result = malloc( size );
    if( !result ) mhdf_setFail( status, "Allocation of %d bytes failed.\n", (int)size );
    return result;
}
size_t mhdf_name_to_path ( const char *  name,
char *  path,
size_t  path_len 
)

Definition at line 48 of file util.c.

References length().

Referenced by mhdf_addElement(), mhdf_createDenseTagData(), mhdf_name_to_path_cat(), mhdf_name_to_path_copy(), and mhdf_openDenseTagData().

{
    size_t length = 1;
    unsigned char* iter;

    if( 0 == strcmp( name, "." ) )
    {
        if( path_len >= 4 ) sprintf( path, "\\%02X", (int)*name );
        return 4;
    }

    for( iter = (unsigned char*)name; *iter; ++iter )
    {
        if( iscntrl( *iter ) || *iter == '/' || *iter == '\\' || *iter > 127 )
            length += 3;
        else
            length += 1;
    }
    if( path_len < length ) return length;

    for( iter = (unsigned char*)name; *iter; ++iter )
    {
        if( iscntrl( *iter ) || *iter == '/' || *iter == '\\' || *iter > 127 )
        {
            sprintf( path, "\\%02X", (int)( *iter ) );
            path += 3;
        }
        else
        {
            *( path++ ) = *iter;
        }
    }

    *path = '\0';
    return length;
}
char* mhdf_name_to_path_cat ( const char *  prefix,
const char *  name,
mhdf_Status status 
)

Definition at line 131 of file util.c.

References buffer, mhdf_malloc(), mhdf_name_to_path(), and size.

Referenced by mhdf_elem_group_from_handle().

{
    size_t size, plen;
    char* buffer;

    plen   = strlen( prefix );
    size   = mhdf_name_to_path( name, NULL, 0 ) + 1;
    buffer = (char*)mhdf_malloc( size + plen, status );
    if( !buffer ) return NULL;

    memcpy( buffer, prefix, plen );
    mhdf_name_to_path( name, buffer + plen, size );
    return buffer;
}
char* mhdf_name_to_path_copy ( const char *  name,
mhdf_Status status 
)

Definition at line 118 of file util.c.

References buffer, mhdf_malloc(), mhdf_name_to_path(), and size.

Referenced by create_tag_common(), get_tag(), mhdf_getTagDataType(), and mhdf_haveDenseTag().

{
    size_t size;
    char* buffer;

    size   = mhdf_name_to_path( name, NULL, 0 );
    buffer = (char*)mhdf_malloc( size, status );
    if( !buffer ) return NULL;

    mhdf_name_to_path( name, buffer, size );
    return buffer;
}
hid_t mhdf_open_table ( hid_t  group,
const char *  path,
int  columns,
hsize_t *  rows_out,
mhdf_Status status 
)

Definition at line 601 of file util.c.

References mhdf_setFail(), mhdf_setOkay(), and rank.

Referenced by mhdf_openAdjacency(), mhdf_openDenseTagData(), mhdf_openPolyConnectivity(), mhdf_openSetChildren(), mhdf_openSetData(), mhdf_openSetParents(), and mhdf_openSparseTagData().

{
    hid_t table_id, space_id;
    hsize_t dims[2];
    int rank;

#if defined( H5Dopen_vers ) && H5Dopen_vers > 1
    table_id = H5Dopen2( group_id, path, H5P_DEFAULT );
#else
    table_id = H5Dopen( group_id, path );
#endif
    if( table_id < 0 )
    {
        mhdf_setFail( status, "HDF5 DataSet creation failed." );
        return -1;
    }

    space_id = H5Dget_space( table_id );
    if( space_id < 0 )
    {
        mhdf_setFail( status, "Internal error in H5Dget_space." );
        H5Dclose( table_id );
        return -1;
    }

    rank = H5Sget_simple_extent_ndims( space_id );
    if( rank != ( columns ? 1 : 2 ) )
    {
        mhdf_setFail( status, "Incorrect DataSpace for DataSet." );
        H5Sclose( space_id );
        H5Dclose( table_id );
        return -1;
    }

    rank = H5Sget_simple_extent_dims( space_id, dims, NULL );
    H5Sclose( space_id );
    if( rank < 0 )
    {
        mhdf_setFail( status, "Internal error calling H5Sget_simple_extent_dims." );
        H5Dclose( table_id );
        return -1;
    }

    *rows_out = dims[0];
    mhdf_setOkay( status );
    return table_id;
}
hid_t mhdf_open_table2 ( hid_t  group,
const char *  path,
int  rank,
hsize_t *  dims_out,
long *  start_id_out,
mhdf_Status status 
)

Definition at line 649 of file util.c.

References mhdf_read_scalar_attrib(), mhdf_setFail(), mhdf_setOkay(), and START_ID_ATTRIB.

Referenced by mhdf_openConnectivity(), mhdf_openNodeCoords(), and mhdf_openSetMeta().

{
    hid_t table_id, space_id;

#if defined( H5Dopen_vers ) && H5Dopen_vers > 1
    table_id = H5Dopen2( group_id, path, H5P_DEFAULT );
#else
    table_id = H5Dopen( group_id, path );
#endif
    if( table_id < 0 )
    {
        mhdf_setFail( status, "HDF5 DataSet creation failed." );
        return -1;
    }

    space_id = H5Dget_space( table_id );
    if( space_id < 0 )
    {
        mhdf_setFail( status, "Internal error in H5Dget_space." );
        H5Dclose( table_id );
        return -1;
    }

    if( H5Sget_simple_extent_ndims( space_id ) != rank )
    {
        mhdf_setFail( status, "Incorrect DataSpace for DataSet." );
        H5Sclose( space_id );
        H5Dclose( table_id );
        return -1;
    }

    rank = H5Sget_simple_extent_dims( space_id, dims_out, NULL );
    H5Sclose( space_id );
    if( rank < 0 )
    {
        mhdf_setFail( status, "Internal error calling H5Sget_simple_extent_dims." );
        H5Dclose( table_id );
        return -1;
    }

    if( !mhdf_read_scalar_attrib( table_id, START_ID_ATTRIB, H5T_NATIVE_LONG, start_id_out, status ) )
    {
        mhdf_setFail( status, "File format error.  Failed to retreive ID offset." );
        H5Dclose( table_id );
        return -1;
    }

    mhdf_setOkay( status );
    return table_id;
}
hid_t mhdf_open_table_simple ( hid_t  group,
const char *  path,
mhdf_Status status 
)

Definition at line 705 of file util.c.

References mhdf_setFail(), and mhdf_setOkay().

Referenced by mhdf_openConnectivitySimple(), mhdf_openNodeCoordsSimple(), and mhdf_openSetMetaSimple().

{
    hid_t table_id;

#if defined( H5Dopen_vers ) && H5Dopen_vers > 1
    table_id = H5Dopen2( group_id, path, H5P_DEFAULT );
#else
    table_id = H5Dopen( group_id, path );
#endif
    if( table_id < 0 )
    {
        mhdf_setFail( status, "HDF5 DataSet creation failed." );
    }
    else
    {
        mhdf_setOkay( status );
    }

    return table_id;
}
int mhdf_path_to_name ( const char *  path,
char *  name 
)

Definition at line 93 of file util.c.

References mhdf_hex_char().

Referenced by mhdf_addElement(), mhdf_getElemHandles(), and mhdf_getTagNames().

{
    const char* iter;
    char c1, c2;

    for( iter = path; *iter; ++iter, ++name )
    {
        if( *iter == '\\' )
        {
            c1 = *++iter;
            c2 = *++iter;
            if( !isxdigit( c1 ) || !isxdigit( c2 ) ) return 0;

            *name = (char)( 16 * mhdf_hex_char( c1 ) + mhdf_hex_char( c2 ) );
        }
        else
        {
            *name = *iter;
        }
    }

    *name = '\0';
    return 1;
}
int mhdf_read_column ( hid_t  data_table,
int  column,
long  offset,
long  count,
hid_t  type,
void *  array,
hid_t  read_prop,
mhdf_Status status 
)

Definition at line 539 of file util.c.

References mhdf_readwrite_column().

Referenced by mhdf_readNodeCoord(), and mhdf_readNodeCoordWithOpt().

{
    return mhdf_readwrite_column( data_id, 1, column, offset, count, type, array, prop, status );
}
int mhdf_read_scalar_attrib ( hid_t  object,
const char *  name,
hid_t  type,
void *  value,
mhdf_Status status 
)

Definition at line 200 of file util.c.

References mhdf_setFail().

Referenced by mhdf_getTagInfo(), mhdf_open_table2(), mhdf_openPolyConnectivity(), read_tag_attrib_data(), and scan_for_max_id().

{
    hid_t attr_id, type_id;
    herr_t rval;

    attr_id = H5Aopen_name( object, name );
    if( attr_id < 0 )
    {
        mhdf_setFail( status, "Failed to create \"%s\" attrib.", name );
        return 0;
    }

    if( type > 0 )
    {
        type_id = type;
    }
    else
    {
        type_id = H5Aget_type( attr_id );
        if( type_id < 0 )
        {
            H5Aclose( attr_id );
            return 0;
        }
    }

    rval = H5Aread( attr_id, type_id, value );
    H5Aclose( attr_id );
    if( type < 1 ) H5Tclose( type_id );
    if( rval < 0 )
    {
        mhdf_setFail( status, "Failed to read \"%s\" attrib.", name );
        return 0;
    }

    return 1;
}
void* mhdf_realloc ( void *  ptr,
size_t  size,
mhdf_Status status 
)

Definition at line 40 of file util.c.

References mhdf_setFail().

Referenced by realloc_data().

{
    void* result;
    result = realloc( ptr, size );
    if( !result ) mhdf_setFail( status, "Allocation of %d bytes failed.\n", (int)size );
    return result;
}
int mhdf_write_column ( hid_t  data_table,
int  column,
long  offset,
long  count,
hid_t  type,
const void *  array,
hid_t  write_prop,
mhdf_Status status 
)

Definition at line 551 of file util.c.

References mhdf_readwrite_column().

Referenced by mhdf_writeNodeCoord(), and mhdf_writeNodeCoordWithOpt().

{
    return mhdf_readwrite_column( data_id, 0, column, offset, count, type, (void*)array, prop, status );
}
int mhdf_write_max_id ( FileHandle file_ptr,
mhdf_Status status 
)

Definition at line 798 of file util.c.

References struct_FileHandle::hdf_handle, struct_FileHandle::max_id, MAX_ID_ATTRIB, mhdf_setFail(), and ROOT_GROUP.

Referenced by mhdf_createConnectivity(), mhdf_createNodeCoords(), mhdf_createPolyConnectivity(), and mhdf_createSetMeta().

{
    hid_t group_id, attr_id, space_id;
    herr_t rval;

#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, "Internal error -- file invalid." );
        return 0;
    }

    attr_id = H5Aopen_name( group_id, MAX_ID_ATTRIB );
    if( attr_id < 0 )
    {
        space_id = H5Screate( H5S_SCALAR );
#if defined( H5Acreate_vers ) && H5Acreate_vers > 1
        attr_id = H5Acreate2( group_id, MAX_ID_ATTRIB, H5T_NATIVE_ULONG, space_id, H5P_DEFAULT, H5P_DEFAULT );
#else
        attr_id = H5Acreate( group_id, MAX_ID_ATTRIB, H5T_NATIVE_ULONG, space_id, H5P_DEFAULT );
#endif
        H5Sclose( space_id );
    }
    H5Gclose( group_id );
    if( attr_id < 0 )
    {
        mhdf_setFail( status, "Failed to create attribute \"%s\" on \"%s\"", MAX_ID_ATTRIB, ROOT_GROUP );
        return 0;
    }

    rval = H5Awrite( attr_id, H5T_NATIVE_ULONG, &file_ptr->max_id );
    H5Aclose( attr_id );
    if( rval < 0 )
    {
        mhdf_setFail( status, "Failed to write \"%s\" attrib.", MAX_ID_ATTRIB );
        return 0;
    }

    return 1;
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines