refactoring

This commit is contained in:
2008-09-25 15:43:24 +00:00
parent 7959742667
commit 07e57ff23a
26 changed files with 1670 additions and 1823 deletions
-1
View File
@@ -378,7 +378,6 @@ src/h5_core/h5_core_private.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_general.c -text
src/h5_core/h5_maps.c -text
src/h5_core/h5_maps.h -text
src/h5_core/h5_openclose.c -text
+43 -27
View File
@@ -36,52 +36,68 @@ EXTRA_DIST = $(EXTRA_HEADERS)
nodist_include_HEADERS =
# What to build... Will be determined by configure script.
lib_LIBRARIES = libH5.a
lib_LIBRARIES = libH5_core.a
# Listing of all possible targets that I may build.
EXTRA_LIBRARIES = libH5.a
EXTRA_LIBRARIES = libH5_core.a
# Header files that I wish to install in $(prefix)/include
include_HEADERS = \
h5_attribs.h \
h5_core.h \
h5_errorhandling.h \
h5_errorhandling_private.h \
h5_hdf5.h \
h5_maps.h \
h5_openclose.h \
h5_qsort_private.h \
h5_readwrite.h \
h5_readwrite_private.h \
h5_types.h \
attribs.h \
errorhandling.h \
errorhandling_private.h \
maps.h \
readwrite.h \
t_errorhandling_private.h \
t_map.h \
t_openclose.h \
t_readwrite.h \
u_readwrite.h
h5b_errorhandling_private.h \
h5t_boundaries.h \
h5t_boundaries_private.h \
h5t_errorhandling_private.h \
h5t_map.h \
h5t_openclose.h \
h5t_readwrite.h \
h5t_readwrite_private.h \
h5t_storemesh.h
h5t_storemesh_private.h
h5u_errorhandling_private.h \
h5u_readwrite.h
# Listing of all possible headers that I may include
EXTRA_HEADERS =
# Listing of sources
libH5_a_SOURCES = \
attribs.c \
errorhandling.c \
general.c \
maps.c \
readwrite.c \
t_errorhandling.c \
t_map.c \
t_openclose.c \
t_readwrite.c \
u_readwrite.c
libH5_core_a_SOURCES = \
h5_attribs.c \
h5_errorhandling.c \
h5_hdf5.c \
h5_maps.c \
h5_openclose.c \
h5_qsort.c \
h5_qsort_r.c \
h5_readwrite.c \
h5t_boundaries.c \
h5t_errorhandling.c \
h5t_map.c \
h5t_openclose.c \
h5t_readwrite.c \
h5t_storemesh.c \
h5u_readwrite.c
all: libH5.a
all: libH5_core.a
libH5.a: $(libH5_a_OBJECTS)
libH5_core.a: $(libH5_core_a_OBJECTS)
echo $(libH5_a_OBJECTS)
${AR} rucs $@ $^
%.o : %.c
$(CC) $(CFLAGS) $(INC) -c $<
$(libH5_a_OBJECTS): h5_core.h
$(libH5_core_a_OBJECTS): h5_core.h
#errorhandling.o: errorhandling.c
+2 -2
View File
@@ -7,7 +7,7 @@
#include <hdf5.h>
#include "h5_core.h"
#include "h5_private.h"
#include "h5_core_private.h"
#include "H5Part.h"
#include "H5Block.h"
@@ -76,7 +76,7 @@ h5_write_attrib (
attrib_name,
attrib_type,
space_id,
H5P_DEFAULT );
H5P_DEFAULT, H5P_DEFAULT );
if ( attrib_id < 0 ) return HANDLE_H5A_CREATE_ERR ( attrib_name );
herr = H5Awrite ( attrib_id, attrib_type, attrib_value);
+13 -56
View File
@@ -3,62 +3,19 @@
#include "h5_types.h"
h5_file*
h5_open_file (
const char *filename,
unsigned flags,
MPI_Comm comm
);
#include "h5_attribs.h"
#include "h5_errorhandling.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_map.h"
#include "h5t_openclose.h"
#include "h5t_readwrite.h"
#include "h5t_storemesh.h"
#include "h5u_readwrite.h"
h5part_int64_t
h5_check_filehandle (
const h5_file *f
);
h5part_int64_t
h5_close_file (
h5_file *f
);
h5part_int64_t
h5_define_stepname_fmt (
h5_file *f,
const char *name,
const h5part_int64_t width
);
h5_err_t
h5_get_stepname_fmt (
h5_file *f,
char *name,
const h5_size_t l_name,
h5_size_t *width
);
h5_err_t
_h5_close_step (
h5_file *f
);
h5_int64_t
h5_has_step (
h5_file * f,
h5_int64_t step
);
h5_int64_t
h5_get_step (
h5_file *f
);
#include "attribs.h"
#include "errorhandling.h"
#include "maps.h"
#include "readwrite.h"
#include "t_boundaries.h"
#include "t_map.h"
#include "t_openclose.h"
#include "t_readwrite.h"
#include "u_readwrite.h"
#endif
+10 -29
View File
@@ -1,9 +1,15 @@
#ifndef __H5_PRIVATE_H
#define __H5_PRIVATE_H
#include "errorhandling_private.h"
#include "t_map_private.h"
#include "t_errorhandling_private.h"
#include "h5_errorhandling_private.h"
#include "h5_qsort_private.h"
#include "h5b_errorhandling_private.h"
#include "h5t_boundaries_private.h"
#include "h5t_map_private.h"
#include "h5t_errorhandling_private.h"
#include "h5t_readwrite_private.h"
#include "h5t_storemesh_private.h"
#include "h5u_errorhandling_private.h"
#define H5PART_GROUPNAME_STEP "Step"
@@ -17,33 +23,8 @@
#define _h5t_build_triangle_id( idx, entity_id ) \
( (idx << (sizeof(entity_id)*8 - 3)) | (entity_id & H5_TET_MASK))
#define SET_FNAME( fname ) h5_set_funcname( fname );
#define CHECK_FILEHANDLE( f ) \
if ( f == NULL ) \
return HANDLE_H5_BADFD_ERR;
#define CHECK_WRITABLE_MODE( f ) \
if ( f->mode==H5PART_READ ) \
return (*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_INVAL, \
"Attempting to write to read-only file" );
#define CHECK_READONLY_MODE( f ) \
if ( ! f->mode==H5PART_READ ) \
return (*h5_get_errorhandler()) ( \
h5_get_funcname(), \
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, \
"Internal error: step_gid <= 0.");
#define TRY(func,exception) if ( func < 0 ) goto exception;
/*!
+74 -20
View File
@@ -7,20 +7,27 @@
#include <hdf5.h>
#include "h5_core.h"
#include "h5_private.h"
#include "H5Part.h"
#include "h5_core_private.h"
h5_error_handler _err_handler = h5_report_errorhandler;
h5_err_t _h5part_errno = H5_SUCCESS;
h5_id_t _debug = 0;
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 char *__funcname = "NONE";
const char * const H5_O_MODES[] = {
"H5_O_RDWR",
"H5_O_RDONLY",
"H5_O_WRONLY",
"H5_O_APPEND"
};
h5_err_t
h5_set_debuglevel (
h5_id_t level
) {
_debug = level;
_h5_debug = level;
return H5_SUCCESS;
}
@@ -28,7 +35,7 @@ h5_err_t
h5_get_debuglevel (
void
) {
return _debug;
return _h5_debug;
}
h5_err_t
@@ -39,18 +46,32 @@ h5_set_errorhandler (
return H5_SUCCESS;
}
h5part_error_handler
h5_error_handler
h5_get_errorhandler (
void
) {
return _err_handler;
}
h5_verror_handler
h5_get_verrorhandler (
void
) {
return _verr_handler;
}
h5_err_t
h5_get_errno (
void
) {
return _h5part_errno;
return _h5_errno;
}
void
h5_set_errno (
h5_err_t h5_errno
) {
_h5_errno = h5_errno;
}
@@ -70,14 +91,29 @@ h5_report_errorhandler (
...
) {
_h5part_errno = eno;
if ( _debug > 0 ) {
_h5_errno = eno;
if ( _h5_debug > 0 ) {
va_list ap;
va_start ( ap, fmt );
h5_vprint_error ( fmt, ap );
va_end ( ap );
}
return _h5part_errno;
return _h5_errno;
}
h5_err_t
h5_report_verrorhandler (
const char *funcname,
const h5_err_t eno,
const char *fmt,
va_list ap
) {
_h5_errno = eno;
if ( _h5_debug > 0 ) {
h5_vprint_error ( fmt, ap );
}
return _h5_errno;
}
/*!
@@ -94,15 +130,15 @@ h5_abort_errorhandler (
...
) {
_h5part_errno = eno;
if ( _debug > 0 ) {
_h5_errno = eno;
if ( _h5_debug > 0 ) {
va_list ap;
va_start ( ap, fmt );
fprintf ( stderr, "%s: ", funcname );
vfprintf ( stderr, fmt, ap );
fprintf ( stderr, "\n" );
}
exit (-(int)_h5part_errno);
exit (-(int)_h5_errno);
}
static void
@@ -112,20 +148,38 @@ _vprintf (
const char *fmt,
va_list ap
) {
char *fmt2 = (char*)malloc( strlen ( prefix ) +strlen ( fmt ) + strlen ( __funcname ) + 16 );
char *fmt2 = (char*)malloc(
strlen ( prefix ) +
strlen ( fmt ) +
strlen ( __funcname ) + 16 );
if ( fmt2 == NULL ) return;
sprintf ( fmt2, "%s: %s: %s\n", prefix, __funcname, fmt );
vfprintf ( stderr, fmt2, ap );
free ( fmt2 );
}
h5_err_t
h5_error (
h5_err_t error_no,
const char *fmt,
...
) {
va_list ap;
va_start ( ap, fmt );
(*h5_get_verrorhandler()) ( h5_get_funcname(), error_no, fmt, ap );
va_end ( ap );
return error_no;
}
void
h5_vprint_error (
const char *fmt,
va_list ap
) {
if ( _debug < 1 ) return;
if ( _h5_debug < 1 ) return;
_vprintf ( stderr, "E", fmt, ap );
}
@@ -147,7 +201,7 @@ h5_vprint_warn (
va_list ap
) {
if ( _debug < 2 ) return;
if ( _h5_debug < 2 ) return;
_vprintf ( stderr, "W", fmt, ap );
}
@@ -169,7 +223,7 @@ h5_vprint_info (
va_list ap
) {
if ( _debug < 3 ) return;
if ( _h5_debug < 3 ) return;
_vprintf ( stdout, "I", fmt, ap );
}
@@ -191,7 +245,7 @@ h5_vprint_debug (
va_list ap
) {
if ( _debug < 4 ) return;
if ( _h5_debug < 4 ) return;
_vprintf ( stdout, "D", fmt, ap );
}
+48
View File
@@ -4,7 +4,35 @@
#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 CHECK_FILEHANDLE( f ) \
if ( f == NULL ) \
return HANDLE_H5_BADFD_ERR;
#define CHECK_WRITABLE_MODE( f ) \
if ( f->mode==H5_O_RDONLY ) \
return (*h5_get_errorhandler()) ( \
h5_get_funcname(), \
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, \
"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, \
"Internal error: step_gid <= 0.");
h5_err_t
h5_set_debuglevel (
@@ -31,6 +59,11 @@ h5_get_errno (
void
);
void
h5_set_errno (
h5_err_t h5_errno
);
h5_err_t
h5_report_errorhandler (
const char *funcname,
@@ -39,6 +72,14 @@ h5_report_errorhandler (
...
);
h5_err_t
h5_report_verrorhandler (
const char *funcname,
const h5_err_t eno,
const char *fmt,
va_list ap
);
h5_err_t
h5_abort_errorhandler (
const char *funcname,
@@ -47,6 +88,13 @@ h5_abort_errorhandler (
...
) ;
h5_err_t
h5_error (
h5_err_t error_no,
const char *fmt,
...
);
void
h5_vprint_error (
const char *fmt,
+193 -288
View File
@@ -1,426 +1,331 @@
#ifndef __ERRORHANDLING_PRIVATE_H
#define __ERRORHANDLING_PRIVATE_H
extern h5part_error_handler _err_handler;
extern h5_err_t _h5part_errno;
extern h5_id_t _debug;
#define h5_error_not_implemented( file, func, lino ) \
h5_error( \
H5_ERR_NOT_IMPLEMENTED, \
"%s: Function \"%s\", line %d not yet implemented!", \
file, func, lino );
#define HANDLE_H5_ERR_NOT_IMPLEMENTED \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_NOT_IMPLEMENTED, \
"Function not yet implemented!" );
#define HANDLE_H5G_OPEN_ERR( s ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
"Cannot open group \"%s\".", s );
#define CHECK_LAYOUT( f ) \
if ( ! f->block->have_layout ) \
return (*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5PART_ERR_LAYOUT, \
"No layout defined." )
#define HANDLE_H5_LAYOUT_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5PART_ERR_LAYOUT, \
"Bad layout." );
#define h5_error_internal( file, func, lino ) \
h5_error( \
H5_ERR_INTERNAL, \
"%s: Internal error: %s line %d!", \
file, func, lino )
#define HANDLE_H5_NOENT_ERR( name ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5PART_ERR_NOENT, \
"Object \"%s\" doesn't exists.", name );
h5_error( \
H5PART_ERR_NOENT, \
"Object \"%s\" doesn't exists.", name );
#define HANDLE_H5_DATASET_RANK_ERR( m, n ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5PART_ERR_INVAL, \
"Wrong rank of dataset: Is %d, but should be %d", \
m, n );
h5_error( \
H5PART_ERR_INVAL, \
"Wrong rank of dataset: Is %d, but should be %d", \
m, n );
#define HANDLE_H5_GROUP_EXISTS_ERR( name ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5PART_ERR_INVAL, \
"Group \"%s\" already exists", name )
#define HANDLE_H5_INTERNAL_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_INTERNAL, \
"Internal error: %s line %d!", __FILE__, __LINE__ )
h5_error( \
H5PART_ERR_INVAL, \
"Group \"%s\" already exists", name )
/**************** H5 *********************/
#define HANDLE_H5_BADFD_ERR \
(*h5_get_errorhandler())( \
h5_get_funcname(), \
h5_error( \
H5_ERR_BADFD, \
"Called with bad filehandle." );
#define HANDLE_H5_INIT_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
h5_error( \
H5_ERR_INIT, \
"Cannot initialize H5Part." );
#define HANDLE_H5_NOMEM_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
h5_error( \
H5_ERR_NOMEM, \
"Out of memory." );
#define HANDLE_H5_SETSTEP_ERR( rc, step ) \
(*h5_get_errorhandler()) ( \
h5_error\
h5_get_funcname(), \
rc, \
"Cannont set time-step to %lld.", (long long)step );
"Cannont set step to %lld.", (long long)step );
#define _h5_handle_file_mode_error( mode_id ) \
h5_error( \
H5_ERR_BADF, \
"Operation not permitted in mode \"%s\"", \
H5_O_MODES[mode_id] );
#define HANDLE_H5_FILE_ACCESS_TYPE_ERR( flags ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_INVAL, \
"Invalid file access type \"%d\".", flags);
h5_error( \
H5_ERR_INVAL, \
"Invalid file access mode \"%d\".", flags);
#define HANDLE_H5_STEP_EXISTS_ERR( step ) \
(*h5_get_errorhandler())( \
h5_get_funcname(), \
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_SET_VIEW_ERR( rc, start, end ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
rc, \
"Cannot set view to (%lld, %lld).", \
(long long)start, (long long)end );
#define HANDLE_H5_NOENTRY_ERR( group_name, type, idx ) \
h5_error( \
H5_ERR_NOENTRY, \
"No entry with index %lld and type %d in group %s!", \
(long long)idx, type, group_name );
#define HANDLE_H5_GET_NUM_PARTICLES_ERR( rc ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
rc, \
"Cannot get number of particles." );
#define HANDLE_H5_NOENTRY_ERR( group_name, type, idx ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_NOENTRY, \
"No entry with index %lld and type %d in group %s!", \
(long long)idx, type, group_name );
#define HANDLE_H5_UNDEF_MESH_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_INVAL, \
"Mesh not yet defined." );
#define HANDLE_H5_UNDEF_LEVEL_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_INVAL, \
"Level not yet defined." );
#define HANDLE_H5_OVERFLOW_ERR( otype, max ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_INVAL, \
"Cannot store more than %d %s", max, otype );
h5_error( \
H5_ERR_INVAL, \
"Cannot store more than %d %s", max, otype );
#define HANDLE_H5_PARENT_ID_ERR( otype, oid, pid ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_INVAL, \
"Impossible parent_id %d for %s with global id %d", \
pid, otype, oid );
#define HANDLE_H5_PARENT_ID_ERR( otype, oid, pid ) \
h5_error( \
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_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_INVAL, \
"%s id %d out of range", \
otype, oid );
h5_error( \
H5_ERR_INVAL, \
"%s id %d out of range", \
otype, oid );
/**************** HDF5 *********************/
/* H5A: Attribute */
#define HANDLE_H5A_CLOSE_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5A_CLOSE_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot terminate access to attribute." );
#define HANDLE_H5A_CREATE_ERR( s ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5A_CREATE_ERR( s ) \
h5_error( \
H5_ERR_HDF5, \
"Cannot create attribute \"%s\".", s );
#define HANDLE_H5A_GET_NAME_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5A_GET_NAME_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot get attribute name." );
#define HANDLE_H5A_GET_NUM_ATTRS_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5A_GET_NUM_ATTRS_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot get number of attributes." );
#define HANDLE_H5A_GET_SPACE_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5A_GET_SPACE_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot get a copy of dataspace for attribute." );
#define HANDLE_H5A_GET_TYPE_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5A_GET_TYPE_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot get attribute datatype." );
#define HANDLE_H5A_OPEN_IDX_ERR( n ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5A_OPEN_IDX_ERR( n ) \
h5_error( \
H5_ERR_HDF5, \
"Cannot open attribute specified by index \"%lld\".", \
(long long)n );
#define HANDLE_H5A_OPEN_NAME_ERR( s ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5A_OPEN_NAME_ERR( s ) \
h5_error( \
H5_ERR_HDF5, \
"Cannot open attribute specified by name \"%s\".", s );
#define HANDLE_H5A_READ_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5A_READ_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot read attribute" );
#define HANDLE_H5A_WRITE_ERR( s ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5A_WRITE_ERR( s ) \
h5_error( \
H5_ERR_HDF5, \
"Cannot write attribute \"%s\".", s );
/* H5D: Dataset */
#define HANDLE_H5D_CLOSE_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5D_CLOSE_ERR \
h5_error( \
H5_ERR_HDF5, \
"Close of dataset failed." );
#define HANDLE_H5D_CREATE_ERR( s ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5D_CREATE_ERR( s ) \
h5_error( \
H5_ERR_HDF5, \
"Cannot create dataset name \"%s\"", \
s );
#define HANDLE_H5D_GET_SPACE_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5D_GET_SPACE_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot get dataspace identifier.");
#define HANDLE_H5D_GET_TYPE_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5D_GET_TYPE_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot determine dataset type.");
#define HANDLE_H5D_OPEN_ERR( s ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5D_OPEN_ERR( s ) \
h5_error( \
H5_ERR_HDF5, \
"Cannot open dataset \"%s\".", s );
#define HANDLE_H5D_READ_ERR( s ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5D_READ_ERR( s ) \
h5_error( \
H5_ERR_HDF5, \
"Read from dataset \"%s\".", \
s );
#define HANDLE_H5D_WRITE_ERR( s ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5D_WRITE_ERR( s ) \
h5_error( \
H5_ERR_HDF5, \
"Write to dataset \"%s\" failed.", \
s );
/* H5F: file */
#define HANDLE_H5F_CLOSE_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5F_CLOSE_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot terminate access to file." );
#define HANDLE_H5F_OPEN_ERR( filename, flags ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
"Cannot open file \"%s\" with mode \"%d\"", filename, flags );
#define HANDLE_H5F_OPEN_ERR( filename, flags ) \
h5_error( \
H5_ERR_HDF5, \
"Cannot open file \"%s\" with mode \"%d\"", \
filename, flags );
/* H5G: group */
#define HANDLE_H5G_CLOSE_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5G_CLOSE_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot terminate access to datagroup." );
#define HANDLE_H5G_CREATE_ERR( s ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5G_CREATE_ERR( s ) \
h5_error( \
H5_ERR_HDF5, \
"Cannot create datagroup \"%s\".", s );
#define HANDLE_H5G_GET_OBJINFO_ERR( s ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5G_GET_OBJINFO_ERR( s ) \
h5_error( \
H5_ERR_HDF5, \
"Cannot get information about object \"%s\".", s );
#define HANDLE_H5G_OPEN_ERR( s ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
"Cannot open group \"%s\".", s );
#define HANDLE_H5G_OPEN_ERR( parent_id, grp_name ) \
h5_error( \
H5_ERR_HDF5, \
"Cannot open group \"%s/%s\".", parent_id, grp_name );
/* H5P: property */
#define HANDLE_H5P_CLOSE_ERR( s ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5P_CLOSE_ERR( s ) \
h5_error( \
H5_ERR_HDF5, \
"Cannot terminate access to property list \"%s\".", s );
#define HANDLE_H5P_CREATE_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5P_CREATE_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot create property list." );
#define HANDLE_H5P_SET_DXPL_MPIO_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
"MPI: Cannot set data transfer mode." );
#define HANDLE_H5P_SET_DXPL_MPIO_ERR \
h5_error( \
H5_ERR_HDF5, \
"MPI: Cannot set data transfer mode." );
#define HANDLE_H5P_SET_FAPL_MPIO_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
"Cannot store IO communicator information to the " \
"file access property list.");
#define HANDLE_H5P_SET_FAPL_MPIO_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot store IO communicator information to the " \
"file access property list.");
/* H5S: dataspace */
#define HANDLE_H5S_CREATE_SIMPLE_ERR( rank ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5PART_ERR_HDF5, \
#define HANDLE_H5S_CREATE_SIMPLE_ERR( rank ) \
h5_error( \
H5_ERR_HDF5, \
"Cannot create dataspace with rank %d.", \
rank );
#define HANDLE_H5S_CREATE_SIMPLE_3D_ERR( dims ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5PART_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_CREATE_SIMPLE_3D_ERR( dims ) \
h5_error( \
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 \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5S_CLOSE_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot terminate access to dataspace." );
#define HANDLE_H5S_GET_SELECT_NPOINTS_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
"Cannot determine the number of elements in dataspace selection." );
#define HANDLE_H5S_GET_SELECT_NPOINTS_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot determine the number of elements" \
"in dataspace selection." );
#define HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot determine number of elements in dataspace." );
#define HANDLE_H5S_SELECT_HYPERSLAB_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
"Cannot set select hyperslap region or add the specified region" );
#define HANDLE_H5S_SELECT_HYPERSLAB_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot set select hyperslap region or add the " \
"specified region" );
#define HANDLE_H5S_GET_SIMPLE_EXTENT_DIMS_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5PART_ERR_HDF5, \
#define HANDLE_H5S_GET_SIMPLE_EXTENT_DIMS_ERR \
h5_error( \
H5PART_ERR_HDF5, \
"Cannot get dimension sizes of dataset" );
/* H5T: type */
#define HANDLE_H5T_ARRAY_CREATE_ERR( type_name, rank ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
"Can't create array datatype object with base datatype %s and rank %d", \
#define HANDLE_H5T_ARRAY_CREATE_ERR( type_name, rank ) \
h5_error( \
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 ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5T_CREATE_ERR( class_name, obj_name ) \
h5_error( \
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 ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5T_INSERT_ERR( field_name, type_name ) \
h5_error( \
H5_ERR_HDF5, \
"Can't insert field %s to compound datatype to handle %s", \
field_name, type_name );
#define HANDLE_H5T_CLOSE_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_HDF5, \
#define HANDLE_H5T_CLOSE_ERR \
h5_error( \
H5_ERR_HDF5, \
"Cannot release datatype." );
/* MPI */
#define HANDLE_MPI_ALLGATHER_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_MPI, \
#define HANDLE_MPI_ALLGATHER_ERR \
h5_error( \
H5_ERR_MPI, \
"Cannot gather data." );
#define HANDLE_MPI_COMM_SIZE_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_MPI, \
#define HANDLE_MPI_COMM_SIZE_ERR \
h5_error( \
H5_ERR_MPI, \
"Cannot get number of processes in my group." );
#define HANDLE_MPI_COMM_RANK_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_MPI, \
#define HANDLE_MPI_COMM_RANK_ERR \
h5_error( \
H5_ERR_MPI, \
"Cannot get rank of the calling process in my group." );
#define HANDLE_MPI_UNAVAILABLE_ERR \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_MPI, \
#define HANDLE_MPI_UNAVAILABLE_ERR \
h5_error( \
H5_ERR_MPI, \
"MPI not available" );
-465
View File
@@ -1,465 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h> /* va_arg - System dependent ?! */
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <hdf5.h>
#include "h5_core.h"
#include "h5_core_private.h"
/*!
\ingroup h5block_private
\internal
Check whether \c f points to a valid file handle.
\return H5_SUCCESS or error code
*/
h5part_int64_t
h5_check_filehandle (
const h5_file *f /*!< filehandle to check validity of */
) {
if ( f == NULL )
return HANDLE_H5_BADFD_ERR;
if ( f->file == 0 )
return HANDLE_H5_BADFD_ERR;
if ( f->block == NULL )
return HANDLE_H5_BADFD_ERR;
return H5_SUCCESS;
}
/*!
Initialize H5Part
*/
static herr_t
_h5_error_handler ( void* unused ) {
if ( h5_get_debuglevel() >= 5 ) {
H5Eprint (stderr);
}
return 0;
}
static h5part_int64_t
_init ( void ) {
static int __init = 0;
herr_t r5;
if ( ! __init ) {
r5 = H5Eset_auto ( _h5_error_handler, NULL );
if ( r5 < 0 ) return H5_ERR_INIT;
}
__init = 1;
return H5_SUCCESS;
}
/*!
\ingroup h5_private
\internal
Initialize unstructured data internal data structure.
\return H5_SUCCESS or error code
*/
static h5part_int64_t
_h5u_open_file (
h5_file *f /*!< IN: file handle */
) {
f->shape = 0;
f->diskshape = H5S_ALL;
f->memshape = H5S_ALL;
f->viewstart = -1;
f->viewend = -1;
f->pnparticles =
(h5part_int64_t*) malloc (f->nprocs * sizeof (h5part_int64_t));
if (f->pnparticles == NULL) {
return HANDLE_H5_NOMEM_ERR;
}
return H5_SUCCESS;
}
/*!
\ingroup h5_private
\internal
Initialize H5Block internal structure.
\return H5_SUCCESS or error code
*/
static h5part_int64_t
_h5b_open_file (
h5_file *f /*!< IN: file handle */
) {
struct h5b_fdata *b;
if ( (f == 0) || (f->file == 0) ) return HANDLE_H5_BADFD_ERR;
if ( f->block ) return H5_SUCCESS;
f->block = (struct h5b_fdata*) malloc( sizeof (*f->block) );
if ( f->block == NULL ) {
return HANDLE_H5_NOMEM_ERR;
}
b = f->block;
memset ( b, 0, sizeof (*b) );
b->user_layout = (struct H5BlockPartition*) malloc (
f->nprocs * sizeof (b->user_layout[0]) );
if ( b->user_layout == NULL ) {
return HANDLE_H5_NOMEM_ERR;
}
b->write_layout = (struct H5BlockPartition*) malloc (
f->nprocs * sizeof (b->write_layout[0]) );
if ( b->write_layout == NULL ) {
return HANDLE_H5_NOMEM_ERR;
}
b->step_idx = -1;
b->blockgroup = -1;
b->shape = -1;
b->diskshape = -1;
b->memshape = -1;
b->field_group_id = -1;
b->have_layout = 0;
return H5_SUCCESS;
}
h5_file*
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 */
) {
h5_info ( "Opening file %s.", filename );
if ( _init() < 0 ) {
HANDLE_H5_INIT_ERR;
return NULL;
}
h5_set_errno ( H5_SUCCESS );
h5_file *f = NULL;
f = (h5_file*) malloc( sizeof (h5_file) );
if( f == NULL ) {
HANDLE_H5_NOMEM_ERR;
goto error_cleanup;
}
memset (f, 0, sizeof (h5_file));
f->prefix_step_name = strdup ( H5PART_GROUPNAME_STEP );
if( f->prefix_step_name == NULL ) {
HANDLE_H5_NOMEM_ERR;
goto error_cleanup;
}
f->width_step_idx = 0;
f->xfer_prop = f->create_prop = f->access_prop = H5P_DEFAULT;
f->comm = 0; /* init values for serial case */
f->nprocs = 1;
f->myproc = 0;
#ifdef PARALLEL_IO
f->comm = comm;
if (MPI_Comm_size (comm, &f->nprocs) != MPI_SUCCESS) {
HANDLE_MPI_COMM_SIZE_ERR;
goto error_cleanup;
}
if (MPI_Comm_rank (comm, &f->myproc) != MPI_SUCCESS) {
HANDLE_MPI_COMM_RANK_ERR;
goto error_cleanup;
}
/* for the SP2... perhaps different for linux */
MPI_Info info = MPI_INFO_NULL;
/* ks: IBM_large_block_io */
MPI_Info_create(&info);
MPI_Info_set(info, "IBM_largeblock_io", "true" );
if (H5Pset_fapl_mpio (f->access_prop, comm, info) < 0) {
HANDLE_H5P_SET_FAPL_MPIO_ERR;
goto error_cleanup;
}
MPI_Info_free(&info);
f->access_prop = H5Pcreate (H5P_FILE_ACCESS);
if (f->access_prop < 0) {
HANDLE_H5P_CREATE_ERR;
goto error_cleanup;
}
/* f->create_prop = H5Pcreate(H5P_FILE_CREATE); */
f->create_prop = H5P_DEFAULT;
/* xfer_prop: also used for parallel I/O, during actual writes
rather than the access_prop which is for file creation. */
f->xfer_prop = H5Pcreate (H5P_DATASET_XFER);
if (f->xfer_prop < 0) {
HANDLE_H5P_CREATE_ERR;
goto error_cleanup;
}
#ifdef COLLECTIVE_IO
if (H5Pset_dxpl_mpio (f->xfer_prop,H5FD_MPIO_COLLECTIVE) < 0) {
HANDLE_H5P_SET_DXPL_MPIO_ERR;
goto error_cleanup;
}
#endif /* COLLECTIVE_IO */
#endif /* PARALLEL_IO */
if ( flags == H5_O_RDONLY ) {
f->file = H5Fopen (filename, H5F_ACC_RDONLY, f->access_prop);
}
else if ( flags == H5_O_WRONLY ){
f->file = H5Fcreate (filename, H5F_ACC_TRUNC, f->create_prop,
f->access_prop);
f->empty = 1;
}
else if ( flags == H5_O_APPEND || H5_O_RDWR ) {
int fd = open (filename, O_RDONLY, 0);
if ( (fd == -1) && (errno == ENOENT) ) {
f->file = H5Fcreate(filename, H5F_ACC_TRUNC,
f->create_prop, f->access_prop);
f->empty = 1;
}
else if (fd != -1) {
close (fd);
f->file = H5Fopen (filename, H5F_ACC_RDWR,
f->access_prop);
}
}
else {
HANDLE_H5_FILE_ACCESS_TYPE_ERR ( flags );
goto error_cleanup;
}
if (f->file < 0) {
HANDLE_H5F_OPEN_ERR ( filename, flags );
goto error_cleanup;
}
f->root_gid = H5Gopen( f->file, "/" );
if ( f->root_gid < 0 ) {
HANDLE_H5G_OPEN_ERR ( "", "" );
goto error_cleanup;
}
f->mode = flags;
f->step_gid = -1;
sprintf (
f->step_name,
"%s#%0*lld",
f->prefix_step_name, f->width_step_idx, (long long) f->step_idx );
if ( _h5u_open_file ( f ) < 0 ) {
goto error_cleanup;
}
if ( _h5b_open_file ( f ) < 0 ) {
goto error_cleanup;
}
if ( _h5t_open_file ( f ) < 0 ) {
goto error_cleanup;
}
return f;
error_cleanup:
if (f != NULL ) {
if (f->prefix_step_name) {
free (f->prefix_step_name);
}
if (f->pnparticles != NULL) {
free (f->pnparticles);
}
free (f);
}
return NULL;
}
/*!
\ingroup h5_private
\internal
De-initialize H5Block internal structure. Open HDF5 objects are
closed and allocated memory freed.
\return H5_SUCCESS or error code
*/
static h5part_int64_t
_h5u_close_file (
h5_file *f /*!< IN: file handle */
) {
herr_t herr;
h5_set_errno ( H5_SUCCESS );
if( f->shape > 0 ) {
herr = H5Sclose( f->shape );
if ( herr < 0 ) HANDLE_H5S_CLOSE_ERR;
f->shape = 0;
}
if( f->diskshape != H5S_ALL ) {
herr = H5Sclose( f->diskshape );
if ( herr < 0 ) HANDLE_H5S_CLOSE_ERR;
f->diskshape = 0;
}
if( f->memshape != H5S_ALL ) {
herr = H5Sclose( f->memshape );
if ( herr < 0 ) HANDLE_H5S_CLOSE_ERR;
f->memshape = 0;
}
if( f->pnparticles ) {
free( f->pnparticles );
}
return h5_get_errno();
}
/*!
\ingroup h5block_private
\internal
De-initialize H5Block internal structure. Open HDF5 objects are
closed and allocated memory freed.
\return H5_SUCCESS or error code
*/
static h5part_int64_t
_h5b_close_file (
h5_file *f /*!< IN: file handle */
) {
herr_t herr;
struct h5b_fdata *b = f->block;
if ( b->blockgroup >= 0 ) {
herr = H5Gclose ( b->blockgroup );
if ( herr < 0 ) return HANDLE_H5G_CLOSE_ERR;
b->blockgroup = -1;
}
if ( b->shape >= 0 ) {
herr = H5Sclose ( b->shape );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
b->shape = -1;
}
if ( b->diskshape >= 0 ) {
herr = H5Sclose ( b->diskshape );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
b->diskshape = -1;
}
if ( b->memshape >= 0 ) {
herr = H5Sclose ( b->memshape );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
b->memshape = -1;
}
free ( f->block );
f->block = NULL;
return H5_SUCCESS;
}
h5part_int64_t
h5_close_file (
h5_file *f
) {
herr_t r = 0;
h5_set_errno ( H5_SUCCESS );
CHECK_FILEHANDLE ( f );
_h5_close_step ( f );
_h5u_close_file ( f );
_h5b_close_file ( f );
_h5t_close_file ( f );
if( f->step_gid >= 0 ) {
r = H5Gclose( f->step_gid );
if ( r < 0 ) HANDLE_H5G_CLOSE_ERR;
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" );
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" );
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" );
f->create_prop = H5P_DEFAULT;
}
if ( f->root_gid >= 0 ) {
r = H5Gclose ( f->root_gid );
if ( r < 0 ) HANDLE_H5G_CLOSE_ERR;
f->root_gid = 0;
}
if ( f->file ) {
r = H5Fclose( f->file );
if ( r < 0 ) HANDLE_H5F_CLOSE_ERR;
f->file = 0;
}
if (f->prefix_step_name) {
free (f->prefix_step_name);
}
free( f );
return h5_get_errno();
}
h5_int64_t
h5_define_stepname_fmt (
h5_file *f,
const char *name,
const h5part_int64_t width
) {
f->prefix_step_name = strdup ( name );
if( f->prefix_step_name == NULL ) {
return HANDLE_H5_NOMEM_ERR;
}
f->width_step_idx = (int)width;
return H5_SUCCESS;
}
h5_err_t
h5_get_stepname_fmt (
h5_file * f,
char *name,
const h5_size_t l_name,
h5_size_t *width
) {
return -1;
}
h5_int64_t
h5_get_step (
h5_file * f
) {
return -1;
}
h5_int64_t
h5_has_step (
h5_file * f,
h5_int64_t step
) {
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 );
}
+1 -1
View File
@@ -3,7 +3,7 @@
#include <hdf5.h>
#include "h5_types.h"
#include "h5_core.h"
#include "h5_private.h"
#include "h5_core_private.h"
h5_err_t
_h5_alloc_smap (
+4 -4
View File
@@ -38,10 +38,10 @@ h5_check_filehandle (
Initialize H5Part
*/
static herr_t
_h5_error_handler ( void* unused ) {
_h5_error_handler ( hid_t estack_id, void* unused ) {
if ( h5_get_debuglevel() >= 5 ) {
H5Eprint (stderr);
H5Eprint (estack_id, stderr);
}
return 0;
}
@@ -52,7 +52,7 @@ _init ( void ) {
herr_t r5;
if ( ! __init ) {
r5 = H5Eset_auto ( _h5_error_handler, NULL );
r5 = H5Eset_auto ( H5E_DEFAULT, _h5_error_handler, NULL );
if ( r5 < 0 ) return H5_ERR_INIT;
}
__init = 1;
@@ -247,7 +247,7 @@ h5_open_file (
HANDLE_H5F_OPEN_ERR ( filename, flags );
goto error_cleanup;
}
f->root_gid = H5Gopen( f->file, "/" );
f->root_gid = H5Gopen( f->file, "/", H5P_DEFAULT );
if ( f->root_gid < 0 ) {
HANDLE_H5G_OPEN_ERR ( "", "" );
goto error_cleanup;
+167 -9
View File
@@ -7,9 +7,7 @@
#include <hdf5.h>
#include "h5_core.h"
#include "h5_private.h"
#include "H5Part.h"
#include "H5Block.h"
#include "h5_core_private.h"
h5part_int64_t
h5_write_data (
@@ -32,7 +30,7 @@ h5_write_data (
name,
type,
shape,
H5P_DEFAULT );
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT );
if ( dataset_id < 0 )
return HANDLE_H5D_CREATE_ERR ( name );
@@ -54,6 +52,165 @@ h5_write_data (
return H5_SUCCESS;
}
h5_err_t
h5_write_dataset (
h5_file * const f, /*!< IN: Handle to open file */
const hid_t group_id,
const char dataset_name[],/*!< IN: Name to associate data with */
const hid_t type_id, /*!< IN: Type of data */
const hid_t memspace_id,
const hid_t diskspace_id,
const void * const data /*!< IN: Data to commit to disk */
) {
h5_info ( "Writing dataset %s/%s.",
h5_get_objname(group_id), dataset_name );
if ( f->mode == O_RDONLY )
return _h5_handle_file_mode_error( f->mode );
/*
file modes:
H5_O_RDONLY: only reading allowed
H5_O_WRONLY: create new file, dataset must not exist
H5_O_APPEND: allows appendings of new datasets to an existing file
H5_O_RDWR: dataset may exist
*/
H5O_info_t dataset_info;
herr_t herr = H5Oget_info_by_name(
group_id,
dataset_name,
&dataset_info,
H5P_DEFAULT );
if ( (herr >= 0) && ( (f->mode==H5_O_WRONLY) || (f->mode==H5_O_APPEND) ) ) {
h5_warn ( "Dataset %s/%s already exist.",
h5_get_objname(group_id), dataset_name );
return _h5_handle_file_mode_error( f->mode );
}
hid_t dataset_id;
if ( herr >= 0 ) {
dataset_id = H5Dopen (
group_id,
dataset_name,
H5P_DEFAULT );
if ( dataset_id < 0 )
return HANDLE_H5D_OPEN_ERR ( dataset_name );
} else {
dataset_id = H5Dcreate (
group_id,
dataset_name,
type_id,
diskspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT );
if ( dataset_id < 0 )
return HANDLE_H5D_CREATE_ERR ( dataset_name );
}
herr = H5Dwrite (
dataset_id,
type_id,
memspace_id,
diskspace_id,
f->xfer_prop,
data );
if ( herr < 0 ) return HANDLE_H5D_WRITE_ERR ( dataset_name );
herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
f->empty = 0;
return H5_SUCCESS;
}
h5_err_t
h5_read_dataset2 (
h5_file * const f,
hid_t group_id,
const char dataset_name[],
hid_t type_id,
hid_t (*set_memspace)(h5_file*,hid_t),
hid_t (*set_diskspace)(h5_file*,hid_t),
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 );
hid_t memspace_id = (*set_memspace)( f, dataset_id );
if ( memspace_id < 0 ) return memspace_id;
hid_t diskspace_id = (*set_diskspace)( f, dataset_id );
if ( diskspace_id < 0 ) return diskspace_id;
h5_err_t h5err = _h5_read_dataset (
f,
dataset_id,
type_id,
memspace_id,
diskspace_id,
data );
if ( h5err < 0 ) return h5err;
herr_t herr = H5Sclose ( diskspace_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
herr = H5Sclose ( memspace_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
return H5_SUCCESS;
}
h5_err_t
h5_read_dataset (
h5_file *f,
hid_t group_id,
const char dataset_name[],
hid_t type_id,
hid_t memspace_id,
hid_t diskspace_id,
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 );
h5_err_t h5err = _h5_read_dataset (
f,
dataset_id,
type_id,
memspace_id,
diskspace_id,
data );
if ( h5err < 0 ) return h5err;
herr_t herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
return H5_SUCCESS;
}
h5_err_t
_h5_read_dataset (
h5_file * const f,
hid_t dataset_id,
hid_t type_id,
hid_t memspace_id,
hid_t diskspace_id,
void * const data ) {
herr_t herr = H5Dread (
dataset_id,
type_id,
memspace_id,
diskspace_id,
f->xfer_prop,
data );
if ( herr < 0 )
return HANDLE_H5D_READ_ERR ( h5_get_objname ( dataset_id ) );
return H5_SUCCESS;
}
/*!
\ingroup h5part_kernel
@@ -191,7 +348,8 @@ _create_step (
(long long)f->step_idx,
(long long)(size_t) f );
f->is_new_step = 1;
f->step_gid = H5Gcreate ( f->file, f->step_name, 0 );
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 );
@@ -208,9 +366,9 @@ _open_step (
(long long)f->step_idx,
(long long)(size_t) f );
f->is_new_step = 0;
f->step_gid = H5Gopen ( f->file, f->step_name );
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->step_name );
return H5_SUCCESS;
}
@@ -258,7 +416,7 @@ _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->step_name );
herr = _open_step ( f );
if ( herr < 0 ) return herr;
} else if ( (f->mode == H5_O_WRONLY) || (f->mode == H5_O_APPEND) ) {
@@ -328,7 +486,7 @@ h5_get_dataset_type(
hid_t group_id,
const char *dataset_name
) {
hid_t dataset_id = H5Dopen ( group_id, dataset_name );
hid_t dataset_id = H5Dopen ( group_id, dataset_name, H5P_DEFAULT );
if ( dataset_id < 0 ) HANDLE_H5D_OPEN_ERR ( dataset_name );
hid_t hdf5_type = H5Dget_type ( dataset_id );
+12
View File
@@ -13,6 +13,18 @@ h5_write_data (
const hid_t diskshape
) ;
h5_err_t
h5_write_dataset (
h5_file * const f,
const hid_t group_id,
const char dataset_name[],
const hid_t type_id,
const hid_t memspace_id,
const hid_t diskspace_id,
const void * const data
) ;
h5part_int64_t
h5_get_num_objects (
hid_t group_id,
+73 -32
View File
@@ -8,6 +8,7 @@
#include <fcntl.h>
#define H5_SUCCESS 0
#define H5_ERR_BADF -9
#define H5_ERR_NOMEM -12
#define H5_ERR_INVAL -22
#define H5_ERR_BADFD -77
@@ -23,10 +24,12 @@
#define H5_ERR_INTERNAL -253
#define H5_ERR_NOT_IMPLEMENTED -254
#define H5_O_RDONLY 0x01
#define H5_O_WRONLY 0x02
#define H5_O_APPEND 0x03
#define H5_O_RDWR 0x04
#define H5_O_RDWR 0
#define H5_O_RDONLY 1
#define H5_O_WRONLY 2
#define H5_O_APPEND 3
extern const char * const H5_O_MODES[];
#ifdef WIN32
typedef __int64 int64_t;
@@ -49,18 +52,24 @@ struct h5_complex {
};
typedef struct h5_complex h5_complex;
enum h5_mesh_types { /* enum with number of vertices(!) */
TRIANGLE_MESH = 3,
TETRAHEDRAL_MESH = 4
enum h5_oid { /* enum with number of vertices(!) */
H5_OID_VERTEX = 1,
H5_OID_EDGE = 2,
H5_OID_TRIANGLE = 3,
H5_OID_TETRAHEDRON = 4
};
#define H5_MAX_VERTICES_PER_ENTITY TETRAHEDRAL_MESH
typedef enum h5_oid h5_oid_t;
#define H5_MAX_VERTICES_PER_ENTITY H5_OID_TETRAHEDRON
struct h5_vertex { /* 32Byte */
h5_id_t id;
h5_id_t unused; /* for right alignment */
h5_float64_t P[3];
};
typedef struct h5_vertex h5_vertex;
typedef struct h5_vertex h5_vertex_t;
struct h5_edge { /* 16Bytes */
h5_id_t id;
@@ -69,6 +78,8 @@ struct h5_edge { /* 16Bytes */
h5_id_t unused; /* for right alignment */
h5_id_t vertex_ids[2];
};
typedef struct h5_edge h5_edge;
typedef struct h5_edge h5_edge_t;
struct h5_triangle { /*24Bytes*/
h5_id_t id;
@@ -76,7 +87,8 @@ struct h5_triangle { /*24Bytes*/
h5_id_t vertex_ids[3];
h5_id_t refined_on_level;
};
typedef struct h5_triangle h5_triangle;
typedef struct h5_triangle h5_triangle_t;
struct h5_tetrahedron { /* 24Bytes */
h5_id_t id;
@@ -85,6 +97,8 @@ struct h5_tetrahedron { /* 24Bytes */
h5_id_t unused; /* for right alignment */
h5_id_t vertex_ids[4];
};
typedef struct h5_tetrahedron h5_tetrahedron;
typedef struct h5_tetrahedron h5_tetrahedron_t;
struct h5_ltriangle {
h5_id_t vertex_ids[3]; /* local(!) vertex ids */
@@ -94,16 +108,18 @@ struct h5_ltetrahedron {
h5_id_t vertex_ids[4]; /* local(!) vertex ids */
};
typedef struct h5_vertex h5_vertex;
typedef struct h5_edge h5_edge;
typedef struct h5_triangle h5_triangle;
typedef struct h5_tetrahedron h5_tetrahedron;
typedef h5_err_t (*h5_error_handler)( const char*, const h5_err_t, const char*,...)
#ifdef __GNUC__
__attribute__ ((format (printf, 3, 4)))
__attribute__ ((format (printf, 3, 4)))
#endif
;
;
typedef h5_err_t (*h5_verror_handler)(
const char*,
const h5_err_t,
const char*,
va_list ap );
typedef h5_error_handler h5part_error_handler;
@@ -157,9 +173,6 @@ struct h5b_fdata {
hid_t field_group_id;
};
struct h5t_fdata_level {
};
union entities {
struct h5_tetrahedron *tets;
struct h5_triangle *tris;
@@ -187,26 +200,48 @@ struct idmap {
} *items;
};
struct boundary {
char name[16];
char label[256];
h5_id_t id; /* name of boundary as integer */
h5_id_t changed; /* true if boundary is new or
has been changed */
h5_id_t gid; /* hdf5 grp id boundary */
h5_id_t *faces;
h5_id_t *lfaces;
h5_size_t *num_faces; /* addit. num of faces per level */
h5_size_t *num_faces_on_level; /* real num of faces per level */
h5_id_t last_accessed_face;
};
typedef struct boundary boundary_t;
struct h5t_fdata {
/*** book-keeping ***/
char mesh_name[16];
enum h5_mesh_types mesh_type;
char mesh_label[256];
enum h5_oid mesh_type;
h5_id_t cur_mesh;
h5_id_t new_mesh; /* idx of the first new mesh or -1 */
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 ... */
h5_id_t cur_level;
h5_id_t new_level; /* idx of the first new level or -1 */
h5_size_t num_levels;
/*** vertices ***/
h5_vertex *vertices;
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;
/*** Entities ***/
union entities entities;
union lentities lentities;
hid_t entity_tid; /* type of mesh: tetrahedral, triangle ... */
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 */
@@ -219,20 +254,25 @@ struct h5t_fdata {
h5_id_t last_retrieved_entity_id;
h5_id_t last_stored_entity_id;
/* HDF5 objects */
/*** Boundary Meshes ***/
h5_id_t num_boundaries; /* number of boundaries */
h5_id_t boundaries_gid; /* hdf5 grp id container group */
hid_t topo_gid; /* grp id of mesh in current level */
boundary_t boundary;
/*** HDF5 objects ***/
hid_t topo_gid; /* grp id of mesh in current level */
hid_t meshes_gid;
hid_t mesh_gid;
/* type ids' for compound types */
hid_t float64_3tuple_tid;
hid_t int32_2tuple_tid;
hid_t int32_3tuple_tid;
hid_t int32_4tuple_tid;
hid_t vertex_tid;
hid_t triangle_tid;
hid_t tet_tid;
/*** type ids' for compound types ***/
hid_t float64_3tuple_tid; /* 3-tuple of 64-bit float */
hid_t int32_2tuple_tid; /* 2-tuple of 32-bit int */
hid_t int32_3tuple_tid; /* 3-tuple of 32-bit int */
hid_t int32_4tuple_tid; /* 4-tuple of 32-bit int */
hid_t vertex_tid; /* vertex structure */
hid_t triangle_tid; /* triangle structure */
hid_t tet_tid; /* tetrahedron structure */
};
/**
@@ -302,5 +342,6 @@ struct h5_file {
};
typedef struct h5_file h5_file;
typedef struct h5_file h5_file_t;
typedef struct h5_file H5PartFile;
#endif
+352 -4
View File
@@ -1,12 +1,360 @@
#include <hdf5.h>
#include "h5/h5_core.h"
#include "h5/h5_core_private.h"
#include "h5_core/h5_core.h"
#include "h5_core/h5_core_private.h"
static h5_err_t
_open_boundaries_group (
h5_file * const f
) {
struct h5t_fdata *t = &f->t;
if ( t->cur_mesh < 0 )
return _h5t_error_undef_mesh ( f );
TRY( (t->boundaries_gid = _h5_open_group (
f, t->mesh_gid, H5T_BOUNDARYMESH_GRPNAME )), error_exit );
return H5_SUCCESS;
error_exit:
return h5_get_errno();
}
static h5_err_t
_open_boundary_group (
h5_file * const f
) {
struct h5t_fdata *t = &f->t;
boundary_t *boundary = &t->boundary;
if ( t->cur_mesh < 0 )
return _h5t_error_undef_mesh ( f );
if ( t->boundaries_gid < 0 ) {
TRY( _open_boundaries_group ( f ), error_exit );
}
boundary->gid = _h5_open_group (
f, t->boundaries_gid, boundary->name );
return H5_SUCCESS;
error_exit:
return h5_get_errno();
}
h5_id_t
h5t_get_num_boundaries (
h5_file * const f
) {
struct h5t_fdata *t = &f->t;
if ( t->cur_mesh < 0 )
return _h5t_error_undef_mesh ( f );
if ( t->num_boundaries < 0 ) {
t->num_boundaries = h5_get_num_objects (
t->mesh_gid,
H5T_BOUNDARYMESH_GRPNAME,
H5G_GROUP );
}
if ( t->num_boundaries < 0 ) t->num_boundaries = 0;
return t->num_boundaries;
}
h5_err_t
h5t_add_boundary (
h5_file *f,
h5t_set_boundary_label (
h5_file * const f,
const char * const bname
) {
return -1;
}
h5_err_t
h5t_get_boundary_label (
h5_file * const f,
char * const boundary_name,
const size_t size
) {
return -1;
}
h5_err_t
h5t_open_boundary (
h5_file * const f,
const h5_id_t boundary_id
) {
struct h5t_fdata *t = &f->t;
boundary_t *boundary = &t->boundary;
TRY( h5t_close_boundary ( f ), error_exit );
if ( t->num_boundaries < 0 ) {
TRY( h5t_get_num_boundaries ( f ), error_exit );
}
if ( (boundary_id < -1) || (boundary_id >= t->num_boundaries) ) {
return HANDLE_H5_OUT_OF_RANGE_ERR( "boundary", boundary_id );
}
if ( boundary_id == -1 ) { /* append new boundary */
boundary->id = t->num_boundaries++;
boundary->changed = boundary_id;
} else {
boundary->id = boundary_id;
}
snprintf ( boundary->name, sizeof (boundary->name),
"%d", boundary->id );
TRY( _open_boundary_group ( f ), error_exit );
return H5_SUCCESS;
error_exit:
return h5_get_errno();
}
h5_err_t
h5t_open_boundary_with_label (
h5_file * const f,
const char * const boundary_label
) {
return -1;
}
h5_err_t
_h5t_read_boundaryfaces (
h5_file * const f
) {
struct h5t_fdata *t = &f->t;
boundary_t *boundary = &t->boundary;
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 );
hid_t diskspace_id = H5Dget_space(dataset_id);
if ( diskspace_id < 0 ) return (hid_t)HANDLE_H5D_GET_SPACE_ERR;
h5_id_t num_faces = H5Sget_simple_extent_npoints ( diskspace_id );
if ( num_faces < 0 )
return HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR;
herr_t herr = H5Sclose ( diskspace_id );
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR;
herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
h5t_add_num_boundaryfaces ( f, num_faces );
h5_err_t h5err = _h5_read_dataset (
f,
dataset_id,
H5T_NATIVE_INT32,
H5S_ALL,
H5S_ALL,
boundary->faces );
if ( h5err < 0 ) return h5err;
herr = H5Dclose ( dataset_id );
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR;
return H5_SUCCESS;
}
h5_err_t
_h5t_write_boundary (
h5_file * const f
) {
struct h5t_fdata *t = &f->t;
boundary_t *boundary = &t->boundary;
hsize_t maxdim = H5S_UNLIMITED;
return _h5t_write_obj (
f,
boundary->gid,
boundary->num_faces[0],
maxdim,
H5T_NATIVE_INT32,
(void*)boundary->faces,
"Faces"
);
}
h5_err_t
h5t_close_boundary (
h5_file * const f
) {
struct h5t_fdata *t = &f->t;
boundary_t *boundary = &t->boundary;
if ( boundary->changed ) {
h5_err_t h5err = _h5t_write_boundary ( f );
if ( h5err < 0 ) return h5err;
}
if ( boundary->faces ) free ( boundary->faces );
if ( boundary->lfaces ) free ( boundary->faces );
if ( boundary->num_faces ) free ( boundary->num_faces );
if ( boundary->num_faces_on_level ) free ( boundary->num_faces_on_level );
bzero ( boundary, sizeof(*boundary) );
TRY( _h5_close_group( boundary->gid ), exception);
boundary->id = -1;
boundary->gid = -1;
boundary->last_accessed_face = -1;
return H5_SUCCESS;
exception:
return h5_get_errno();
}
h5_err_t
h5t_add_num_boundaryfaces (
h5_file * const f,
const h5_id_t num_faces
) {
struct h5t_fdata *t = &f->t;
boundary_t *boundary = &t->boundary;
boundary->num_faces = realloc (
boundary->num_faces,
t->num_levels*sizeof(boundary->num_faces[0]) );
boundary->num_faces_on_level = realloc (
boundary->num_faces_on_level,
t->num_levels*sizeof(boundary->num_faces_on_level[0]) );
boundary->faces = realloc (
boundary->faces,
num_faces*sizeof(boundary->faces[0]) );
boundary->lfaces = realloc (
boundary->lfaces,
num_faces*sizeof(boundary->lfaces[0]) );
if ( boundary->num_faces == NULL ||
boundary->num_faces_on_level == NULL ||
boundary->faces == NULL ||
boundary->lfaces == NULL ) {
return HANDLE_H5_NOMEM_ERR;
}
memset ( boundary->num_faces,
0, t->num_levels*sizeof(boundary->num_faces[0]) );
memset ( boundary->num_faces_on_level,
0, t->num_levels*sizeof(boundary->num_faces_on_level[0]) );
memset ( boundary->faces,
-1, num_faces*sizeof(boundary->faces[0]) );
memset (
boundary->lfaces,
0, num_faces*sizeof(boundary->lfaces[0]) );
boundary->num_faces[0] = num_faces;
boundary->last_accessed_face = -1;
return H5_SUCCESS;
}
/*!
Number of boundary faces in current level
*/
h5_id_t
h5t_get_num_boundaryfaces (
h5_file * const f
) {
return -1;
}
h5_id_t
h5t_store_boundaryface (
h5_file * const f,
h5_id_t * const global_vids
) {
struct h5t_fdata *t = &f->t;
if ( t->vertices == NULL ) {
h5_err_t h5err = _h5t_read_mesh ( f );
if ( h5err < 0 ) return h5err;
}
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON: {
h5_id_t local_vids[3];
h5_err_t h5err = h5t_map_global_vertex_ids2local (
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_store_boundaryface_local_id ( f, local_tid );
}
default:
return -1;
}
}
h5_id_t
h5t_store_boundaryface_global_id (
h5_file * const f,
const h5_id_t global_fid
) {
struct h5t_fdata *t = &f->t;
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON: {
h5_id_t local_tid = h5t_map_global_triangle_id2local (
f, global_fid );
if ( local_tid < 0 ) return local_tid;
return h5t_store_boundaryface_local_id ( f, local_tid );
}
default:
return -1;
}
}
h5_id_t
h5t_store_boundaryface_local_id (
h5_file * const f,
const h5_id_t local_fid
) {
struct h5t_fdata *t = &f->t;
boundary_t *boundary = &t->boundary;
if ( boundary->num_faces == NULL )
return HANDLE_H5_OVERFLOW_ERR (
"boundary faces",
-1 );
if ( ++(boundary->last_accessed_face) >= boundary->num_faces[0] )
return HANDLE_H5_OVERFLOW_ERR (
"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 ) {
return _h5t_error_store_boundaryface_local_id (
local_fid );
}
h5_id_t global_tid = h5t_map_local_triangle_id2global(
f, local_fid );
boundary->faces[boundary->last_accessed_face] = global_tid;
return H5_SUCCESS;
}
default:
return -1;
}
}
h5_err_t
h5t_start_traverse_boundary_faces (
h5_file * const f
) {
struct h5t_fdata *t = &f->t;
boundary_t *boundary = &t->boundary;
if ( boundary->faces == NULL ) {
TRY( _h5t_read_boundaryfaces ( f ), error_exit );
}
boundary->last_accessed_face = -1;
error_exit:
return h5_get_errno();
}
h5_id_t
h5t_traverse_boundary_faces (
h5_file * const f,
h5_id_t * const global_id,
h5_id_t * const parent_id,
h5_id_t vertex_ids[]
) {
return -1;
}
+51 -5
View File
@@ -1,10 +1,56 @@
#ifndef __T_BOUNDARIES_H
#define __T_BOUNDARIES_H
#ifndef __H5T_BOUNDARIES_H
#define __H5T_BOUNDARIES_H
h5_err_t
h5t_add_boundary (
h5_file *f,
const char * const bname
h5t_open_boundary (
h5_file * const f,
const h5_id_t boundary_id
);
h5_err_t
h5t_close_boundary (
h5_file * const f
);
h5_err_t
h5t_add_num_boundaryfaces (
h5_file * const f,
const h5_id_t num
);
h5_id_t
h5t_get_num_boundaryfaces (
h5_file * const f
);
h5_id_t
h5t_store_boundaryface (
h5_file * const f,
h5_id_t * const vertices
);
h5_id_t
h5t_store_boundaryface_global_id (
h5_file * const f,
const h5_id_t global_fid
);
h5_id_t
h5t_store_boundaryface_local_id (
h5_file * const f,
const h5_id_t local_fid
);
h5_err_t
h5t_start_traverse_boundary_faces (
h5_file * const f
);
h5_id_t
h5t_traverse_boundary_faces (
h5_file * const f,
h5_id_t * const global_id,
h5_id_t * const parent_id,
h5_id_t vertex_ids[]
);
#endif
+44 -12
View File
@@ -7,7 +7,15 @@
#include <hdf5.h>
#include "h5_core.h"
#include "h5_private.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 (
@@ -16,12 +24,13 @@ _h5t_handle_get_global_entity_id_err (
) {
struct h5t_fdata *t = &f->t;
switch ( t->mesh_type ) {
case TETRAHEDRAL_MESH:
return _h5t_handle_get_global_tet_id_err ( global_vids );
case TRIANGLE_MESH:
return _h5t_handle_get_global_tri_id_err ( global_vids );
case H5_OID_TETRAHEDRON:
return _h5t_error_global_tet_id_nexist ( global_vids );
case H5_OID_TRIANGLE:
return _h5t_error_global_tri_id_nexist ( global_vids );
default:
return h5_error_internal( __FILE__, __func__, __LINE__ );
}
return -1;
}
h5_err_t
@@ -31,11 +40,34 @@ _h5t_handle_get_local_entity_id_err (
) {
struct h5t_fdata *t = &f->t;
switch ( t->mesh_type ) {
case TETRAHEDRAL_MESH:
return _h5t_handle_get_local_tet_id_err ( local_vids );
case TRIANGLE_MESH:
return _h5t_handle_get_local_triangle_id_err ( local_vids );
case H5_OID_TETRAHEDRON:
return _h5t_error_local_tet_id_nexist ( local_vids );
case H5_OID_TRIANGLE:
return _h5t_error_local_triangle_id_nexist ( local_vids );
default:
return h5_error_internal( __FILE__, __func__, __LINE__ );
}
}
h5_err_t
_h5t_error_illegal_object_type (
h5_file_t * const f,
h5_oid_t oid ) {
struct h5t_fdata *t = &f->t;
switch ( t->mesh_type ) {
case H5_OID_TETRAHEDRON:
return h5_error_internal( __FILE__, __func__, __LINE__ );
case H5_OID_TRIANGLE:
switch ( oid ) {
case H5_OID_TETRAHEDRON:
return h5_error (
H5_ERR_INVAL,
"Illegal topological entity tetrahedron"
" in triangle mesh." );
default:
return h5_error_internal( __FILE__, __func__, __LINE__ );
}
default:
return h5_error_internal( __FILE__, __func__, __LINE__ );
}
return -1;
}
+41 -31
View File
@@ -1,5 +1,6 @@
#ifndef __T_ERRORHANDLING_H
#define __T_ERRORHANDLING_H
#ifndef __H5T_ERRORHANDLING_PRIVATE_H
#define __H5T_ERRORHANDLING_PRIVATE_H
h5_err_t
_h5t_handle_get_global_entity_id_err (
@@ -13,53 +14,62 @@ _h5t_handle_get_local_entity_id_err (
const h5_id_t * const local_vids
);
#define H5T_HANDLE_GID_NOT_EXIST_ERR( name, id ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_NOENTRY, \
"Global %s id %ld does not exist!", \
h5_err_t
_h5t_error_illegal_object_type (
h5_file_t * const f,
h5_oid_t oid );
#define _h5t_error_undef_mesh( f ) \
h5_error( \
H5_ERR_INVAL, \
"Mesh not yet defined." );
#define _h5t_error_undef_level( f ) \
h5_error( \
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!", \
name, (long)id );
#define _h5t_handle_global_id_not_exist_err( name, id ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_NOENTRY, \
"%s with global id %ld does not exist!", \
name, (long)id );
#define _h5t_handle_get_global_tet_id_err( vids ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
#define _h5t_error_global_tet_id_nexist( vids ) \
h5_error( \
H5_ERR_NOENTRY, \
"Tetrahedron with global vertex ids (%d,%d,%d,%d) doesn't exist!", \
vids[0], vids[1], vids[2], vids[3] );
#define _h5t_handle_get_global_tri_id_err( vids ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_NOENTRY, \
#define _h5t_error_global_tri_id_nexist( vids ) \
h5_error( \
H5_ERR_NOENTRY, \
"Triangle with global vertex ids (%d,%d,%d) doesn't exist!", \
vids[0], vids[1], vids[2] );
#define _h5t_handle_get_local_tet_id_err( vids ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_NOENTRY, \
#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!", \
vids[0], vids[1], vids[2], vids[3] );
#define _h5t_handle_get_local_triangle_id_err( vids ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
#define _h5t_error_local_triangle_id_nexist( vids ) \
h5_error( \
H5_ERR_NOENTRY, \
"Triangle with local vertex ids (%d,%d,%d) doesn't exist!", \
vids[0], vids[1], vids[2] );
#define _h5t_handle_get_global_triangle_id_err( vids ) \
(*h5_get_errorhandler()) ( \
h5_get_funcname(), \
H5_ERR_NOENTRY, \
#define _h5t_error_global_triangle_id_nexist( vids ) \
h5_error( \
H5_ERR_NOENTRY, \
"Triangle with global vertex ids (%d,%d,%d) 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!", \
local_fid );
#endif
+118 -92
View File
@@ -1,8 +1,67 @@
#include <hdf5.h>
#include "h5/h5_core.h"
#include "h5/h5_private.h"
#include "h5/t_map.h"
#include "h5_core/h5_core.h"
#include "h5_core/h5_core_private.h"
/*!
Compare to vertices given by their 3-dimensional coordinates
*/
static int
_cmp_vertices (
h5_float64_t *P1,
h5_float64_t *P2
) {
int i;
for ( i = 0; i < 3; i++ ) {
if ( P1[i] < P2[i] ) return -1;
else if (P1[i] > P2[i] )return 1;
}
return 0;
}
static int
_qsort_cmp_vertices (
void * _f,
const void* _local_vid1,
const void* _local_vid2
) {
h5_file *f = (h5_file*)_f;
h5_id_t local_vid1 = *(h5_id_t*)_local_vid1;
h5_id_t local_vid2 = *(h5_id_t*)_local_vid2;
return _cmp_vertices (
f->t.vertices[local_vid1].P,
f->t.vertices[local_vid2].P );
}
/*!
We assume that the number of vertices is already known.
*/
h5_err_t
_h5t_sort_vertices (
h5_file_t * const f
) {
struct h5t_fdata *t = &f->t;
h5_id_t num_vertices = t->num_vertices[t->num_levels-1];
h5_id_t i;
for ( i = 0; i < num_vertices; i++ ) {
t->sorted_lvertices.items[i] = i;
}
t->sorted_lvertices.num_items = num_vertices;
_h5_qsort_r (
t->sorted_lvertices.items,
num_vertices,
sizeof(t->sorted_lvertices.items[0]),
f,
_qsort_cmp_vertices );
return H5_SUCCESS;
}
/*!
Returns the local vertex id of the i-th vertex of an entity. For triangles
@@ -21,7 +80,7 @@ _get_local_vertex_id_of_entity (
h5_id_t global_vid = -1;
switch ( t->mesh_type ) {
case TETRAHEDRAL_MESH: {
case H5_OID_TETRAHEDRON: {
local_vid = t->lentities.tets[local_eid].vertex_ids[ith_vertex];
if ( local_vid == -1 ) {
global_vid =
@@ -33,7 +92,7 @@ _get_local_vertex_id_of_entity (
}
break;
}
case TRIANGLE_MESH: {
case H5_OID_TRIANGLE: {
local_vid = t->lentities.tris[local_eid].vertex_ids[ith_vertex];
if ( local_vid == -1 ) {
global_vid =
@@ -45,6 +104,8 @@ _get_local_vertex_id_of_entity (
}
break;
}
default:
return h5_error_internal ( __FILE__, __func__, __LINE__ );
}
return local_vid;
}
@@ -69,21 +130,7 @@ _get_vertex_of_entity (
return t->vertices[local_vid].P;
}
/*!
Compare to vertices given by their 3-dimensional coordinates
*/
static int
_cmp_vertices (
h5_float64_t *P1,
h5_float64_t *P2
) {
int i;
for ( i = 0; i < 3; i++ ) {
if ( P1[i] < P2[i] ) return -1;
else if (P1[i] > P2[i] )return 1;
}
return 0;
}
/*!
Compare two entities given by their local vertex ids
@@ -147,29 +194,36 @@ _cmp_entities1 (
return 0;
}
/*
The re-rentrant version of qsort(3) is not available on many systems, thus ...
*/
static h5_file *_f;
static int
_qsort_cmp_entities0 ( const void* _local_eid1, const void* _local_eid2 ) {
_qsort_cmp_entities0 (
void *_f,
const void* _local_eid1,
const void* _local_eid2
) {
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_entities ( f, local_eid1, local_eid2 );
}
static int
_qsort_cmp_entities1 ( const void* _local_eid1, const void* _local_eid2 ) {
_qsort_cmp_entities1 (
void *_f,
const void* _local_eid1,
const void* _local_eid2
) {
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_entities1 ( f, local_eid1, local_eid2 );
}
/*!
Sort entities geometrically.
*/
static h5_err_t
_sort_entities (
h5_err_t
_h5t_sort_entities (
h5_file *f
) {
@@ -189,14 +243,17 @@ _sort_entities (
t->sorted_lentities[k].num_items = num_entities;
}
_f = f;
qsort ( t->sorted_lentities[0].items,
_h5_qsort_r (
t->sorted_lentities[0].items,
num_entities,
sizeof(t->sorted_lentities[0].items[0]),
f,
_qsort_cmp_entities0 );
qsort ( t->sorted_lentities[1].items,
_h5_qsort_r (
t->sorted_lentities[1].items,
num_entities,
sizeof(t->sorted_lentities[1].items[0]),
f,
_qsort_cmp_entities1 );
return H5_SUCCESS;
@@ -290,28 +347,6 @@ _search_entity (
return -(low+1); // not found
}
h5_err_t
_h5t_read_mesh (
h5_file *f
) {
struct h5t_fdata *t = &f->t;
if ( t->vertices == NULL ) {
h5_err_t h5err = _h5t_read_vertices ( f );
if ( h5err < 0 ) return h5err;
}
if ( t->entities.data == NULL ) {
h5_err_t h5err = _h5t_read_entities ( f );
if ( h5err < 0 ) return h5err;
}
if ( t->sorted_lentities[0].items == NULL ) {
_sort_entities ( f );
}
return H5_SUCCESS;
}
/*!
Get local id of entity given by local vertex id's
*/
@@ -342,7 +377,7 @@ 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_handle_global_id_not_exist_err ("vertex", global_id );
return _h5t_error_global_id_nexist ("vertex", global_id );
return local_id;
}
@@ -371,7 +406,7 @@ h5t_map_global_vertex_ids2local (
local_vids[i] = h5t_map_global_vertex_id2local (
f, global_vids[i] );
if ( local_vids[i] < 0 )
return _h5t_handle_global_id_not_exist_err (
return _h5t_error_global_id_nexist (
"vertex", global_vids[i] );
}
return H5_SUCCESS;
@@ -388,16 +423,17 @@ h5t_map_local_entity_id2global (
struct h5t_fdata *t = &f->t;
switch ( t->mesh_type ) {
case TETRAHEDRAL_MESH:
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;
case TRIANGLE_MESH:
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;
default:
return h5_error_internal ( __FILE__, __func__, __LINE__ );
}
return -1;
}
/*!
@@ -571,20 +607,21 @@ h5t_get_global_triangle_id (
}
switch ( t->mesh_type ) {
case TETRAHEDRAL_MESH: {
case H5_OID_TETRAHEDRON: {
h5_id_t local_vids[3];
h5_err_t h5err = h5t_map_global_vertex_ids2local (
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_handle_get_global_triangle_id_err( global_vids );
return _h5t_error_global_triangle_id_nexist ( global_vids );
return h5t_map_local_triangle_id2global ( f, local_tid );
}
case TRIANGLE_MESH:
case H5_OID_TRIANGLE:
return h5t_get_global_entity_id ( f, global_vids );
default:
return h5_error_internal ( __FILE__, __func__, __LINE__ );
}
return -1;
}
/*!
@@ -598,33 +635,20 @@ h5t_get_local_triangle_id (
struct h5t_fdata *t = &f->t;
switch ( t->mesh_type ) {
case TETRAHEDRAL_MESH: {
struct h5t_fdata *t = &f->t;
if ( t->vertices == NULL ) {
h5_err_t h5err = _h5t_read_vertices ( f );
if ( h5err < 0 ) return h5err;
}
if ( t->entities.data == NULL ) {
h5_err_t h5err = _h5t_read_entities ( f );
if ( h5err < 0 ) return h5err;
}
if ( t->sorted_lentities[0].items == NULL ) {
_sort_entities ( f );
}
case H5_OID_TETRAHEDRON: {
h5_err_t h5err = _h5t_read_mesh ( f );
if ( h5err < 0 ) return h5err;
h5_id_t local_tid = _tetm_search_triangle ( f, local_vids );
if ( local_tid == -1 ) {
return _h5t_handle_get_local_triangle_id_err (
local_vids );
return _h5t_error_local_triangle_id_nexist(local_vids);
}
return local_tid;
}
case TRIANGLE_MESH:
case H5_OID_TRIANGLE:
return h5t_get_local_entity_id ( f, local_vids );
default:
return h5_error_internal ( __FILE__, __func__, __LINE__ );
}
return -1;
}
h5_id_t
@@ -635,7 +659,7 @@ h5t_map_global_entity_id2local (
struct h5t_fdata *t = &f->t;
h5_id_t local_eid = _h5_search_idmap ( &t->map_entity_g2l, global_eid );
if ( local_eid < 0 )
return _h5t_handle_global_id_not_exist_err ( "entity", global_eid );
return _h5t_error_global_id_nexist ( "entity", global_eid );
return local_eid;
}
@@ -651,19 +675,20 @@ h5t_map_global_triangle_id2local (
) {
struct h5t_fdata *t = &f->t;
switch ( t->mesh_type ) {
case TETRAHEDRAL_MESH: {
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 (
f, global_tet_id );
if ( local_tet_id < 0 )
return _h5t_handle_global_id_not_exist_err (
return _h5t_error_global_id_nexist (
"triangle", global_tri_id );
return local_tet_id | (global_tri_id & ~H5_TET_MASK);
}
case TRIANGLE_MESH:
case H5_OID_TRIANGLE:
return h5t_map_global_entity_id2local ( f, global_tri_id );
default:
return h5_error_internal ( __FILE__, __func__, __LINE__ );
}
return -1;
}
/*!
@@ -678,7 +703,7 @@ h5t_map_local_triangle_id2global (
) {
struct h5t_fdata *t = &f->t;
switch ( t->mesh_type ) {
case TETRAHEDRAL_MESH: {
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 (
f, local_tet_id );
@@ -687,8 +712,9 @@ h5t_map_local_triangle_id2global (
"triangle", local_tri_id );
return global_tet_id | (local_tri_id & ~H5_TET_MASK);
}
case TRIANGLE_MESH:
case H5_OID_TRIANGLE:
return h5t_map_local_entity_id2global ( f, local_tri_id );
default:
return h5_error_internal ( __FILE__, __func__, __LINE__ );
}
return -1;
}
+12 -2
View File
@@ -3,16 +3,26 @@
h5_err_t
_h5t_sort_global_vertex_ids (
h5_file * const f,
h5_file_t * const f,
h5_id_t * const global_vids,
const h5_size_t size
);
h5_err_t
_h5t_sort_local_vertex_ids (
h5_file * const f,
h5_file_t * const f,
h5_id_t * const local_vids,
const h5_size_t size
);
h5_err_t
_h5t_sort_vertices (
h5_file_t * const f
);
h5_err_t
_h5t_sort_entities (
h5_file_t * const f
);
#endif
+225 -8
View File
@@ -7,9 +7,8 @@
#include <fcntl.h>
#include <hdf5.h>
#include "h5/h5_core.h"
#include "h5/h5_private.h"
#include "H5Part.h"
#include "h5_core/h5_core.h"
#include "h5_core/h5_core_private.h"
/*
create several HDF5 types
@@ -21,28 +20,28 @@ _create_array_types (
struct h5t_fdata *t = &f->t;
hsize_t dims[1] = { 3 };
hid_t hid = H5Tarray_create ( H5T_NATIVE_DOUBLE, 1, dims, NULL);
hid_t hid = H5Tarray_create ( H5T_NATIVE_DOUBLE, 1, dims );
if ( hid < 0 ) {
return HANDLE_H5T_ARRAY_CREATE_ERR ( "H5T_NATIVE_DOUBLE", 1 );
}
t->float64_3tuple_tid = hid;
dims[0] = 2;
hid = H5Tarray_create ( H5T_NATIVE_INT32, 1, dims, NULL );
hid = H5Tarray_create ( H5T_NATIVE_INT32, 1, dims );
if ( hid < 0 ) {
return HANDLE_H5T_ARRAY_CREATE_ERR ( "H5T_NATIVE_INT32", 1 );
}
t->int32_2tuple_tid = hid;
dims[0] = 3;
hid = H5Tarray_create ( H5T_NATIVE_INT32, 1, dims, NULL );
hid = H5Tarray_create ( H5T_NATIVE_INT32, 1, dims );
if ( hid < 0 ) {
return HANDLE_H5T_ARRAY_CREATE_ERR ( "H5T_NATIVE_INT32", 1 );
}
t->int32_3tuple_tid = hid;
dims[0] = 4;
hid = H5Tarray_create ( H5T_NATIVE_INT32, 1, dims, NULL );
hid = H5Tarray_create ( H5T_NATIVE_INT32, 1, dims );
if ( hid < 0 ) {
return HANDLE_H5T_ARRAY_CREATE_ERR ( "H5T_NATIVE_INT32", 1 );
}
@@ -221,6 +220,8 @@ _h5t_init_fdata (
t->topo_gid = -1;
t->meshes_gid = -1;
t->mesh_gid = -1;
t->num_boundaries = -1;
return H5_SUCCESS;
}
@@ -241,7 +242,6 @@ _h5t_open_file (
) {
h5_err_t h5err = H5_SUCCESS;;
f->t.new_mesh = -1;
if (( h5err = _h5t_init_fdata ( f )) < 0 ) return h5err;
if (( h5err = _create_array_types ( f )) < 0 ) return h5err;
@@ -273,3 +273,220 @@ _h5t_close_file (
return h5err;
}
h5_err_t
_h5t_init_step (
h5_file_t * const f
) {
return H5_SUCCESS;
}
/*
- write data
- close HDF5 objects we cannot reuse
- free memory
*/
h5_err_t
_h5t_close_step (
h5_file * f
) {
return H5_SUCCESS;
}
h5_err_t
_h5t_open_topo_group (
h5_file_t * const f
) {
struct h5t_fdata *t = &f->t;
t->topo_gid = _h5_open_group ( f, f->root_gid, H5T_CONTAINER_GRPNAME );
return t->topo_gid;
}
h5_err_t
_h5t_open_meshes_group (
h5_file_t * const f
) {
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 ( t->mesh_type) {
case H5_OID_TETRAHEDRON:
t->meshes_gid = _h5_open_group ( f, t->topo_gid, "TetMeshes" );
break;
case H5_OID_TRIANGLE:
t->meshes_gid = _h5_open_group ( f, t->topo_gid, "TriangleMeshes" );
break;
default:
t->meshes_gid = -1;
}
return (h5_err_t)t->meshes_gid;
}
h5_err_t
_h5t_open_mesh_group (
h5_file_t * const f
) {
struct h5t_fdata *t = &f->t;
if ( t->meshes_gid < 0 ) {
h5_err_t h5err = _h5t_open_meshes_group ( f );
if ( h5err < 0 ) return h5err;
}
t->mesh_gid = _h5_open_group ( f, t->meshes_gid, t->mesh_name );
return (h5_err_t)t->mesh_gid;
}
/*
If the value of parameter \c id is \c -1, a new mesh will be appended.
*/
h5_err_t
h5t_open_mesh (
h5_file_t * const f,
h5_id_t id,
const h5_oid_t type
) {
struct h5t_fdata *t = &f->t;
h5_err_t h5err = _h5t_close_mesh ( f );
if ( h5err < 0 ) return h5err;
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 );
}
if ( id == -1 ) { /* append new mesh */
id = t->num_meshes;
}
t->mesh_type = type;
snprintf ( t->mesh_name, sizeof (t->mesh_name), "%d", id );
switch( type ) {
case H5_OID_TETRAHEDRON:
t->entity_tid = t->tet_tid;
break;
case H5_OID_TRIANGLE:
t->entity_tid = t->triangle_tid;
break;
default:
return -1;
}
h5err = _h5t_open_mesh_group ( f );
if ( h5err < 0 ) return h5err;
t->cur_mesh = id;
if ( id != t->num_meshes ) { /* open existing */
t->num_levels = h5t_get_num_levels ( f );
if ( t->num_levels < 0 ) return t->num_levels;
} else { /* append new */
t->num_meshes++;
t->mesh_changed = id;
t->num_levels = 0;
}
return H5_SUCCESS;
}
static h5_err_t
_close_hdf5_objs (
h5_file_t * const f
) {
return H5_SUCCESS;
}
static h5_err_t
_release_memory (
h5_file_t * const f
) {
struct h5t_fdata *t = &f->t;
if ( t->num_vertices ) {
free ( t->num_vertices );
}
t->num_vertices = NULL;
if ( t->num_entities ) {
free ( t->num_entities );
}
t->num_entities = NULL;
if ( t->num_entities_on_level ) {
free ( t->num_entities_on_level );
}
t->num_entities_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 );
}
t->map_entity_g2l.items = NULL;
if ( t->vertices ) {
free ( t->vertices );
}
t->vertices = NULL;
if ( t->entities.data ) {
free ( t->entities.data );
}
t->entities.data = NULL;
return H5_SUCCESS;
}
h5_err_t
_h5t_close_mesh (
h5_file_t * const f /*!< file handle */
) {
h5_err_t h5err = H5_SUCCESS;
h5err = _h5t_write_mesh ( f );
if ( h5err < 0 ) return h5err;
h5err = _close_hdf5_objs ( f );
if ( h5err < 0 ) return h5err;
h5err = _release_memory ( f );
if ( h5err < 0 ) return h5err;
h5err = h5t_close_boundary ( f );
if ( h5err < 0 ) return h5err;
if (( h5err = _h5t_init_fdata ( f )) < 0 ) return h5err;
return h5err;
}
h5_err_t
h5t_open_level (
h5_file_t * const f,
const h5_id_t id
) {
struct h5t_fdata *t = &f->t;
if ( (id < 0) || (id >= t->num_levels) )
return HANDLE_H5_OUT_OF_RANGE_ERR ( "Level", id );
t->cur_level = id;
t->last_retrieved_vertex_id = -1;
t->last_retrieved_entity_id = -1;
return H5_SUCCESS;
}
+46 -3
View File
@@ -3,16 +3,59 @@
h5_err_t
_h5t_open_file (
h5_file * f /*!< IN: file handle */
h5_file_t * const f
);
h5_err_t
_h5t_close_file (
h5_file *fh /*!< IN: file handle */
h5_file_t * const f
);
h5_err_t
_h5t_init_fdata (
h5_file * f
h5_file_t * const f
);
h5_err_t
h5t_open_mesh (
h5_file_t * const f,
const h5_id_t id,
const h5_oid_t type
);
h5_err_t
_h5t_open_topo_group (
h5_file_t * const f
);
h5_err_t
_h5t_open_meshes_group (
h5_file_t * const f
);
h5_err_t
_h5t_open_mesh_group (
h5_file_t * const f
);
h5_err_t
_h5t_close_mesh (
h5_file_t * const f
);
h5_err_t
h5t_open_level (
h5_file_t * const f,
const h5_id_t id
);
h5_err_t
_h5t_init_step (
h5_file_t * const f
);
h5_err_t
_h5t_close_step (
h5_file_t * const f
);
#endif
File diff suppressed because it is too large Load Diff
+14 -43
View File
@@ -2,31 +2,14 @@
#define __T_READWRITE_H
h5_err_t
_h5t_init_step (
h5_file * f
);
h5_err_t
_h5t_close_step (
h5_file * f
);
h5_err_t
_h5t_close_mesh (
_h5t_write_mesh (
h5_file * f
);
h5_size_t
h5t_get_num_meshes (
h5_file * f,
const enum h5_mesh_types type
);
h5_err_t
h5t_open_mesh (
h5_file * f,
h5_id_t id,
const enum h5_mesh_types type
const enum h5_oid type
);
h5_id_t
@@ -39,40 +22,16 @@ h5t_get_num_levels (
h5_file * f
);
h5_err_t
h5t_open_level (
h5_file * f,
const h5_id_t id
);
h5_id_t
h5t_get_level (
h5_file * f
);
h5_id_t
h5t_add_level (
h5_file * f
);
h5_err_t
_h5t_read_vertices (
h5_file * f
);
h5_size_t
h5t_add_num_vertices (
h5_file * f,
const h5_size_t num
);
h5_id_t
h5t_store_vertex (
h5_file * f,
const h5_id_t id,
const h5_float64_t P[3]
);
h5_size_t
h5t_get_num_vertices_on_level (
h5_file * f
@@ -90,6 +49,18 @@ h5t_traverse_vertices (
h5_float64_t P[3]
);
h5_size_t
h5t_add_num_tets (
h5_file * f,
const h5_size_t num
) ;
h5_size_t
h5t_add_num_triangles (
h5_file * f,
const h5_size_t num
) ;
h5_size_t
h5t_add_num_entities (
h5_file * f,
+14 -8
View File
@@ -6,9 +6,15 @@
#include <fcntl.h>
#include <hdf5.h>
#include "h5_core.h"
#include "h5_private.h"
#include "H5Part.h"
#include "h5_core/h5_core.h"
#include "h5_core/h5_core_private.h"
h5_int64_t
h5u_has_view (
h5_file *f
) {
return ( f->viewstart >= 0 ) && ( f->viewend >= 0 );
}
static hid_t
_get_diskshape_for_reading (
@@ -21,7 +27,7 @@ _get_diskshape_for_reading (
hid_t space = H5Dget_space(dataset);
if ( space < 0 ) return (hid_t)HANDLE_H5D_GET_SPACE_ERR;
if ( H5PartHasView(f) ){
if ( h5u_has_view ( f ) ) {
hsize_t stride;
hsize_t count;
#ifdef HDF5V160
@@ -63,7 +69,7 @@ _get_memshape_for_reading (
hid_t dataset
) {
if(H5PartHasView(f)) {
if ( h5u_has_view ( f ) ) {
hsize_t dmax=H5S_UNLIMITED;
hsize_t len = f->viewend - f->viewstart;
hid_t r = H5Screate_simple(1,&len,&dmax);
@@ -101,14 +107,14 @@ H5U_get_num_elems (
dataset_name, sizeof (dataset_name) );
if ( herr < 0 ) return herr;
dataset_id = H5Dopen ( f->step_gid, dataset_name );
dataset_id = H5Dopen ( f->step_gid, dataset_name, H5P_DEFAULT );
if ( dataset_id < 0 )
return HANDLE_H5D_OPEN_ERR ( dataset_name );
space_id = _get_diskshape_for_reading ( f, dataset_id );
if ( space_id < 0 ) return (h5part_int64_t)space_id;
if ( H5PartHasView ( f ) ) {
if ( h5u_has_view ( f ) ) {
nparticles = H5Sget_select_npoints ( space_id );
if ( nparticles < 0 ) return HANDLE_H5S_GET_SELECT_NPOINTS_ERR;
}
@@ -144,7 +150,7 @@ H5U_read_elems (
h5part_int64_t h5err = h5_set_step ( f, f->step_idx );
if ( h5err < 0 ) return h5err;
}
dataset_id = H5Dopen ( f->step_gid, name );
dataset_id = H5Dopen ( f->step_gid, name, H5P_DEFAULT );
if ( dataset_id < 0 ) return HANDLE_H5D_OPEN_ERR ( name );
space_id = _get_diskshape_for_reading ( f, dataset_id );
+23 -18
View File
@@ -1,12 +1,12 @@
#ifndef __U_READWRITE_H
#define __U_READWRITE_H
h5part_int64_t
h5_int64_t
H5U_get_num_elems (
h5_file *f
);
h5part_int64_t
h5_int64_t
H5U_read_elems (
h5_file *f,
const char *name,
@@ -14,13 +14,13 @@ H5U_read_elems (
const hid_t type
);
h5part_int64_t
h5_int64_t
H5U_set_num_elements (
h5_file *f,
h5part_int64_t nparticles
h5_int64_t nparticles
);
h5part_int64_t
h5_int64_t
H5U_write_data (
h5_file *f,
const char *name,
@@ -28,37 +28,42 @@ H5U_write_data (
const hid_t type
);
h5part_int64_t
h5_int64_t
h5u_has_view (
h5_file *f
);
h5_int64_t
H5U_reset_view (
h5_file *f
);
h5part_int64_t
h5_int64_t
H5U_set_view (
h5_file *f,
h5part_int64_t start,
h5part_int64_t end
h5_int64_t start,
h5_int64_t end
);
h5part_int64_t
h5_int64_t
H5U_get_view (
h5_file *f,
h5part_int64_t *start,
h5part_int64_t *end
h5_int64_t *start,
h5_int64_t *end
);
h5part_int64_t
h5_int64_t
H5U_set_canonical_view (
h5_file *f
);
h5part_int64_t
h5_int64_t
H5U_get_dataset_info (
h5_file *f,
const h5part_int64_t idx,
const h5_int64_t idx,
char *dataset_name,
const h5part_int64_t len_dataset_name,
h5part_int64_t *type,
h5part_int64_t *nelem
const h5_int64_t len_dataset_name,
h5_int64_t *type,
h5_int64_t *nelem
);
#endif