MOAB: Mesh Oriented datABase
(version 5.4.1)
|
#include <stdlib.h>
#include <string.h>
#include <H5Tpublic.h>
#include <H5Gpublic.h>
#include <H5Dpublic.h>
#include <H5Spublic.h>
#include <H5Apublic.h>
#include <H5Ppublic.h>
#include "status.h"
#include "file-handle.h"
#include "mhdf.h"
#include "util.h"
#include "names-and-paths.h"
Go to the source code of this file.
Functions | |
hid_t | mhdf_getNativeType (hid_t input_type, int size, mhdf_Status *status) |
Make type native-endian. | |
static hid_t | get_tag (mhdf_FileHandle file_handle, const char *tag_name, hid_t *id_type, mhdf_Status *status) |
static hid_t | get_tag_type (FileHandle *file_ptr, const char *tag_path, mhdf_Status *status) |
static int | store_tag_val_in_attrib (hid_t tag_id, const char *attrib_name, hid_t type_id, const void *value, hsize_t value_size, mhdf_Status *status) |
static hid_t | create_tag_common (mhdf_FileHandle file_handle, const char *tag_name, enum mhdf_TagDataType tag_type, int size, int storage, const void *default_value, int default_value_size_in, const void *global_value, int global_value_size_in, hid_t hdf_type, hid_t hdf_base_type, mhdf_Status *status) |
hid_t | mhdf_getTagDataType (mhdf_FileHandle file_handle, const char *tag_name, mhdf_Status *status) |
Get handle to HDF5 type object for tag data. | |
void | mhdf_createTag (mhdf_FileHandle file_handle, const char *tag_name, enum mhdf_TagDataType tag_type, int size, int storage, const void *default_value, const void *global_value, hid_t hdf_type, hid_t hdf_base_type, mhdf_Status *status) |
Add a tag to the file. | |
void | mhdf_createVarLenTag (mhdf_FileHandle file_handle, const char *tag_name, enum mhdf_TagDataType tag_type, int storage, const void *default_value, int default_value_length, const void *global_value, int global_value_length, hid_t hdf_type, hid_t hdf_base_type, mhdf_Status *status) |
Add variable-length tag to file. | |
int | mhdf_getNumberTags (mhdf_FileHandle file_handle, mhdf_Status *status) |
Get the number of tags in the file. | |
char ** | mhdf_getTagNames (mhdf_FileHandle file_handle, int *num_names_out, mhdf_Status *status) |
Get the name for each tag defined in the file. | |
static int | get_attrib_array_length_handle (hid_t attrib_id) |
static int | get_attrib_array_length_name (hid_t file, const char *path) |
void | mhdf_getTagInfo (mhdf_FileHandle file_handle, const char *tag_name, enum mhdf_TagDataType *class_out, int *size_out, int *tstt_storage_out, int *have_default_out, int *have_global_out, int *have_sparse_out, mhdf_Status *status) |
Get the description of a specified tag. | |
static int | read_tag_attrib_data (hid_t tag_id, const char *attrib_name, hid_t type_id, void *data, int is_var_len, mhdf_Status *status) |
void | mhdf_getTagValues (mhdf_FileHandle file_handle, const char *tag_name, hid_t output_data_type, void *default_value, void *global_value, mhdf_Status *status) |
Get the default and global values of the tag. | |
int | mhdf_haveDenseTag (mhdf_FileHandle file_handle, const char *tag_name, const char *type_handle, mhdf_Status *status) |
Check if the file contains dense tag data for the specified tag and element group. | |
hid_t | mhdf_createDenseTagData (mhdf_FileHandle file_handle, const char *tag_name, const char *type_handle, long num_values, mhdf_Status *status) |
Create an object to hold dense tag values for a given element group. | |
hid_t | mhdf_openDenseTagData (mhdf_FileHandle file_handle, const char *tag_name, const char *type_handle, long *num_values_out, mhdf_Status *status) |
Open the object containing dense tag values for a given element group. | |
void | mhdf_createSparseTagData (mhdf_FileHandle file_handle, const char *tag_name, long num_values, hid_t handles_out[2], mhdf_Status *status) |
Create file objects to store sparse tag data. | |
void | mhdf_createVarLenTagData (mhdf_FileHandle file_handle, const char *tag_name, long num_entities, long num_values, hid_t handles_out[3], mhdf_Status *status) |
Create file objects to store (sparse) variable-length tag data. | |
void | mhdf_openSparseTagData (mhdf_FileHandle file_handle, const char *tag_name, long *num_entity_out, long *num_values_out, hid_t handles_out[3], mhdf_Status *status) |
Create file objects to read sparse tag data. | |
void | mhdf_writeSparseTagEntities (hid_t table_id, long offset, long count, hid_t int_type, const void *id_list, mhdf_Status *status) |
Write Global ID list for sparse tag data. | |
void | mhdf_writeSparseTagEntitiesWithOpt (hid_t table_id, long offset, long count, hid_t int_type, const void *id_list, hid_t io_prop, mhdf_Status *status) |
void | mhdf_writeTagValues (hid_t table_id, long offset, long count, hid_t tag_type, const void *tag_data, mhdf_Status *status) |
Write tag values. | |
void | mhdf_writeTagValuesWithOpt (hid_t table_id, long offset, long count, hid_t tag_type, const void *tag_data, hid_t io_prop, mhdf_Status *status) |
void | mhdf_writeSparseTagIndices (hid_t table_id, long offset, long count, hid_t int_type, const void *indices, mhdf_Status *status) |
Write sparse tag end indices for variable-length tag data. | |
void | mhdf_writeSparseTagIndicesWithOpt (hid_t table_id, long offset, long count, hid_t int_type, const void *indices, hid_t io_prop, mhdf_Status *status) |
void | mhdf_readSparseTagEntities (hid_t table_id, long offset, long count, hid_t int_type, void *id_list, mhdf_Status *status) |
Read Global ID list for sparse tag data. | |
void | mhdf_readSparseTagEntitiesWithOpt (hid_t table_id, long offset, long count, hid_t int_type, void *id_list, hid_t io_prop, mhdf_Status *status) |
void | mhdf_readTagValues (hid_t table_id, long offset, long count, hid_t tag_type, void *tag_data, mhdf_Status *status) |
Read tag values. | |
void | mhdf_readTagValuesWithOpt (hid_t table_id, long offset, long count, hid_t tag_type, void *tag_data, hid_t io_prop, mhdf_Status *status) |
void | mhdf_readSparseTagIndices (hid_t table_id, long offset, long count, hid_t int_type, void *indices, mhdf_Status *status) |
Read sparse tag end indices for variable-length tag data. | |
void | mhdf_readSparseTagIndicesWithOpt (hid_t table_id, long offset, long count, hid_t int_type, void *indices, hid_t io_prop, mhdf_Status *status) |
static hid_t create_tag_common | ( | mhdf_FileHandle | file_handle, |
const char * | tag_name, | ||
enum mhdf_TagDataType | tag_type, | ||
int | size, | ||
int | storage, | ||
const void * | default_value, | ||
int | default_value_size_in, | ||
const void * | global_value, | ||
int | global_value_size_in, | ||
hid_t | hdf_type, | ||
hid_t | hdf_base_type, | ||
mhdf_Status * | status | ||
) | [static] |
Definition at line 235 of file tags.c.
References struct_FileHandle::hdf_handle, mhdf_BITFIELD, mhdf_BOOLEAN, mhdf_check_valid_file(), mhdf_create_scalar_attrib(), mhdf_ENTITY_ID, mhdf_FLOAT, mhdf_INTEGER, mhdf_name_to_path_copy(), mhdf_OPAQUE, mhdf_setFail(), mhdf_setOkay(), store_tag_val_in_attrib(), TAG_DEFAULT_ATTRIB, TAG_GLOBAL_ATTRIB, TAG_GROUP, TAG_HANDLE_TYPE_ATTRIB, TAG_TYPE_ATTRIB, and TAG_TYPE_NAME.
Referenced by mhdf_createTag(), and mhdf_createVarLenTag().
{ hid_t temp_id, group_id, tag_id; char* path; FileHandle* file_ptr; herr_t rval; hsize_t arr_len; int one = 1, var_len = 0; hsize_t default_value_size = default_value_size_in; hsize_t global_value_size = global_value_size_in; int close_base_type = 0; /* Force standard data types over user-specified types */ if( tag_type != mhdf_OPAQUE ) hdf_type = 0; if( tag_type != mhdf_ENTITY_ID ) hdf_base_type = 0; /* Validate input */ file_ptr = (FileHandle*)file_handle; if( !mhdf_check_valid_file( file_ptr, status ) ) return -1; if( !tag_name || !*tag_name ) { mhdf_setFail( status, "Invalid tag name" ); return -1; } /* Open the tag group */ #if defined( H5Gopen_vers ) && H5Gopen_vers > 1 group_id = H5Gopen2( file_ptr->hdf_handle, TAG_GROUP, H5P_DEFAULT ); #else group_id = H5Gopen( file_ptr->hdf_handle, TAG_GROUP ); #endif if( group_id < 0 ) { mhdf_setFail( status, "H5Gopen(\"%s\") failed.", TAG_GROUP ); return -1; } /* Create path string for tag object */ path = mhdf_name_to_path_copy( tag_name, status ); if( !path ) { H5Gclose( group_id ); return -1; } /* Create group for this tag */ #if defined( H5Gcreate_vers ) && H5Gcreate_vers > 1 tag_id = H5Gcreate2( group_id, path, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT ); #else tag_id = H5Gcreate( group_id, path, 3 ); #endif if( tag_id < 0 ) { mhdf_setFail( status, "H5Gcreate( \"%s\" ) failed.", path ); free( path ); H5Gclose( group_id ); return -1; } /* Store the tag name as the comment on the group entry */ rval = H5Gset_comment( group_id, path, tag_name ); H5Gclose( group_id ); free( path ); if( rval < 0 ) { mhdf_setFail( status, "H5Gset_comment failed for tag \"%s\"", tag_name ); H5Gclose( tag_id ); return -1; } /* Store TSTT tag type as attribute */ rval = mhdf_create_scalar_attrib( tag_id, TAG_TYPE_ATTRIB, H5T_NATIVE_INT, &storage, status ); if( !rval ) { H5Gclose( tag_id ); return -1; } if( hdf_type ) { hdf_type = H5Tcopy( hdf_type ); arr_len = 1; } else { switch( tag_type ) { default: case mhdf_OPAQUE: arr_len = 1; hdf_type = H5Tcreate( H5T_OPAQUE, abs( size ) ); H5Tset_tag( hdf_type, "tag_data" ); break; case mhdf_BITFIELD: arr_len = 1; if( size <= 0 ) { mhdf_setFail( status, "Invalid size (%d) for bit tag.", (int)size ); return -1; } else if( size <= 8 ) hdf_type = H5Tcopy( H5T_NATIVE_B8 ); else if( size <= 16 ) hdf_type = H5Tcopy( H5T_NATIVE_B16 ); else if( size <= 32 ) hdf_type = H5Tcopy( H5T_NATIVE_B32 ); else if( size <= 64 ) hdf_type = H5Tcopy( H5T_NATIVE_B64 ); else { mhdf_setFail( status, "Cannot create a bit tag larger than 64-bits. %d bits requested.\n", (int)size ); return -1; } if( 0 > H5Tset_precision( hdf_type, size ) ) { mhdf_setFail( status, "H5Tset_precision failed." ); return -1; } break; case mhdf_ENTITY_ID: arr_len = abs( size ); hdf_type = H5Tcopy( H5T_NATIVE_ULONG ); break; case mhdf_BOOLEAN: arr_len = abs( size ); hdf_type = H5Tcopy( H5T_NATIVE_UCHAR ); break; case mhdf_INTEGER: arr_len = abs( size ); hdf_type = H5Tcopy( H5T_NATIVE_INT ); break; case mhdf_FLOAT: arr_len = abs( size ); hdf_type = H5Tcopy( H5T_NATIVE_DOUBLE ); break; } } if( hdf_type <= 0 ) { mhdf_setFail( status, "Failed to create tag type object." ); H5Gclose( tag_id ); return -1; } if( hdf_base_type && H5Tget_class( hdf_type ) != H5Tget_class( hdf_base_type ) ) { mhdf_setFail( status, "Invalid base type for tag default/global data" ); H5Gclose( tag_id ); return -1; } if( size < -1 || !arr_len ) { mhdf_setFail( status, "Invalid 'size' parameter passed to mhdf_createTag (%d)", (int)size ); H5Gclose( tag_id ); return -1; } else if( size == -1 ) { /* Note: we don't do anything with this here. We rely on * the app to ask us to create the index table later. */ arr_len = 1; /* need to know this later, when storing default/global values */ var_len = 1; } else if( arr_len > 1 ) { #if defined( H5Tarray_create_vers ) && H5Tarray_create_vers > 1 temp_id = H5Tarray_create2( hdf_type, 1, &arr_len ); #else temp_id = H5Tarray_create( hdf_type, 1, &arr_len, NULL ); #endif H5Tclose( hdf_type ); if( temp_id < 0 ) { mhdf_setFail( status, "Failed to create tag type object." ); H5Gclose( tag_id ); return -1; } hdf_type = temp_id; if( hdf_base_type ) { if( H5Tequal( hdf_base_type, hdf_type ) > 0 ) { hdf_base_type = hdf_type; } else { #if defined( H5Tarray_create_vers ) && H5Tarray_create_vers > 1 temp_id = H5Tarray_create2( hdf_base_type, 1, &arr_len ); #else temp_id = H5Tarray_create( hdf_base_type, 1, &arr_len, NULL ); #endif if( temp_id < 0 ) { mhdf_setFail( status, "Failed to create tag type object." ); H5Gclose( tag_id ); H5Tclose( hdf_type ); return -1; } hdf_base_type = temp_id; close_base_type = 1; } } } if( !hdf_base_type ) hdf_base_type = hdf_type; /* Create tag type object, or write attribute if opaque */ #if defined( H5Tcommit_vers ) && H5Tcommit_vers > 1 rval = H5Tcommit2( tag_id, TAG_TYPE_NAME, hdf_type, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT ); #else rval = H5Tcommit( tag_id, TAG_TYPE_NAME, hdf_type ); #endif if( rval < 0 ) { mhdf_setFail( status, "H5Tcommit failed for tag \"%s\"", tag_name ); if( close_base_type ) H5Tclose( hdf_base_type ); H5Tclose( hdf_type ); H5Gclose( tag_id ); return -1; } /* If tag is entity handle, make note of it */ if( tag_type == mhdf_ENTITY_ID ) { rval = mhdf_create_scalar_attrib( tag_id, TAG_HANDLE_TYPE_ATTRIB, H5T_NATIVE_INT, &one, status ); if( !rval ) { if( close_base_type ) H5Tclose( hdf_base_type ); H5Gclose( tag_id ); H5Tclose( hdf_type ); return -1; } } /* Store the default value as a attribute of the tag group */ if( default_value ) { rval = store_tag_val_in_attrib( tag_id, TAG_DEFAULT_ATTRIB, hdf_base_type, default_value, var_len ? default_value_size : 1, status ); if( !rval ) { if( close_base_type ) H5Tclose( hdf_base_type ); H5Gclose( tag_id ); H5Tclose( hdf_type ); return -1; } } /* Store global tag value as attribute */ if( global_value ) { rval = store_tag_val_in_attrib( tag_id, TAG_GLOBAL_ATTRIB, hdf_base_type, global_value, var_len ? global_value_size : 1, status ); if( !rval ) { if( close_base_type ) H5Tclose( hdf_base_type ); H5Gclose( tag_id ); H5Tclose( hdf_type ); return -1; } } if( close_base_type ) H5Tclose( hdf_base_type ); H5Tclose( hdf_type ); mhdf_setOkay( status ); return tag_id; }
static int get_attrib_array_length_handle | ( | hid_t | attrib_id | ) | [static] |
Definition at line 741 of file tags.c.
References rank.
Referenced by get_attrib_array_length_name().
{ hid_t type_id; int rank; hsize_t dims[H5S_MAX_RANK]; int perm[H5S_MAX_RANK]; type_id = H5Aget_type( attrib_id ); switch( H5Tget_class( type_id ) ) { case H5T_NO_CLASS: dims[0] = -1; break; case H5T_OPAQUE: dims[0] = H5Tget_size( type_id ); break; case H5T_ARRAY: #if defined( H5Tget_array_dims_vers ) && H5Tget_array_dims_vers > 1 (void)perm; /* suppress warning */ rank = H5Tget_array_dims2( type_id, dims ); #else rank = H5Tget_array_dims( type_id, dims, perm ); #endif if( rank == 1 ) break; else return -1; default: dims[0] = 1; break; } H5Tclose( type_id ); return dims[0]; }
static int get_attrib_array_length_name | ( | hid_t | file, |
const char * | path | ||
) | [static] |
Definition at line 793 of file tags.c.
References get_attrib_array_length_handle().
Referenced by mhdf_getTagInfo(), and read_tag_attrib_data().
{ hid_t attrib_id; int result; attrib_id = H5Aopen_name( file, path ); if( attrib_id < 0 ) return -1; result = get_attrib_array_length_handle( attrib_id ); H5Aclose( attrib_id ); return result; }
static hid_t get_tag | ( | mhdf_FileHandle | file_handle, |
const char * | tag_name, | ||
hid_t * | id_type, | ||
mhdf_Status * | status | ||
) | [static] |
Definition at line 106 of file tags.c.
References struct_FileHandle::hdf_handle, struct_FileHandle::id_type, mhdf_check_valid_file(), mhdf_name_to_path_copy(), mhdf_setFail(), mhdf_setOkay(), and TAG_GROUP.
Referenced by mhdf_createSparseTagData(), mhdf_createVarLenTagData(), mhdf_getTagInfo(), mhdf_getTagValues(), and mhdf_openSparseTagData().
{ hid_t group_id, tag_id; char* path; FileHandle* file_ptr; file_ptr = (FileHandle*)file_handle; if( !mhdf_check_valid_file( file_ptr, status ) ) return -1; if( NULL != id_type ) *id_type = file_ptr->id_type; path = mhdf_name_to_path_copy( tag_name, status ); if( NULL == path ) return -1; #if defined( H5Gopen_vers ) && H5Gopen_vers > 1 group_id = H5Gopen2( file_ptr->hdf_handle, TAG_GROUP, H5P_DEFAULT ); #else group_id = H5Gopen( file_ptr->hdf_handle, TAG_GROUP ); #endif if( group_id < 0 ) { mhdf_setFail( status, "Failed to open tag group." ); free( path ); return -1; } #if defined( H5Gopen_vers ) && H5Gopen_vers > 1 tag_id = H5Gopen2( group_id, path, H5P_DEFAULT ); #else tag_id = H5Gopen( group_id, path ); #endif H5Gclose( group_id ); free( path ); if( tag_id < 0 ) { mhdf_setFail( status, "Failed to open tag data for tag \"%s\".", tag_name ); return -1; } mhdf_setOkay( status ); return tag_id; }
static hid_t get_tag_type | ( | FileHandle * | file_ptr, |
const char * | tag_path, | ||
mhdf_Status * | status | ||
) | [static] |
Definition at line 149 of file tags.c.
References struct_FileHandle::hdf_handle, mhdf_setFail(), TAG_GROUP, and TAG_TYPE_NAME.
Referenced by mhdf_createDenseTagData(), and mhdf_getTagDataType().
{ hid_t group_id, tag_id, type_id; #if defined( H5Gopen_vers ) && H5Gopen_vers > 1 group_id = H5Gopen2( file_ptr->hdf_handle, TAG_GROUP, H5P_DEFAULT ); #else group_id = H5Gopen( file_ptr->hdf_handle, TAG_GROUP ); #endif if( group_id < 0 ) { mhdf_setFail( status, "Failed to open tag group." ); return -1; } #if defined( H5Gopen_vers ) && H5Gopen_vers > 1 tag_id = H5Gopen2( group_id, tag_path, H5P_DEFAULT ); #else tag_id = H5Gopen( group_id, tag_path ); #endif H5Gclose( group_id ); if( tag_id < 0 ) { mhdf_setFail( status, "Failed to open group for tag \"%s\".", tag_path ); return -1; } #if defined( H5Topen_vers ) && H5Topen_vers > 1 type_id = H5Topen2( tag_id, TAG_TYPE_NAME, H5P_DEFAULT ); #else type_id = H5Topen( tag_id, TAG_TYPE_NAME ); #endif H5Gclose( tag_id ); if( type_id < 0 ) { mhdf_setFail( status, "Failed to open type data for tag \"%s\".", tag_path ); return -1; } return type_id; }
static int read_tag_attrib_data | ( | hid_t | tag_id, |
const char * | attrib_name, | ||
hid_t | type_id, | ||
void * | data, | ||
int | is_var_len, | ||
mhdf_Status * | status | ||
) | [static] |
Definition at line 1075 of file tags.c.
References get_attrib_array_length_name(), mhdf_find_attribute(), mhdf_read_scalar_attrib(), and mhdf_setFail().
Referenced by mhdf_getTagValues().
{ int rval, ilen; unsigned idx; hid_t read_type = type_id; hsize_t len; /* Check if tag has attribute */ rval = mhdf_find_attribute( tag_id, attrib_name, &idx, status ); if( rval < 0 ) return 0; else if( 0 == rval ) return 1; if( NULL == data ) { mhdf_setFail( status, "Invalid input." ); return 0; } if( is_var_len ) { /* len = get_attrib_array_length_index(tag_id, index); */ ilen = get_attrib_array_length_name( tag_id, attrib_name ); if( ilen < 0 ) { mhdf_setFail( status, "Failed to read length of default/mesh value for tag" ); return 0; } len = ilen; /* caller passes type_id == 0 for OPAQUE */ if( 0 == type_id ) read_type = H5Tcreate( H5T_OPAQUE, len ); else { #if defined( H5Tarray_create_vers ) && H5Tarray_create_vers > 1 read_type = H5Tarray_create2( type_id, 1, &len ); #else read_type = H5Tarray_create( type_id, 1, &len, 0 ); #endif } if( read_type < 0 ) { mhdf_setFail( status, "Failed to read mesh/default value for tag" ); return 0; } } rval = mhdf_read_scalar_attrib( tag_id, attrib_name, read_type, data, status ); if( is_var_len ) H5Tclose( read_type ); return rval; }
static int store_tag_val_in_attrib | ( | hid_t | tag_id, |
const char * | attrib_name, | ||
hid_t | type_id, | ||
const void * | value, | ||
hsize_t | value_size, | ||
mhdf_Status * | status | ||
) | [static] |
Helper function to write default and mesh values for tag
tag_id | The file object upon which to attach the attribute |
attrib_name | The name of the attribute object |
type_id | The data type of the attribute data |
value | Pointer to attribute data |
value_size | Size of attribute data, as multiple of type indicated by type_id. Should be 1 except for variable-length tag data. |
Definition at line 199 of file tags.c.
References mhdf_create_scalar_attrib(), and mhdf_setFail().
Referenced by create_tag_common().
{ hid_t write_type; int rval; if( value_size == 1 ) write_type = type_id; else if( H5Tget_class( type_id ) == H5T_OPAQUE ) { write_type = H5Tcreate( H5T_OPAQUE, value_size ); } else { #if defined( H5Tarray_create_vers ) && H5Tarray_create_vers > 1 write_type = H5Tarray_create2( type_id, 1, &value_size ); #else write_type = H5Tarray_create( type_id, 1, &value_size, 0 ); #endif } if( write_type < 0 ) { mhdf_setFail( status, "Error constructing type object for tag mesh/default value" ); return -1; } rval = mhdf_create_scalar_attrib( tag_id, attrib_name, write_type, value, status ); if( write_type != type_id ) H5Tclose( write_type ); return rval; }