- several API changes

- refactoring
- ... and more
This commit is contained in:
2009-01-30 14:56:01 +00:00
parent 35280e88e0
commit caeefd811d
51 changed files with 2308 additions and 1686 deletions
+12
View File
@@ -377,9 +377,12 @@ src/h5_core/h5_attribs.c -text
src/h5_core/h5_attribs.h -text
src/h5_core/h5_core.h -text
src/h5_core/h5_core_private.h -text
src/h5_core/h5_errno.h -text
src/h5_core/h5_errorhandling.c -text
src/h5_core/h5_errorhandling.h -text
src/h5_core/h5_errorhandling_private.h -text
src/h5_core/h5_fcmp.c -text
src/h5_core/h5_fcmp.h -text
src/h5_core/h5_hdf5.c -text
src/h5_core/h5_hdf5.h -text
src/h5_core/h5_maps.c -text
@@ -395,12 +398,18 @@ src/h5_core/h5_readwrite_private.h -text
src/h5_core/h5_syscall.c -text
src/h5_core/h5_syscall_private.h -text
src/h5_core/h5_types.h -text
src/h5_core/h5_types_private.h -text
src/h5_core/h5b_errorhandling_private.h -text
src/h5_core/h5b_types_private.h -text
src/h5_core/h5t_boundaries.c -text
src/h5_core/h5t_boundaries.h -text
src/h5_core/h5t_boundaries_private.h -text
src/h5_core/h5t_consts.c -text
src/h5_core/h5t_consts_private.h -text
src/h5_core/h5t_errorhandling.c -text
src/h5_core/h5t_errorhandling_private.h -text
src/h5_core/h5t_inquiry.c -text
src/h5_core/h5t_inquiry.h -text
src/h5_core/h5t_map.c -text
src/h5_core/h5t_map.h -text
src/h5_core/h5t_map_private.h -text
@@ -416,6 +425,9 @@ src/h5_core/h5t_types_private.h -text
src/h5_core/h5u_errorhandling_private.h -text
src/h5_core/h5u_readwrite.c -text
src/h5_core/h5u_readwrite.h -text
src/h5_core/h5u_types_private.h -text
src/h5_core/hdf5_misc.c -text
src/h5_core/hdf5_misc.h -text
test/H5Block/BlockTestSpecs.txt -text
test/H5Block/H5BlockDissolveGhosts.c -text
test/H5Block/H5BlockParTestScalarField.c -text
+12 -4
View File
@@ -47,6 +47,7 @@ include_HEADERS = \
h5_core.h \
h5_errorhandling.h \
h5_errorhandling_private.h \
h5_fcmp.h \
h5_hdf5.h \
h5_maps.h \
h5_openclose.h \
@@ -58,15 +59,18 @@ include_HEADERS = \
h5b_errorhandling_private.h \
h5t_boundaries.h \
h5t_boundaries_private.h \
h5t_consts_private.h \
h5t_errorhandling_private.h \
h5t_inquiry.h \
h5t_map.h \
h5t_openclose.h \
h5t_readwrite.h \
h5t_readwrite_private.h \
h5t_storemesh.h
h5t_storemesh_private.h
h5t_storemesh.h \
h5t_storemesh_private.h \
h5u_errorhandling_private.h \
h5u_readwrite.h
h5u_readwrite.h \
hdf5_misc.h
# Listing of all possible headers that I may include
EXTRA_HEADERS =
@@ -75,6 +79,7 @@ EXTRA_HEADERS =
libH5_core_a_SOURCES = \
h5_attribs.c \
h5_errorhandling.c \
h5_fcmp.c \
h5_hdf5.c \
h5_maps.c \
h5_openclose.c \
@@ -83,12 +88,15 @@ libH5_core_a_SOURCES = \
h5_readwrite.c \
h5_syscall.c \
h5t_boundaries.c \
h5t_consts.c \
h5t_errorhandling.c \
h5t_inquiry.c \
h5t_map.c \
h5t_openclose.c \
h5t_readwrite.c \
h5t_storemesh.c \
h5u_readwrite.c
h5u_readwrite.c \
hdf5_misc.c
all: libH5_core.a
+83 -45
View File
@@ -11,11 +11,26 @@
#include "H5Part.h"
#include "H5Block.h"
h5_int64_t
/*!
\ingroup h5_core
\defgroup h5_core_attrib Attribute handling
*/
/*!
\ingroup h5_core_attrib
Read attribute of HDF5 object.
\return \c H5_SUCCESS or error code.
\sa h5_write_attrib(), h5_get_num_attribs(), h5_get_attrib_info()
*/
h5_err_t
h5_read_attrib (
hid_t id,
const char *attrib_name,
void *attrib_value
h5_file_t * const f, /*!< handle to open file */
const hid_t id, /*!< id of HDF5 object */
const char *attrib_name, /*!< name of HDF5 attribute to read */
void * const attrib_value /*!< OUT: attribute value */
) {
herr_t herr;
@@ -26,41 +41,49 @@ h5_read_attrib (
hsize_t nelem;
attrib_id = H5Aopen_name ( id, attrib_name );
if ( attrib_id <= 0 ) return HANDLE_H5A_OPEN_NAME_ERR( attrib_name );
if ( attrib_id <= 0 ) return HANDLE_H5A_OPEN_NAME_ERR( f, attrib_name );
mytype = H5Aget_type ( attrib_id );
if ( mytype < 0 ) return HANDLE_H5A_GET_TYPE_ERR;
if ( mytype < 0 ) return HANDLE_H5A_GET_TYPE_ERR( f );
space_id = H5Aget_space ( attrib_id );
if ( space_id < 0 ) return HANDLE_H5A_GET_SPACE_ERR;
if ( space_id < 0 ) return HANDLE_H5A_GET_SPACE_ERR( f );
nelem = H5Sget_simple_extent_npoints ( space_id );
if ( nelem < 0 ) return HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR;
if ( nelem < 0 ) return HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR( f );
type_id = h5_normalize_h5_type ( mytype );
type_id = h5_normalize_h5_type ( f, mytype );
herr = H5Aread (attrib_id, type_id, attrib_value );
if ( herr < 0 ) return HANDLE_H5A_READ_ERR;
if ( herr < 0 ) return HANDLE_H5A_READ_ERR( f );
herr = H5Sclose ( space_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR( f );
herr = H5Tclose ( mytype );
if ( herr < 0 ) return HANDLE_H5T_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5T_CLOSE_ERR( f );
herr = H5Aclose ( attrib_id );
if ( herr < 0 ) return HANDLE_H5A_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5A_CLOSE_ERR( f );
return H5_SUCCESS;
}
h5_int64_t
/*!
\ingroup h5_core_attrib
Write attribute to HDF5 object.
\return \c H5_SUCCESS or error code.
*/
h5_err_t
h5_write_attrib (
hid_t id,
const char *attrib_name,
const hid_t attrib_type,
const void *attrib_value,
const hsize_t attrib_nelem
h5_file_t * const f, /*!< handle to open file */
const hid_t id, /*!< id of HDF5 object */
const char *attrib_name, /*!< name of HDF5 attribute to write */
const hid_t attrib_type, /*!< HDF5 type of attribute */
const void *attrib_value, /*!< value of attribute */
const hsize_t attrib_nelem /*!< number of elements (dimension) */
) {
herr_t herr;
@@ -69,7 +92,7 @@ h5_write_attrib (
space_id = H5Screate_simple (1, &attrib_nelem, NULL);
if ( space_id < 0 )
return HANDLE_H5S_CREATE_SIMPLE_ERR ( 1 );
return HANDLE_H5S_CREATE_SIMPLE_ERR ( f, 1 );
attrib_id = H5Acreate (
id,
@@ -77,28 +100,36 @@ h5_write_attrib (
attrib_type,
space_id,
H5P_DEFAULT, H5P_DEFAULT );
if ( attrib_id < 0 ) return HANDLE_H5A_CREATE_ERR ( attrib_name );
if ( attrib_id < 0 ) return HANDLE_H5A_CREATE_ERR ( f, attrib_name );
herr = H5Awrite ( attrib_id, attrib_type, attrib_value);
if ( herr < 0 ) return HANDLE_H5A_WRITE_ERR ( attrib_name );
if ( herr < 0 ) return HANDLE_H5A_WRITE_ERR ( f, attrib_name );
herr = H5Aclose ( attrib_id );
if ( herr < 0 ) return HANDLE_H5A_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5A_CLOSE_ERR( f );
herr = H5Sclose ( space_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR( f );
return H5_SUCCESS;
}
h5_int64_t
/*!
\ingroup h5_core_attrib
Get information about an attribute of a HDF5 object.
\return \c H5_SUCCESS or error code.
*/
h5_err_t
h5_get_attrib_info (
hid_t id,
const h5_int64_t attrib_idx,
char *attrib_name,
const h5_int64_t len_attrib_name,
h5_int64_t *attrib_type,
h5_int64_t *attrib_nelem
h5_file_t * const f, /*!< handle to open file */
const hid_t id, /*!< id of HDF5 object */
const h5_int64_t attrib_idx, /*!< index of attribute */
char *attrib_name, /*!< OUT: name of attribute */
const h5_int64_t len_attrib_name, /*!< buffer length */
h5_int64_t *attrib_type, /*!< OUT: H5 type of attribute */
h5_int64_t *attrib_nelem /*!< OUT: number of elements (dimension) */
) {
herr_t herr;
@@ -107,51 +138,58 @@ h5_get_attrib_info (
hid_t space_id;
attrib_id = H5Aopen_idx ( id, (unsigned int)attrib_idx );
if ( attrib_id < 0 ) return HANDLE_H5A_OPEN_IDX_ERR ( attrib_idx );
if ( attrib_id < 0 ) return HANDLE_H5A_OPEN_IDX_ERR ( f, attrib_idx );
if ( attrib_nelem ) {
space_id = H5Aget_space ( attrib_id );
if ( space_id < 0 ) return HANDLE_H5A_GET_SPACE_ERR;
if ( space_id < 0 ) return HANDLE_H5A_GET_SPACE_ERR( f );
*attrib_nelem = H5Sget_simple_extent_npoints ( space_id );
if ( *attrib_nelem < 0 )
return HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR;
return HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR( f );
herr = H5Sclose ( space_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR( f );
}
if ( attrib_name ) {
herr = H5Aget_name (
attrib_id,
(size_t)len_attrib_name,
attrib_name );
if ( herr < 0 ) return HANDLE_H5A_GET_NAME_ERR;
if ( herr < 0 ) return HANDLE_H5A_GET_NAME_ERR( f );
}
if ( attrib_type ) {
mytype = H5Aget_type ( attrib_id );
if ( mytype < 0 ) return HANDLE_H5A_GET_TYPE_ERR;
if ( mytype < 0 ) return HANDLE_H5A_GET_TYPE_ERR( f );
*attrib_type = h5_normalize_h5_type ( mytype );
*attrib_type = h5_normalize_h5_type ( f, mytype );
herr = H5Tclose ( mytype );
if ( herr < 0 ) return HANDLE_H5T_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5T_CLOSE_ERR( f );
}
herr = H5Aclose ( attrib_id);
if ( herr < 0 ) return HANDLE_H5A_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5A_CLOSE_ERR( f );
return H5_SUCCESS;
}
h5_int64_t
/*!
\ingroup h5_core_attrib
Get number of attributes of a HDF5 object.
\return number of attributes or error code.
*/
h5_size_t
h5_get_num_attribs (
h5_file_t *f,
hid_t id
h5_file_t * const f, /*!< handle to open file */
const hid_t id
) {
CHECK_FILEHANDLE ( f );
int nattribs = H5Aget_num_attrs ( id );
if ( nattribs < 0 ) HANDLE_H5A_GET_NUM_ATTRS_ERR;
if ( nattribs < 0 ) HANDLE_H5A_GET_NUM_ATTRS_ERR( f );
return (h5_int64_t) nattribs;
return (h5_size_t) nattribs;
}
+4 -1
View File
@@ -3,6 +3,7 @@
h5_int64_t
h5_read_attrib (
h5_file_t * const f,
hid_t id,
const char *attrib_name,
void *attrib_value
@@ -10,6 +11,7 @@ h5_read_attrib (
h5_int64_t
h5_write_attrib (
h5_file_t * const f,
hid_t id,
const char *attrib_name,
const hid_t attrib_type,
@@ -19,6 +21,7 @@ h5_write_attrib (
h5_int64_t
h5_get_attrib_info (
h5_file_t * const f,
hid_t id,
const h5_int64_t attrib_idx,
char *attrib_name,
@@ -29,7 +32,7 @@ h5_get_attrib_info (
h5_int64_t
h5_get_num_attribs (
h5_file_t *f,
h5_file_t * constf,
hid_t id
);
+4 -1
View File
@@ -2,20 +2,23 @@
#define __H5_CORE_H
#include "h5_types.h"
#include "h5_errno.h"
#include "h5_attribs.h"
#include "h5_errorhandling.h"
#include "h5_fcmp.h"
#include "h5_hdf5.h"
#include "h5_maps.h"
#include "h5_openclose.h"
#include "h5_readwrite.h"
#include "h5_readwrite_private.h"
#include "h5t_boundaries.h"
#include "h5t_inquiry.h"
#include "h5t_map.h"
#include "h5t_openclose.h"
#include "h5t_readwrite.h"
#include "h5t_storemesh.h"
#include "h5u_readwrite.h"
#include "hdf5_misc.h"
#endif
+24 -70
View File
@@ -1,13 +1,17 @@
#ifndef __H5_PRIVATE_H
#define __H5_PRIVATE_H
#include "h5_types_private.h"
#include "h5b_types_private.h"
#include "h5t_types_private.h"
#include "h5u_types_private.h"
#include "h5_errorhandling_private.h"
#include "h5_qsort_private.h"
#include "h5_syscall_private.h"
#include "h5b_errorhandling_private.h"
#include "h5t_boundaries_private.h"
#include "h5t_consts_private.h"
#include "h5t_map_private.h"
#include "h5t_errorhandling_private.h"
#include "h5t_readwrite_private.h"
@@ -22,24 +26,30 @@
#define H5BLOCK_GROUPNAME_BLOCK H5B_CONTAINER_GRPNAME
#define H5_TET_MASK ( (h5_id_t) (0xffffffff >> 3) )
#define _h5t_build_triangle_id( idx, entity_id ) \
( (idx << (sizeof(entity_id)*8 - 3)) | (entity_id & H5_TET_MASK))
/*
ID's: 64bit
Tets:
00000000 tttttttt tttttttt tttttttt tttttttt tttttttt tttttttt tttttttt
00 TT TT TT TT TT TT
Trinagles:
000100dd tttttttt tttttttt tttttttt tttttttt tttttttt tttttttt tttttttt
1D TT TT TT TT TT TT
Edges:
00100eee tttttttt tttttttt tttttttt tttttttt tttttttt tttttttt tttttttt
2E TT TT TT TT TT TT
*/
#define H5_TET_MASK ( (h5_id_t) (ULLONG_MAX >> 8) )
#define _h5t_build_triangle_id( idx, eid ) \
( ( 1ull << (sizeof(eid)*8-4)) | \
(idx << (sizeof(eid)*7)) | \
(eid & H5_TET_MASK))
#if __SIZEOF_POINTER__ == 4
#define TRY(func) if ( (int32_t)(func) == (int32_t)(-1) ) return H5_ERR;
#define TRY2(func,exception) if ( (int32_t)(func) == (int32_t)(-1) ) goto exception;
#elif __SIZEOF_POINTER__ == 8
#define TRY(func) \
if ( (int64_t)(func) == (int64_t)(-1) ) \
if ( (int64_t)(ptrdiff_t)(func) == (int64_t)(-1) ) \
return H5_ERR;
#define TRY2(func,exception) \
if ( (int64_t)(func) == (int64_t)(-1) ) \
if ( (int64_t)(ptrdiff_t)(func) == (int64_t)(-1) ) \
goto exception;
#else
#error "Unknown pointer size!"
#endif
/*!
The functions declared here are not part of the API, but may be used
@@ -50,14 +60,6 @@
Don't use them in applications!
*/
struct _iter_op_data {
int stop_idx;
int count;
int type;
char *name;
size_t len;
char *pattern;
};
h5_int64_t
h5_set_step (
@@ -78,57 +80,9 @@ h5_iteration_operator (
);
#define SET_FNAME( fname ) h5_set_funcname( fname );
hid_t
h5_normalize_h5_type (
hid_t type
);
h5_int64_t
h5_read_attrib (
hid_t id,
const char *attrib_name,
void *attrib_value
);
h5_int64_t
h5_write_attrib (
hid_t id,
const char *attrib_name,
const hid_t attrib_type,
const void *attrib_value,
const hsize_t attrib_nelem
);
h5_int64_t
h5_get_attrib_info (
hid_t id,
const h5_int64_t attrib_idx,
char *attrib_name,
const h5_int64_t len_attrib_name,
h5_int64_t *attrib_type,
h5_int64_t *attrib_nelem
);
h5_int64_t
h5_get_num_objects (
hid_t group_id,
const char *group_name,
const hid_t type
);
h5_int64_t
h5_get_num_objects_matching_pattern (
hid_t group_id,
const char *group_name,
const hid_t type,
char * const pattern
);
h5_int64_t
_H5Part_get_object_name (
h5_file_t * const f,
hid_t group_id,
const char *group_name,
const hid_t type,
+22
View File
@@ -0,0 +1,22 @@
#ifndef __H5_ERRNO_H
#define __H5_ERRNO_H
#define H5_SUCCESS 0
#define H5_ERR -1
#define H5_ERR_BADF -9
#define H5_ERR_NOMEM -12
#define H5_ERR_INVAL -22
#define H5_ERR_BADFD -77
#define H5_ERR_LAYOUT -100
#define H5_ERR_NOENT -101
#define H5_ERR_INIT -200
#define H5_ERR_NOENTRY -201
#define H5_ERR_MPI -201
#define H5_ERR_HDF5 -202
#define H5_ERR_INTERNAL -253
#define H5_ERR_NOT_IMPLEMENTED -254
#endif
+172 -115
View File
@@ -9,12 +9,14 @@
#include "h5_core.h"
#include "h5_core_private.h"
static h5_error_handler _err_handler = h5_report_errorhandler;
static h5_verror_handler _verr_handler = h5_report_verrorhandler;
static h5_err_t _h5_errno = H5_SUCCESS;
static h5_id_t _h5_debug = 0;
static h5_errorhandler_t _h5_errhandler = h5_report_errorhandler;
static h5_int32_t _h5_debuglevel = 0;
static char *__funcname = "NONE";
/*!
\ingroup h5_core
\defgroup h5_core_errorhandling
*/
//static char *__funcname = "NONE";
const char * const H5_O_MODES[] = {
"H5_O_RDWR",
@@ -23,128 +25,148 @@ const char * const H5_O_MODES[] = {
"H5_O_APPEND"
};
/*!
\ingroup h5_core_errorhandling
Set debug/verbosity level. On level 0 all output will be supressed (even
error messages). On level 1 error messages, on level 2 warning messages
and on level 3 informational messages will be printed. On level 4 debug
messages will be printed.
Values less than 0 are equivalent to 0. Values greater than 4 are equivalent
to 4.
\return \c H5_SUCCESS on success.
\return \c H5_ERR_INVAL if debug level is invalid.
*/
h5_err_t
h5_set_debuglevel (
h5_id_t level
h5_id_t debuglevel /*!< debug level */
) {
_h5_debug = level;
if ( debuglevel < 0 || debuglevel > 4 ) return H5_ERR_INVAL;
_h5_debuglevel = debuglevel;
return H5_SUCCESS;
}
h5_err_t
/*!
\ingroup h5_core_errorhandling
Get current debug/verbosity level.
\return current debug level
*/
h5_id_t
h5_get_debuglevel (
void
) {
return _h5_debug;
return _h5_debuglevel;
}
/*!
\ingroup h5_core_errorhandling
Set own error handler.
\return \c H5_SUCCESS
*/
h5_err_t
h5_set_errorhandler (
h5_error_handler handler
h5_errorhandler_t handler
) {
_err_handler = handler;
_h5_errhandler = handler;
return H5_SUCCESS;
}
h5_error_handler
/*!
\ingroup h5_core_errorhandling
Return pointer to current error handler.
\return \c H5_SUCCESS
*/
h5_errorhandler_t
h5_get_errorhandler (
void
) {
return _err_handler;
return _h5_errhandler;
}
h5_verror_handler
h5_get_verrorhandler (
void
) {
return _verr_handler;
}
/*!
\ingroup h5_core_errorhandling
Get current error number.
\return \c H5_SUCCESS
*/
h5_err_t
h5_get_errno (
void
h5_file_t * const f
) {
return _h5_errno;
return f->__errno;
}
/*!
\ingroup h5_core_errorhandling
Set error number.
\return \c H5_SUCCESS
*/
void
h5_set_errno (
h5_file_t * const f,
h5_err_t h5_errno
) {
_h5_errno = h5_errno;
f->__errno = h5_errno;
}
/*!
\ingroup h5part_errhandle
\ingroup h5_core_errorhandling
This is the H5Part default error handler. If an error occures, an
error message will be printed and an error number will be returned.
This is the H5 default error handler. If an error occures, the
error message will be printed, if debug level is greater than 0.
\return value given in \c eno
\return \c f->__errno
*/
h5_err_t
h5_report_errorhandler (
const char *funcname,
const h5_err_t eno,
const char *fmt,
...
) {
_h5_errno = eno;
if ( _h5_debug > 0 ) {
va_list ap;
va_start ( ap, fmt );
h5_vprint_error ( fmt, ap );
va_end ( ap );
}
return _h5_errno;
}
h5_err_t
h5_report_verrorhandler (
const char *funcname,
const h5_err_t eno,
h5_file_t * const f,
const char *fmt,
va_list ap
) {
_h5_errno = eno;
if ( _h5_debug > 0 ) {
h5_vprint_error ( fmt, ap );
if ( _h5_debuglevel > 0 ) {
h5_verror ( f, fmt, ap );
}
return _h5_errno;
return f->__errno;
}
/*!
\ingroup h5part_errhandle
\ingroup h5_core_errorhandling
If an error occures, an error message will be printed and the
program exists with the error code given in \c eno.
If an error occures, the error message will be printed and the
program exists with the error code given in \c f->__errno.
*/
h5_err_t
h5_abort_errorhandler (
const char *funcname,
const h5_err_t eno,
h5_file_t * const f,
const char *fmt,
...
va_list ap
) {
_h5_errno = eno;
if ( _h5_debug > 0 ) {
va_list ap;
va_start ( ap, fmt );
fprintf ( stderr, "%s: ", funcname );
if ( _h5_debuglevel > 0 ) {
fprintf ( stderr, "%s: ", f->__funcname );
vfprintf ( stderr, fmt, ap );
fprintf ( stderr, "\n" );
}
exit (-(int)_h5_errno);
exit (-(int)f->__errno);
}
static void
_vprintf (
FILE* f,
const char *prefix,
const char *__funcname,
const char *fmt,
va_list ap
) {
@@ -154,140 +176,175 @@ _vprintf (
strlen ( __funcname ) + 16 );
if ( fmt2 == NULL ) return;
sprintf ( fmt2, "%s: %s: %s\n", prefix, __funcname, fmt );
vfprintf ( stderr, fmt2, ap );
vfprintf ( f, fmt2, ap );
free ( fmt2 );
}
/*!
\ingroup h5_core_errorhandling
Print error message via error handler.
\return \c f->__errno
*/
h5_err_t
h5_error (
h5_err_t error_no,
h5_file_t * const f,
h5_err_t __errno,
const char *fmt,
...
) {
f->__errno = __errno;
va_list ap;
va_start ( ap, fmt );
(*h5_get_verrorhandler()) ( h5_get_funcname(), error_no, fmt, ap );
(*_h5_errhandler)( f, fmt, ap );
va_end ( ap );
return error_no;
return f->__errno;
}
/*!
\ingroup h5_core_errorhandling
Print error message to \c stderr. For use in error handlers only.
*/
void
h5_vprint_error (
h5_verror (
h5_file_t * const f,
const char *fmt,
va_list ap
) {
if ( _h5_debug < 1 ) return;
_vprintf ( stderr, "E", fmt, ap );
if ( _h5_debuglevel < 1 ) return;
_vprintf ( stderr, "E", f->__funcname, fmt, ap );
}
void
h5_print_error (
const char *fmt,
...
) {
va_list ap;
va_start ( ap, fmt );
h5_vprint_error ( fmt, ap );
va_end ( ap );
}
/*!
\ingroup h5_core_errorhandling
Print a warning message to \c stderr.
*/
void
h5_vprint_warn (
h5_vwarn (
h5_file_t * const f,
const char *fmt,
va_list ap
) {
if ( _h5_debug < 2 ) return;
_vprintf ( stderr, "W", fmt, ap );
if ( _h5_debuglevel < 2 ) return;
_vprintf ( stderr, "W", f->__funcname, fmt, ap );
}
/*!
\ingroup h5_core_errorhandling
Print a warning message to \c stderr.
*/
void
h5_print_warn (
h5_warn (
h5_file_t * const f,
const char *fmt,
...
) {
va_list ap;
va_start ( ap, fmt );
h5_vprint_warn ( fmt, ap );
h5_vwarn ( f, fmt, ap );
va_end ( ap );
}
/*!
\ingroup h5_core_errorhandling
Print an informational message to \c stdout.
*/
void
h5_vprint_info (
h5_vinfo (
h5_file_t * const f,
const char *fmt,
va_list ap
) {
if ( _h5_debug < 3 ) return;
_vprintf ( stdout, "I", fmt, ap );
if ( _h5_debuglevel < 3 ) return;
_vprintf ( stdout, "I", f->__funcname, fmt, ap );
}
/*!
\ingroup h5_core_errorhandling
Print an informational message to \c stdout.
*/
void
h5_print_info (
h5_info (
h5_file_t * const f,
const char *fmt,
...
) {
va_list ap;
va_start ( ap, fmt );
h5_vprint_info ( fmt, ap );
h5_vinfo ( f, fmt, ap );
va_end ( ap );
}
/*!
\ingroup h5_core_errorhandling
Print a debug message to \c stdout.
*/
void
h5_vprint_debug (
h5_vdebug (
h5_file_t * const f,
const char *fmt,
va_list ap
) {
if ( _h5_debug < 4 ) return;
_vprintf ( stdout, "D", fmt, ap );
if ( _h5_debuglevel < 4 ) return;
_vprintf ( stdout, "D", f->__funcname, fmt, ap );
}
/*!
\ingroup h5_core_errorhandling
Print a debug message to \c stdout.
*/
void
h5_print_debug (
h5_debug (
h5_file_t * const f,
const char *fmt,
...
) {
va_list ap;
va_start ( ap, fmt );
h5_vprint_debug ( fmt, ap );
h5_vdebug ( f, fmt, ap );
va_end ( ap );
}
/*!
\ingroup h5_core_errorhandling
Set function name. This name will used as prefix to all message.
*/
void
h5_set_funcname (
const char * const fname
h5_file_t * const f,
const char * const fname
) {
__funcname = (char * const) fname;
f->__funcname = (char * const) fname;
}
/*!
\ingroup h5_core_errorhandling
Get function name.
*/
const char *
h5_get_funcname (
void
h5_file_t * const f
) {
return __funcname;
return f->__funcname;
}
const char *
h5_get_objname (
hid_t id
) {
static char objname[256];
memset ( objname, 0, sizeof(objname) );
ssize_t size = H5Iget_name ( id, objname, sizeof(objname) );
if ( size < 0 ) {
strcpy ( objname, "[error getting object name]" );
} else if ( size == 0 ) {
strcpy ( objname, "[no name associated with identifier]" );
}
return objname;
}
+52 -64
View File
@@ -1,42 +1,35 @@
#ifndef __ERRORHANDLING_H
#define __ERRORHANDLING_H
#define h5_debug h5_print_debug
#define h5_info h5_print_info
#define h5_warn h5_print_warn
#if 0
#define h5_error h5_print_error
#endif
#define SET_FNAME( fname ) h5_set_funcname( fname );
#define SET_FNAME( f, fname ) h5_set_funcname( f, fname );
#define CHECK_FILEHANDLE( f ) \
if ( f == NULL ) \
return HANDLE_H5_BADFD_ERR;
return HANDLE_H5_BADFD_ERR( f );
#define CHECK_WRITABLE_MODE( f ) \
if ( f->mode==H5_O_RDONLY ) \
return (*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_INVAL, \
#define CHECK_WRITABLE_MODE( f ) \
if ( f->mode==H5_O_RDONLY ) \
return h5_error ( \
f, \
H5_ERR_INVAL, \
"Attempting to write to read-only file" );
#define CHECK_READONLY_MODE( f ) \
if ( ! f->mode==H5_O_RDONLY ) \
return (*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_INVAL, \
#define CHECK_READONLY_MODE( f ) \
if ( ! f->mode==H5_O_RDONLY ) \
return h5_error ( \
f, \
H5_ERR_INVAL, \
"Operation is not allowed on writable files." );
#define CHECK_TIMEGROUP( f ) \
if ( f->step_gid <= 0 ) \
return (*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_INVAL, \
#define CHECK_TIMEGROUP( f ) \
if ( f->step_gid <= 0 ) \
return h5_error ( \
f, \
H5_ERR_INVAL, \
"Internal error: step_gid <= 0.");
h5_err_t
h5_set_debuglevel (
h5_id_t level
h5_id_t debuglevel
);
h5_err_t
@@ -46,126 +39,121 @@ h5_get_debuglevel (
h5_err_t
h5_set_errorhandler (
h5_error_handler handler
h5_errorhandler_t errorhandler
);
h5_error_handler
h5_errorhandler_t
h5_get_errorhandler (
void
);
h5_err_t
h5_get_errno (
void
h5_file_t * const f
);
void
h5_set_errno (
h5_file_t * const f,
h5_err_t h5_errno
);
h5_err_t
h5_report_errorhandler (
const char *funcname,
const h5_err_t eno,
const char *fmt,
...
);
h5_err_t
h5_report_verrorhandler (
const char *funcname,
const h5_err_t eno,
h5_file_t * const f,
const char *fmt,
va_list ap
);
h5_err_t
h5_abort_errorhandler (
const char *funcname,
const h5_err_t eno,
h5_file_t * const f,
const char *fmt,
...
va_list ap
) ;
h5_err_t
h5_error (
h5_file_t * const f,
h5_err_t error_no,
const char *fmt,
...
);
void
h5_vprint_error (
const char *fmt,
va_list ap
);
void
h5_print_error (
const char *fmt,
... )
)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
__attribute__ ((format (printf, 3, 4)))
#endif
;
void
h5_vprint_warn (
h5_verror (
h5_file_t * const f,
const char *fmt,
va_list ap
);
void
h5_print_warn (
h5_vwarn (
h5_file_t * const f,
const char *fmt,
va_list ap
);
void
h5_warn (
h5_file_t * const f,
const char *fmt,
...
)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
__attribute__ ((format (printf, 2, 3)))
#endif
;
void
h5_vprint_info (
h5_vinfo (
h5_file_t * const f,
const char *fmt,
va_list ap
);
void
h5_print_info (
h5_info (
h5_file_t * const f,
const char *fmt,
...
)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
__attribute__ ((format (printf, 2, 3)))
#endif
;
void
h5_vprint_debug (
h5_vdebug (
h5_file_t * const f,
const char *fmt,
va_list ap
);
void
h5_print_debug (
h5_debug (
h5_file_t * const f,
const char *fmt,
...
)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
__attribute__ ((format (printf, 2, 3)))
#endif
;
void
h5_set_funcname (
h5_file_t * const f,
const char * const fname
);
const char *
h5_get_funcname (
void
h5_file_t * const f
);
const char *
+147 -89
View File
@@ -1,332 +1,390 @@
#ifndef __ERRORHANDLING_PRIVATE_H
#define __ERRORHANDLING_PRIVATE_H
#define h5_error_not_implemented( file, func, lino ) \
#define h5_error_not_implemented( f, file, func, lino ) \
h5_error( \
f, \
H5_ERR_NOT_IMPLEMENTED, \
"%s: Function \"%s\", line %d not yet implemented!", \
file, func, lino );
#define h5_error_internal( file, func, lino ) \
#define h5_error_internal( f, file, func, lino ) \
h5_error( \
f, \
H5_ERR_INTERNAL, \
"%s: Internal error: %s line %d!", \
file, func, lino )
#define HANDLE_H5_NOENT_ERR( name ) \
h5_error( \
H5PART_ERR_NOENT, \
#define HANDLE_H5_NOENT_ERR( f, name ) \
h5_error( \
f, \
H5_ERR_NOENT, \
"Object \"%s\" doesn't exists.", name );
#define HANDLE_H5_DATASET_RANK_ERR( m, n ) \
h5_error( \
H5PART_ERR_INVAL, \
#define HANDLE_H5_DATASET_RANK_ERR( f, m, n ) \
h5_error( \
f, \
H5_ERR_INVAL, \
"Wrong rank of dataset: Is %d, but should be %d", \
m, n );
#define HANDLE_H5_GROUP_EXISTS_ERR( name ) \
h5_error( \
H5PART_ERR_INVAL, \
#define HANDLE_H5_GROUP_EXISTS_ERR( f, name ) \
h5_error( \
f, \
H5_ERR_INVAL, \
"Group \"%s\" already exists", name )
/**************** H5 *********************/
#define HANDLE_H5_BADFD_ERR \
h5_error( \
H5_ERR_BADFD, \
#define HANDLE_H5_BADFD_ERR( f ) \
h5_error( \
f, \
H5_ERR_BADFD, \
"Called with bad filehandle." );
#define HANDLE_H5_INIT_ERR \
h5_error( \
H5_ERR_INIT, \
"Cannot initialize H5Part." );
#define HANDLE_H5_INIT_ERR( f ) \
h5_error( \
f, \
H5_ERR_INIT, \
"Cannot initialize H5." );
#define HANDLE_H5_NOMEM_ERR \
h5_error( \
H5_ERR_NOMEM, \
#define HANDLE_H5_NOMEM_ERR( f ) \
h5_error( \
f, \
H5_ERR_NOMEM, \
"Out of memory." );
#define HANDLE_H5_SETSTEP_ERR( rc, step ) \
h5_error\
h5_get_funcname(), \
rc, \
#define HANDLE_H5_SETSTEP_ERR( f, rc, step ) \
h5_error( \
f, \
h5_get_funcname(), \
rc, \
"Cannont set step to %lld.", (long long)step );
#define _h5_handle_file_mode_error( mode_id ) \
h5_error( \
#define _h5_handle_file_mode_error( f, mode_id ) \
h5_error( \
f, \
H5_ERR_BADF, \
"Operation not permitted in mode \"%s\"", \
H5_O_MODES[mode_id] );
#define HANDLE_H5_FILE_ACCESS_TYPE_ERR( flags ) \
h5_error( \
H5_ERR_INVAL, \
#define HANDLE_H5_FILE_ACCESS_TYPE_ERR( f, flags ) \
h5_error( \
f, \
H5_ERR_INVAL, \
"Invalid file access mode \"%d\".", flags);
#define HANDLE_H5_STEP_EXISTS_ERR( step ) \
h5_error( \
H5_ERR_INVAL, \
"Step #%lld already exists, step cannot be set to an existing" \
" step in write and append mode", (long long)step );
#define HANDLE_H5_STEP_EXISTS_ERR( f, step ) \
h5_error( \
f, \
H5_ERR_INVAL, \
"Step #%lld already exists, step cannot be set " \
"to an existing step in write and append mode", \
(long long)step );
#define HANDLE_H5_NOENTRY_ERR( group_name, type, idx ) \
#define HANDLE_H5_NOENTRY_ERR( f, group_name, type, idx ) \
h5_error( \
f, \
H5_ERR_NOENTRY, \
"No entry with index %lld and type %d in group %s!", \
(long long)idx, type, group_name );
#define HANDLE_H5_OVERFLOW_ERR( otype, max ) \
h5_error( \
H5_ERR_INVAL, \
"Cannot store more than %d %s", max, otype );
#define HANDLE_H5_OVERFLOW_ERR( f, otype, max ) \
h5_error( \
f, \
H5_ERR_INVAL, \
"Cannot store more than %lld %s", max, otype );
#define HANDLE_H5_PARENT_ID_ERR( otype, oid, pid ) \
#define HANDLE_H5_PARENT_ID_ERR( f, otype, oid, pid ) \
h5_error( \
f, \
H5_ERR_INVAL, \
"Impossible parent_id %d for %s with global id %d", \
pid, otype, oid );
#define HANDLE_H5_OUT_OF_RANGE_ERR( otype, oid ) \
h5_error( \
H5_ERR_INVAL, \
"%s id %d out of range", \
#define HANDLE_H5_OUT_OF_RANGE_ERR( f, otype, oid ) \
h5_error( \
f, \
H5_ERR_INVAL, \
"%s id %lld out of range", \
otype, oid );
/**************** HDF5 *********************/
/* H5A: Attribute */
#define HANDLE_H5A_CLOSE_ERR \
#define HANDLE_H5A_CLOSE_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot terminate access to attribute." );
#define HANDLE_H5A_CREATE_ERR( s ) \
#define HANDLE_H5A_CREATE_ERR( f, s ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot create attribute \"%s\".", s );
#define HANDLE_H5A_GET_NAME_ERR \
#define HANDLE_H5A_GET_NAME_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot get attribute name." );
#define HANDLE_H5A_GET_NUM_ATTRS_ERR \
#define HANDLE_H5A_GET_NUM_ATTRS_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot get number of attributes." );
#define HANDLE_H5A_GET_SPACE_ERR \
#define HANDLE_H5A_GET_SPACE_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot get a copy of dataspace for attribute." );
#define HANDLE_H5A_GET_TYPE_ERR \
#define HANDLE_H5A_GET_TYPE_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot get attribute datatype." );
#define HANDLE_H5A_OPEN_IDX_ERR( n ) \
#define HANDLE_H5A_OPEN_IDX_ERR( f, n ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot open attribute specified by index \"%lld\".", \
(long long)n );
#define HANDLE_H5A_OPEN_NAME_ERR( s ) \
#define HANDLE_H5A_OPEN_NAME_ERR( f, s ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot open attribute specified by name \"%s\".", s );
#define HANDLE_H5A_READ_ERR \
#define HANDLE_H5A_READ_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot read attribute" );
#define HANDLE_H5A_WRITE_ERR( s ) \
#define HANDLE_H5A_WRITE_ERR( f, s ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot write attribute \"%s\".", s );
/* H5D: Dataset */
#define HANDLE_H5D_CLOSE_ERR \
#define HANDLE_H5D_CLOSE_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Close of dataset failed." );
#define HANDLE_H5D_CREATE_ERR( s ) \
#define HANDLE_H5D_CREATE_ERR( f, s ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot create dataset name \"%s\"", \
s );
#define HANDLE_H5D_GET_SPACE_ERR \
#define HANDLE_H5D_GET_SPACE_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot get dataspace identifier.");
#define HANDLE_H5D_GET_TYPE_ERR \
#define HANDLE_H5D_GET_TYPE_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot determine dataset type.");
#define HANDLE_H5D_OPEN_ERR( s ) \
#define HANDLE_H5D_OPEN_ERR( f, s ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot open dataset \"%s\".", s );
#define HANDLE_H5D_READ_ERR( s ) \
#define HANDLE_H5D_READ_ERR( f, s ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Read from dataset \"%s\".", \
s );
#define HANDLE_H5D_WRITE_ERR( s ) \
#define HANDLE_H5D_WRITE_ERR( f, s ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Write to dataset \"%s\" failed.", \
s );
/* H5F: file */
#define HANDLE_H5F_CLOSE_ERR \
#define HANDLE_H5F_CLOSE_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot terminate access to file." );
#define HANDLE_H5F_OPEN_ERR( filename, flags ) \
#define HANDLE_H5F_OPEN_ERR( f, filename, flags ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot open file \"%s\" with mode \"%d\"", \
filename, flags );
/* H5G: group */
#define HANDLE_H5G_CLOSE_ERR \
#define HANDLE_H5G_CLOSE_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot terminate access to datagroup." );
#define HANDLE_H5G_CREATE_ERR( s ) \
#define HANDLE_H5G_CREATE_ERR( f, s ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot create datagroup \"%s\".", s );
#define HANDLE_H5G_GET_OBJINFO_ERR( s ) \
#define HANDLE_H5G_GET_OBJINFO_ERR( f, s ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot get information about object \"%s\".", s );
#define HANDLE_H5G_OPEN_ERR( parent_id, grp_name ) \
#define HANDLE_H5G_OPEN_ERR( f, parent_id, grp_name ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot open group \"%s/%s\".", parent_id, grp_name );
/* H5P: property */
#define HANDLE_H5P_CLOSE_ERR( s ) \
#define HANDLE_H5P_CLOSE_ERR( f, s ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot terminate access to property list \"%s\".", s );
#define HANDLE_H5P_CREATE_ERR \
#define HANDLE_H5P_CREATE_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot create property list." );
#define HANDLE_H5P_SET_DXPL_MPIO_ERR \
#define HANDLE_H5P_SET_DXPL_MPIO_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"MPI: Cannot set data transfer mode." );
#define HANDLE_H5P_SET_FAPL_MPIO_ERR \
#define HANDLE_H5P_SET_FAPL_MPIO_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot store IO communicator information to the " \
"file access property list.");
/* H5S: dataspace */
#define HANDLE_H5S_CREATE_SIMPLE_ERR( rank ) \
#define HANDLE_H5S_CREATE_SIMPLE_ERR( f, rank ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot create dataspace with rank %d.", \
rank );
#define HANDLE_H5S_CREATE_SIMPLE_3D_ERR( dims ) \
#define HANDLE_H5S_CREATE_SIMPLE_3D_ERR( f, dims ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot create 3d dataspace with dimension sizes " \
"\"(%lld,%lld,%lld)\".", \
(long long)dims[0], (long long)dims[1], (long long)dims[2] );
#define HANDLE_H5S_CLOSE_ERR \
#define HANDLE_H5S_CLOSE_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot terminate access to dataspace." );
#define HANDLE_H5S_GET_SELECT_NPOINTS_ERR \
#define HANDLE_H5S_GET_SELECT_NPOINTS_ERR(f) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot determine the number of elements" \
"in dataspace selection." );
#define HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR \
#define HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot determine number of elements in dataspace." );
#define HANDLE_H5S_SELECT_HYPERSLAB_ERR \
#define HANDLE_H5S_SELECT_HYPERSLAB_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot set select hyperslap region or add the " \
"specified region" );
#define HANDLE_H5S_GET_SIMPLE_EXTENT_DIMS_ERR \
#define HANDLE_H5S_GET_SIMPLE_EXTENT_DIMS_ERR( f ) \
h5_error( \
H5PART_ERR_HDF5, \
f, \
H5_ERR_HDF5, \
"Cannot get dimension sizes of dataset" );
/* H5T: type */
#define HANDLE_H5T_ARRAY_CREATE_ERR( type_name, rank ) \
#define HANDLE_H5T_ARRAY_CREATE_ERR( f, type_name, rank ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Can't create array datatype object with base " \
"datatype %s and rank %d", \
type_name, rank );
#define HANDLE_H5T_CREATE_ERR( class_name, obj_name ) \
#define HANDLE_H5T_CREATE_ERR( f, class_name, obj_name ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Can't create datatype object of class %s to handle %s.", \
class_name, obj_name );
#define HANDLE_H5T_INSERT_ERR( field_name, type_name ) \
#define HANDLE_H5T_INSERT_ERR( f, field_name, type_name ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Can't insert field %s to compound datatype to handle %s", \
field_name, type_name );
#define HANDLE_H5T_CLOSE_ERR \
#define HANDLE_H5T_CLOSE_ERR( f ) \
h5_error( \
f, \
H5_ERR_HDF5, \
"Cannot release datatype." );
/* MPI */
#define HANDLE_MPI_ALLGATHER_ERR \
#define HANDLE_MPI_ALLGATHER_ERR( f ) \
h5_error( \
f, \
H5_ERR_MPI, \
"Cannot gather data." );
#define HANDLE_MPI_COMM_SIZE_ERR \
#define HANDLE_MPI_COMM_SIZE_ERR( f ) \
h5_error( \
f, \
H5_ERR_MPI, \
"Cannot get number of processes in my group." );
#define HANDLE_MPI_COMM_RANK_ERR \
#define HANDLE_MPI_COMM_RANK_ERR( f ) \
h5_error( \
f, \
H5_ERR_MPI, \
"Cannot get rank of the calling process in my group." );
#define HANDLE_MPI_UNAVAILABLE_ERR \
#define HANDLE_MPI_UNAVAILABLE_ERR( f ) \
h5_error( \
f, \
H5_ERR_MPI, \
"MPI not available" );
#endif
+35
View File
@@ -0,0 +1,35 @@
#include <assert.h>
#include <stdlib.h>
#include <hdf5.h>
#include "h5_types.h"
/*!
Compare to floating point numbers using integers. See
http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
for a detailed explanation.
*/
int
_h5_fcmp (
h5_float64_t A,
h5_float64_t B,
h5_int64_t maxUlps ) {
// Make sure maxUlps is non-negative and small enough that the
// default NAN won't compare as equal to anything.
assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024);
assert ( sizeof(long long) == sizeof(h5_int64_t) );
// Make [ab]Int lexicographically ordered as a twos-complement int
h5_int64_t aInt = *(h5_int64_t*)&A;
if (aInt < 0)
aInt = 0x8000000000000000LL - aInt;
h5_int64_t bInt = *(h5_int64_t*)&B;
if (bInt < 0)
bInt = 0x8000000000000000LL - bInt;
h5_int64_t intDiff = aInt - bInt;
if (llabs(intDiff) <= maxUlps)
return 0;
return intDiff;
}
+10
View File
@@ -0,0 +1,10 @@
#ifndef __H5_FCMP_H
#define __H5_FCMP_H
int
_h5_fcmp (
h5_float64_t A,
h5_float64_t B,
h5_int32_t maxUlps );
#endif
+6 -2
View File
@@ -15,12 +15,14 @@ _h5_open_group (
if ( herr >= 0 ) {
h5_info (
f,
"Opening group %s/%s.",
h5_get_objname(parent_gid),
grpname );
gid = H5Gopen ( parent_gid, grpname, H5P_DEFAULT );
} else {
h5_info (
f,
"Creating group %s/%s.",
h5_get_objname(parent_gid),
grpname );
@@ -29,6 +31,7 @@ _h5_open_group (
}
if ( gid < 0 )
return HANDLE_H5G_OPEN_ERR (
f,
h5_get_objname(parent_gid),
grpname );
@@ -37,13 +40,14 @@ _h5_open_group (
h5_err_t
_h5_close_group (
h5_file_t * const f,
hid_t group_id
) {
const char *group_name = h5_get_objname( group_id );
herr_t herr = H5Gclose ( group_id );
if ( herr < 0 ) {
return (*h5_get_errorhandler()) (
h5_get_funcname(),
return h5_error (
f,
H5_ERR_HDF5,
"Cannot terminate access to group \"%s\".",
group_name );
+1
View File
@@ -10,6 +10,7 @@ _h5_open_group (
h5_err_t
_h5_close_group (
h5_file_t *f,
hid_t group_id
);
#endif
+12 -13
View File
@@ -7,14 +7,13 @@
h5_err_t
_h5_alloc_smap (
h5_file_t * const f,
struct smap *map,
h5_size_t size
const h5_size_t size
) {
int new = ( map == NULL );
map->items = realloc ( map->items, size * sizeof ( map->items[0] ) );
if ( map->items == NULL ) {
return HANDLE_H5_NOMEM_ERR;
}
int new = ( map->items == NULL );
size_t size_in_bytes = size * sizeof ( map->items[0] );
TRY( map->items = _h5_alloc ( f, map->items, size_in_bytes ) );
map->size = size;
if ( new ) map->num_items = 0;
return H5_SUCCESS;
@@ -22,14 +21,13 @@ _h5_alloc_smap (
h5_err_t
_h5_alloc_idmap (
h5_file_t * const f,
struct idmap *map,
h5_size_t size
const h5_size_t size
) {
int new = ( map == NULL );
map->items = realloc ( map->items, size * sizeof ( map->items[0] ) );
if ( map->items == NULL ) {
return HANDLE_H5_NOMEM_ERR;
}
int new = ( map->items == NULL );
size_t size_in_bytes = size * sizeof ( map->items[0] );
TRY( map->items = _h5_alloc ( f, map->items, size_in_bytes ) );
map->size = size;
if ( new ) map->num_items = 0;
return H5_SUCCESS;
@@ -38,13 +36,14 @@ _h5_alloc_idmap (
h5_err_t
_h5_insert_idmap (
h5_file_t * const f,
struct idmap *map,
h5_id_t global_id,
h5_id_t local_id
) {
if ( map->num_items == map->size )
return HANDLE_H5_OVERFLOW_ERR( "g2lmap", map->size );
return HANDLE_H5_OVERFLOW_ERR( f, "g2lmap", map->size );
h5_id_t i = _h5_search_idmap ( map, global_id );
if ( i >= 0 ) /* global id already in use ? */
+5 -2
View File
@@ -3,18 +3,21 @@
h5_err_t
_h5_alloc_smap (
h5_file_t * const f,
struct smap *map,
h5_size_t size
const h5_size_t size
);
h5_err_t
_h5_alloc_idmap (
h5_file_t * const f,
struct idmap *map,
h5_size_t size
const h5_size_t size
);
h5_err_t
_h5_insert_idmap (
h5_file_t * const f,
struct idmap *map,
h5_id_t global_id,
h5_id_t local_id
+163 -73
View File
@@ -11,25 +11,27 @@
#include "h5_core_private.h"
/*!
\ingroup h5block_private
\ingroup h5_core
\defgroup h5_core_filehandling
*/
\internal
/*!
\ingroup h5_core_filehandling
Check whether \c f points to a valid file handle.
\return H5_SUCCESS or error code
*/
h5_int64_t
h5_err_t
h5_check_filehandle (
const h5_file_t *f /*!< filehandle to check validity of */
h5_file_t * const f /*!< filehandle to check validity of */
) {
if ( f == NULL )
return HANDLE_H5_BADFD_ERR;
return HANDLE_H5_BADFD_ERR( f );
if ( f->file == 0 )
return HANDLE_H5_BADFD_ERR;
if ( f->block == NULL )
return HANDLE_H5_BADFD_ERR;
return HANDLE_H5_BADFD_ERR( f );
return H5_SUCCESS;
}
@@ -38,9 +40,11 @@ h5_check_filehandle (
Initialize H5Part
*/
static herr_t
_h5_error_handler ( hid_t estack_id, void* unused ) {
if ( h5_get_debuglevel() >= 5 ) {
_h5_error_handler (
hid_t estack_id,
void* __f
) {
if ( h5_get_debuglevel () >= 5 ) {
H5Eprint (estack_id, stderr);
}
return 0;
@@ -80,7 +84,7 @@ _h5u_open_file (
f->pnparticles =
(h5_int64_t*) malloc (f->nprocs * sizeof (h5_int64_t));
if (f->pnparticles == NULL) {
return HANDLE_H5_NOMEM_ERR;
return HANDLE_H5_NOMEM_ERR( f );
}
return H5_SUCCESS;
}
@@ -100,24 +104,24 @@ _h5b_open_file (
) {
struct h5b_fdata *b;
if ( (f == 0) || (f->file == 0) ) return HANDLE_H5_BADFD_ERR;
if ( f->block ) return H5_SUCCESS;
if ( (f == 0) || (f->file == 0) ) return HANDLE_H5_BADFD_ERR( f );
if ( f->b ) return H5_SUCCESS;
f->block = (struct h5b_fdata*) malloc( sizeof (*f->block) );
if ( f->block == NULL ) {
return HANDLE_H5_NOMEM_ERR;
f->b = (struct h5b_fdata*) malloc( sizeof (*f->b) );
if ( f->b == NULL ) {
return HANDLE_H5_NOMEM_ERR( f );
}
b = f->block;
b = f->b;
memset ( b, 0, sizeof (*b) );
b->user_layout = (struct H5BlockPartition*) malloc (
b->user_layout = (struct h5b_partition*) malloc (
f->nprocs * sizeof (b->user_layout[0]) );
if ( b->user_layout == NULL ) {
return HANDLE_H5_NOMEM_ERR;
return HANDLE_H5_NOMEM_ERR( f );
}
b->write_layout = (struct H5BlockPartition*) malloc (
b->write_layout = (struct h5b_partition*) malloc (
f->nprocs * sizeof (b->write_layout[0]) );
if ( b->write_layout == NULL ) {
return HANDLE_H5_NOMEM_ERR;
return HANDLE_H5_NOMEM_ERR( f );
}
b->step_idx = -1;
b->blockgroup = -1;
@@ -130,33 +134,50 @@ _h5b_open_file (
return H5_SUCCESS;
}
/*!
\ingroup h5_core_filehandling
Open file with name \c filename. This function is available in the paralell
and serial version. In the serial case \c comm may have any value.
\return File handle.
\return NULL on error.
*/
h5_file_t *
h5_open_file (
const char *filename, /*!< [in] The name of the data file to open. */
unsigned flags, /*!< [in] The access mode for the file. */
MPI_Comm comm /*!< [in] MPI communicator */
const char *filename, /*!< The name of the data file to open. */
h5_int32_t flags, /*!< The access mode for the file. */
MPI_Comm comm, /*!< MPI communicator */
const char *funcname /*!< calling function name */
) {
h5_info ( "Opening file %s.", filename );
if ( _init() < 0 ) {
HANDLE_H5_INIT_ERR;
return NULL;
}
h5_set_errno ( H5_SUCCESS );
h5_file_t *f = NULL;
f = (h5_file_t*) malloc( sizeof (h5_file_t) );
if( f == NULL ) {
HANDLE_H5_NOMEM_ERR;
goto error_cleanup;
fprintf(
stderr,
"E: %s: Can't open file %s. Not enough memory!",
funcname,
filename );
return NULL;
}
memset (f, 0, sizeof (h5_file_t));
if ( _init() < 0 ) {
HANDLE_H5_INIT_ERR( f );
return NULL;
}
f->__funcname = funcname;
h5_info ( f, "Opening file %s.", filename );
f->prefix_step_name = strdup ( H5PART_GROUPNAME_STEP );
if( f->prefix_step_name == NULL ) {
HANDLE_H5_NOMEM_ERR;
HANDLE_H5_NOMEM_ERR( f );
goto error_cleanup;
}
f->width_step_idx = 0;
@@ -225,7 +246,7 @@ h5_open_file (
f->access_prop);
f->empty = 1;
}
else if ( flags == H5_O_APPEND || H5_O_RDWR ) {
else if ( flags == H5_O_APPEND || flags == H5_O_RDWR ) {
int fd = open (filename, O_RDONLY, 0);
if ( (fd == -1) && (errno == ENOENT) ) {
f->file = H5Fcreate(filename, H5F_ACC_TRUNC,
@@ -239,17 +260,17 @@ h5_open_file (
}
}
else {
HANDLE_H5_FILE_ACCESS_TYPE_ERR ( flags );
HANDLE_H5_FILE_ACCESS_TYPE_ERR ( f, flags );
goto error_cleanup;
}
if (f->file < 0) {
HANDLE_H5F_OPEN_ERR ( filename, flags );
HANDLE_H5F_OPEN_ERR ( f, filename, flags );
goto error_cleanup;
}
f->root_gid = H5Gopen( f->file, "/", H5P_DEFAULT );
if ( f->root_gid < 0 ) {
HANDLE_H5G_OPEN_ERR ( "", "" );
HANDLE_H5G_OPEN_ERR ( f, "", "" );
goto error_cleanup;
}
f->mode = flags;
@@ -299,29 +320,29 @@ h5_open_file (
*/
static h5_int64_t
_h5u_close_file (
h5_file_t *f /*!< IN: file handle */
h5_file_t *f /*!< file handle */
) {
herr_t herr;
h5_set_errno ( H5_SUCCESS );
f->__errno = H5_SUCCESS;
if( f->shape > 0 ) {
herr = H5Sclose( f->shape );
if ( herr < 0 ) HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) HANDLE_H5S_CLOSE_ERR( f );
f->shape = 0;
}
if( f->diskshape != H5S_ALL ) {
herr = H5Sclose( f->diskshape );
if ( herr < 0 ) HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) HANDLE_H5S_CLOSE_ERR( f );
f->diskshape = 0;
}
if( f->memshape != H5S_ALL ) {
herr = H5Sclose( f->memshape );
if ( herr < 0 ) HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) HANDLE_H5S_CLOSE_ERR( f );
f->memshape = 0;
}
if( f->pnparticles ) {
free( f->pnparticles );
}
return h5_get_errno();
return f->__errno;
}
/*!
@@ -340,40 +361,49 @@ _h5b_close_file (
) {
herr_t herr;
struct h5b_fdata *b = f->block;
struct h5b_fdata *b = f->b;
if ( b->blockgroup >= 0 ) {
herr = H5Gclose ( b->blockgroup );
if ( herr < 0 ) return HANDLE_H5G_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5G_CLOSE_ERR( f );
b->blockgroup = -1;
}
if ( b->shape >= 0 ) {
herr = H5Sclose ( b->shape );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR( f );
b->shape = -1;
}
if ( b->diskshape >= 0 ) {
herr = H5Sclose ( b->diskshape );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR( f );
b->diskshape = -1;
}
if ( b->memshape >= 0 ) {
herr = H5Sclose ( b->memshape );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR( f );
b->memshape = -1;
}
free ( f->block );
f->block = NULL;
free ( f->b );
f->b = NULL;
return H5_SUCCESS;
}
/*!
\ingroup h5_core_filehandling
The h5_close_file() call writes all buffered data to disk, releases
all previously allocated memory and terminates access to the associated
HDF5 file.
\return H5_SUCCESS or error code
*/
h5_int64_t
h5_close_file (
h5_file_t *f
h5_file_t *f /*!< file handle */
) {
herr_t r = 0;
h5_set_errno ( H5_SUCCESS );
f->__errno = H5_SUCCESS;
CHECK_FILEHANDLE ( f );
@@ -385,32 +415,32 @@ h5_close_file (
if( f->step_gid >= 0 ) {
r = H5Gclose( f->step_gid );
if ( r < 0 ) HANDLE_H5G_CLOSE_ERR;
if ( r < 0 ) HANDLE_H5G_CLOSE_ERR( f );
f->step_gid = -1;
}
if( f->xfer_prop != H5P_DEFAULT ) {
r = H5Pclose( f->xfer_prop );
if ( r < 0 ) HANDLE_H5P_CLOSE_ERR ( "f->xfer_prop" );
if ( r < 0 ) HANDLE_H5P_CLOSE_ERR ( f, "f->xfer_prop" );
f->xfer_prop = H5P_DEFAULT;
}
if( f->access_prop != H5P_DEFAULT ) {
r = H5Pclose( f->access_prop );
if ( r < 0 ) HANDLE_H5P_CLOSE_ERR ( "f->access_prop" );
if ( r < 0 ) HANDLE_H5P_CLOSE_ERR ( f, "f->access_prop" );
f->access_prop = H5P_DEFAULT;
}
if( f->create_prop != H5P_DEFAULT ) {
r = H5Pclose( f->create_prop );
if ( r < 0 ) HANDLE_H5P_CLOSE_ERR ( "f->create_prop" );
if ( r < 0 ) HANDLE_H5P_CLOSE_ERR ( f, "f->create_prop" );
f->create_prop = H5P_DEFAULT;
}
if ( f->root_gid >= 0 ) {
r = H5Gclose ( f->root_gid );
if ( r < 0 ) HANDLE_H5G_CLOSE_ERR;
if ( r < 0 ) HANDLE_H5G_CLOSE_ERR( f );
f->root_gid = 0;
}
if ( f->file ) {
r = H5Fclose( f->file );
if ( r < 0 ) HANDLE_H5F_CLOSE_ERR;
if ( r < 0 ) HANDLE_H5F_CLOSE_ERR( f );
f->file = 0;
}
if (f->prefix_step_name) {
@@ -418,48 +448,108 @@ h5_close_file (
}
free( f );
return h5_get_errno();
return f->__errno;
}
/*!
\ingroup h5_core_filehandling
Define format of the step names.
Example: ==H5FedDefineStepNameFormat( f, "Step", 6 )== defines step names
like ==Step#000042==.
\return \c H5_SUCCESS or error code
*/
h5_int64_t
h5_define_stepname_fmt (
h5_set_stepname_fmt (
h5_file_t *f,
const char *name,
const h5_int64_t width
) {
f->prefix_step_name = strdup ( name );
if( f->prefix_step_name == NULL ) {
return HANDLE_H5_NOMEM_ERR;
return HANDLE_H5_NOMEM_ERR( f );
}
f->width_step_idx = (int)width;
return H5_SUCCESS;
}
/*!
\ingroup h5_core_filehandling
Get format of the step names.
\return \c H5_SUCCESS or error code
*/
h5_err_t
h5_get_stepname_fmt (
h5_file_t * f,
char *name,
const h5_size_t l_name,
h5_size_t *width
h5_file_t *f, /*!< Handle to file */
char *name, /*!< OUT: Prefix */
const h5_size_t l_name, /*!< length of buffer name */
h5_size_t *width /*!< OUT: Width of the number */
) {
return -1;
}
h5_int64_t
/*!
\ingroup h5_core_filehandling
Get current step number.
\return Current step number or error code
*/
h5_id_t
h5_get_step (
h5_file_t * f
h5_file_t * f /*!< file handle */
) {
return -1;
}
/*!
\ingroup h5_core_filehandling
h5_int64_t
Check whether step with number \c stepno exists.
\return True (value != 0) if step with \c stepno exists.
\return False (0) otherwise
*/
h5_err_t
h5_has_step (
h5_file_t * f,
h5_int64_t step
h5_file_t * f, /*!< file handle */
h5_id_t stepno /*!< step number to check */
) {
char name[128];
sprintf ( name, "%s#%0*lld", f->prefix_step_name, f->width_step_idx, (long long) step );
return ( H5Gget_objinfo( f->file, name, 1, NULL ) >= 0 );
sprintf ( name, "%s#%0*ld",
f->prefix_step_name, f->width_step_idx, (long) stepno );
return ( H5Gget_info_by_name( f->file, name, NULL, H5P_DEFAULT ) >= 0 );
}
/*!
\ingroup h5_core_filehandling
Start traversing steps.
\return \c H5_SUCCESS or error code
*/
h5_err_t
h5_start_traverse_steps (
h5_file_t * f /*!< file handle */
) {
return -1;
}
/*!
\ingroup h5_core_filehandling
Go to next step.
\return \c H5_SUCCESS or error code
*/
h5_err_t
h5_traverse_steps (
h5_file_t * f /*!< file handle */
) {
return -1;
}
+19 -9
View File
@@ -4,30 +4,31 @@
h5_file_t *
h5_open_file (
const char *filename,
unsigned flags,
MPI_Comm comm
h5_int32_t flags,
MPI_Comm comm,
const char *funcname
);
h5_int64_t
h5_check_filehandle (
const h5_file_t *f
h5_file_t * const f
);
h5_int64_t
h5_close_file (
h5_file_t *f
h5_file_t * const f
);
h5_int64_t
h5_define_stepname_fmt (
h5_file_t *f,
h5_file_t * const f,
const char *name,
const h5_int64_t width
);
h5_err_t
h5_get_stepname_fmt (
h5_file_t *f,
h5_file_t * const f,
char *name,
const h5_size_t l_name,
h5_size_t *width
@@ -35,18 +36,27 @@ h5_get_stepname_fmt (
h5_err_t
_h5_close_step (
h5_file_t *f
h5_file_t * const f
);
h5_int64_t
h5_has_step (
h5_file_t * f,
h5_file_t * const f,
h5_int64_t step
);
h5_int64_t
h5_get_step (
h5_file_t *f
h5_file_t * const f
);
h5_err_t
h5_start_traverse_steps (
h5_file_t * f /*!< file handle */
);
h5_err_t
h5_traverse_steps (
h5_file_t * f /*!< file handle */
);
#endif
+47 -165
View File
@@ -14,38 +14,37 @@ h5_write_data (
h5_file_t *f, /*!< IN: Handle to open file */
const char *name, /*!< IN: Name to associate array with */
const void *array, /*!< IN: Array to commit to disk */
const hid_t type, /*!< IN: Type of data */
const hid_t groupid,
const hid_t shape,
const hid_t memshape,
const hid_t diskshape
const hid_t type_id, /*!< IN: Type of data */
const hid_t group_id,
const hid_t memspace_id,
const hid_t diskspace_id
) {
herr_t herr;
hid_t dataset_id;
h5_info ( "Writing dataset %s/%s.", h5_get_objname(groupid), name );
h5_info ( f, "Writing dataset %s/%s.", h5_get_objname(group_id), name );
dataset_id = H5Dcreate (
groupid,
group_id,
name,
type,
shape,
type_id,
diskspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT );
if ( dataset_id < 0 )
return HANDLE_H5D_CREATE_ERR ( name );
return HANDLE_H5D_CREATE_ERR ( f, name );
herr = H5Dwrite (
dataset_id,
type,
memshape,
diskshape,
type_id,
memspace_id,
diskspace_id,
f->xfer_prop,
array );
if ( herr < 0 ) return HANDLE_H5D_WRITE_ERR ( name );
if ( herr < 0 ) return HANDLE_H5D_WRITE_ERR ( f, name );
herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR( f );
f->empty = 0;
@@ -62,11 +61,11 @@ h5_write_dataset (
const hid_t diskspace_id,
const void * const data /*!< IN: Data to commit to disk */
) {
h5_info ( "Writing dataset %s/%s.",
h5_info ( f, "Writing dataset %s/%s.",
h5_get_objname(group_id), dataset_name );
if ( f->mode == O_RDONLY )
return _h5_handle_file_mode_error( f->mode );
return _h5_handle_file_mode_error( f, f->mode );
/*
file modes:
@@ -83,9 +82,10 @@ h5_write_dataset (
H5P_DEFAULT );
if ( (herr >= 0) && ( (f->mode==H5_O_WRONLY) || (f->mode==H5_O_APPEND) ) ) {
h5_warn ( "Dataset %s/%s already exist.",
h5_warn ( f,
"Dataset %s/%s already exist.",
h5_get_objname(group_id), dataset_name );
return _h5_handle_file_mode_error( f->mode );
return _h5_handle_file_mode_error( f, f->mode );
}
hid_t dataset_id;
if ( herr >= 0 ) {
@@ -94,7 +94,7 @@ h5_write_dataset (
dataset_name,
H5P_DEFAULT );
if ( dataset_id < 0 )
return HANDLE_H5D_OPEN_ERR ( dataset_name );
return HANDLE_H5D_OPEN_ERR ( f, dataset_name );
} else {
dataset_id = H5Dcreate (
group_id,
@@ -103,7 +103,7 @@ h5_write_dataset (
diskspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT );
if ( dataset_id < 0 )
return HANDLE_H5D_CREATE_ERR ( dataset_name );
return HANDLE_H5D_CREATE_ERR ( f, dataset_name );
}
herr = H5Dwrite (
dataset_id,
@@ -113,10 +113,10 @@ h5_write_dataset (
f->xfer_prop,
data );
if ( herr < 0 ) return HANDLE_H5D_WRITE_ERR ( dataset_name );
if ( herr < 0 ) return HANDLE_H5D_WRITE_ERR ( f, dataset_name );
herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR( f );
f->empty = 0;
@@ -134,7 +134,7 @@ h5_read_dataset2 (
void * const data ) {
hid_t dataset_id = H5Dopen ( group_id, dataset_name, H5P_DEFAULT );
if ( dataset_id < 0 ) return HANDLE_H5D_OPEN_ERR ( dataset_name );
if ( dataset_id < 0 ) return HANDLE_H5D_OPEN_ERR ( f, dataset_name );
hid_t memspace_id = (*set_memspace)( f, dataset_id );
if ( memspace_id < 0 ) return memspace_id;
@@ -152,12 +152,12 @@ h5_read_dataset2 (
if ( h5err < 0 ) return h5err;
herr_t herr = H5Sclose ( diskspace_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR( f );
herr = H5Sclose ( memspace_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR( f );
herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR( f );
return H5_SUCCESS;
}
@@ -173,7 +173,7 @@ h5_read_dataset (
void * const data ) {
hid_t dataset_id = H5Dopen ( group_id, dataset_name, H5P_DEFAULT );
if ( dataset_id < 0 ) return HANDLE_H5D_OPEN_ERR ( dataset_name );
if ( dataset_id < 0 ) return HANDLE_H5D_OPEN_ERR ( f, dataset_name );
h5_err_t h5err = _h5_read_dataset (
f,
@@ -185,7 +185,7 @@ h5_read_dataset (
if ( h5err < 0 ) return h5err;
herr_t herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR( f );
return H5_SUCCESS;
}
@@ -207,142 +207,21 @@ _h5_read_dataset (
f->xfer_prop,
data );
if ( herr < 0 )
return HANDLE_H5D_READ_ERR ( h5_get_objname ( dataset_id ) );
return HANDLE_H5D_READ_ERR ( f, h5_get_objname ( dataset_id ) );
return H5_SUCCESS;
}
/*!
\ingroup h5part_kernel
Iterator for \c H5Giterate().
*/
herr_t
h5_iteration_operator (
hid_t group_id, /*!< [in] group id */
const char *member_name,/*!< [in] group name */
void *operator_data /*!< [in,out] data passed to the iterator */
) {
struct _iter_op_data *data = (struct _iter_op_data*)operator_data;
herr_t herr;
H5G_stat_t objinfo;
if ( data->type != H5G_UNKNOWN ) {
herr = H5Gget_objinfo ( group_id, member_name, 1, &objinfo );
if ( herr < 0 ) return (herr_t)HANDLE_H5G_GET_OBJINFO_ERR ( member_name );
if ( objinfo.type != data->type )
return 0;/* don't count, continue iteration */
}
if ( data->name && (data->stop_idx == data->count) ) {
memset ( data->name, 0, data->len );
strncpy ( data->name, member_name, data->len-1 );
return 1; /* stop iteration */
}
/*
count only if pattern is NULL or member name matches
*/
if ( !data->pattern ||
(strncmp (member_name, data->pattern, strlen(data->pattern)) == 0)
) {
data->count++;
}
return 0; /* continue iteration */
}
/*!
\ingroup h5part_kernel
Get number of object of type \c type in HDF5 group \c group_id.
*/
h5_int64_t
h5_get_num_objects (
hid_t group_id,
const char *group_name,
const hid_t type
) {
return h5_get_num_objects_matching_pattern (
group_id,
group_name,
type,
NULL );
}
/*!
\ingroup h5part_kernel
Get number of objects of type \c type matching ^pattern.
If pattern is NULL, count all objects of given type.
*/
h5_int64_t
h5_get_num_objects_matching_pattern (
hid_t group_id,
const char *group_name,
const hid_t type,
char * const pattern
) {
h5_int64_t herr;
int idx = 0;
struct _iter_op_data data;
memset ( &data, 0, sizeof ( data ) );
data.type = type;
data.pattern = pattern;
herr = H5Giterate ( group_id, group_name, &idx,
h5_iteration_operator, &data );
if ( herr < 0 ) return herr;
return data.count;
}
/*!
\ingroup h5part_kernel
Iterator for \c H5Giterate().
*/
h5_int64_t
h5_get_object_name (
hid_t group_id,
const char *group_name,
const hid_t type,
const h5_int64_t idx,
char *obj_name,
const h5_int64_t len_obj_name
) {
herr_t herr;
struct _iter_op_data data;
int iterator_idx = 0;
memset ( &data, 0, sizeof ( data ) );
data.stop_idx = (hid_t)idx;
data.type = type;
data.name = obj_name;
data.len = (size_t)len_obj_name;
herr = H5Giterate ( group_id, group_name, &iterator_idx,
h5_iteration_operator,
&data );
if ( herr < 0 ) return (h5_int64_t)herr;
if ( herr == 0 ) HANDLE_H5_NOENTRY_ERR( group_name,
type, idx );
return H5_SUCCESS;
}
h5_int64_t
_create_step (
h5_file_t * f
) {
h5_print_debug (
h5_debug (
f,
"Proc[%d]: Create step #%lld for file %lld",
f->myproc,
(long long)f->step_idx,
@@ -351,7 +230,7 @@ _create_step (
f->step_gid = H5Gcreate ( f->file, f->step_name, 0,
H5P_DEFAULT, H5P_DEFAULT );
if ( f->step_gid < 0 )
return HANDLE_H5G_CREATE_ERR ( f->step_name );
return HANDLE_H5G_CREATE_ERR ( f, f->step_name );
return H5_SUCCESS;
}
@@ -360,7 +239,8 @@ h5_int64_t
_open_step (
h5_file_t * f
) {
h5_print_info (
h5_info (
f,
"Proc[%d]: Open step #%lld for file %lld",
f->myproc,
(long long)f->step_idx,
@@ -368,7 +248,7 @@ _open_step (
f->is_new_step = 0;
f->step_gid = H5Gopen ( f->file, f->step_name, H5P_DEFAULT );
if ( f->step_gid < 0 )
return HANDLE_H5G_OPEN_ERR( "", f->step_name );
return HANDLE_H5G_OPEN_ERR( f, "", f->step_name );
return H5_SUCCESS;
}
@@ -394,7 +274,7 @@ _h5_close_step (
if ( h5err < 0 ) return h5err;
herr_t herr = H5Gclose ( f->step_gid );
if ( herr < 0 ) return HANDLE_H5G_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5G_CLOSE_ERR( f );
f->step_gid = -1;
@@ -416,11 +296,11 @@ _set_step (
herr_t herr = H5Gget_objinfo( f->file, f->step_name, 1, NULL );
if( f->mode == H5_O_RDONLY ) {
if ( herr < 0 ) return HANDLE_H5G_OPEN_ERR( "", f->step_name );
if ( herr < 0 ) return HANDLE_H5G_OPEN_ERR( f, "", f->step_name );
herr = _open_step ( f );
if ( herr < 0 ) return herr;
} else if ( (f->mode == H5_O_WRONLY) || (f->mode == H5_O_APPEND) ) {
if ( herr > 0 ) return HANDLE_H5_STEP_EXISTS_ERR ( step_idx );
if ( herr > 0 ) return HANDLE_H5_STEP_EXISTS_ERR ( f, step_idx );
herr = _create_step ( f );
if ( herr < 0 ) return herr;
} else if ( (f->mode == H5_O_RDWR) && (herr < 0) ) {
@@ -456,6 +336,7 @@ h5_set_step (
*/
hid_t
h5_normalize_h5_type (
h5_file_t * const f,
hid_t type
) {
H5T_class_t tclass = H5Tget_class ( type );
@@ -475,7 +356,7 @@ h5_normalize_h5_type (
default:
; /* NOP */
}
h5_print_warn ( "Unknown type %d", (int)type );
h5_warn ( f, "Unknown type %d", (int)type );
return -1;
}
@@ -483,22 +364,23 @@ h5_normalize_h5_type (
h5_int64_t
h5_get_dataset_type(
h5_file_t * const f,
hid_t group_id,
const char *dataset_name
) {
hid_t dataset_id = H5Dopen ( group_id, dataset_name, H5P_DEFAULT );
if ( dataset_id < 0 ) HANDLE_H5D_OPEN_ERR ( dataset_name );
if ( dataset_id < 0 ) HANDLE_H5D_OPEN_ERR ( f, dataset_name );
hid_t hdf5_type = H5Dget_type ( dataset_id );
if ( hdf5_type < 0 ) HANDLE_H5D_GET_TYPE_ERR;
if ( hdf5_type < 0 ) HANDLE_H5D_GET_TYPE_ERR( f );
h5_int64_t type = (h5_int64_t) h5_normalize_h5_type ( hdf5_type );
h5_int64_t type = (h5_int64_t) h5_normalize_h5_type ( f, hdf5_type );
herr_t herr = H5Tclose(hdf5_type);
if ( herr < 0 ) HANDLE_H5T_CLOSE_ERR;
if ( herr < 0 ) HANDLE_H5T_CLOSE_ERR( f );
herr = H5Dclose(dataset_id);
if ( herr < 0 ) HANDLE_H5D_CLOSE_ERR;
if ( herr < 0 ) HANDLE_H5D_CLOSE_ERR( f );
return type;
}
+9 -31
View File
@@ -6,11 +6,10 @@ h5_write_data (
h5_file_t *f,
const char *name,
const void *array,
const hid_t type,
const hid_t groupid,
const hid_t shape,
const hid_t memshape,
const hid_t diskshape
const hid_t type_id,
const hid_t group_id,
const hid_t memspace_id,
const hid_t diskspace_id
) ;
h5_err_t
@@ -25,52 +24,31 @@ h5_write_dataset (
) ;
h5_int64_t
h5_get_num_objects (
hid_t group_id,
const char *group_name,
const hid_t type
);
h5_int64_t
h5_get_num_objects_matching_pattern (
hid_t group_id,
const char *group_name,
const hid_t type,
char * const pattern
);
h5_int64_t
h5_get_object_name (
hid_t group_id,
const char *group_name,
const hid_t type,
const h5_int64_t idx,
char *obj_name,
const h5_int64_t len_obj_name
);
h5_int64_t
h5_set_step (
h5_file_t *f, /*!< [in] Handle to open file */
h5_file_t * const f,
const h5_int64_t step /*!< [in] Time-step to set. */
);
hid_t
h5_normalize_h5_type (
h5_file_t * const f,
hid_t type
);
h5_int64_t
h5_get_dataset_type(
h5_file_t * const f,
hid_t group_id,
const char *dataset_name
);
h5_int64_t
h5_has_index (
h5_file_t *f, /*!< [in] Handle to open file */
h5_int64_t step /*!< [in] Step number to query */
h5_file_t * const f, /*!< [in] Handle to open file */
h5_int64_t step /*!< [in] Step number to query */
);
#endif
+4 -1
View File
@@ -5,11 +5,14 @@
void *
_h5_alloc (
h5_file_t * const f,
void *ptr,
const size_t size ) {
h5_debug ( f, "Allocating %ld bytes.", size );
ptr = realloc ( ptr, size );
if ( ptr == NULL ) {
return (void*)HANDLE_H5_NOMEM_ERR;
HANDLE_H5_NOMEM_ERR( f );
return (void*)(-1);
}
return ptr;
}
+1
View File
@@ -3,6 +3,7 @@
void *
_h5_alloc (
h5_file_t * const f,
void *ptr,
const size_t size );
+26 -103
View File
@@ -7,24 +7,6 @@
#include <errno.h>
#include <fcntl.h>
#define H5_SUCCESS 0
#define H5_ERR -1
#define H5_ERR_BADF -9
#define H5_ERR_NOMEM -12
#define H5_ERR_INVAL -22
#define H5_ERR_BADFD -77
#define H5_ERR_LAYOUT -100
#define H5_ERR_NOENT -101
#define H5_ERR_INIT -200
#define H5_ERR_NOENTRY -201
#define H5_ERR_MPI -201
#define H5_ERR_HDF5 -202
#define H5_ERR_INTERNAL -253
#define H5_ERR_NOT_IMPLEMENTED -254
#define H5_O_RDWR 0
#define H5_O_RDONLY 1
#define H5_O_WRONLY 2
@@ -38,27 +20,22 @@ typedef __int64 int64_t;
typedef int64_t h5_int64_t;
typedef int32_t h5_int32_t;
typedef int32_t h5_id_t;
typedef int32_t h5_size_t; /* size in number of elements */
typedef int32_t h5_err_t;
typedef int64_t h5_id_t;
typedef int64_t h5_size_t; /* size in number of elements */
typedef int64_t h5_ssize_t; /* size in number of elements */
typedef int64_t h5_err_t;
typedef double h5_float64_t;
typedef float h5_float32_t;
struct h5_complex {
h5_float64_t r,i;
};
typedef struct h5_complex h5_complex_t;
typedef h5_err_t (*h5_error_handler)( const char*, const h5_err_t, const char*,...)
#ifdef __GNUC__
__attribute__ ((format (printf, 3, 4)))
#endif
;
typedef h5_err_t (*h5_verror_handler)(
const char*,
const h5_err_t,
struct h5_file;
typedef h5_err_t (*h5_errorhandler_t)(
struct h5_file * const,
const char*,
va_list ap );
@@ -66,52 +43,9 @@ typedef h5_err_t (*h5_verror_handler)(
typedef unsigned long MPI_Comm;
#endif
struct h5u_fdata {
hsize_t nparticles; /* -> u.nparticles */
h5_int64_t viewstart; /* -1 if no view is available: A "view" looks */
h5_int64_t viewend; /* at a subset of the data. */
/**
the number of particles in each processor.
With respect to the "VIEW", these numbers
can be regarded as non-overlapping subsections
of the particle array stored in the file.
So they can be used to compute the offset of
the view for each processor
*/
h5_int64_t *pnparticles;
hid_t shape;
hid_t diskshape;
hid_t memshape;
};
struct H5BlockPartition {
h5_int64_t i_start;
h5_int64_t i_end;
h5_int64_t j_start;
h5_int64_t j_end;
h5_int64_t k_start;
h5_int64_t k_end;
};
struct h5b_fdata {
h5_int64_t step_idx;
h5_int64_t i_max;
h5_int64_t j_max;
h5_int64_t k_max;
struct H5BlockPartition *user_layout;
struct H5BlockPartition *write_layout;
int have_layout;
hid_t shape;
hid_t memshape;
hid_t diskshape;
hid_t blockgroup;
hid_t field_group_id;
};
struct smap;
typedef struct smap smap_t;
struct idmap;
/**
\struct h5_file
@@ -123,29 +57,33 @@ struct h5b_fdata {
*/
struct h5_file {
hid_t file; /* file id -> fid */
unsigned mode; /* file access mode */
int empty;
unsigned mode; /* file access mode */
hid_t xfer_prop;
hid_t create_prop;
hid_t access_prop;
h5_err_t __errno; /* error number */
const char * __funcname; /* H5Block/Fed/Part API function*/
hid_t root_gid; /* id of group "/" */
/* MPI */
MPI_Comm comm; /* MPI communicator */
int nprocs; /* number of processors */
int myproc; /* The index of the processor
this process is running on. */
MPI_Comm comm; /* MPI communicator */
/* HDF5 */
hid_t xfer_prop; /* file transfer properties */
hid_t create_prop; /* file create properties */
hid_t access_prop; /* file access properties */
hid_t root_gid; /* id of root group */
hid_t step_gid; /* id of current step */
/* step internal data */
char *prefix_step_name; /* Prefix of step name */
int width_step_idx; /* pad step index with 0 up to this */
char step_name[128]; /* full step name */
h5_int64_t step_idx; /* step index */
hid_t step_gid; /* HDF5 grp id of current step */
int is_new_step;
/*
@@ -175,27 +113,12 @@ struct h5_file {
/* END unstructured */
struct h5u_fdata *u;
struct h5b_fdata *block;
struct h5b_fdata *b;
struct h5t_fdata *t;
};
typedef struct h5_file h5_file_t;
struct smap {
h5_size_t size; /* allocated space in number of items */
h5_size_t num_items; /* stored items */
h5_id_t *items;
};
struct idmap {
h5_size_t size; /* allocated space in number of items */
h5_size_t num_items; /* stored items */
struct {
h5_id_t global_id;
h5_id_t local_id;
} *items;
};
enum h5_oid { /* enum with number of vertices(!) */
H5_OID_VERTEX = 1,
H5_OID_EDGE = 2,
+20
View File
@@ -0,0 +1,20 @@
#ifndef __H5_TYPES_PRIVATE_H
#define __H5_TYPES_PRIVATE_H
struct smap {
h5_size_t size; /* allocated space in number of items */
h5_size_t num_items; /* stored items */
h5_id_t *items;
};
struct idmap {
h5_size_t size; /* allocated space in number of items */
h5_size_t num_items; /* stored items */
struct {
h5_id_t global_id;
h5_id_t local_id;
} *items;
};
#endif
+7 -5
View File
@@ -2,14 +2,16 @@
#define __H5B_ERRORHANDLING_PRIVATE_H
#define CHECK_LAYOUT( f ) \
if ( ! f->block->have_layout ) \
if ( ! f->b->have_layout ) \
return h5_error( \
H5PART_ERR_LAYOUT, \
f, \
H5_ERR_LAYOUT, \
"No layout defined." )
#define HANDLE_H5_LAYOUT_ERR \
h5_error( \
H5PART_ERR_LAYOUT, \
#define HANDLE_H5_LAYOUT_ERR( f ) \
h5_error( \
f, \
H5_ERR_LAYOUT, \
"Bad layout." );
#endif
+30
View File
@@ -0,0 +1,30 @@
#ifndef __H5B_TYPES_PRIVATE_H
#define __H5B_TYPES_PRIVATE_H
struct h5b_partition {
h5_int64_t i_start;
h5_int64_t i_end;
h5_int64_t j_start;
h5_int64_t j_end;
h5_int64_t k_start;
h5_int64_t k_end;
};
struct h5b_fdata {
h5_id_t step_idx;
h5_size_t i_max;
h5_size_t j_max;
h5_size_t k_max;
struct h5b_partition *user_layout;
struct h5b_partition *write_layout;
int have_layout;
h5_size_t chunk[3];
hid_t shape;
hid_t memshape;
hid_t diskshape;
hid_t blockgroup;
hid_t field_group_id;
};
typedef struct h5b_fdata h5b_fdata_t;
#endif
+19 -16
View File
@@ -43,7 +43,7 @@ h5t_get_num_boundaries (
if ( t->cur_mesh < 0 )
return _h5t_error_undef_mesh ( f );
if ( t->num_boundaries < 0 ) {
t->num_boundaries = h5_get_num_objects (
t->num_boundaries = hdf5_get_num_objects (
t->mesh_gid,
H5T_BOUNDARYMESH_GRPNAME,
H5G_GROUP );
@@ -82,7 +82,7 @@ h5t_open_boundary (
TRY( h5t_get_num_boundaries ( f ) );
}
if ( (boundary_id < -1) || (boundary_id >= t->num_boundaries) ) {
return HANDLE_H5_OUT_OF_RANGE_ERR( "boundary", boundary_id );
return HANDLE_H5_OUT_OF_RANGE_ERR( f, "boundary", boundary_id );
}
if ( boundary_id == -1 ) { /* append new boundary */
boundary->id = t->num_boundaries++;
@@ -91,7 +91,7 @@ h5t_open_boundary (
boundary->id = boundary_id;
}
snprintf ( boundary->name, sizeof (boundary->name),
"%d", boundary->id );
"%lld", boundary->id );
TRY( _open_boundary_group ( f ) );
return H5_SUCCESS;
@@ -115,20 +115,20 @@ _h5t_read_boundaryfaces (
const char * const dataset_name = "Faces";
hid_t dataset_id = H5Dopen ( boundary->gid, dataset_name, H5P_DEFAULT );
if ( dataset_id < 0 )
return HANDLE_H5D_OPEN_ERR ( dataset_name );
return HANDLE_H5D_OPEN_ERR ( f, dataset_name );
hid_t diskspace_id = H5Dget_space(dataset_id);
if ( diskspace_id < 0 ) return (hid_t)HANDLE_H5D_GET_SPACE_ERR;
if ( diskspace_id < 0 ) return (hid_t)HANDLE_H5D_GET_SPACE_ERR ( f );
h5_id_t num_faces = H5Sget_simple_extent_npoints ( diskspace_id );
if ( num_faces < 0 )
return HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR;
return HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR ( f );
herr_t herr = H5Sclose ( diskspace_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR ( f );
h5t_add_num_boundaryfaces ( f, num_faces );
@@ -142,7 +142,7 @@ _h5t_read_boundaryfaces (
if ( h5err < 0 ) return h5err;
herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR ( f );
return H5_SUCCESS;
}
@@ -185,7 +185,7 @@ h5t_close_boundary (
bzero ( boundary, sizeof(*boundary) );
TRY( _h5_close_group( boundary->gid ) );
TRY( _h5_close_group( f, boundary->gid ) );
boundary->id = -1;
boundary->gid = -1;
@@ -218,7 +218,7 @@ h5t_add_num_boundaryfaces (
boundary->num_faces_on_level == NULL ||
boundary->faces == NULL ||
boundary->lfaces == NULL ) {
return HANDLE_H5_NOMEM_ERR;
return HANDLE_H5_NOMEM_ERR ( f );
}
memset ( boundary->num_faces,
0, t->num_levels*sizeof(boundary->num_faces[0]) );
@@ -260,12 +260,12 @@ h5t_store_boundaryface (
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON: {
h5_id_t local_vids[3];
h5_err_t h5err = h5t_map_global_vertex_ids2local (
h5_err_t h5err = h5t_map_global_vids2local (
f, global_vids, 3, local_vids );
if ( h5err < 0 ) return h5err;
h5_id_t local_tid = h5t_get_local_triangle_id ( f, local_vids );
if ( local_tid < 0 )
return _h5t_error_local_triangle_id_nexist( local_vids );
return _h5t_error_local_triangle_id_nexist( f, local_vids );
return h5t_store_boundaryface_local_id ( f, local_tid );
}
default:
@@ -302,18 +302,21 @@ h5t_store_boundaryface_local_id (
if ( boundary->num_faces == NULL )
return HANDLE_H5_OVERFLOW_ERR (
f,
"boundary faces",
-1 );
(h5_ssize_t)-1 );
if ( ++(boundary->last_accessed_face) >= boundary->num_faces[0] )
return HANDLE_H5_OVERFLOW_ERR (
f,
"boundary faces",
boundary->num_faces[0] );
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON: {
h5_id_t local_tet_id = local_fid & H5_TET_MASK;
if ( t->entities.tets[local_tet_id].parent_id != -1 ) {
if ( t->elems.tets[local_tet_id].parent_id != -1 ) {
return _h5t_error_store_boundaryface_local_id (
f,
local_fid );
}
h5_id_t global_tid = h5t_map_local_triangle_id2global(
@@ -345,7 +348,7 @@ h5t_traverse_boundary_faces (
h5_file_t * const f,
h5_id_t * const global_id,
h5_id_t * const parent_id,
h5_id_t vertex_ids[]
h5_id_t vids[]
) {
return -1;
}
+1 -1
View File
@@ -51,6 +51,6 @@ h5t_traverse_boundary_faces (
h5_file_t * const f,
h5_id_t * const global_id,
h5_id_t * const parent_id,
h5_id_t vertex_ids[]
h5_id_t vids[]
);
#endif
+25
View File
@@ -0,0 +1,25 @@
const char * _h5t_oid_names[] = {
"N.N.",
"vertex",
"edge",
"triangle",
"tetrahedron"
};
const char * _h5t_meshes_grpnames[] = {
"N.N.",
"N.N.",
"N.N.",
"TriangleMeshes",
"TetMeshes"
};
const char *
_h5t_map_oid2str (
h5_id_t oid
) {
if ( oid < 0 || oid >= sizeof(_h5t_oid_names)/sizeof(char*) ) {
return "[invalid oid]";
}
return _h5t_oid_names[oid];
}
+12
View File
@@ -0,0 +1,12 @@
#ifndef __H5T_CONSTS_PRIVATE_H
#define __H5T_CONSTS_PRIVATE_H
extern char * _h5t_oid_names[];
extern char * _h5t_meshes_grpnames[];
const char *
_h5t_map_oid2str (
h5_id_t oid
);
#endif
+12 -19
View File
@@ -9,43 +9,35 @@
#include "h5_core.h"
#include "h5_core_private.h"
const char * H5_OID_NAMES[] = {
"N.N.",
"vertex",
"edge",
"triangle",
"tetrahedron"
};
h5_err_t
_h5t_handle_get_global_entity_id_err (
_h5t_handle_get_global_eid_err (
h5_file_t *f,
const h5_id_t * const global_vids
) {
struct h5t_fdata *t = f->t;
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON:
return _h5t_error_global_tet_id_nexist ( global_vids );
return _h5t_error_global_tet_id_nexist ( f, global_vids );
case H5_OID_TRIANGLE:
return _h5t_error_global_tri_id_nexist ( global_vids );
return _h5t_error_global_tri_id_nexist ( f, global_vids );
default:
return h5_error_internal( __FILE__, __func__, __LINE__ );
return h5_error_internal( f, __FILE__, __func__, __LINE__ );
}
}
h5_err_t
_h5t_handle_get_local_entity_id_err (
_h5t_handle_get_local_eid_err (
h5_file_t *f,
const h5_id_t * const local_vids
) {
struct h5t_fdata *t = f->t;
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON:
return _h5t_error_local_tet_id_nexist ( local_vids );
return _h5t_error_local_tet_id_nexist ( f, local_vids );
case H5_OID_TRIANGLE:
return _h5t_error_local_triangle_id_nexist ( local_vids );
return _h5t_error_local_triangle_id_nexist ( f, local_vids );
default:
return h5_error_internal( __FILE__, __func__, __LINE__ );
return h5_error_internal( f, __FILE__, __func__, __LINE__ );
}
}
@@ -56,18 +48,19 @@ _h5t_error_illegal_object_type (
struct h5t_fdata *t = f->t;
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON:
return h5_error_internal( __FILE__, __func__, __LINE__ );
return h5_error_internal( f, __FILE__, __func__, __LINE__ );
case H5_OID_TRIANGLE:
switch ( oid ) {
case H5_OID_TETRAHEDRON:
return h5_error (
f,
H5_ERR_INVAL,
"Illegal topological entity tetrahedron"
" in triangle mesh." );
default:
return h5_error_internal( __FILE__, __func__, __LINE__ );
return h5_error_internal( f, __FILE__, __func__, __LINE__ );
}
default:
return h5_error_internal( __FILE__, __func__, __LINE__ );
return h5_error_internal( f, __FILE__, __func__, __LINE__ );
}
}
+37 -28
View File
@@ -3,13 +3,13 @@
h5_err_t
_h5t_handle_get_global_entity_id_err (
_h5t_handle_get_global_eid_err (
h5_file_t *f,
const h5_id_t * const global_vids
);
h5_err_t
_h5t_handle_get_local_entity_id_err (
_h5t_handle_get_local_eid_err (
h5_file_t *f,
const h5_id_t * const local_vids
);
@@ -21,55 +21,64 @@ _h5t_error_illegal_object_type (
#define _h5t_error_undef_mesh( f ) \
h5_error( \
f, \
H5_ERR_INVAL, \
"Mesh not yet defined." );
#define _h5t_error_undef_level( f ) \
h5_error( \
f, \
H5_ERR_INVAL, \
"Level not yet defined." );
#define _h5t_error_global_id_nexist( name, id ) \
h5_error( \
H5_ERR_NOENTRY, \
"%s with global id %ld does not exist!", \
#define _h5t_error_global_id_nexist( f, name, id ) \
h5_error( \
f, \
H5_ERR_NOENTRY, \
"%s with global id %lld does not exist!", \
name, (long)id );
#define _h5t_error_global_tet_id_nexist( vids ) \
h5_error( \
#define _h5t_error_global_tet_id_nexist( f, vids ) \
h5_error( \
f, \
H5_ERR_NOENTRY, \
"Tetrahedron with global vertex ids (%d,%d,%d,%d) doesn't exist!", \
"Tetrahedron with global vertex ids (%lld,%lld,%lld,%lld) doesn't exist!", \
vids[0], vids[1], vids[2], vids[3] );
#define _h5t_error_global_tri_id_nexist( vids ) \
h5_error( \
H5_ERR_NOENTRY, \
"Triangle with global vertex ids (%d,%d,%d) doesn't exist!", \
#define _h5t_error_global_tri_id_nexist( f, vids ) \
h5_error( \
f, \
H5_ERR_NOENTRY, \
"Triangle with global vertex ids (%lld,%lld,%lld) doesn't exist!", \
vids[0], vids[1], vids[2] );
#define _h5t_error_local_tet_id_nexist( vids ) \
h5_error( \
H5_ERR_NOENTRY, \
"Tetrahedron with local vertex ids (%d,%d,%d,%d) doesn't exist!", \
#define _h5t_error_local_tet_id_nexist( f, vids ) \
h5_error( \
f, \
H5_ERR_NOENTRY, \
"Tetrahedron with local vertex ids (%lld,%lld,%lld,%lld) doesn't exist!", \
vids[0], vids[1], vids[2], vids[3] );
#define _h5t_error_local_triangle_id_nexist( vids ) \
h5_error( \
#define _h5t_error_local_triangle_id_nexist( f, vids ) \
h5_error( \
f, \
H5_ERR_NOENTRY, \
"Triangle with local vertex ids (%d,%d,%d) doesn't exist!", \
"Triangle with local vertex ids (%lld,%lld,%lld) doesn't exist!", \
vids[0], vids[1], vids[2] );
#define _h5t_error_global_triangle_id_nexist( vids ) \
h5_error( \
H5_ERR_NOENTRY, \
"Triangle with global vertex ids (%d,%d,%d) doesn't exist!", \
#define _h5t_error_global_triangle_id_nexist( f, vids ) \
h5_error( \
f, \
H5_ERR_NOENTRY, \
"Triangle with global vertex ids (%lld,%lld,%lld) doesn't exist!", \
vids[0], vids[1], vids[2] );
#define _h5t_error_store_boundaryface_local_id( local_fid ) \
h5_error( \
H5_ERR_INVAL, \
"Boundary face with local id %d is not on level 0!", \
#define _h5t_error_store_boundaryface_local_id( f, local_fid ) \
h5_error( \
f, \
H5_ERR_INVAL, \
"Boundary face with local id %lld is not on level 0!", \
local_fid );
#endif
+211
View File
@@ -0,0 +1,211 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h> /* va_arg - System dependent ?! */
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <hdf5.h>
#include "h5_core/h5_core.h"
#include "h5_core/h5_core_private.h"
h5_size_t
h5t_get_num_meshes (
h5_file_t * f,
const enum h5_oid type
) {
struct h5t_fdata *t = f->t;
if ( t->num_meshes != -1 ) {
return t->num_meshes;
}
if ( t->topo_gid < 0 ) {
TRY( _h5t_open_topo_group ( f ) );
}
TRY( t->num_meshes = (h5_size_t)hdf5_get_num_objects (
t->topo_gid,
_h5t_meshes_grpnames[t->mesh_type],
H5G_GROUP ) );
return t->num_meshes;
}
/*
*/
h5_size_t
h5t_get_num_levels (
h5_file_t * f
) {
struct h5t_fdata *t = f->t;
h5_err_t h5err;
if ( t->num_levels >= 0 ) return t->num_levels;
if ( t->cur_mesh < 0 ) {
return _h5t_error_undef_mesh ( f );
}
if ( t->mesh_gid < 0 ) {
h5err = _h5t_open_mesh_group ( f );
if ( h5err < 0 ) return h5err;
}
hid_t dataset_id = H5Dopen ( t->mesh_gid, "NumVertices", H5P_DEFAULT );
if ( dataset_id < 0 )
return HANDLE_H5D_OPEN_ERR ( f, "NumVertices" );
hid_t diskspace_id = H5Dget_space( dataset_id );
if ( diskspace_id < 0 )
return HANDLE_H5D_GET_SPACE_ERR ( f );
hssize_t size = H5Sget_simple_extent_npoints ( diskspace_id );
if ( size < 0 )
return HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR ( f );
herr_t herr = H5Sclose ( diskspace_id );
if ( herr < 0 )
return HANDLE_H5S_CLOSE_ERR ( f );
t->num_levels = size;
return size;
}
/*
query number of topological elems:
* on this cnode on current level
H5FedGetNumXXX(), h5t_get_num_elems()
* on given cnode on current level
H5FedGetNumXXXCnode(), h5t_get_num_elems_cnode()
* on this cnode on current level total (internal)
_h5t_get_num_elems_total()
* on given cnode on current level total (internal)
* on all cnodes on current level
H5FedGetNumXXXCnodeTotal()
* on all cnodes on current level total (internal)
* on this cnode on given level
H5FedGetNumXXXOnLevel()
* on this cnode on given level total (internal)
* on given cnode on given level
H5FedGetNumXXXCnodeOnLevel()
* on given cnode on given level total (internal)
* on all cnodes on given level
H5FedGetNumXXXTotalOnLevel()
* on all cnodes on given level total (internal)
* on this cnode on last level (internal)
* on given cnode on last level (internal)
* on this cnode on last level total (internal)
* on given cnode on last level total (internal)
* on all cnodes on last level (internal)
* on all cnodes on last level total (internal)
*/
/*!
Return number of elems on compute node \c cnode_id
and level \c level_id. If \cnode_id is equal \c -1 return the
number of elems in the entire mesh. If \level_id is equal \c -1
return the number of elems in the last level.
\remark
Refined elems are *not* counted.
*/
h5_size_t
h5t_get_num_elems (
h5_file_t * f,
hid_t cnode_id,
hid_t level_id
) {
struct h5t_fdata *t = f->t;
if ( cnode_id < 0 ) {
cnode_id = f->nprocs;
}
if ( level_id < 0 ) {
level_id = f->t->num_levels-1;
}
if ( t->cur_mesh < 0 ) {
return _h5t_error_undef_mesh ( f );
}
if ( t->cur_level < 0 ) {
return _h5t_error_undef_level( f );
}
if ( t->num_elems_on_level == NULL ) {
TRY( _h5t_read_num_elems ( f ) );
}
return t->num_elems_on_level[t->cur_level];
}
/*!
Return number of all elems on compute node \c cnode_id
and level \c level_id including refined elems. If
\cnode_id is equal \c -1 return the number of elems
in the entire mesh. If \level_id is equal \c -1
return the number of elems in the last level.
*/
h5_size_t
h5t_get_num_elems_total (
h5_file_t * f,
hid_t cnode_id,
hid_t level_id
) {
struct h5t_fdata *t = f->t;
if ( cnode_id < 0 ) {
cnode_id = f->nprocs;
}
if ( level_id < 0 ) {
level_id = f->t->num_levels-1;
}
if ( t->cur_mesh < 0 ) {
return _h5t_error_undef_mesh ( f );
}
if ( t->num_elems == NULL ) {
TRY( _h5t_read_num_elems ( f ) );
}
return t->num_elems[level_id];
}
/*!
Return number of vertices on compute node \c cnode_id
and level \c level_id. If \cnode_id is equal \c -1 return the
number of vertices in the entire mesh. If \level_id is equal \c -1
return the number of vertices in the last level.
\remark
There is nothing like "refined vertices".
*/
h5_size_t
h5t_get_num_vertices (
h5_file_t * f,
hid_t cnode_id,
hid_t level_id
) {
struct h5t_fdata *t = f->t;
if ( cnode_id < 0 ) {
cnode_id = f->nprocs;
}
if ( level_id < 0 ) {
level_id = f->t->num_levels-1;
}
if ( t->cur_mesh < 0 ) {
return _h5t_error_undef_mesh ( f );
}
if ( t->cur_level < 0 ) {
return _h5t_error_undef_level( f );
}
if ( t->num_vertices == NULL ) {
TRY( _h5t_read_num_vertices ( f ) );
}
return t->num_vertices[level_id];
}
h5_id_t
h5t_get_level (
h5_file_t * f
) {
struct h5t_fdata *t = f->t;
return t->cur_level;
}
+42
View File
@@ -0,0 +1,42 @@
#ifndef __H5T_INQUIRY_H
#define __H5T_INQUIRY_H
h5_size_t
h5t_get_num_meshes (
h5_file_t * f,
const enum h5_oid type
);
h5_size_t
h5t_get_num_levels (
h5_file_t * f
);
h5_size_t
h5t_get_num_elems (
h5_file_t * f,
hid_t cnode_id,
hid_t level_id
);
h5_size_t
h5t_get_num_elems_total (
h5_file_t * f,
hid_t cnode_id,
hid_t level_id
);
h5_size_t
h5t_get_num_vertices (
h5_file_t * f,
hid_t cnode_id,
hid_t level_id
);
h5_id_t
h5t_get_level (
h5_file_t * f
);
#endif
+188 -153
View File
@@ -8,13 +8,14 @@
*/
static int
_cmp_vertices (
h5_float64_t *P1,
h5_float64_t *P2
h5_float64_t P0[3],
h5_float64_t P1[3]
) {
int i;
for ( i = 0; i < 3; i++ ) {
if ( P1[i] < P2[i] ) return -1;
else if (P1[i] > P2[i] )return 1;
int diff = _h5_fcmp ( P0[i], P1[i], 10 );
if ( diff < 0 ) return -1;
else if ( diff > 0 ) return 1;
}
return 0;
}
@@ -63,13 +64,52 @@ _h5t_sort_vertices (
}
static h5_id_t
_search_vertex (
h5_file_t * const f,
h5_float64_t P0[3]
) {
struct h5t_fdata *t = f->t;
register h5_id_t low = 0;
register h5_id_t high = t->sorted_lvertices.num_items - 1;
while (low <= high) {
register int mid = (low + high) / 2;
h5_id_t local_vid = t->sorted_lvertices.items[mid];
h5_float64_t *P1 = t->vertices[local_vid].P;
int diff = _cmp_vertices ( P0, P1 );
if ( diff < 0 )
high = mid - 1;
else if ( diff > 0 )
low = mid + 1;
else
return mid; // found
}
return -(low+1); // not found
}
h5_id_t
_h5t_get_local_vid (
h5_file_t * const f,
h5_float64_t P[3]
) {
struct h5t_fdata *t = f->t;
h5_id_t local_vid;
TRY2( local_vid = _search_vertex ( f, P ), fail );
return t->sorted_lvertices.items[local_vid];
fail:
return H5_ERR;
}
/*!
Returns the local vertex id of the i-th vertex of an entity. For triangles
Returns the local vertex id of the i-th vertex of an element. For triangles
i is in [0,1,2], for tetraheda i is in [0,1,2,3].
*/
static h5_id_t
_get_local_vertex_id_of_entity (
_get_local_vid_of_elem (
h5_file_t * f,
int ith_vertex,
h5_id_t local_eid
@@ -81,50 +121,50 @@ _get_local_vertex_id_of_entity (
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON: {
local_vid = t->lentities.tets[local_eid].vertex_ids[ith_vertex];
local_vid = t->elems_ldta.tets[local_eid].vids[ith_vertex];
if ( local_vid == -1 ) {
global_vid =
t->entities.tets[local_eid].vertex_ids[ith_vertex];
t->elems.tets[local_eid].vids[ith_vertex];
local_vid = _h5_search_idmap (
&t->map_vertex_g2l, global_vid );
t->lentities.tets[local_eid].vertex_ids[ith_vertex] =
t->elems_ldta.tets[local_eid].vids[ith_vertex] =
local_vid;
}
break;
}
case H5_OID_TRIANGLE: {
local_vid = t->lentities.tris[local_eid].vertex_ids[ith_vertex];
local_vid = t->elems_ldta.tris[local_eid].vids[ith_vertex];
if ( local_vid == -1 ) {
global_vid =
t->entities.tris[local_eid].vertex_ids[ith_vertex];
t->elems.tris[local_eid].vids[ith_vertex];
local_vid = _h5_search_idmap (
&t->map_vertex_g2l, global_vid );
t->lentities.tris[local_eid].vertex_ids[ith_vertex] =
t->elems_ldta.tris[local_eid].vids[ith_vertex] =
local_vid;
}
break;
}
default:
return h5_error_internal ( __FILE__, __func__, __LINE__ );
return h5_error_internal ( f, __FILE__, __func__, __LINE__ );
}
return local_vid;
}
/*!
Return the coordinates of the i-th vertex of the entity given by its local
entity id. For triangles \c i is in \c [0,1,2], for tetraheda \c i is in
Return the coordinates of the i-th vertex of the element given by its local
element id. For triangles \c i is in \c [0,1,2], for tetraheda \c i is in
\c [0,1,2,3].
*/
static h5_float64_t*
_get_vertex_of_entity (
_get_vertex_of_elem (
h5_file_t * f,
int ith_vertex,
h5_id_t local_entity_id
h5_id_t local_eid
) {
struct h5t_fdata *t = f->t;
h5_id_t local_vid = _get_local_vertex_id_of_entity (
f, ith_vertex, local_entity_id );
h5_id_t local_vid = _get_local_vid_of_elem (
f, ith_vertex, local_eid );
if ( local_vid == -1 )
return NULL;
return t->vertices[local_vid].P;
@@ -133,10 +173,10 @@ _get_vertex_of_entity (
/*!
Compare two entities given by their local vertex ids
Compare two elems given by their local vertex ids
*/
static int
_vcmp_entities (
_vcmp_elems (
h5_file_t *f,
h5_id_t *e1,
h5_id_t *e2
@@ -155,10 +195,10 @@ _vcmp_entities (
}
/*!
compare two entities given by their local id
compare two elems given by their local id
*/
static int
_cmp_entities (
_cmp_elems (
h5_file_t * f,
h5_id_t local_eid1,
h5_id_t local_eid2
@@ -167,8 +207,8 @@ _cmp_entities (
int i;
for ( i = 0; i < t->mesh_type; i++ ) {
int r = _cmp_vertices (
_get_vertex_of_entity ( f, i, local_eid1 ),
_get_vertex_of_entity ( f, i, local_eid2 ) );
_get_vertex_of_elem ( f, i, local_eid1 ),
_get_vertex_of_elem ( f, i, local_eid2 ) );
if ( r < 0 ) return -1;
else if ( r > 0 ) return 1;
}
@@ -176,7 +216,7 @@ _cmp_entities (
}
static int
_cmp_entities1 (
_cmp_elems1 (
h5_file_t * f,
h5_id_t local_eid1,
h5_id_t local_eid2
@@ -186,8 +226,8 @@ _cmp_entities1 (
int i;
for ( i = 0; i < t->mesh_type; i++ ) {
int r = _cmp_vertices (
_get_vertex_of_entity ( f, imap[i], local_eid1 ),
_get_vertex_of_entity ( f, imap[i], local_eid2 ) );
_get_vertex_of_elem ( f, imap[i], local_eid1 ),
_get_vertex_of_elem ( f, imap[i], local_eid2 ) );
if ( r < 0 ) return -1;
else if ( r > 0 ) return 1;
}
@@ -196,7 +236,7 @@ _cmp_entities1 (
static int
_qsort_cmp_entities0 (
_qsort_cmp_elems0 (
void *_f,
const void* _local_eid1,
const void* _local_eid2
@@ -204,11 +244,11 @@ _qsort_cmp_entities0 (
h5_file_t *f = (h5_file_t*)_f;
h5_id_t local_eid1 = *(h5_id_t*)_local_eid1;
h5_id_t local_eid2 = *(h5_id_t*)_local_eid2;
return _cmp_entities ( f, local_eid1, local_eid2 );
return _cmp_elems ( f, local_eid1, local_eid2 );
}
static int
_qsort_cmp_entities1 (
_qsort_cmp_elems1 (
void *_f,
const void* _local_eid1,
const void* _local_eid2
@@ -216,45 +256,43 @@ _qsort_cmp_entities1 (
h5_file_t *f = (h5_file_t*)_f;
h5_id_t local_eid1 = *(h5_id_t*)_local_eid1;
h5_id_t local_eid2 = *(h5_id_t*)_local_eid2;
return _cmp_entities1 ( f, local_eid1, local_eid2 );
return _cmp_elems1 ( f, local_eid1, local_eid2 );
}
/*!
Sort entities geometrically.
Sort elems geometrically.
*/
h5_err_t
_h5t_sort_entities (
_h5t_sort_elems (
h5_file_t *f
) {
struct h5t_fdata *t = f->t;
h5_size_t num_entities = h5t_get_num_entities ( f );
if ( num_entities < 0 ) return num_entities;
h5_size_t num_elems;
TRY( num_elems = h5t_get_num_elems_total ( f, f->myproc, -1 ) );
int k;
h5_id_t i;
for ( k = 0; k < 2; k++ ) {
h5_err_t h5err = _h5_alloc_smap (
&t->sorted_lentities[k], num_entities );
if ( h5err < 0 ) return h5err;
for ( i = 0; i < num_entities; i++ ) {
t->sorted_lentities[k].items[i] = i;
TRY( _h5_alloc_smap ( f, &t->sorted_elems_ldta[k], num_elems ) );
for ( i = 0; i < num_elems; i++ ) {
t->sorted_elems_ldta[k].items[i] = i;
}
t->sorted_lentities[k].num_items = num_entities;
t->sorted_elems_ldta[k].num_items = num_elems;
}
_h5_qsort_r (
t->sorted_lentities[0].items,
num_entities,
sizeof(t->sorted_lentities[0].items[0]),
t->sorted_elems_ldta[0].items,
num_elems,
sizeof(t->sorted_elems_ldta[0].items[0]),
f,
_qsort_cmp_entities0 );
_qsort_cmp_elems0 );
_h5_qsort_r (
t->sorted_lentities[1].items,
num_entities,
sizeof(t->sorted_lentities[1].items[0]),
t->sorted_elems_ldta[1].items,
num_elems,
sizeof(t->sorted_elems_ldta[1].items[0]),
f,
_qsort_cmp_entities1 );
_qsort_cmp_elems1 );
return H5_SUCCESS;
}
@@ -263,7 +301,7 @@ _h5t_sort_entities (
Sort (small) array of local vertex ids geometrically.
*/
h5_err_t
_h5t_sort_local_vertex_ids (
_h5t_sort_local_vids (
h5_file_t * const f,
h5_id_t * const local_vids, /* IN/OUT: local vertex ids */
const h5_size_t size /* size of array */
@@ -288,55 +326,55 @@ _h5t_sort_local_vertex_ids (
}
h5_err_t
_h5t_sort_global_vertex_ids (
_h5t_sort_global_vids (
h5_file_t * const f,
h5_id_t * const global_vids, /* IN/OUT: global vertex ids */
const h5_size_t size /* size of array */
) {
h5_id_t local_vids[H5_MAX_VERTICES_PER_ENTITY];
h5_id_t local_vids[H5_MAX_VERTICES_PER_ELEM];
const h5_id_t *global_vid = global_vids;
h5_id_t *local_vid = local_vids;
h5_id_t i;
for ( i = 0; i < size; i++, local_vid++, global_vid++ ) {
*local_vid = h5t_map_global_vertex_id2local ( f, *global_vid );
if ( *local_vid < 0 )
return *local_vid;
TRY(
*local_vid = h5t_map_global_vid2local(
f, *global_vid )
);
}
h5_err_t h5err = _h5t_sort_local_vertex_ids ( f, local_vids, size );
if ( h5err < 0 ) return h5err;
TRY( _h5t_sort_local_vids ( f, local_vids, size ) );
for ( i = 0; i < size; i++ ) {
global_vids[i] = h5t_map_local_vertex_id2global ( f, local_vids[i] );
global_vids[i] = h5t_map_local_vid2global (
f, local_vids[i] );
}
return H5_SUCCESS;
}
/*!
Binary search an entity given by its local vertex ids.
Binary search an element given by its local vertex ids.
\result index in t->map_entity_s2l[0].items
\result index in t->map_elem_s2l[0].items
*/
static h5_id_t
_search_entity (
_search_elem (
h5_file_t *f,
h5_id_t * const local_vids /* local vertex ids */
) {
struct h5t_fdata *t = f->t;
_h5t_sort_local_vertex_ids ( f, local_vids, t->mesh_type );
_h5t_sort_local_vids ( f, local_vids, t->mesh_type );
register h5_id_t low = 0;
register h5_id_t high = t->sorted_lentities[0].num_items - 1;
register h5_id_t *entity1 = local_vids;
register h5_id_t high = t->sorted_elems_ldta[0].num_items - 1;
register h5_id_t *elem1 = local_vids;
while (low <= high) {
register int mid = (low + high) / 2;
h5_id_t local_eid = t->sorted_lentities[0].items[mid];
h5_id_t *entity2 = t->lentities.tets[local_eid].vertex_ids;
int diff = _vcmp_entities ( f, entity1, entity2 );
h5_id_t local_eid = t->sorted_elems_ldta[0].items[mid];
h5_id_t *elem2 = t->elems_ldta.tets[local_eid].vids;
int diff = _vcmp_elems ( f, elem1, elem2 );
if ( diff < 0 )
high = mid - 1;
else if ( diff > 0 )
@@ -348,28 +386,27 @@ _search_entity (
}
/*!
Get local id of entity given by local vertex id's
Get local id of elem given by local vertex id's
*/
h5_id_t
h5t_get_local_entity_id (
h5t_get_local_eid (
h5_file_t *f,
h5_id_t * const local_vids /* IN/OUT: local vertex id's */
) {
struct h5t_fdata *t = f->t;
h5_id_t local_eid = _search_entity ( f, local_vids );
if ( local_eid < 0 ) {
return _h5t_handle_get_local_entity_id_err ( f, local_vids );
}
return t->sorted_lentities[0].items[local_eid];
h5_id_t local_eid;
TRY2( local_eid = _search_elem ( f, local_vids ), fail );
return t->sorted_elems_ldta[0].items[local_eid];
fail:
return _h5t_handle_get_local_eid_err ( f, local_vids );
}
/*!
Map a global vertex id to corresponding local vertex id.
*/
h5_id_t
h5t_map_global_vertex_id2local (
h5t_map_global_vid2local (
h5_file_t *f,
const h5_id_t global_id
) {
@@ -377,24 +414,24 @@ h5t_map_global_vertex_id2local (
h5_id_t local_id = _h5_search_idmap ( &t->map_vertex_g2l, global_id );
if ( local_id < 0 )
return _h5t_error_global_id_nexist ("vertex", global_id );
return _h5t_error_global_id_nexist ( f, "vertex", global_id );
return local_id;
}
h5_id_t
h5t_map_local_vertex_id2global (
h5t_map_local_vid2global (
h5_file_t *f,
const h5_id_t local_vid
) {
struct h5t_fdata *t = f->t;
if ( local_vid < 0 || local_vid > t->num_vertices[t->num_levels-1] )
return HANDLE_H5_OUT_OF_RANGE_ERR ( "vertex", local_vid );
return HANDLE_H5_OUT_OF_RANGE_ERR ( f, "vertex", local_vid );
return t->vertices[local_vid].id;
}
h5_err_t
h5t_map_global_vertex_ids2local (
h5t_map_global_vids2local (
h5_file_t *f,
const h5_id_t * const global_vids,
const h5_id_t size,
@@ -403,20 +440,21 @@ h5t_map_global_vertex_ids2local (
h5_id_t i;
for ( i = 0; i < size; i++ ) {
local_vids[i] = h5t_map_global_vertex_id2local (
local_vids[i] = h5t_map_global_vid2local (
f, global_vids[i] );
if ( local_vids[i] < 0 )
return _h5t_error_global_id_nexist (
f,
"vertex", global_vids[i] );
}
return H5_SUCCESS;
}
/*!
Map a local entity id to corresponding global id.
Map a local elem id to corresponding global id.
*/
h5_id_t
h5t_map_local_entity_id2global (
h5t_map_local_eid2global (
h5_file_t *f,
const h5_id_t local_eid
) {
@@ -424,51 +462,47 @@ h5t_map_local_entity_id2global (
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON:
if ( local_eid < 0 || local_eid > t->num_entities[t->num_levels-1] )
return HANDLE_H5_OUT_OF_RANGE_ERR ( "tet", local_eid );
return t->entities.tets[local_eid].id;
if ( local_eid < 0 || local_eid > t->num_elems[t->num_levels-1] )
return HANDLE_H5_OUT_OF_RANGE_ERR ( f, "tet", local_eid );
return t->elems.tets[local_eid].id;
case H5_OID_TRIANGLE:
if ( local_eid < 0 || local_eid > t->num_entities[t->num_levels-1] )
return HANDLE_H5_OUT_OF_RANGE_ERR ( "triangle", local_eid );
return t->entities.tris[local_eid].id;
if ( local_eid < 0 || local_eid > t->num_elems[t->num_levels-1] )
return HANDLE_H5_OUT_OF_RANGE_ERR (
f, "triangle", local_eid );
return t->elems.tris[local_eid].id;
default:
return h5_error_internal ( __FILE__, __func__, __LINE__ );
return h5_error_internal ( f, __FILE__, __func__, __LINE__ );
}
}
/*!
Get global id of entity given by global vertex id's
Get global id of elem given by global vertex id's
*/
h5_id_t
h5t_get_global_entity_id (
h5t_get_global_eid (
h5_file_t *f,
const h5_id_t * const global_vids /* global vertex id's */
) {
struct h5t_fdata *t = f->t;
h5_id_t local_vids[H5_MAX_VERTICES_PER_ENTITY];
h5_id_t local_vids[H5_MAX_VERTICES_PER_ELEM];
if ( t->vertices == NULL ) {
h5_err_t h5err = _h5t_read_mesh ( f );
if ( h5err < 0 ) return h5err;
TRY( _h5t_read_mesh ( f ) );
}
h5_err_t h5err = h5t_map_global_vertex_ids2local (
TRY2( h5t_map_global_vids2local (
f,
global_vids,
t->mesh_type,
local_vids );
if ( h5err < 0 )
return _h5t_handle_get_global_entity_id_err ( f, global_vids );
h5_id_t local_eid = h5t_get_local_entity_id ( f, local_vids );
if ( local_eid < 0 )
return _h5t_handle_get_global_entity_id_err ( f, global_vids );
return h5t_map_local_entity_id2global ( f, local_eid );
local_vids ), fail );
h5_id_t local_eid;
TRY2( local_eid = h5t_get_local_eid ( f, local_vids ), fail );
return h5t_map_local_eid2global ( f, local_eid );
fail:
return _h5t_handle_get_global_eid_err ( f, global_vids );
}
static int
_search_ith_vertex_in_entity (
_search_ith_vertex_in_elem (
h5_file_t * const f,
const int i,
h5_id_t local_vid
@@ -476,14 +510,14 @@ _search_ith_vertex_in_entity (
struct h5t_fdata *t = f->t;
register h5_id_t low = 0;
register h5_id_t high = t->sorted_lentities[i].num_items - 1;
register h5_id_t high = t->sorted_elems_ldta[i].num_items - 1;
register h5_float64_t *vertex1 = t->vertices[local_vid].P;
while (low <= high) {
register int mid = (low + high) / 2;
h5_id_t local_eid = t->sorted_lentities[i].items[mid];
h5_id_t local_vid2 = t->lentities.tets[local_eid].vertex_ids[i];
h5_id_t local_eid = t->sorted_elems_ldta[i].items[mid];
h5_id_t local_vid2 = t->elems_ldta.tets[local_eid].vids[i];
h5_float64_t *vertex2 = t->vertices[local_vid2].P;
int diff = _cmp_vertices ( vertex1, vertex2 );
@@ -506,22 +540,22 @@ _tetm_contain_triangle (
) {
struct h5t_fdata *t = f->t;
h5_id_t *local_vids_of_entity = t->lentities.tets[local_eid].vertex_ids;
h5_id_t *local_vids_of_elem = t->elems_ldta.tets[local_eid].vids;
if ( i == 0 &&
local_vids[1] == local_vids_of_entity[1] &&
local_vids[2] == local_vids_of_entity[2]
local_vids[1] == local_vids_of_elem[1] &&
local_vids[2] == local_vids_of_elem[2]
) return 0;
else if ( i == 0 &&
local_vids[1] == local_vids_of_entity[1] &&
local_vids[2] == local_vids_of_entity[3]
local_vids[1] == local_vids_of_elem[1] &&
local_vids[2] == local_vids_of_elem[3]
) return 1;
else if ( i == 0 &&
local_vids[1] == local_vids_of_entity[2] &&
local_vids[2] == local_vids_of_entity[3]
local_vids[1] == local_vids_of_elem[2] &&
local_vids[2] == local_vids_of_elem[3]
) return 2;
else if ( i == 1 &&
local_vids[1] == local_vids_of_entity[2] &&
local_vids[2] == local_vids_of_entity[3]
local_vids[1] == local_vids_of_elem[2] &&
local_vids[2] == local_vids_of_elem[3]
) return 3;
return -1;
}
@@ -538,22 +572,22 @@ _tetm_search_triangle (
) {
struct h5t_fdata *t = f->t;
_h5t_sort_local_vertex_ids ( f, local_vids, 3 );
_h5t_sort_local_vids ( f, local_vids, 3 );
/*
search for Vertex_id(tri,0) in the tuple of all 0th vertices of all tets
search for vid(tri,0) in the tuple of all 0th vertices of all tets
if there is one:
take the smallest tet with Vertex_id(tri,0) == Vertex_id(tet,0)
loop over all tets with Vertex_id(tri,0) == Vertex_id(tet,0)
take the smallest tet with vid(tri,0) == vid(tet,0)
loop over all tets with vid(tri,0) == vid(tet,0)
until we find a tet the triangle is belonging to.
else
search for Vertex_id(tri,0) in the tuple of all 1st vertices of
search for vid(tri,0) in the tuple of all 1st vertices of
all tets
if there is one:
take the smallest tet with
Vertex_id(tri,0) == Vertex_id(tet,0)
vid(tri,0) == vid(tet,0)
loop over all tets with
Vertex_id(tri,0) == Vertex_id(tet,0)
vid(tri,0) == vid(tet,0)
until we find a tet the triangle is belonging to.
*/
@@ -562,28 +596,28 @@ _tetm_search_triangle (
h5_id_t local_eid[2];
h5_id_t tidx[2];
for ( i = 0; i < 2; i++ ) {
idx[i] = _search_ith_vertex_in_entity ( f, i, local_vids[0] );
idx[i] = _search_ith_vertex_in_elem ( f, i, local_vids[0] );
while ( idx[i] > 0 && /* get leftmost */
local_vids[0] == _get_local_vertex_id_of_entity (
f, i, t->sorted_lentities[0].items[idx[i]-1] ) )
local_vids[0] == _get_local_vid_of_elem (
f, i, t->sorted_elems_ldta[0].items[idx[i]-1] ) )
idx[i]--;
do {
/* check whether triangle is in entity given by local id */
local_eid[i] = t->sorted_lentities[i].items[idx[i]];
/* check whether triangle is in elem given by local id */
local_eid[i] = t->sorted_elems_ldta[i].items[idx[i]];
tidx[i] = _tetm_contain_triangle (
f, local_vids, i, local_eid[i] );
if ( tidx[i] >= 0 ) break;
idx[i]++;
} while ( local_vids[0] == _get_local_vertex_id_of_entity (
} while ( local_vids[0] == _get_local_vid_of_elem (
f, i, local_eid[i] ) );
}
if ( idx[0] < 0 && idx[1] < 0 ) return -1;
if ( idx[0] < 0 ) return _h5t_build_triangle_id ( tidx[1], local_eid[1] );
if ( idx[1] < 0 ) return _h5t_build_triangle_id ( tidx[0], local_eid[0] );
if ( _cmp_entities( f, local_eid[0], local_eid[1] ) < 0 )
if ( _cmp_elems( f, local_eid[0], local_eid[1] ) < 0 )
return _h5t_build_triangle_id ( tidx[0], local_eid[0] );
else
return _h5t_build_triangle_id ( tidx[1], local_eid[1] );
@@ -609,18 +643,19 @@ h5t_get_global_triangle_id (
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON: {
h5_id_t local_vids[3];
h5_err_t h5err = h5t_map_global_vertex_ids2local (
h5_err_t h5err = h5t_map_global_vids2local (
f, global_vids, 3, local_vids );
if ( h5err < 0 ) return h5err;
h5_id_t local_tid = h5t_get_local_triangle_id ( f, local_vids );
if ( local_tid < 0 )
return _h5t_error_global_triangle_id_nexist ( global_vids );
return _h5t_error_global_triangle_id_nexist (
f, global_vids );
return h5t_map_local_triangle_id2global ( f, local_tid );
}
case H5_OID_TRIANGLE:
return h5t_get_global_entity_id ( f, global_vids );
return h5t_get_global_eid ( f, global_vids );
default:
return h5_error_internal ( __FILE__, __func__, __LINE__ );
return h5_error_internal ( f, __FILE__, __func__, __LINE__ );
}
}
@@ -640,26 +675,26 @@ h5t_get_local_triangle_id (
if ( h5err < 0 ) return h5err;
h5_id_t local_tid = _tetm_search_triangle ( f, local_vids );
if ( local_tid == -1 ) {
return _h5t_error_local_triangle_id_nexist(local_vids);
return _h5t_error_local_triangle_id_nexist( f, local_vids );
}
return local_tid;
}
case H5_OID_TRIANGLE:
return h5t_get_local_entity_id ( f, local_vids );
return h5t_get_local_eid ( f, local_vids );
default:
return h5_error_internal ( __FILE__, __func__, __LINE__ );
return h5_error_internal ( f, __FILE__, __func__, __LINE__ );
}
}
h5_id_t
h5t_map_global_entity_id2local (
h5t_map_global_eid2local (
h5_file_t * const f,
const h5_id_t global_eid
) {
struct h5t_fdata *t = f->t;
h5_id_t local_eid = _h5_search_idmap ( &t->map_entity_g2l, global_eid );
h5_id_t local_eid = _h5_search_idmap ( &t->map_elem_g2l, global_eid );
if ( local_eid < 0 )
return _h5t_error_global_id_nexist ( "entity", global_eid );
return _h5t_error_global_id_nexist ( f, "elem", global_eid );
return local_eid;
}
@@ -677,17 +712,17 @@ h5t_map_global_triangle_id2local (
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON: {
h5_id_t global_tet_id = global_tri_id & H5_TET_MASK;
h5_id_t local_tet_id = h5t_map_global_entity_id2local (
h5_id_t local_tet_id = h5t_map_global_eid2local (
f, global_tet_id );
if ( local_tet_id < 0 )
return _h5t_error_global_id_nexist (
"triangle", global_tri_id );
f, "triangle", global_tri_id );
return local_tet_id | (global_tri_id & ~H5_TET_MASK);
}
case H5_OID_TRIANGLE:
return h5t_map_global_entity_id2local ( f, global_tri_id );
return h5t_map_global_eid2local ( f, global_tri_id );
default:
return h5_error_internal ( __FILE__, __func__, __LINE__ );
return h5_error_internal ( f, __FILE__, __func__, __LINE__ );
}
}
@@ -705,16 +740,16 @@ h5t_map_local_triangle_id2global (
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON: {
h5_id_t local_tet_id = local_tri_id & H5_TET_MASK;
h5_id_t global_tet_id = h5t_map_local_entity_id2global (
h5_id_t global_tet_id = h5t_map_local_eid2global (
f, local_tet_id );
if ( global_tet_id < 0 )
return HANDLE_H5_OUT_OF_RANGE_ERR(
"triangle", local_tri_id );
f, "triangle", local_tri_id );
return global_tet_id | (local_tri_id & ~H5_TET_MASK);
}
case H5_OID_TRIANGLE:
return h5t_map_local_entity_id2global ( f, local_tri_id );
return h5t_map_local_eid2global ( f, local_tri_id );
default:
return h5_error_internal ( __FILE__, __func__, __LINE__ );
return h5_error_internal ( f, __FILE__, __func__, __LINE__ );
}
}
+13 -7
View File
@@ -2,13 +2,13 @@
#define __T_MAP_H
h5_id_t
h5t_map_global_vertex_id2local (
h5t_map_global_vid2local (
h5_file_t *f,
h5_id_t global_vid
);
h5_err_t
h5t_map_global_vertex_ids2local (
h5t_map_global_vids2local (
h5_file_t *f,
const h5_id_t * const global_vids,
const h5_id_t size,
@@ -16,19 +16,19 @@ h5t_map_global_vertex_ids2local (
);
h5_id_t
h5t_map_local_vertex_id2global (
h5t_map_local_vid2global (
h5_file_t *f,
h5_id_t local_vid
);
h5_id_t
h5t_map_local_entity_id2global (
h5t_map_local_eid2global (
h5_file_t *f,
h5_id_t local_eid
);
h5_id_t
h5t_map_global_entity_id2local (
h5t_map_global_eid2local (
h5_file_t * const f,
const h5_id_t global_eid
);
@@ -46,13 +46,19 @@ h5t_map_global_triangle_id2local (
);
h5_id_t
h5t_get_local_entity_id (
_h5t_get_local_vid (
h5_file_t * const f,
h5_float64_t P[3]
);
h5_id_t
h5t_get_local_eid (
h5_file_t *f,
h5_id_t * const local_vids
);
h5_id_t
h5t_get_global_entity_id (
h5t_get_global_eid (
h5_file_t *f,
const h5_id_t * const global_vids
);
+3 -3
View File
@@ -2,14 +2,14 @@
#define __T_MAP_PRIVATE_H
h5_err_t
_h5t_sort_global_vertex_ids (
_h5t_sort_global_vids (
h5_file_t * const f,
h5_id_t * const global_vids,
const h5_size_t size
);
h5_err_t
_h5t_sort_local_vertex_ids (
_h5t_sort_local_vids (
h5_file_t * const f,
h5_id_t * const local_vids,
const h5_size_t size
@@ -21,7 +21,7 @@ _h5t_sort_vertices (
);
h5_err_t
_h5t_sort_entities (
_h5t_sort_elems (
h5_file_t * const f
);
+46 -48
View File
@@ -22,28 +22,28 @@ _create_array_types (
hsize_t dims[1] = { 3 };
hid_t hid = H5Tarray_create ( H5T_NATIVE_DOUBLE, 1, dims );
if ( hid < 0 ) {
return HANDLE_H5T_ARRAY_CREATE_ERR ( "H5T_NATIVE_DOUBLE", 1 );
return HANDLE_H5T_ARRAY_CREATE_ERR ( f, "H5T_NATIVE_DOUBLE", 1 );
}
t->float64_3tuple_tid = hid;
dims[0] = 2;
hid = H5Tarray_create ( H5T_NATIVE_INT32, 1, dims );
if ( hid < 0 ) {
return HANDLE_H5T_ARRAY_CREATE_ERR ( "H5T_NATIVE_INT32", 1 );
return HANDLE_H5T_ARRAY_CREATE_ERR ( f, "H5T_NATIVE_INT32", 1 );
}
t->int32_2tuple_tid = hid;
dims[0] = 3;
hid = H5Tarray_create ( H5T_NATIVE_INT32, 1, dims );
if ( hid < 0 ) {
return HANDLE_H5T_ARRAY_CREATE_ERR ( "H5T_NATIVE_INT32", 1 );
return HANDLE_H5T_ARRAY_CREATE_ERR ( f, "H5T_NATIVE_INT32", 1 );
}
t->int32_3tuple_tid = hid;
dims[0] = 4;
hid = H5Tarray_create ( H5T_NATIVE_INT32, 1, dims );
if ( hid < 0 ) {
return HANDLE_H5T_ARRAY_CREATE_ERR ( "H5T_NATIVE_INT32", 1 );
return HANDLE_H5T_ARRAY_CREATE_ERR ( f, "H5T_NATIVE_INT32", 1 );
}
t->int32_4tuple_tid = hid;
@@ -58,7 +58,7 @@ _create_vertex_type (
hid_t hid = H5Tcreate ( H5T_COMPOUND, sizeof(struct h5_vertex) );
if ( hid < 0 ) {
return HANDLE_H5T_CREATE_ERR ( "H5T_COMPOUND", "verticies" );
return HANDLE_H5T_CREATE_ERR ( f, "H5T_COMPOUND", "verticies" );
}
t->vertex_tid = hid;
@@ -68,7 +68,7 @@ _create_vertex_type (
HOFFSET(struct h5_vertex, id),
H5T_NATIVE_INT32 );
if ( herr < 0 ) {
return HANDLE_H5T_INSERT_ERR ( "id", "verticies" );
return HANDLE_H5T_INSERT_ERR ( f, "id", "verticies" );
}
herr = H5Tinsert (
@@ -77,7 +77,7 @@ _create_vertex_type (
HOFFSET(struct h5_vertex, unused),
H5T_NATIVE_INT32 );
if ( herr < 0 ) {
return HANDLE_H5T_INSERT_ERR ( "unused", "verticies" );
return HANDLE_H5T_INSERT_ERR ( f, "unused", "verticies" );
}
herr = H5Tinsert (
@@ -86,7 +86,7 @@ _create_vertex_type (
HOFFSET(struct h5_vertex, P),
t->float64_3tuple_tid );
if ( herr < 0 ) {
return HANDLE_H5T_INSERT_ERR ( "P", "verticies" );
return HANDLE_H5T_INSERT_ERR ( f, "P", "verticies" );
}
return H5_SUCCESS;
@@ -100,7 +100,7 @@ _create_triangle_type (
hid_t hid = H5Tcreate ( H5T_COMPOUND, sizeof(struct h5_triangle) );
if ( hid < 0 ) {
return HANDLE_H5T_CREATE_ERR ( "H5T_COMPOUND", "triangle" );
return HANDLE_H5T_CREATE_ERR ( f, "H5T_COMPOUND", "triangle" );
}
t->triangle_tid = hid;
@@ -110,7 +110,7 @@ _create_triangle_type (
HOFFSET(struct h5_triangle, id),
H5T_NATIVE_INT32 );
if ( herr < 0 ) {
return HANDLE_H5T_INSERT_ERR ( "id", "triangle" );
return HANDLE_H5T_INSERT_ERR ( f, "id", "triangle" );
}
herr = H5Tinsert (
@@ -119,7 +119,7 @@ _create_triangle_type (
HOFFSET(struct h5_triangle, parent_id),
H5T_NATIVE_INT32 );
if ( herr < 0 ) {
return HANDLE_H5T_INSERT_ERR ( "parent_id", "triangle" );
return HANDLE_H5T_INSERT_ERR ( f, "parent_id", "triangle" );
}
herr = H5Tinsert (
@@ -128,16 +128,16 @@ _create_triangle_type (
HOFFSET(struct h5_triangle, refined_on_level),
H5T_NATIVE_INT32 );
if ( herr < 0 ) {
return HANDLE_H5T_INSERT_ERR ( "refined_on_level", "triangle" );
return HANDLE_H5T_INSERT_ERR ( f, "refined_on_level", "triangle" );
}
herr = H5Tinsert (
t->triangle_tid,
"vertex_ids",
HOFFSET(struct h5_triangle, vertex_ids),
"vids",
HOFFSET(struct h5_triangle, vids),
t->int32_3tuple_tid );
if ( herr < 0 ) {
return HANDLE_H5T_INSERT_ERR ( "vertex_ids", "triangle" );
return HANDLE_H5T_INSERT_ERR ( f, "vids", "triangle" );
}
return H5_SUCCESS;
@@ -151,7 +151,7 @@ _create_tet_type (
hid_t hid = H5Tcreate ( H5T_COMPOUND, sizeof(struct h5_tetrahedron) );
if ( hid < 0 ) {
return HANDLE_H5T_CREATE_ERR ( "H5T_COMPOUND", "tetrahedra" );
return HANDLE_H5T_CREATE_ERR ( f, "H5T_COMPOUND", "tetrahedra" );
}
t->tet_tid = hid;
@@ -161,7 +161,7 @@ _create_tet_type (
HOFFSET(struct h5_tetrahedron, id),
H5T_NATIVE_INT32 );
if ( herr < 0 ) {
return HANDLE_H5T_INSERT_ERR ( "id", "tetrahedra" );
return HANDLE_H5T_INSERT_ERR ( f, "id", "tetrahedra" );
}
herr = H5Tinsert (
@@ -170,7 +170,7 @@ _create_tet_type (
HOFFSET(struct h5_tetrahedron, parent_id),
H5T_NATIVE_INT32 );
if ( herr < 0 ) {
return HANDLE_H5T_INSERT_ERR ( "parent_id", "tetrahedra" );
return HANDLE_H5T_INSERT_ERR ( f, "parent_id", "tetrahedra" );
}
herr = H5Tinsert (
@@ -179,7 +179,7 @@ _create_tet_type (
HOFFSET(struct h5_tetrahedron, refined_on_level),
H5T_NATIVE_INT32 );
if ( herr < 0 ) {
return HANDLE_H5T_INSERT_ERR ( "refined_on_level", "tetrahedra" );
return HANDLE_H5T_INSERT_ERR ( f, "refined_on_level", "tetrahedra" );
}
herr = H5Tinsert (
@@ -188,16 +188,16 @@ _create_tet_type (
HOFFSET(struct h5_tetrahedron, unused),
H5T_NATIVE_INT32 );
if ( herr < 0 ) {
return HANDLE_H5T_INSERT_ERR ( "unused", "tetrahedra" );
return HANDLE_H5T_INSERT_ERR ( f, "unused", "tetrahedra" );
}
herr = H5Tinsert (
t->tet_tid,
"vertex_ids",
HOFFSET(struct h5_tetrahedron, vertex_ids),
"vids",
HOFFSET(struct h5_tetrahedron, vids),
t->int32_4tuple_tid );
if ( herr < 0 ) {
return HANDLE_H5T_INSERT_ERR ( "vertex_ids", "tetrahedra" );
return HANDLE_H5T_INSERT_ERR ( f, "vids", "tetrahedra" );
}
return H5_SUCCESS;
@@ -215,8 +215,8 @@ _init_fdata (
t->num_levels = -1;
t->new_level = -1;
t->cur_level = -1;
t->last_stored_vertex_id = -1;
t->last_stored_entity_id = -1;
t->last_stored_vid = -1;
t->last_stored_eid = -1;
t->topo_gid = -1;
t->meshes_gid = -1;
t->mesh_gid = -1;
@@ -240,7 +240,7 @@ h5_err_t
_h5t_open_file (
h5_file_t * f /*!< IN: file handle */
) {
TRY( f->t = _h5_alloc ( NULL, sizeof(*f->t) ) );
TRY( f->t = _h5_alloc ( f, NULL, sizeof(*f->t) ) );
TRY( _init_fdata ( f ) );
TRY( _create_array_types ( f ) );
TRY( _create_vertex_type ( f ) );
@@ -352,15 +352,14 @@ h5t_open_mesh (
) {
struct h5t_fdata *t = f->t;
h5_err_t h5err = _h5t_close_mesh ( f );
if ( h5err < 0 ) return h5err;
TRY( _h5t_close_mesh ( f ) );
if ( t->num_meshes < 0 ) {
h5_size_t result = h5t_get_num_meshes ( f, type );
t->num_meshes = ( result > 0 ? result : 0 );
}
if ( (id < -1) || (id >= t->num_meshes) ) {
return HANDLE_H5_OUT_OF_RANGE_ERR( "mesh", id );
return HANDLE_H5_OUT_OF_RANGE_ERR( f, "mesh", id );
}
if ( id == -1 ) { /* append new mesh */
id = t->num_meshes;
@@ -370,17 +369,16 @@ h5t_open_mesh (
switch( type ) {
case H5_OID_TETRAHEDRON:
t->entity_tid = t->tet_tid;
t->elem_tid = t->tet_tid;
break;
case H5_OID_TRIANGLE:
t->entity_tid = t->triangle_tid;
t->elem_tid = t->triangle_tid;
break;
default:
return -1;
}
h5err = _h5t_open_mesh_group ( f );
if ( h5err < 0 ) return h5err;
TRY( _h5t_open_mesh_group ( f ) );
t->cur_mesh = id;
@@ -416,35 +414,35 @@ _release_memory (
}
t->num_vertices = NULL;
if ( t->num_entities ) {
free ( t->num_entities );
if ( t->num_elems ) {
free ( t->num_elems );
}
t->num_entities = NULL;
t->num_elems = NULL;
if ( t->num_entities_on_level ) {
free ( t->num_entities_on_level );
if ( t->num_elems_on_level ) {
free ( t->num_elems_on_level );
}
t->num_entities_on_level = NULL;
t->num_elems_on_level = NULL;
if ( t->map_vertex_g2l.items ) {
free ( t->map_vertex_g2l.items );
}
t->map_vertex_g2l.items = NULL;
if ( t->map_entity_g2l.items ) {
free ( t->map_entity_g2l.items );
if ( t->map_elem_g2l.items ) {
free ( t->map_elem_g2l.items );
}
t->map_entity_g2l.items = NULL;
t->map_elem_g2l.items = NULL;
if ( t->vertices ) {
free ( t->vertices );
}
t->vertices = NULL;
if ( t->entities.data ) {
free ( t->entities.data );
if ( t->elems.data ) {
free ( t->elems.data );
}
t->entities.data = NULL;
t->elems.data = NULL;
return H5_SUCCESS;
}
@@ -481,10 +479,10 @@ h5t_open_level (
struct h5t_fdata *t = f->t;
if ( (id < 0) || (id >= t->num_levels) )
return HANDLE_H5_OUT_OF_RANGE_ERR ( "Level", id );
return HANDLE_H5_OUT_OF_RANGE_ERR ( f, "Level", id );
t->cur_level = id;
t->last_retrieved_vertex_id = -1;
t->last_retrieved_entity_id = -1;
t->last_retrieved_vid = -1;
t->last_retrieved_eid = -1;
return H5_SUCCESS;
}
+126 -292
View File
@@ -71,13 +71,13 @@ _write_vertices (
}
static h5_err_t
_write_entities (
_write_elems (
h5_file_t * f
) {
struct h5t_fdata *t = f->t;
h5_err_t h5err;
if ( t->num_entities <= 0 ) return H5_SUCCESS;
if ( t->num_elems <= 0 ) return H5_SUCCESS;
if ( t->mesh_gid < 0 ) {
h5err = _h5t_open_mesh_group ( f );
@@ -88,11 +88,11 @@ _write_entities (
h5err = _h5t_write_obj (
f,
t->mesh_gid,
t->num_entities[t->num_levels-1],
t->num_elems[t->num_levels-1],
maxdim,
t->entity_tid,
(void*)t->entities.data,
"Entities"
t->elem_tid,
(void*)t->elems.data,
"Elems"
);
if ( h5err < 0 ) return h5err;
@@ -102,8 +102,8 @@ _write_entities (
t->num_levels,
maxdim,
H5T_NATIVE_INT32,
(void*)t->num_entities,
"NumEntities"
(void*)t->num_elems,
"NumElems"
);
if ( h5err < 0 ) return h5err;
@@ -113,8 +113,8 @@ _write_entities (
t->num_levels,
maxdim,
H5T_NATIVE_INT32,
(void*)t->num_entities_on_level,
"NumEntitiesOnLevel"
(void*)t->num_elems_on_level,
"NumElemsOnLevel"
);
}
@@ -129,83 +129,12 @@ _h5t_write_mesh (
h5err = _write_vertices( f );
if ( h5err < 0 ) return h5err;
h5err = _write_entities( f );
h5err = _write_elems( f );
if ( h5err < 0 ) return h5err;
return H5_SUCCESS;
}
h5_size_t
h5t_get_num_meshes (
h5_file_t * f,
const enum h5_oid type
) {
struct h5t_fdata *t = f->t;
if ( t->topo_gid < 0 ) {
h5_err_t h5err = _h5t_open_topo_group ( f );
if ( h5err < 0 ) return h5err;
}
switch ( type ) {
case H5_OID_TETRAHEDRON:
return (h5_size_t)h5_get_num_objects (
t->topo_gid,
"TetMeshes",
H5G_GROUP );
case H5_OID_TRIANGLE:
return (h5_size_t)h5_get_num_objects (
t->topo_gid,
"TriangleMeshes",
H5G_GROUP );
default:
return -1;
}
}
/*
*/
h5_size_t
h5t_get_num_levels (
h5_file_t * f
) {
struct h5t_fdata *t = f->t;
h5_err_t h5err;
if ( t->num_levels >= 0 ) return t->num_levels;
if ( t->cur_mesh < 0 ) {
return _h5t_error_undef_mesh ( f );
}
if ( t->mesh_gid < 0 ) {
h5err = _h5t_open_mesh_group ( f );
if ( h5err < 0 ) return h5err;
}
hid_t dataset_id = H5Dopen ( t->mesh_gid, "NumVertices", H5P_DEFAULT );
if ( dataset_id < 0 )
return HANDLE_H5D_OPEN_ERR ( "NumVertices" );
hid_t diskspace_id = H5Dget_space( dataset_id );
if ( diskspace_id < 0 )
return HANDLE_H5D_GET_SPACE_ERR;
hssize_t size = H5Sget_simple_extent_npoints ( diskspace_id );
if ( size < 0 )
return HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR;
herr_t herr = H5Sclose ( diskspace_id );
if ( herr < 0 )
return HANDLE_H5S_CLOSE_ERR;
t->num_levels = size;
return size;
}
h5_id_t
h5t_get_level (
h5_file_t * f
) {
struct h5t_fdata *t = f->t;
return t->cur_level;
}
/*
read everything with this function !?
*/
@@ -220,7 +149,7 @@ _read_dataset (
void * const data ) {
hid_t dataset_id = H5Dopen ( group_id, dataset_name, H5P_DEFAULT );
if ( dataset_id < 0 ) return HANDLE_H5D_OPEN_ERR ( dataset_name );
if ( dataset_id < 0 ) return HANDLE_H5D_OPEN_ERR ( f, dataset_name );
hid_t mem_space_id = (*open_mem_space)( f, dataset_id );
if ( mem_space_id < 0 ) return mem_space_id;
@@ -235,26 +164,26 @@ _read_dataset (
f->xfer_prop,
data );
if ( herr < 0 )
return HANDLE_H5D_READ_ERR ( h5_get_objname ( dataset_id ) );
return HANDLE_H5D_READ_ERR ( f, hdf5_get_objname ( dataset_id ) );
if ( file_space_id != H5S_ALL ) {
herr = H5Sclose ( file_space_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
}
if ( mem_space_id != H5S_ALL )
if ( mem_space_id != H5S_ALL ) {
herr = H5Sclose ( mem_space_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
}
herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR ( f );
return H5_SUCCESS;
}
static hid_t
_open_mem_space_vertices (
h5_file_t * f,
h5_file_t * const f,
hid_t dataset_id
) {
return H5S_ALL;
@@ -262,7 +191,7 @@ _open_mem_space_vertices (
static hid_t
_open_file_space_vertices (
h5_file_t * f,
h5_file_t * const f,
hid_t dataset_id
) {
return H5S_ALL;
@@ -270,15 +199,15 @@ _open_file_space_vertices (
static hid_t
_open_space_all (
h5_file_t * f,
h5_file_t * const f,
hid_t dataset_id
) {
return H5S_ALL;
}
static h5_err_t
_read_num_vertices (
h5_file_t * f
h5_err_t
_ht5_read_num_vertices (
h5_file_t * const f
) {
h5_err_t h5err;
struct h5t_fdata *t = f->t;
@@ -288,10 +217,10 @@ _read_num_vertices (
if ( h5err < 0 ) return h5err;
}
ssize_t num_bytes = t->num_levels*sizeof ( t->num_vertices[0] );
h5_debug ( "Allocating %ld bytes.", num_bytes );
h5_debug ( f, "Allocating %ld bytes.", num_bytes );
t->num_vertices = realloc ( t->num_vertices, num_bytes );
if ( t->num_vertices == NULL )
return HANDLE_H5_NOMEM_ERR;
return HANDLE_H5_NOMEM_ERR ( f );
h5err = _read_dataset (
f,
t->mesh_gid,
@@ -309,31 +238,24 @@ h5_err_t
_h5t_read_vertices (
h5_file_t * f
) {
h5_err_t h5err;
struct h5t_fdata *t = f->t;
if ( t->mesh_gid < 0 ) {
h5err = _h5t_open_mesh_group ( f );
if ( h5err < 0 ) return h5err;
TRY( _h5t_open_mesh_group ( f ) );
}
if ( t->num_vertices == NULL ) {
h5err = _read_num_vertices ( f );
if ( h5err < 0 ) return h5err;
TRY( _ht5_read_num_vertices ( f ) );
}
h5err = _h5t_alloc_num_vertices ( f, t->num_vertices[t->num_levels-1] );
if ( h5err < 0 ) return h5err;
h5err = _read_dataset (
f,
t->mesh_gid,
"Vertices",
t->vertex_tid,
_open_mem_space_vertices,
_open_file_space_vertices,
t->vertices );
if ( h5err < 0 ) return h5err;
TRY( _h5t_alloc_num_vertices ( f, t->num_vertices[t->num_levels-1] ) );
TRY( _read_dataset (
f,
t->mesh_gid,
"Vertices",
t->vertex_tid,
_open_mem_space_vertices,
_open_file_space_vertices,
t->vertices ) );
h5_id_t local_vid = 0;
for ( ; local_vid < t->num_vertices[t->num_levels-1]; local_vid++ ) {
@@ -348,24 +270,6 @@ _h5t_read_vertices (
return H5_SUCCESS;
}
h5_size_t
h5t_get_num_vertices_on_level (
h5_file_t * f
) {
struct h5t_fdata *t = f->t;
if ( t->cur_mesh < 0 ) {
return _h5t_error_undef_mesh ( f );
}
if ( t->cur_level < 0 ) {
return _h5t_error_undef_level( f );
}
if ( t->num_vertices == NULL ) {
h5_err_t h5err = _read_num_vertices ( f );
if ( h5err < 0 ) return h5err;
}
return t->num_vertices[t->cur_level];
}
h5_err_t
h5t_start_traverse_vertices (
@@ -373,7 +277,7 @@ h5t_start_traverse_vertices (
) {
struct h5t_fdata *t = f->t;
t->last_retrieved_vertex_id = -1;
t->last_retrieved_vid = -1;
return H5_SUCCESS;
}
@@ -389,84 +293,53 @@ h5t_traverse_vertices (
h5_err_t h5err = _h5t_read_vertices ( f );
if ( h5err < 0 ) return h5err;
}
if ( t->last_retrieved_vertex_id+1 >= t->num_vertices[t->cur_level] ) {
h5_debug ( "Traversing done!" );
if ( t->last_retrieved_vid+1 >= t->num_vertices[t->cur_level] ) {
h5_debug ( f, "Traversing done!" );
return 0;
}
h5_vertex_t *vertex = &t->vertices[++t->last_retrieved_vertex_id];
h5_vertex_t *vertex = &t->vertices[++t->last_retrieved_vid];
*id = vertex->id;
memcpy ( P, &vertex->P, sizeof ( vertex->P ) );
return t->last_retrieved_vertex_id;
return t->last_retrieved_vid;
}
static h5_err_t
_read_num_entities (
h5_file_t * f
h5_err_t
_h5t_read_num_elems (
h5_file_t * const f
) {
h5_err_t h5err;
struct h5t_fdata *t = f->t;
if ( t->mesh_gid < 0 ) {
h5err = _h5t_open_mesh_group ( f );
if ( h5err < 0 ) return h5err;
TRY( _h5t_open_mesh_group ( f ) );
}
ssize_t num_bytes = t->num_levels*sizeof ( t->num_entities[0] );
h5_debug ( "Allocating %ld bytes.", num_bytes );
t->num_entities = realloc ( t->num_entities, num_bytes );
if ( t->num_entities == NULL )
return HANDLE_H5_NOMEM_ERR;
h5err = _read_dataset (
f,
t->mesh_gid,
"NumEntities",
H5T_NATIVE_INT32,
_open_space_all,
_open_space_all,
t->num_entities );
if ( h5err < 0 ) return h5err;
return H5_SUCCESS;
}
static h5_err_t
_read_num_entities_on_level (
h5_file_t * f
) {
h5_err_t h5err;
struct h5t_fdata *t = f->t;
if ( t->cur_level < 0 )
return _h5t_error_undef_level( f );
if ( t->mesh_gid < 0 ) {
h5err = _h5t_open_mesh_group ( f );
if ( h5err < 0 ) return h5err;
}
ssize_t num_bytes = t->num_levels*sizeof ( t->num_entities_on_level[0] );
h5_debug ( "Allocating %ld bytes.", num_bytes );
t->num_entities_on_level = realloc ( t->num_entities_on_level, num_bytes );
if ( t->num_entities_on_level == NULL )
return HANDLE_H5_NOMEM_ERR;
h5err = _read_dataset (
f,
t->mesh_gid,
"NumEntitiesOnLevel",
H5T_NATIVE_INT32,
_open_space_all,
_open_space_all,
t->num_entities_on_level );
if ( h5err < 0 ) return h5err;
size_t size = t->num_levels * sizeof ( t->num_elems[0] );
TRY( t->num_elems = _h5_alloc ( f, NULL, size ) );
TRY( t->num_elems_on_level = _h5_alloc ( f, NULL, size ) );
TRY( _read_dataset (
f,
t->mesh_gid,
"NumElems",
H5T_NATIVE_INT32,
_open_space_all,
_open_space_all,
t->num_elems ) );
TRY( _read_dataset (
f,
t->mesh_gid,
"NumElemsOnLevel",
H5T_NATIVE_INT32,
_open_space_all,
_open_space_all,
t->num_elems_on_level ) );
return H5_SUCCESS;
}
static hid_t
_open_mem_space_entities (
_open_mem_space_elems (
h5_file_t * f,
hid_t dataset_id
) {
@@ -474,7 +347,7 @@ _open_mem_space_entities (
}
static hid_t
_open_file_space_entities (
_open_file_space_elems (
h5_file_t * f,
hid_t dataset_id
) {
@@ -482,7 +355,7 @@ _open_file_space_entities (
}
h5_err_t
_h5t_read_entities (
_h5t_read_elems (
h5_file_t * f
) {
h5_err_t h5err;
@@ -493,49 +366,44 @@ _h5t_read_entities (
if ( h5err < 0 ) return h5err;
}
if ( t->num_entities == NULL ) {
h5err = _read_num_entities ( f );
if ( h5err < 0 ) return h5err;
if ( t->num_elems == NULL ) {
TRY( _h5t_read_num_elems ( f ) );
}
h5err = _h5t_alloc_num_entities ( f, 0, t->num_entities[t->num_levels-1] );
h5err = _read_dataset (
f,
t->mesh_gid,
"Entities",
t->entity_tid,
_open_mem_space_entities,
_open_file_space_entities,
t->entities.data );
if ( h5err < 0 ) return h5err;
TRY( _h5t_alloc_num_elems ( f, 0, t->num_elems[t->num_levels-1] ) );
TRY( _read_dataset (
f,
t->mesh_gid,
"Elems",
t->elem_tid,
_open_mem_space_elems,
_open_file_space_elems,
t->elems.data ) );
/*
setup structure with local vertex ids
*/
h5_id_t local_eid = 0;
h5_id_t num_entities = t->num_entities[t->num_levels-1];
h5_id_t num_elems = t->num_elems[t->num_levels-1];
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON:
for ( local_eid = 0; local_eid < num_entities; local_eid++ ) {
h5err = h5t_map_global_vertex_ids2local (
f,
t->entities.tets[local_eid].vertex_ids,
t->mesh_type,
t->lentities.tets[local_eid].vertex_ids
);
if ( h5err < 0 ) return h5err;
for ( local_eid = 0; local_eid < num_elems; local_eid++ ) {
TRY( h5t_map_global_vids2local (
f,
t->elems.tets[local_eid].vids,
t->mesh_type,
t->elems_ldta.tets[local_eid].vids
) );
}
break;
case H5_OID_TRIANGLE:
for ( local_eid = 0; local_eid < num_entities; local_eid++ ) {
h5err = h5t_map_global_vertex_ids2local (
f,
t->entities.tris[local_eid].vertex_ids,
t->mesh_type,
t->lentities.tris[local_eid].vertex_ids
);
if ( h5err < 0 ) return h5err;
for ( local_eid = 0; local_eid < num_elems; local_eid++ ) {
TRY( h5t_map_global_vids2local (
f,
t->elems.tris[local_eid].vids,
t->mesh_type,
t->elems_ldta.tris[local_eid].vids
) );
}
break;
default:
@@ -545,40 +413,6 @@ _h5t_read_entities (
return H5_SUCCESS;
}
h5_size_t
h5t_get_num_entities_on_level (
h5_file_t * f
) {
struct h5t_fdata *t = f->t;
if ( t->cur_mesh < 0 ) {
return _h5t_error_undef_mesh ( f );
}
if ( t->cur_level < 0 ) {
return _h5t_error_undef_level( f );
}
if ( t->num_entities_on_level == NULL ) {
h5_err_t h5err = _read_num_entities_on_level ( f );
if ( h5err < 0 ) return h5err;
}
return t->num_entities_on_level[t->cur_level];
}
h5_size_t
h5t_get_num_entities (
h5_file_t * f
) {
struct h5t_fdata *t = f->t;
if ( t->cur_mesh < 0 ) {
return _h5t_error_undef_mesh ( f );
}
if ( t->num_entities == NULL ) {
h5_err_t h5err = _read_num_entities ( f );
if ( h5err < 0 ) return h5err;
}
return t->num_entities[t->num_levels-1];
}
h5_err_t
h5t_start_traverse_tets (
@@ -591,7 +425,7 @@ h5t_start_traverse_tets (
return H5_ERR_INVAL;
}
case H5_OID_TETRAHEDRON: {
t->last_retrieved_entity_id = -1;
t->last_retrieved_eid = -1;
return H5_SUCCESS;
}
default:
@@ -609,30 +443,30 @@ _traverse_tets (
) {
struct h5t_fdata *t = f->t;
if ( t->entities.data == NULL ) {
h5_err_t h5err = _h5t_read_entities ( f );
if ( t->elems.data == NULL ) {
h5_err_t h5err = _h5t_read_elems ( f );
if ( h5err < 0 ) return h5err;
}
if ( t->last_retrieved_entity_id+1 >= t->num_entities[t->cur_level] ) {
h5_debug ( "Traversing done!" );
if ( t->last_retrieved_eid+1 >= t->num_elems[t->cur_level] ) {
h5_debug ( f, "Traversing done!" );
return 0;
}
h5_tetrahedron_t *tet = &t->entities.tets[++t->last_retrieved_entity_id];
h5_tetrahedron_t *tet = &t->elems.tets[++t->last_retrieved_eid];
while ( (tet->refined_on_level != -1) &&
(tet->refined_on_level <= t->cur_level) ){
tet++;
t->last_retrieved_entity_id++;
if ( t->last_retrieved_entity_id >= t->num_entities[t->cur_level] ) {
return h5_error_internal( __FILE__, __func__, __LINE__ );
t->last_retrieved_eid++;
if ( t->last_retrieved_eid >= t->num_elems[t->cur_level] ) {
return h5_error_internal( f, __FILE__, __func__, __LINE__ );
}
}
*id = tet->id;
*parent_id = tet->parent_id;
memcpy ( ids, &tet->vertex_ids, sizeof ( tet->vertex_ids ) );
memcpy ( ids, &tet->vids, sizeof ( tet->vids ) );
return t->last_retrieved_entity_id;
return t->last_retrieved_eid;
}
h5_id_t
@@ -653,7 +487,7 @@ h5t_traverse_tets (
return _traverse_tets ( f, id, parent_id, ids );
}
default:
return h5_error_internal( __FILE__, __func__, __LINE__ );
return h5_error_internal( f, __FILE__, __func__, __LINE__ );
}
}
@@ -666,14 +500,14 @@ h5t_start_traverse_triangles (
switch ( t->mesh_type ) {
case H5_OID_TRIANGLE: {
t->last_retrieved_entity_id = -1;
t->last_retrieved_eid = -1;
return H5_SUCCESS;
}
case H5_OID_TETRAHEDRON: {
return h5_error_not_implemented( __FILE__, __func__, __LINE__ );
return h5_error_not_implemented( f, __FILE__, __func__, __LINE__ );
}
default:
return h5_error_internal( __FILE__, __func__, __LINE__ );
return h5_error_internal( f, __FILE__, __func__, __LINE__ );
}
}
@@ -688,30 +522,30 @@ _traverse_triangles (
) {
struct h5t_fdata *t = f->t;
if ( t->entities.data == NULL ) {
h5_err_t h5err = _h5t_read_entities ( f );
if ( t->elems.data == NULL ) {
h5_err_t h5err = _h5t_read_elems ( f );
if ( h5err < 0 ) return h5err;
}
if ( t->last_retrieved_entity_id+1 >= t->num_entities[t->cur_level] ) {
h5_debug ( "Traversing done!" );
if ( t->last_retrieved_eid+1 >= t->num_elems[t->cur_level] ) {
h5_debug ( f, "Traversing done!" );
return 0;
}
h5_triangle_t *tri = &t->entities.tris[++t->last_retrieved_entity_id];
h5_triangle_t *tri = &t->elems.tris[++t->last_retrieved_eid];
while ( (tri->refined_on_level != -1) &&
(tri->refined_on_level <= t->cur_level) ){
tri++;
t->last_retrieved_entity_id++;
if ( t->last_retrieved_entity_id >= t->num_entities[t->cur_level] ) {
return h5_error_internal( __FILE__, __func__, __LINE__ );
t->last_retrieved_eid++;
if ( t->last_retrieved_eid >= t->num_elems[t->cur_level] ) {
return h5_error_internal( f, __FILE__, __func__, __LINE__ );
}
}
*id = tri->id;
*parent_id = tri->parent_id;
memcpy ( ids, &tri->vertex_ids, sizeof ( tri->vertex_ids ) );
memcpy ( ids, &tri->vids, sizeof ( tri->vids ) );
return t->last_retrieved_entity_id;
return t->last_retrieved_eid;
}
h5_id_t
@@ -730,10 +564,10 @@ h5t_traverse_triangles (
return _traverse_triangles ( f, id, parent_id, ids );
}
case H5_OID_TETRAHEDRON: {
return h5_error_not_implemented( __FILE__, __func__, __LINE__ );
return h5_error_not_implemented( f, __FILE__, __func__, __LINE__ );
}
default:
return h5_error_internal( __FILE__, __func__, __LINE__ );
return h5_error_internal( f, __FILE__, __func__, __LINE__ );
}
}
@@ -748,13 +582,13 @@ _h5t_read_mesh (
if ( h5err < 0 ) return h5err;
}
if ( t->entities.data == NULL ) {
h5_err_t h5err = _h5t_read_entities ( f );
if ( t->elems.data == NULL ) {
h5_err_t h5err = _h5t_read_elems ( f );
if ( h5err < 0 ) return h5err;
}
if ( t->sorted_lentities[0].items == NULL ) {
_h5t_sort_entities ( f );
if ( t->sorted_elems_ldta[0].items == NULL ) {
_h5t_sort_elems ( f );
}
return H5_SUCCESS;
}
+4 -51
View File
@@ -6,37 +6,16 @@ _h5t_write_mesh (
h5_file_t * f
);
h5_size_t
h5t_get_num_meshes (
h5_file_t * f,
const enum h5_oid type
);
h5_id_t
h5t_add_mesh (
h5_file_t * f
);
h5_size_t
h5t_get_num_levels (
h5_file_t * f
);
h5_id_t
h5t_get_level (
h5_file_t * f
);
h5_err_t
_h5t_read_vertices (
h5_file_t * f
);
h5_size_t
h5t_get_num_vertices_on_level (
h5_file_t * f
);
h5_err_t
h5t_start_traverse_vertices (
h5_file_t * f
@@ -62,39 +41,13 @@ h5t_add_num_triangles (
) ;
h5_size_t
h5t_add_num_entities (
h5t_add_num_elems (
h5_file_t * f,
const h5_size_t num
) ;
h5_size_t
h5t_get_num_entities (
h5_file_t * f
);
h5_size_t
h5t_get_num_entities_on_level (
h5_file_t * f
);
h5_id_t
h5t_store_tet (
h5_file_t * f,
const h5_id_t id,
const h5_id_t parent_id,
const h5_id_t vertex_ids[4]
);
h5_id_t
h5t_store_triangle (
h5_file_t * f,
const h5_id_t id,
const h5_id_t parent_id,
const h5_id_t vertex_ids[3]
);
h5_err_t
_h5t_read_entities (
_h5t_read_elems (
h5_file_t * f
);
@@ -108,7 +61,7 @@ h5t_traverse_tets (
h5_file_t * f,
h5_id_t * const id,
h5_id_t * const parent_id,
h5_id_t vertex_ids[4]
h5_id_t vids[4]
);
@@ -122,7 +75,7 @@ h5t_traverse_triangles (
h5_file_t * f,
h5_id_t * const id,
h5_id_t * const parent_id,
h5_id_t vertex_ids[3]
h5_id_t vids[3]
);
#endif
+10
View File
@@ -17,4 +17,14 @@ _h5t_read_mesh (
h5_file_t *f
);
h5_err_t
_h5t_read_num_elems (
h5_file_t * const f
);
h5_err_t
_h5t_read_num_vertices (
h5_file_t * const f
);
#endif
+294 -150
View File
@@ -1,13 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h> /* va_arg - System dependent ?! */
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <hdf5.h>
#include "h5_core/h5_core.h"
#include "h5t_types_private.h"
#include "h5_core/h5_types_private.h"
#include "h5_core/h5t_types_private.h"
#include "h5_core/h5_core_private.h"
h5_id_t
@@ -31,16 +25,16 @@ h5t_add_level (
t->num_vertices = realloc ( t->num_vertices, num_bytes );
t->num_vertices[t->cur_level] = -1;
t->num_entities = realloc ( t->num_entities, num_bytes );
t->num_entities[t->cur_level] = -1;
t->num_entities_on_level = realloc ( t->num_entities_on_level, num_bytes );
t->num_entities_on_level[t->cur_level] = -1;
t->num_elems = realloc ( t->num_elems, num_bytes );
t->num_elems[t->cur_level] = -1;
t->num_elems_on_level = realloc ( t->num_elems_on_level, num_bytes );
t->num_elems_on_level[t->cur_level] = -1;
t->new_level = t->cur_level;
if ( t->cur_level == 0 ) {
/* nothing stored yet */
t->last_stored_vertex_id = -1;
t->last_stored_entity_id = -1;
t->last_stored_vid = -1;
t->last_stored_eid = -1;
}
return t->cur_level;
}
@@ -53,14 +47,14 @@ _h5t_alloc_num_vertices (
struct h5t_fdata *t = f->t;
ssize_t num_bytes = num_vertices*sizeof ( t->vertices[0] );
h5_debug ( "Allocating %ld bytes.", num_bytes );
h5_debug ( f, "Allocating %ld bytes.", num_bytes );
t->vertices = realloc ( t->vertices, num_bytes );
if ( t->vertices == NULL ) {
return HANDLE_H5_NOMEM_ERR;
return HANDLE_H5_NOMEM_ERR ( f );
}
TRY( _h5_alloc_idmap (&t->map_vertex_g2l, num_vertices ) );
TRY( _h5_alloc_smap (&t->sorted_lvertices, num_vertices ) );
TRY( _h5_alloc_idmap ( f, &t->map_vertex_g2l, num_vertices ) );
TRY( _h5_alloc_smap ( f, &t->sorted_lvertices, num_vertices ) );
return H5_SUCCESS;
}
@@ -93,9 +87,9 @@ h5t_store_vertex (
/*
more than allocated
*/
if ( t->last_stored_vertex_id+1 >= t->num_vertices[t->cur_level] )
return HANDLE_H5_OVERFLOW_ERR( "vertex",
t->num_vertices[t->cur_level] );
if ( t->last_stored_vid+1 >= t->num_vertices[t->cur_level] )
return HANDLE_H5_OVERFLOW_ERR(
f, "vertex", t->num_vertices[t->cur_level] );
/*
missing call to add the first level
@@ -108,123 +102,160 @@ h5t_store_vertex (
*/
if ( (t->cur_level == 0) && (
(global_id < 0) || (global_id >= t->num_vertices[0]) ) ) {
return HANDLE_H5_OUT_OF_RANGE_ERR( "vertex", global_id );
return HANDLE_H5_OUT_OF_RANGE_ERR( f, "vertex", global_id );
}
if ( (t->cur_level > 0) && (
(global_id < t->num_vertices[t->cur_level-1]) ||
(global_id >= t->num_vertices[t->cur_level]) ) ) {
return HANDLE_H5_OUT_OF_RANGE_ERR( "vertex", global_id );
return HANDLE_H5_OUT_OF_RANGE_ERR( f, "vertex", global_id );
}
h5_id_t local_id = ++t->last_stored_vertex_id;
h5_id_t local_id = ++t->last_stored_vid;
h5_vertex_t *vertex = &t->vertices[local_id];
vertex->id = global_id;
memcpy ( &vertex->P, P, sizeof ( vertex->P ) );
_h5_insert_idmap ( &t->map_vertex_g2l, global_id, local_id );
_h5_insert_idmap ( f, &t->map_vertex_g2l, global_id, local_id );
return local_id;
}
h5_err_t
_h5t_alloc_num_entities (
_h5t_alloc_num_elems (
h5_file_t * const f,
const size_t cur_num_entities,
const size_t new_num_entities
const size_t cur_num_elems,
const size_t new_num_elems
) {
struct h5t_fdata *t = f->t;
size_t sizeof_entity = 0;
size_t sizeof_lentity = 0;
size_t sizeof_elem = 0;
size_t sizeof_lelem = 0;
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON:
sizeof_entity = sizeof ( t->entities.tets[0] );
sizeof_lentity = sizeof ( t->lentities.tets[0] );
sizeof_elem = sizeof ( t->elems.tets[0] );
sizeof_lelem = sizeof ( t->elems_ldta.tets[0] );
break;
case H5_OID_TRIANGLE:
sizeof_entity = sizeof ( t->entities.tris[0] );
sizeof_lentity = sizeof ( t->lentities.tris[0] );
sizeof_elem = sizeof ( t->elems.tris[0] );
sizeof_lelem = sizeof ( t->elems_ldta.tris[0] );
break;
default:
return -1;
}
t->entities.data = realloc (
t->entities.data, new_num_entities * sizeof_entity );
if ( t->entities.data == NULL ) {
t->elems.data = realloc (
t->elems.data, new_num_elems * sizeof_elem );
if ( t->elems.data == NULL ) {
return H5_ERR_NOMEM;
}
t->lentities.data = realloc (
t->lentities.data, new_num_entities*sizeof_lentity );
if ( t->lentities.data == NULL ) {
t->elems_ldta.data = realloc (
t->elems_ldta.data, new_num_elems*sizeof_lelem );
if ( t->elems_ldta.data == NULL ) {
return H5_ERR_NOMEM;
}
memset (
t->lentities.data+cur_num_entities*sizeof_lentity,
t->elems_ldta.data+cur_num_elems*sizeof_lelem,
-1,
(new_num_entities-cur_num_entities) * sizeof_lentity );
(new_num_elems-cur_num_elems) * sizeof_lelem );
return _h5_alloc_idmap (&t->map_entity_g2l, new_num_entities );
return _h5_alloc_idmap ( f, &t->map_elem_g2l, new_num_elems );
}
h5_err_t
h5_add_num_tets (
_h5t_add_num_elements (
h5_file_t * const f,
const h5_size_t num
) {
struct h5t_fdata *t = f->t;
if ( t->mesh_type != H5_OID_TETRAHEDRON ) {
_h5t_error_illegal_object_type ( f, H5_OID_TETRAHEDRON );
}
size_t cur_num_elems = t->cur_level > 0 ?
t->num_elems[t->cur_level-1] : 0;
size_t new_num_elems = t->cur_level > 0 ?
num + t->num_elems[t->cur_level-1] : num;
t->num_elems[t->cur_level] = new_num_elems;
t->num_elems_on_level[t->cur_level] = t->cur_level > 0 ?
num + t->num_elems_on_level[t->cur_level-1] : num;
return _h5t_alloc_num_elems ( f, cur_num_elems, new_num_elems );
}
h5_err_t
h5t_add_num_elements (
h5_file_t * const f,
const h5_size_t num
) {
TRY( _h5t_add_num_vertices ( f, num+3 ) );
TRY( _h5t_add_num_entities ( f, num ) );
TRY( _h5t_add_num_elements ( f, num ) );
return H5_SUCCESS;
}
h5_err_t
h5_add_num_triangles (
h5_file_t * const f,
const h5_size_t num
) {
struct h5t_fdata *t = f->t;
if ( t->mesh_type != H5_OID_TRIANGLE ) {
_h5t_error_illegal_object_type ( f, H5_OID_TRIANGLE );
}
TRY( _h5t_add_num_vertices ( f, num+2 ) );
TRY( _h5t_add_num_entities ( f, num ) );
return H5_SUCCESS;
}
h5_err_t
_h5t_add_num_entities (
h5_file_t * const f,
const h5_size_t num
) {
struct h5t_fdata *t = f->t;
size_t cur_num_entities = t->cur_level > 0 ?
t->num_entities[t->cur_level-1] : 0;
size_t new_num_entities = t->cur_level > 0 ?
num + t->num_entities[t->cur_level-1] : num;
t->num_entities[t->cur_level] = new_num_entities;
t->num_entities_on_level[t->cur_level] = t->cur_level > 0 ?
num + t->num_entities_on_level[t->cur_level-1] : num;
return _h5t_alloc_num_entities ( f, cur_num_entities, new_num_entities );
}
h5_id_t
h5t_store_tet (
h5t_store_element (
h5_file_t * const f,
const h5_id_t local_parent_cid, /*!< local parent id of element
if level \c >0 else \c -1 */
const h5_id_t local_vids[] /*!< local vertex id's */
) {
struct h5t_fdata *t = f->t;
/* level set? */
if ( t->cur_level < 0 )
return _h5t_error_undef_level( f );
/* more than allocated? */
if ( t->last_stored_eid+1 >= t->num_elems[t->cur_level] )
return HANDLE_H5_OVERFLOW_ERR(
f, _h5t_map_oid2str(t->type),
t->num_elems[t->cur_level] );
/* check parent id */
if (
( t->cur_level == 0 && local_parent_cid != -1 ) ||
( t->cur_level > 0 && local_parent_cid < 0 ) ||
( t->cur_level > 0
&& local_parent_cid >= t->num_elems[t->cur_level-1] )
) {
return HANDLE_H5_PARENT_ID_ERR (
f,
_h5t_map_oid2str(t->type),
local_parent_cid );
}
h5_id_t local_id = ++t->last_stored_eid;
h5_tetrahedron_t *tet = &t->elems.tets[local_id];
tet->id = global_id;
tet->parent_id = parent_id;
tet->refined_on_level = -1;
tet->unused = 0;
memcpy ( &tet->vids, vids, sizeof ( tet->vids ) );
_h5t_sort_global_vids ( f, tet->vids, 4 );
_h5_insert_idmap ( f, &t->map_elem_g2l, global_id, local_id );
if ( parent_id >= 0 ) {
h5_id_t local_parent_id = _h5_search_idmap (
&t->map_elem_g2l, parent_id );
if ( t->elems.tets[local_parent_id].refined_on_level < 0 ) {
t->elems.tets[local_parent_id].refined_on_level =
t->cur_level;
t->num_elems_on_level[t->cur_level]--;
}
}
return local_id;
}
h5_id_t
_h5t_store_tet (
h5_file_t * const f,
const h5_id_t global_id, /*!< global tetrahedron id */
const h5_id_t parent_id, /*!< global parent id
if level \c >0 else \c -1 */
const h5_id_t vertex_ids[4] /*!< tuple with vertex id's */
const h5_id_t vids[4] /*!< tuple with vertex id's */
) {
struct h5t_fdata *t = f->t;
@@ -232,12 +263,12 @@ h5t_store_tet (
/*
more than allocated
*/
if ( t->last_stored_entity_id+1 >= t->num_entities[t->cur_level] )
if ( t->last_stored_eid+1 >= t->num_elems[t->cur_level] )
return HANDLE_H5_OVERFLOW_ERR(
"tet", t->num_entities[t->cur_level] );
f, "tet", t->num_elems[t->cur_level] );
/*
missing call to add the first level
level not set
*/
if ( t->cur_level < 0 )
return _h5t_error_undef_level( f );
@@ -247,48 +278,48 @@ h5t_store_tet (
*/
if ( (t->cur_level == 0) &&
(parent_id != -1) ) {
return HANDLE_H5_PARENT_ID_ERR ( "tet", global_id, parent_id );
return HANDLE_H5_PARENT_ID_ERR ( f, "tet", global_id, parent_id );
}
if ( (t->cur_level > 0) &&
(parent_id < 0) ) {
return HANDLE_H5_PARENT_ID_ERR ( "tet", global_id, parent_id );
return HANDLE_H5_PARENT_ID_ERR ( f, "tet", global_id, parent_id );
}
if ( (t->cur_level > 0) &&
(parent_id >= t->num_entities[t->cur_level-1]) ) {
return HANDLE_H5_PARENT_ID_ERR ( "tet", global_id, parent_id );
(parent_id >= t->num_elems[t->cur_level-1]) ) {
return HANDLE_H5_PARENT_ID_ERR ( f, "tet", global_id, parent_id );
}
/*
check id
*/
if ( (t->cur_level == 0) && (
(global_id < 0) || (global_id >= t->num_entities[0]) ) ) {
return HANDLE_H5_OUT_OF_RANGE_ERR( "tet", global_id );
(global_id < 0) || (global_id >= t->num_elems[0]) ) ) {
return HANDLE_H5_OUT_OF_RANGE_ERR( f, "tet", global_id );
}
if ( (t->cur_level > 0) && (
(global_id < t->num_entities[t->cur_level-1]) ||
(global_id >= t->num_entities[t->cur_level]) ) ) {
return HANDLE_H5_OUT_OF_RANGE_ERR( "tet", global_id );
(global_id < t->num_elems[t->cur_level-1]) ||
(global_id >= t->num_elems[t->cur_level]) ) ) {
return HANDLE_H5_OUT_OF_RANGE_ERR( f, "tet", global_id );
}
h5_id_t local_id = ++t->last_stored_entity_id;
h5_tetrahedron_t *tet = &t->entities.tets[local_id];
h5_id_t local_id = ++t->last_stored_eid;
h5_tetrahedron_t *tet = &t->elems.tets[local_id];
tet->id = global_id;
tet->parent_id = parent_id;
tet->refined_on_level = -1;
tet->unused = 0;
memcpy ( &tet->vertex_ids, vertex_ids, sizeof ( tet->vertex_ids ) );
memcpy ( &tet->vids, vids, sizeof ( tet->vids ) );
_h5t_sort_global_vertex_ids ( f, tet->vertex_ids, 4 );
_h5_insert_idmap ( &t->map_entity_g2l, global_id, local_id );
_h5t_sort_global_vids ( f, tet->vids, 4 );
_h5_insert_idmap ( f, &t->map_elem_g2l, global_id, local_id );
if ( parent_id >= 0 ) {
h5_id_t local_parent_id = _h5_search_idmap (
&t->map_entity_g2l, parent_id );
if ( t->entities.tets[local_parent_id].refined_on_level < 0 ) {
t->entities.tets[local_parent_id].refined_on_level =
&t->map_elem_g2l, parent_id );
if ( t->elems.tets[local_parent_id].refined_on_level < 0 ) {
t->elems.tets[local_parent_id].refined_on_level =
t->cur_level;
t->num_entities_on_level[t->cur_level]--;
t->num_elems_on_level[t->cur_level]--;
}
}
return local_id;
@@ -298,10 +329,9 @@ h5t_store_tet (
h5_id_t
h5t_store_triangle (
h5_file_t * const f,
const h5_id_t global_id, /*!< global triangle id */
const h5_id_t parent_id, /*!< global parent id
if level \c >0 else \c -1 */
const h5_id_t vertex_ids[3] /*!< tuple with vertex id's */
const h5_id_t vids[3] /*!< tuple with vertex id's */
) {
struct h5t_fdata *t = f->t;
@@ -309,9 +339,9 @@ h5t_store_triangle (
/*
more than allocated
*/
if ( t->last_stored_entity_id+1 >= t->num_entities[t->cur_level] )
if ( t->last_stored_eid+1 >= t->num_elems[t->cur_level] )
return HANDLE_H5_OVERFLOW_ERR(
"triangle", t->num_entities[t->cur_level] );
f, "triangle", t->num_elems[t->cur_level] );
/*
missing call to add the first level
@@ -324,45 +354,45 @@ h5t_store_triangle (
*/
if ( (t->cur_level == 0) && (parent_id != -1) ) {
return HANDLE_H5_PARENT_ID_ERR (
"triangle", global_id, parent_id );
f, "triangle", global_id, parent_id );
}
if ( (t->cur_level > 0) && (parent_id < 0) ) {
return HANDLE_H5_PARENT_ID_ERR (
"triangle", global_id, parent_id );
f, "triangle", global_id, parent_id );
}
if ( (t->cur_level>0) && (parent_id >= t->num_entities[t->cur_level-1]) ) {
if ( (t->cur_level>0) && (parent_id >= t->num_elems[t->cur_level-1]) ) {
return HANDLE_H5_PARENT_ID_ERR (
"triangle", global_id, parent_id );
f, "triangle", global_id, parent_id );
}
/*
check id
*/
if ( (t->cur_level == 0) && (
(global_id < 0) || (global_id >= t->num_entities[0]) ) ) {
return HANDLE_H5_OUT_OF_RANGE_ERR( "triangle", global_id );
(global_id < 0) || (global_id >= t->num_elems[0]) ) ) {
return HANDLE_H5_OUT_OF_RANGE_ERR( f, "triangle", global_id );
}
if ( (t->cur_level > 0) && (
(global_id < t->num_entities[t->cur_level-1]) ||
(global_id >= t->num_entities[t->cur_level]) ) ) {
return HANDLE_H5_OUT_OF_RANGE_ERR( "triangle", global_id );
(global_id < t->num_elems[t->cur_level-1]) ||
(global_id >= t->num_elems[t->cur_level]) ) ) {
return HANDLE_H5_OUT_OF_RANGE_ERR( f, "triangle", global_id );
}
h5_id_t local_id = ++t->last_stored_entity_id;
h5_triangle_t *tri = &t->entities.tris[local_id];
h5_id_t local_id = ++t->last_stored_eid;
h5_triangle_t *tri = &t->elems.tris[local_id];
tri->id = global_id;
tri->parent_id = parent_id;
tri->refined_on_level = -1;
memcpy ( &tri->vertex_ids, vertex_ids, sizeof ( tri->vertex_ids ) );
memcpy ( &tri->vids, vids, sizeof ( tri->vids ) );
_h5_insert_idmap ( &t->map_entity_g2l, global_id, local_id );
_h5_insert_idmap ( f, &t->map_elem_g2l, global_id, local_id );
if ( parent_id >= 0 ) {
h5_id_t local_parent_id = _h5_search_idmap (
&t->map_entity_g2l, parent_id );
if ( t->entities.tris[local_parent_id].refined_on_level < 0 ) {
t->entities.tris[local_parent_id].refined_on_level =
&t->map_elem_g2l, parent_id );
if ( t->elems.tris[local_parent_id].refined_on_level < 0 ) {
t->elems.tris[local_parent_id].refined_on_level =
t->cur_level;
t->num_entities_on_level[t->cur_level]--;
t->num_elems_on_level[t->cur_level]--;
}
}
return local_id;
@@ -375,17 +405,35 @@ h5t_store_triangle (
\return local id of vertex
*/
h5_err_t
h5_id_t
_h5t_bisect_edge (
h5_file_t * const f,
h5_id_t local_vid0,
h5_id_t local_vid1
) {
struct h5t_fdata *t = f->t;
h5_id_t local_id = -1;
h5_float64_t *P0 = t->vertices[local_vid0].P;
h5_float64_t *P1 = t->vertices[local_vid1].P;
return H5_SUCCESS;
/*
Get number of vertices on this node. This will be used as local id.
Get number of vertices. This will be used as (temporary) global id.
Compute vertice
if new vertice: store
*/
local_id = h5t_get_num_vertices( f, f->myproc, -1 );
h5_vertex_t *vertex = &t->vertices[local_id];
vertex->id = h5t_get_num_vertices( f, -1, -1 );
vertex->P[0] = ( P0[0] + P1[0] ) / 2.0;
vertex->P[1] = ( P0[1] + P1[1] ) / 2.0;
vertex->P[2] = ( P0[2] + P1[2] ) / 2.0;
if ( _h5t_get_local_vid( f, vertex->P ) == H5_ERR ) {
t->num_vertices[t->cur_level]++;
}
return local_id;
}
/*!
@@ -396,47 +444,143 @@ _h5t_bisect_edge (
h5_id_t
h5t_refine_tet (
h5_file_t * const f,
const h5_id_t global_tid
const h5_id_t parent_tet_global_id
) {
struct h5t_fdata *t = f->t;
h5_id_t local_vids[6];
h5_id_t local_tid;
TRY( local_tid = h5t_map_global_entity_id2local( f, global_tid ) );
h5_id_t parent_tet_local_id;
TRY( parent_tet_local_id = h5t_map_global_eid2local(
f, parent_tet_global_id ) );
local_vids[0] = _h5t_bisect_edge(
f,
t->lentities.tets[local_tid].vertex_ids[0],
t->lentities.tets[local_tid].vertex_ids[1] );
t->elems_ldta.tets[parent_tet_local_id].vids[0],
t->elems_ldta.tets[parent_tet_local_id].vids[1] );
local_vids[1] = _h5t_bisect_edge(
f,
t->lentities.tets[local_tid].vertex_ids[0],
t->lentities.tets[local_tid].vertex_ids[2] );
t->elems_ldta.tets[parent_tet_local_id].vids[0],
t->elems_ldta.tets[parent_tet_local_id].vids[2] );
local_vids[2] = _h5t_bisect_edge(
f,
t->lentities.tets[local_tid].vertex_ids[0],
t->lentities.tets[local_tid].vertex_ids[3] );
t->elems_ldta.tets[parent_tet_local_id].vids[0],
t->elems_ldta.tets[parent_tet_local_id].vids[3] );
local_vids[3] = _h5t_bisect_edge(
f,
t->lentities.tets[local_tid].vertex_ids[1],
t->lentities.tets[local_tid].vertex_ids[2] );
t->elems_ldta.tets[parent_tet_local_id].vids[1],
t->elems_ldta.tets[parent_tet_local_id].vids[2] );
local_vids[4] = _h5t_bisect_edge(
f,
t->lentities.tets[local_tid].vertex_ids[1],
t->lentities.tets[local_tid].vertex_ids[3] );
t->elems_ldta.tets[parent_tet_local_id].vids[1],
t->elems_ldta.tets[parent_tet_local_id].vids[3] );
local_vids[5] = _h5t_bisect_edge(
f,
t->lentities.tets[local_tid].vertex_ids[2],
t->lentities.tets[local_tid].vertex_ids[3] );
t->elems_ldta.tets[parent_tet_local_id].vids[2],
t->elems_ldta.tets[parent_tet_local_id].vids[3] );
/*
add new tets
*/
#if 0
h5t_store_tet (
h5_id_t new_tet_local_vids[4];
/* 0 */
h5_id_t new_tet_local_id = h5t_get_num_elems( f, f->myproc, -1 );
new_tet_local_vids[0] = t->elems_ldta.tets[parent_tet_local_id].vids[0];
new_tet_local_vids[1] = local_vids[0]; // (01)
new_tet_local_vids[2] = local_vids[1]; // (02)
new_tet_local_vids[3] = local_vids[2]; // (03)
TRY2( h5t_store_tet (
f,
-1,
global_id,
#endif
return H5_SUCCESS;
new_tet_local_id,
parent_tet_global_id,
new_tet_local_vids ), fail );
/* 1 */
new_tet_local_id = h5t_get_num_elems( f, f->myproc, -1 );
new_tet_local_vids[0] = t->elems_ldta.tets[parent_tet_local_id].vids[1];
new_tet_local_vids[1] = local_vids[0]; // (01)
new_tet_local_vids[2] = local_vids[3]; // (12)
new_tet_local_vids[3] = local_vids[4]; // (13)
TRY2( h5t_store_tet (
f,
new_tet_local_id,
parent_tet_global_id,
new_tet_local_vids ), fail );
/* 2 */
new_tet_local_id = h5t_get_num_elems( f, f->myproc, -1 );
new_tet_local_vids[0] = t->elems_ldta.tets[parent_tet_local_id].vids[2];
new_tet_local_vids[1] = local_vids[1]; // (02)
new_tet_local_vids[2] = local_vids[3]; // (12)
new_tet_local_vids[3] = local_vids[5]; // (23)
TRY2( h5t_store_tet (
f,
new_tet_local_id,
parent_tet_global_id,
new_tet_local_vids ), fail );
/* 3 */
new_tet_local_id = h5t_get_num_elems( f, f->myproc, -1 );
new_tet_local_vids[0] = t->elems_ldta.tets[parent_tet_local_id].vids[3];
new_tet_local_vids[1] = local_vids[2]; // (03)
new_tet_local_vids[2] = local_vids[4]; // (13)
new_tet_local_vids[3] = local_vids[5]; // (23)
TRY2( h5t_store_tet (
f,
new_tet_local_id,
parent_tet_global_id,
new_tet_local_vids ), fail );
/* 4 */
new_tet_local_id = h5t_get_num_elems( f, f->myproc, -1 );
new_tet_local_vids[0] = local_vids[0]; // (01)
new_tet_local_vids[1] = local_vids[1]; // (02)
new_tet_local_vids[2] = local_vids[2]; // (03)
new_tet_local_vids[3] = local_vids[4]; // (13)
TRY2( h5t_store_tet (
f,
new_tet_local_id,
parent_tet_global_id,
new_tet_local_vids ), fail );
/* 5 */
new_tet_local_id = h5t_get_num_elems( f, f->myproc, -1 );
new_tet_local_vids[0] = local_vids[0]; // (01)
new_tet_local_vids[1] = local_vids[1]; // (02)
new_tet_local_vids[2] = local_vids[3]; // (12)
new_tet_local_vids[3] = local_vids[4]; // (13)
TRY2( h5t_store_tet (
f,
new_tet_local_id,
parent_tet_global_id,
new_tet_local_vids ), fail );
/* 6 */
new_tet_local_id = h5t_get_num_elems( f, f->myproc, -1 );
new_tet_local_vids[0] = local_vids[1]; // (02)
new_tet_local_vids[1] = local_vids[2]; // (03)
new_tet_local_vids[2] = local_vids[4]; // (13)
new_tet_local_vids[3] = local_vids[5]; // (23)
TRY2( h5t_store_tet (
f,
new_tet_local_id,
parent_tet_global_id,
new_tet_local_vids ), fail );
/* 7 */
new_tet_local_id = h5t_get_num_elems( f, f->myproc, -1 );
new_tet_local_vids[0] = local_vids[1]; // (02)
new_tet_local_vids[1] = local_vids[3]; // (12)
new_tet_local_vids[2] = local_vids[4]; // (13)
new_tet_local_vids[3] = local_vids[5]; // (23)
TRY2( h5t_store_tet (
f,
new_tet_local_id,
parent_tet_global_id,
new_tet_local_vids ), fail );
return H5_SUCCESS;
fail:
return H5_ERR;
}
+2 -2
View File
@@ -30,7 +30,7 @@ h5t_store_tet (
h5_file_t * const f,
const h5_id_t global_id,
const h5_id_t parent_id,
const h5_id_t vertex_ids[4]
const h5_id_t vids[4]
);
h5_id_t
@@ -38,6 +38,6 @@ h5t_store_triangle (
h5_file_t * const f,
const h5_id_t global_id,
const h5_id_t parent_id,
const h5_id_t vertex_ids[3]
const h5_id_t vids[3]
);
#endif
+4 -4
View File
@@ -14,15 +14,15 @@ _h5t_add_num_vertices (
);
h5_err_t
_h5t_add_num_entities (
_h5t_add_num_elems (
h5_file_t * const f,
const h5_size_t num
);
h5_err_t
_h5t_alloc_num_entities (
_h5t_alloc_num_elems (
h5_file_t * const f,
const size_t cur_num_entities,
const size_t new_num_entities
const size_t cur_num_elems,
const size_t new_num_elems
);
#endif
+45 -52
View File
@@ -2,60 +2,54 @@
#define __H5T_TYPES_PRIVATE_H
struct h5_vertex { /* 32Byte */
h5_id_t id;
h5_id_t unused; /* for right alignment */
struct h5_vertex {
h5_id_t vid;
h5_float64_t P[3];
};
typedef struct h5_vertex h5_vertex_t;
struct h5_edge { /* 16Bytes */
h5_id_t id;
h5_id_t parent_id;
h5_id_t refined_on_evel; /* = 0 if not refined*/
h5_id_t unused; /* for right alignment */
h5_id_t vertex_ids[2];
};
typedef struct h5_edge h5_edge_t;
struct h5_triangle { /*24Bytes*/
h5_id_t id;
h5_id_t parent_id;
h5_id_t vertex_ids[3];
struct h5_triangle {
h5_id_t cid;
h5_id_t parent_cid;
h5_id_t refined_on_level;
h5_id_t vids[3];
};
typedef struct h5_triangle h5_triangle_t;
struct h5_tetrahedron { /* 24Bytes */
h5_id_t id;
h5_id_t parent_id;
struct h5_tetrahedron {
h5_id_t cid;
h5_id_t parent_cid;
h5_id_t refined_on_level;
h5_id_t unused; /* for right alignment */
h5_id_t vertex_ids[4];
h5_id_t vids[4];
};
typedef struct h5_tetrahedron h5_tetrahedron_t;
typedef struct h5_tetrahedron h5_tet_t;
struct h5_ltriangle {
h5_id_t vertex_ids[3]; /* local(!) vertex ids */
struct h5_triangle_local {
h5_id_t parent_cid;
h5_id_t vids[3]; /* local(!) vertex ids */
};
typedef struct h5_triangle_local h5_triangle_local_t;
struct h5_tet_local_ids {
h5_id_t parent_cid;
h5_id_t vids[4]; /* local(!) vertex ids */
};
typedef struct h5_tet_local h5_tet_local_t;
union elems {
h5_tet_t *tets;
h5_triangle_t *tris;
void *data;
};
struct h5_ltetrahedron {
h5_id_t vertex_ids[4]; /* local(!) vertex ids */
union elems_local {
h5_tet_local_t *tets;
h5_triangle_local_t *tris;
void *data;
};
union entities {
struct h5_tetrahedron *tets;
struct h5_triangle *tris;
void *data;
};
union lentities {
struct h5_ltetrahedron *tets;
struct h5_ltriangle *tris;
void *data;
};
struct boundary {
char name[16];
char label[256];
@@ -81,9 +75,8 @@ struct h5t_fdata {
h5_id_t mesh_changed; /* true if mesh is new or has
been changed */
h5_id_t num_meshes;
hid_t entity_tid; /* HDF5 type id: tet, triangle
hid_t elem_tid; /* HDF5 type id: tet, triangle
etc */
h5_id_t cur_level;
h5_id_t new_level; /* idx of the first new level
or -1 */
@@ -94,25 +87,25 @@ struct h5t_fdata {
h5_size_t *num_vertices;
struct idmap map_vertex_g2l; /* map global id to local id */
struct smap sorted_lvertices;
h5_id_t last_retrieved_vertex_id;
h5_id_t last_stored_vertex_id;
h5_id_t last_retrieved_vid;
h5_id_t last_stored_vid;
/*** Entities ***/
union entities entities;
union lentities lentities; /* local vertex id's of
entities */
h5_size_t *num_entities;
h5_size_t *num_entities_on_level;
struct idmap map_entity_g2l; /* map global id to local id */
/*** Elements ***/
union elems elems;
union elems_local elems_ldta; /* local vertex id's of
elems */
h5_size_t *num_elems;
h5_size_t *num_elems_on_level;
struct idmap map_elem_g2l; /* map global id to local id */
struct smap /* array with geometrically */
sorted_lentities[H5_MAX_VERTICES_PER_ENTITY];/* sorted local entitiy ids
sorted_elems_ldta[H5_MAX_VERTICES_PER_ELEM];/* sorted local entitiy ids
[0]: 0,1,2,3 sorted
[1]: 1,0,2,3 sorted */
h5_id_t last_retrieved_entity_id;
h5_id_t last_stored_entity_id;
h5_id_t last_retrieved_eid;
h5_id_t last_stored_eid;
/*** Boundary Meshes ***/
h5_id_t num_boundaries; /* number of boundaries */
+7 -5
View File
@@ -1,14 +1,16 @@
#ifndef __H5U_ERRORHANDLING_PRIVATE_H
#define __H5U_ERRORHANDLING_PRIVATE_H
#define HANDLE_H5_SET_VIEW_ERR( rc, start, end ) \
h5_error( \
rc, \
"Cannot set view to (%lld, %lld).", \
#define HANDLE_H5_SET_VIEW_ERR( f, rc, start, end ) \
h5_error( \
f, \
rc, \
"Cannot set view to (%lld, %lld).", \
(long long)start, (long long)end );
#define HANDLE_H5_GET_NUM_PARTICLES_ERR( rc ) \
#define HANDLE_H5_GET_NUM_PARTICLES_ERR( f, rc ) \
h5_error( \
f, \
rc, \
"Cannot get number of particles." );
+57 -53
View File
@@ -25,7 +25,7 @@ _get_diskshape_for_reading (
herr_t r;
hid_t space = H5Dget_space(dataset);
if ( space < 0 ) return (hid_t)HANDLE_H5D_GET_SPACE_ERR;
if ( space < 0 ) return (hid_t)HANDLE_H5D_GET_SPACE_ERR ( f );
if ( h5u_has_view ( f ) ) {
hsize_t stride;
@@ -46,15 +46,17 @@ _get_diskshape_for_reading (
r = H5Sselect_hyperslab (
f->diskshape, H5S_SELECT_SET,
&start, &stride, &count, NULL);
if ( r < 0 ) return (hid_t)HANDLE_H5S_SELECT_HYPERSLAB_ERR;
if ( r < 0 )
return (hid_t)HANDLE_H5S_SELECT_HYPERSLAB_ERR ( f );
}
/* now we select a subset */
r = H5Sselect_hyperslab (
space,H5S_SELECT_SET,
&start, &stride, &count, NULL );
if ( r < 0 ) return (hid_t)HANDLE_H5S_SELECT_HYPERSLAB_ERR;
if ( r < 0 ) return (hid_t)HANDLE_H5S_SELECT_HYPERSLAB_ERR ( f );
h5_print_debug (
h5_debug (
f,
"Selection: range=%d:%d, npoints=%d s=%d",
(int)f->viewstart,(int)f->viewend,
(int)H5Sget_simple_extent_npoints(space),
@@ -73,7 +75,7 @@ _get_memshape_for_reading (
hsize_t dmax=H5S_UNLIMITED;
hsize_t len = f->viewend - f->viewstart;
hid_t r = H5Screate_simple(1,&len,&dmax);
if ( r < 0 ) return (hid_t)HANDLE_H5S_CREATE_SIMPLE_ERR ( 1 );
if ( r < 0 ) return (hid_t)HANDLE_H5S_CREATE_SIMPLE_ERR ( f, 1 );
return r;
}
else {
@@ -82,7 +84,7 @@ _get_memshape_for_reading (
}
h5_int64_t
H5U_get_num_elems (
h5u_get_num_elems (
h5_file_t *f /*!< [in] Handle to open file */
) {
@@ -99,7 +101,7 @@ H5U_get_num_elems (
"%s#%0*lld",
f->prefix_step_name, f->width_step_idx, (long long) f->step_idx );
herr = h5_get_object_name (
herr = hdf5_get_object_name (
f->file,
step_name,
H5G_DATASET,
@@ -109,32 +111,32 @@ H5U_get_num_elems (
dataset_id = H5Dopen ( f->step_gid, dataset_name, H5P_DEFAULT );
if ( dataset_id < 0 )
return HANDLE_H5D_OPEN_ERR ( dataset_name );
return HANDLE_H5D_OPEN_ERR ( f, dataset_name );
space_id = _get_diskshape_for_reading ( f, dataset_id );
if ( space_id < 0 ) return (h5_int64_t)space_id;
if ( h5u_has_view ( f ) ) {
nparticles = H5Sget_select_npoints ( space_id );
if ( nparticles < 0 ) return HANDLE_H5S_GET_SELECT_NPOINTS_ERR;
if ( nparticles < 0 ) return HANDLE_H5S_GET_SELECT_NPOINTS_ERR ( f );
}
else {
nparticles = H5Sget_simple_extent_npoints ( space_id );
if ( nparticles < 0 )
return HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR;
return HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR ( f );
}
if ( space_id != H5S_ALL ) {
herr = H5Sclose ( space_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
}
herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR ( f );
return (h5_int64_t) nparticles;
}
h5_int64_t
H5U_read_elems (
h5u_read_elems (
h5_file_t *f, /*!< [in] Handle to open file */
const char *name, /*!< [in] Name to associate dataset with */
void *array, /*!< [out] Array of data */
@@ -151,7 +153,7 @@ H5U_read_elems (
if ( h5err < 0 ) return h5err;
}
dataset_id = H5Dopen ( f->step_gid, name, H5P_DEFAULT );
if ( dataset_id < 0 ) return HANDLE_H5D_OPEN_ERR ( name );
if ( dataset_id < 0 ) return HANDLE_H5D_OPEN_ERR ( f, name );
space_id = _get_diskshape_for_reading ( f, dataset_id );
if ( space_id < 0 ) return (h5_int64_t)space_id;
@@ -168,25 +170,25 @@ H5U_read_elems (
(get hyperslab if needed) */
f->xfer_prop, /* ignore... its for parallel reads */
array );
if ( herr < 0 ) return HANDLE_H5D_READ_ERR ( name );
if ( herr < 0 ) return HANDLE_H5D_READ_ERR ( f, name );
if ( space_id != H5S_ALL ) {
herr = H5Sclose (space_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
}
if ( memspace_id != H5S_ALL )
herr = H5Sclose ( memspace_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR ( f );
return H5_SUCCESS;
}
h5_int64_t
H5U_set_num_elements (
h5u_set_num_elements (
h5_file_t *f, /*!< [in] Handle to open file */
h5_int64_t nparticles /*!< [in] Number of particles */
) {
@@ -208,24 +210,24 @@ H5U_set_num_elements (
#endif
if ( f->diskshape != H5S_ALL ) {
r = H5Sclose( f->diskshape );
if ( r < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( r < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
f->diskshape = H5S_ALL;
}
if(f->memshape != H5S_ALL) {
r = H5Sclose( f->memshape );
if ( r < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( r < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
f->memshape = H5S_ALL;
}
if( f->shape ) {
r = H5Sclose(f->shape);
if ( r < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( r < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
}
f->nparticles =(hsize_t) nparticles;
#ifndef PARALLEL_IO
f->shape = H5Screate_simple (1,
&(f->nparticles),
NULL);
if ( f->shape < 0 ) HANDLE_H5S_CREATE_SIMPLE_ERR ( 1 );
if ( f->shape < 0 ) HANDLE_H5S_CREATE_SIMPLE_ERR ( f, 1 );
#else /* PARALLEL_IO */
/*
@@ -259,9 +261,9 @@ H5U_set_num_elements (
return HANDLE_MPI_ALLGATHER_ERR;
}
if ( f->myproc == 0 ) {
h5_print_debug ( "Particle offsets:" );
h5_debug ( "Particle offsets:" );
for(i=0;i<f->nprocs;i++)
h5_print_debug ( "\tnp=%lld",
h5_debug ( "\tnp=%lld",
(long long) f->pnparticles[i] );
}
/* should I create a selection here? */
@@ -312,7 +314,7 @@ H5U_set_num_elements (
}
h5_int64_t
H5U_write_data (
h5u_write_data (
h5_file_t *f, /*!< IN: Handle to open file */
const char *name, /*!< IN: Name to associate array with */
const void *array, /*!< IN: Array to commit to disk */
@@ -335,7 +337,7 @@ H5U_write_data (
}
h5_int64_t
H5U_reset_view (
h5u_reset_view (
h5_file_t *f
) {
@@ -345,25 +347,25 @@ H5U_reset_view (
f->viewend = -1;
if ( f->shape != 0 ){
herr = H5Sclose(f->shape);
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
f->shape=0;
}
if(f->diskshape!=0 && f->diskshape!=H5S_ALL){
herr = H5Sclose(f->diskshape);
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
f->diskshape=H5S_ALL;
}
f->diskshape = H5S_ALL;
if(f->memshape!=0 && f->memshape!=H5S_ALL){
herr = H5Sclose ( f->memshape );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
f->memshape=H5S_ALL;
}
return H5_SUCCESS;
}
h5_int64_t
H5U_set_view (
h5u_set_view (
h5_file_t *f, /*!< [in] Handle to open file */
h5_int64_t start, /*!< [in] Start particle */
h5_int64_t end /*!< [in] End particle */
@@ -373,11 +375,12 @@ H5U_set_view (
hsize_t stride = 1;
hsize_t dmax = H5S_UNLIMITED;
h5_print_debug (
h5_debug (
f,
"Set view (%lld,%lld).",
(long long)start,(long long)end);
herr = H5U_reset_view ( f );
herr = h5u_reset_view ( f );
if ( herr < 0 ) return herr;
if ( start == -1 && end == -1 ) return H5_SUCCESS;
@@ -389,19 +392,20 @@ H5U_set_view (
For now, we interpret start=-1 to mean 0 and
end==-1 to mean end of file
*/
total = (hsize_t) H5U_get_num_elems ( f );
if ( total < 0 ) return HANDLE_H5_GET_NUM_PARTICLES_ERR ( total );
total = (hsize_t) h5u_get_num_elems ( f );
if ( total < 0 ) return HANDLE_H5_GET_NUM_PARTICLES_ERR ( f, total );
if ( start == -1 ) start = 0;
if ( end == -1 ) end = total;
h5_print_debug ( "Total nparticles=%lld", (long long)total );
h5_debug ( f, "Total nparticles=%lld", (long long)total );
/* so, is this selection inclusive or exclusive?
it appears to be inclusive for both ends of the range.
*/
if ( end < start ) {
h5_print_warn (
h5_warn (
f,
"Nonfatal error. "
"End of view (%lld) is less than start (%lld).",
(long long)end, (long long)start );
@@ -415,17 +419,17 @@ H5U_set_view (
/* declare overall datasize */
f->shape = H5Screate_simple ( 1, &total, &total );
if ( f->shape < 0 )
return HANDLE_H5S_CREATE_SIMPLE_ERR ( 1 );
return HANDLE_H5S_CREATE_SIMPLE_ERR ( f, 1 );
/* declare overall data size but then will select a subset */
f->diskshape= H5Screate_simple ( 1, &total, &total );
if ( f->diskshape < 0 )
return HANDLE_H5S_CREATE_SIMPLE_ERR ( 1 );
return HANDLE_H5S_CREATE_SIMPLE_ERR ( f, 1 );
/* declare local memory datasize */
f->memshape = H5Screate_simple(1,&(f->nparticles),&dmax);
if ( f->memshape < 0 )
return HANDLE_H5S_CREATE_SIMPLE_ERR ( 1 );
return HANDLE_H5S_CREATE_SIMPLE_ERR ( f, 1 );
herr = H5Sselect_hyperslab (
f->diskshape,
@@ -434,13 +438,13 @@ H5U_set_view (
&stride,
&total,
NULL );
if ( herr < 0 ) return HANDLE_H5S_SELECT_HYPERSLAB_ERR;
if ( herr < 0 ) return HANDLE_H5S_SELECT_HYPERSLAB_ERR ( f );
return H5_SUCCESS;
}
h5_int64_t
H5U_get_view (
h5u_get_view (
h5_file_t *f,
h5_int64_t *start,
h5_int64_t *end
@@ -456,9 +460,9 @@ H5U_get_view (
viewend = f->viewend;
}
else {
viewend = H5U_get_num_elems ( f );
viewend = h5u_get_num_elems ( f );
if ( viewend < 0 )
return HANDLE_H5_GET_NUM_PARTICLES_ERR ( viewend );
return HANDLE_H5_GET_NUM_PARTICLES_ERR ( f, viewend );
}
if ( start ) *start = viewstart;
@@ -468,11 +472,11 @@ H5U_get_view (
}
h5_int64_t
H5U_set_canonical_view (
h5u_set_canonical_view (
h5_file_t *f
) {
h5_int64_t herr = H5U_reset_view ( f );
if ( herr < 0 ) return HANDLE_H5_SET_VIEW_ERR( herr, -1, -1 );
h5_int64_t herr = h5u_reset_view ( f );
if ( herr < 0 ) return HANDLE_H5_SET_VIEW_ERR( f, herr, -1, -1 );
#ifdef PARALLEL_IO
h5_int64_t start = 0;
@@ -480,7 +484,7 @@ H5U_set_canonical_view (
h5_int64_t n = 0;
int i = 0;
n = H5U_get_num_elems ( f );
n = h5u_get_num_elems ( f );
if ( n < 0 ) return HANDLE_H5_GET_NUM_PARTICLES_ERR ( n );
/*
now lets query the attributes for this group to see if there
@@ -504,7 +508,7 @@ H5U_set_canonical_view (
start += f->pnparticles[i];
}
end = start + f->pnparticles[f->myproc] - 1;
herr = H5U_set_view ( f, start, end );
herr = h5u_set_view ( f, start, end );
if ( herr < 0 ) return HANDLE_H5_SET_VIEW_ERR ( herr, start, end );
#endif
@@ -517,7 +521,7 @@ H5U_set_canonical_view (
Get information about dataset in current index given by its index
*/
h5_int64_t
H5U_get_dataset_info (
h5u_get_dataset_info (
h5_file_t *f, /*!< [in] Handle to open file */
const h5_int64_t idx,/*!< [in] Index of the dataset */
char *dataset_name, /*!< [out] Name of dataset */
@@ -527,7 +531,7 @@ H5U_get_dataset_info (
h5_int64_t *nelem /*!< [out] Number of elements. */
) {
h5_int64_t herr = h5_get_object_name (
h5_int64_t herr = hdf5_get_object_name (
f->file,
f->step_name,
H5G_DATASET,
@@ -537,12 +541,12 @@ H5U_get_dataset_info (
if ( herr < 0 ) return herr;
if ( nelem ) {
*nelem = H5U_get_num_elems ( f );
*nelem = h5u_get_num_elems ( f );
if ( *nelem < 0 ) return *nelem;
}
if ( type ) {
*type = h5_get_dataset_type( f->step_gid, dataset_name );
*type = h5_get_dataset_type( f, f->step_gid, dataset_name );
if ( *type < 0 ) return *type;
}
+9 -9
View File
@@ -2,12 +2,12 @@
#define __U_READWRITE_H
h5_int64_t
H5U_get_num_elems (
h5u_get_num_elems (
h5_file_t *f
);
h5_int64_t
H5U_read_elems (
h5u_read_elems (
h5_file_t *f,
const char *name,
void *array,
@@ -15,13 +15,13 @@ H5U_read_elems (
);
h5_int64_t
H5U_set_num_elements (
h5u_set_num_elements (
h5_file_t *f,
h5_int64_t nparticles
);
h5_int64_t
H5U_write_data (
h5u_write_data (
h5_file_t *f,
const char *name,
const void *array,
@@ -34,31 +34,31 @@ h5u_has_view (
);
h5_int64_t
H5U_reset_view (
h5u_reset_view (
h5_file_t *f
);
h5_int64_t
H5U_set_view (
h5u_set_view (
h5_file_t *f,
h5_int64_t start,
h5_int64_t end
);
h5_int64_t
H5U_get_view (
h5u_get_view (
h5_file_t *f,
h5_int64_t *start,
h5_int64_t *end
);
h5_int64_t
H5U_set_canonical_view (
h5u_set_canonical_view (
h5_file_t *f
);
h5_int64_t
H5U_get_dataset_info (
h5u_get_dataset_info (
h5_file_t *f,
const h5_int64_t idx,
char *dataset_name,
+25
View File
@@ -0,0 +1,25 @@
#ifndef __H5B_TYPES_PRIVATE_H
#define __H5B_TYPES_PRIVATE_H
struct h5u_fdata {
hsize_t nparticles; /* -> u.nparticles */
h5_int64_t viewstart; /* -1 if no view is available: A "view" looks */
h5_int64_t viewend; /* at a subset of the data. */
/**
the number of particles in each processor.
With respect to the "VIEW", these numbers
can be regarded as non-overlapping subsections
of the particle array stored in the file.
So they can be used to compute the offset of
the view for each processor
*/
h5_int64_t *pnparticles;
hid_t shape;
hid_t diskshape;
hid_t memshape;
};
typedef struct h5u_fdata h5u_fdata_t;
#endif
+155
View File
@@ -0,0 +1,155 @@
#include <hdf5.h>
#include "h5_core.h"
#include "h5_core_private.h"
struct _iter_op_data {
int stop_idx;
int count;
int type;
char *name;
size_t len;
char *pattern;
};
/*!
\ingroup h5part_kernel
Iterator for \c H5Giterate().
*/
static herr_t
_iteration_operator (
hid_t group_id, /*!< [in] group id */
const char *member_name,/*!< [in] group name */
void *operator_data /*!< [in,out] data passed to the iterator */
) {
struct _iter_op_data *data = (struct _iter_op_data*)operator_data;
herr_t herr;
H5G_stat_t objinfo;
if ( data->type != H5G_UNKNOWN ) {
herr = H5Gget_objinfo ( group_id, member_name, 1, &objinfo );
if ( herr < 0 )
return -1;
if ( objinfo.type != data->type )
return 0;/* don't count, continue iteration */
}
if ( data->name && (data->stop_idx == data->count) ) {
memset ( data->name, 0, data->len );
strncpy ( data->name, member_name, data->len-1 );
return 1; /* stop iteration */
}
/*
count only if pattern is NULL or member name matches
*/
if ( !data->pattern ||
(strncmp (member_name, data->pattern, strlen(data->pattern)) == 0)
) {
data->count++;
}
return 0; /* continue iteration */
}
/*!
\ingroup h5part_kernel
Get number of objects of type \c type matching ^pattern.
If pattern is NULL, count all objects of given type.
*/
h5_int64_t
hdf5_get_num_objects_matching_pattern (
hid_t group_id,
const char *group_name,
const hid_t type,
char * const pattern
) {
int idx = 0;
struct _iter_op_data data;
memset ( &data, 0, sizeof ( data ) );
data.type = type;
data.pattern = pattern;
TRY( H5Giterate ( group_id, group_name, &idx,
_iteration_operator, &data ) );
return data.count;
}
/*!
\ingroup h5part_kernel
Get number of object of type \c type in HDF5 group \c group_id.
*/
h5_int64_t
hdf5_get_num_objects (
hid_t group_id,
const char *group_name,
const hid_t type
) {
return hdf5_get_num_objects_matching_pattern (
group_id,
group_name,
type,
NULL );
}
const char *
hdf5_get_objname (
hid_t id
) {
static char objname[256];
memset ( objname, 0, sizeof(objname) );
ssize_t size = H5Iget_name ( id, objname, sizeof(objname) );
if ( size < 0 ) {
strcpy ( objname, "[error getting object name]" );
} else if ( size == 0 ) {
strcpy ( objname, "[no name associated with identifier]" );
}
return objname;
}
/*!
\ingroup h5part_kernel
Iterator for \c H5Giterate().
@@@ to be fixed: idx not found error handling
*/
h5_int64_t
hdf5_get_object_name (
hid_t group_id,
const char *group_name,
const hid_t type,
const h5_int64_t idx,
char *obj_name,
const h5_int64_t len_obj_name
) {
herr_t herr;
struct _iter_op_data data;
int iterator_idx = 0;
memset ( &data, 0, sizeof ( data ) );
data.stop_idx = (hid_t)idx;
data.type = type;
data.name = obj_name;
data.len = (size_t)len_obj_name;
herr = H5Giterate ( group_id, group_name, &iterator_idx,
_iteration_operator,
&data );
if ( herr < 0 ) return (h5_int64_t)herr;
return H5_SUCCESS;
}
+34
View File
@@ -0,0 +1,34 @@
#ifndef __HDF5_MISC_H
#define __HDF5_MISC_H
h5_int64_t
hdf5_get_num_objects (
hid_t group_id,
const char *group_name,
const hid_t type
);
h5_int64_t
hdf5_get_num_objects_matching_pattern (
hid_t group_id,
const char *group_name,
const hid_t type,
char * const pattern
);
const char *
hdf5_get_objname (
hid_t id
);
h5_int64_t
hdf5_get_object_name (
hid_t group_id,
const char *group_name,
const hid_t type,
const h5_int64_t idx,
char *obj_name,
const h5_int64_t len_obj_name
);
#endif