- start implementing wrappers for HDF5 calls
- bugfixes - ...
This commit is contained in:
+28
-61
@@ -32,39 +32,25 @@ h5_read_attrib (
|
||||
const char *attrib_name, /*!< name of HDF5 attribute to read */
|
||||
void * const attrib_value /*!< OUT: attribute value */
|
||||
) {
|
||||
|
||||
herr_t herr;
|
||||
hid_t attrib_id;
|
||||
hid_t space_id;
|
||||
hid_t type_id;
|
||||
hid_t mytype;
|
||||
hsize_t nelem;
|
||||
|
||||
attrib_id = H5Aopen_name ( id, 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( f );
|
||||
|
||||
space_id = H5Aget_space ( attrib_id );
|
||||
if ( space_id < 0 ) return HANDLE_H5A_GET_SPACE_ERR( f );
|
||||
TRY ( attrib_id = _h5_open_attribute_by_name ( f, id, attrib_name ) );
|
||||
TRY ( mytype = _h5_get_attribute_type ( f, attrib_id ) );
|
||||
TRY ( space_id = _h5_get_attribute_space ( f, attrib_id ) );
|
||||
|
||||
nelem = H5Sget_simple_extent_npoints ( space_id );
|
||||
if ( nelem < 0 ) return HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR( f );
|
||||
|
||||
type_id = h5_normalize_h5_type ( f, mytype );
|
||||
|
||||
herr = H5Aread (attrib_id, type_id, attrib_value );
|
||||
if ( herr < 0 ) return HANDLE_H5A_READ_ERR( f );
|
||||
|
||||
herr = H5Sclose ( space_id );
|
||||
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR( f );
|
||||
|
||||
herr = H5Tclose ( mytype );
|
||||
if ( herr < 0 ) return HANDLE_H5T_CLOSE_ERR( f );
|
||||
|
||||
herr = H5Aclose ( attrib_id );
|
||||
if ( herr < 0 ) return HANDLE_H5A_CLOSE_ERR( f );
|
||||
TRY ( _h5_read_attribute ( f, attrib_id, type_id, attrib_value ) );
|
||||
TRY ( _h5_close_dataspace( f, space_id ) );
|
||||
TRY ( _h5_close_type( f, mytype ) );
|
||||
TRY ( _h5_close_attribute ( f, attrib_id ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
@@ -85,31 +71,21 @@ h5_write_attrib (
|
||||
const void *attrib_value, /*!< value of attribute */
|
||||
const hsize_t attrib_nelem /*!< number of elements (dimension) */
|
||||
) {
|
||||
|
||||
herr_t herr;
|
||||
hid_t space_id;
|
||||
hid_t attrib_id;
|
||||
|
||||
space_id = H5Screate_simple (1, &attrib_nelem, NULL);
|
||||
if ( space_id < 0 )
|
||||
return HANDLE_H5S_CREATE_SIMPLE_ERR ( f, 1 );
|
||||
TRY ( space_id = _h5_create_dataset_space ( f, 1, &attrib_nelem, NULL) );
|
||||
TRY ( attrib_id = _h5_create_attribute (
|
||||
f,
|
||||
id,
|
||||
attrib_name,
|
||||
attrib_type,
|
||||
space_id,
|
||||
H5P_DEFAULT, H5P_DEFAULT ) );
|
||||
|
||||
attrib_id = H5Acreate (
|
||||
id,
|
||||
attrib_name,
|
||||
attrib_type,
|
||||
space_id,
|
||||
H5P_DEFAULT, H5P_DEFAULT );
|
||||
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 ( f, attrib_name );
|
||||
|
||||
herr = H5Aclose ( attrib_id );
|
||||
if ( herr < 0 ) return HANDLE_H5A_CLOSE_ERR( f );
|
||||
|
||||
herr = H5Sclose ( space_id );
|
||||
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR( f );
|
||||
TRY ( _h5_write_attribute ( f, attrib_id, attrib_type, attrib_value ) );
|
||||
TRY ( _h5_close_attribute ( f, attrib_id ) );
|
||||
TRY ( _h5_close_dataspace ( f, space_id ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
@@ -131,8 +107,6 @@ h5_get_attrib_info (
|
||||
h5_int64_t *attrib_type, /*!< OUT: H5 type of attribute */
|
||||
h5_int64_t *attrib_nelem /*!< OUT: number of elements (dimension) */
|
||||
) {
|
||||
|
||||
herr_t herr;
|
||||
hid_t attrib_id;
|
||||
hid_t mytype;
|
||||
hid_t space_id;
|
||||
@@ -141,34 +115,27 @@ h5_get_attrib_info (
|
||||
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( f );
|
||||
TRY ( space_id = _h5_get_attribute_space ( f, attrib_id ) );
|
||||
|
||||
*attrib_nelem = H5Sget_simple_extent_npoints ( space_id );
|
||||
if ( *attrib_nelem < 0 )
|
||||
return HANDLE_H5S_GET_SIMPLE_EXTENT_NPOINTS_ERR( f );
|
||||
|
||||
herr = H5Sclose ( space_id );
|
||||
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR( f );
|
||||
TRY( _h5_close_dataspace( f, space_id ) );
|
||||
}
|
||||
if ( attrib_name ) {
|
||||
herr = H5Aget_name (
|
||||
attrib_id,
|
||||
(size_t)len_attrib_name,
|
||||
attrib_name );
|
||||
if ( herr < 0 ) return HANDLE_H5A_GET_NAME_ERR( f );
|
||||
TRY ( _h5_get_attribute_name (
|
||||
f,
|
||||
attrib_id,
|
||||
(size_t)len_attrib_name,
|
||||
attrib_name ) );
|
||||
}
|
||||
if ( attrib_type ) {
|
||||
mytype = H5Aget_type ( attrib_id );
|
||||
if ( mytype < 0 ) return HANDLE_H5A_GET_TYPE_ERR( f );
|
||||
|
||||
TRY ( mytype = _h5_get_attribute_type ( f, attrib_id ) );
|
||||
*attrib_type = h5_normalize_h5_type ( f, mytype );
|
||||
|
||||
herr = H5Tclose ( mytype );
|
||||
if ( herr < 0 ) return HANDLE_H5T_CLOSE_ERR( f );
|
||||
TRY ( _h5_close_type( f, mytype ) );
|
||||
}
|
||||
herr = H5Aclose ( attrib_id);
|
||||
if ( herr < 0 ) return HANDLE_H5A_CLOSE_ERR( f );
|
||||
TRY ( _h5_close_attribute ( f, attrib_id ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __ATTRIBS_H
|
||||
#define __ATTRIBS_H
|
||||
#ifndef __H5_ATTRIBS_H
|
||||
#define __H5_ATTRIBS_H
|
||||
|
||||
h5_int64_t
|
||||
h5_read_attrib (
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#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"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __H5_PRIVATE_H
|
||||
#define __H5_PRIVATE_H
|
||||
#ifndef __H5_CORE_PRIVATE_H
|
||||
#define __H5_CORE_PRIVATE_H
|
||||
|
||||
#include "h5_types_private.h"
|
||||
#include "h5b_types_private.h"
|
||||
@@ -8,15 +8,20 @@
|
||||
|
||||
#include "h5_errorhandling_private.h"
|
||||
#include "h5_qsort_private.h"
|
||||
#include "h5_readwrite_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_map_private.h"
|
||||
#include "h5t_readwrite_private.h"
|
||||
#include "h5t_storemesh_private.h"
|
||||
|
||||
#include "h5u_errorhandling_private.h"
|
||||
#include "h5u_types_private.h"
|
||||
|
||||
#define H5PART_GROUPNAME_STEP "Step"
|
||||
|
||||
@@ -45,10 +50,10 @@
|
||||
(eid & H5_TET_MASK))
|
||||
|
||||
#define TRY(func) \
|
||||
if ( (int64_t)(ptrdiff_t)(func) == (int64_t)(-1) ) \
|
||||
if ( (int64_t)(ptrdiff_t)(func) < (int64_t)0 ) \
|
||||
return H5_ERR;
|
||||
#define TRY2(func,exception) \
|
||||
if ( (int64_t)(ptrdiff_t)(func) == (int64_t)(-1) ) \
|
||||
if ( (int64_t)(ptrdiff_t)(func) < (int64_t)0 ) \
|
||||
goto exception;
|
||||
|
||||
/*!
|
||||
|
||||
@@ -43,7 +43,7 @@ h5_err_t
|
||||
h5_set_debuglevel (
|
||||
h5_id_t debuglevel /*!< debug level */
|
||||
) {
|
||||
if ( debuglevel < 0 || debuglevel > 4 ) return H5_ERR_INVAL;
|
||||
if ( debuglevel < 0 || debuglevel > 5 ) return H5_ERR_INVAL;
|
||||
_h5_debuglevel = debuglevel;
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __ERRORHANDLING_H
|
||||
#define __ERRORHANDLING_H
|
||||
#ifndef __H5_ERRORHANDLING_H
|
||||
#define __H5_ERRORHANDLING_H
|
||||
|
||||
#define SET_FNAME( f, fname ) h5_set_funcname( f, fname );
|
||||
#define CHECK_FILEHANDLE( f ) \
|
||||
@@ -156,9 +156,4 @@ h5_get_funcname (
|
||||
h5_file_t * const f
|
||||
);
|
||||
|
||||
const char *
|
||||
h5_get_objname (
|
||||
hid_t id
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __ERRORHANDLING_PRIVATE_H
|
||||
#define __ERRORHANDLING_PRIVATE_H
|
||||
#ifndef __H5_ERRORHANDLING_PRIVATE_H
|
||||
#define __H5_ERRORHANDLING_PRIVATE_H
|
||||
|
||||
#define h5_error_not_implemented( f, file, func, lino ) \
|
||||
h5_error( \
|
||||
@@ -42,12 +42,6 @@
|
||||
H5_ERR_BADFD, \
|
||||
"Called with bad filehandle." );
|
||||
|
||||
#define HANDLE_H5_INIT_ERR( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_INIT, \
|
||||
"Cannot initialize H5." );
|
||||
|
||||
#define HANDLE_H5_NOMEM_ERR( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
@@ -96,12 +90,12 @@
|
||||
H5_ERR_INVAL, \
|
||||
"Cannot store more than %lld %s", max, otype );
|
||||
|
||||
#define HANDLE_H5_PARENT_ID_ERR( f, otype, oid, pid ) \
|
||||
#define HANDLE_H5_PARENT_ID_ERR( f, otype, parent_id ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_INVAL, \
|
||||
"Impossible parent_id %d for %s with global id %d", \
|
||||
pid, otype, oid );
|
||||
"Impossible parent_id %lld for %s.", \
|
||||
parent_id, otype );
|
||||
|
||||
#define HANDLE_H5_OUT_OF_RANGE_ERR( f, otype, oid ) \
|
||||
h5_error( \
|
||||
@@ -112,42 +106,12 @@
|
||||
|
||||
/**************** HDF5 *********************/
|
||||
/* H5A: Attribute */
|
||||
#define HANDLE_H5A_CLOSE_ERR( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot terminate access to attribute." );
|
||||
|
||||
#define HANDLE_H5A_CREATE_ERR( f, s ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot create attribute \"%s\".", s );
|
||||
|
||||
#define HANDLE_H5A_GET_NAME_ERR( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot get attribute name." );
|
||||
|
||||
#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( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot get a copy of dataspace for attribute." );
|
||||
|
||||
#define HANDLE_H5A_GET_TYPE_ERR( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot get attribute datatype." );
|
||||
|
||||
#define HANDLE_H5A_OPEN_IDX_ERR( f, n ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
@@ -155,129 +119,14 @@
|
||||
"Cannot open attribute specified by index \"%lld\".", \
|
||||
(long long)n );
|
||||
|
||||
#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( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot read attribute" );
|
||||
|
||||
#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( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Close of dataset failed." );
|
||||
|
||||
#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( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot get dataspace identifier.");
|
||||
|
||||
#define HANDLE_H5D_GET_TYPE_ERR( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot determine dataset type.");
|
||||
|
||||
#define HANDLE_H5D_OPEN_ERR( f, s ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot open dataset \"%s\".", s );
|
||||
|
||||
#define HANDLE_H5D_READ_ERR( f, s ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Read from dataset \"%s\".", \
|
||||
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( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot terminate access to file." );
|
||||
|
||||
#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( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot terminate access to datagroup." );
|
||||
|
||||
#define HANDLE_H5G_CREATE_ERR( f, s ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot create datagroup \"%s\".", 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( 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( f, s ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot terminate access to property list \"%s\".", s );
|
||||
|
||||
#define HANDLE_H5P_CREATE_ERR( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot create property list." );
|
||||
|
||||
#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( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
@@ -286,13 +135,6 @@
|
||||
"file access property list.");
|
||||
|
||||
/* H5S: dataspace */
|
||||
#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( f, dims ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
@@ -301,12 +143,6 @@
|
||||
"\"(%lld,%lld,%lld)\".", \
|
||||
(long long)dims[0], (long long)dims[1], (long long)dims[2] );
|
||||
|
||||
#define HANDLE_H5S_CLOSE_ERR( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot terminate access to dataspace." );
|
||||
|
||||
#define HANDLE_H5S_GET_SELECT_NPOINTS_ERR(f) \
|
||||
h5_error( \
|
||||
f, \
|
||||
@@ -333,34 +169,6 @@
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot get dimension sizes of dataset" );
|
||||
|
||||
/* H5T: type */
|
||||
#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( 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( 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( f ) \
|
||||
h5_error( \
|
||||
f, \
|
||||
H5_ERR_HDF5, \
|
||||
"Cannot release datatype." );
|
||||
|
||||
/* MPI */
|
||||
#define HANDLE_MPI_ALLGATHER_ERR( f ) \
|
||||
|
||||
+618
-18
@@ -3,49 +3,75 @@
|
||||
#include "h5_core/h5_core.h"
|
||||
#include "h5_core/h5_core_private.h"
|
||||
|
||||
/****** G r o u p ************************************************************/
|
||||
/*!
|
||||
Open HDF5 group. If group doesn't exist create it.
|
||||
|
||||
\param[in] f file handle
|
||||
\param[in] loc_id location id
|
||||
\param[in] group_name name of group to open
|
||||
*/
|
||||
hid_t
|
||||
_h5_open_group (
|
||||
h5_file_t * f,
|
||||
const hid_t parent_gid,
|
||||
const char * const grpname
|
||||
const hid_t loc_id,
|
||||
const char * const group_name
|
||||
) {
|
||||
hid_t gid;
|
||||
hid_t group_id;
|
||||
herr_t herr = H5Gget_objinfo(
|
||||
parent_gid, grpname, 1, NULL );
|
||||
loc_id, group_name, 1, NULL );
|
||||
|
||||
/*
|
||||
check access modes:
|
||||
Open Create
|
||||
H5_O_RDWR x x
|
||||
H5_O_RDONLY x -
|
||||
H5_O_WRONLY x x (overwrite/append data to existing dataset)
|
||||
H5_O_APPEND x x (append datasets to an existing group)
|
||||
*/
|
||||
|
||||
if ( herr >= 0 ) {
|
||||
h5_info (
|
||||
f,
|
||||
"Opening group %s/%s.",
|
||||
h5_get_objname(parent_gid),
|
||||
grpname );
|
||||
gid = H5Gopen ( parent_gid, grpname, H5P_DEFAULT );
|
||||
h5_get_objname ( loc_id ),
|
||||
group_name );
|
||||
group_id = H5Gopen ( loc_id, group_name, H5P_DEFAULT );
|
||||
} else {
|
||||
CHECK_WRITABLE_MODE( f );
|
||||
h5_info (
|
||||
f,
|
||||
"Creating group %s/%s.",
|
||||
h5_get_objname(parent_gid),
|
||||
grpname );
|
||||
gid = H5Gcreate ( parent_gid, grpname, 0,
|
||||
h5_get_objname ( loc_id ),
|
||||
group_name );
|
||||
group_id = H5Gcreate ( loc_id, group_name, 0,
|
||||
H5P_DEFAULT, H5P_DEFAULT );
|
||||
}
|
||||
if ( gid < 0 )
|
||||
return HANDLE_H5G_OPEN_ERR (
|
||||
if ( group_id < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
h5_get_objname(parent_gid),
|
||||
grpname );
|
||||
H5_ERR_HDF5,
|
||||
"Cannot open group \"%s/%s\".",
|
||||
h5_get_objname ( loc_id ),
|
||||
group_name );
|
||||
|
||||
return gid;
|
||||
return group_id;
|
||||
}
|
||||
|
||||
/*!
|
||||
Close group.
|
||||
|
||||
\param[in] f file handle
|
||||
\param[in] group_id id of group to close
|
||||
*/
|
||||
h5_err_t
|
||||
_h5_close_group (
|
||||
h5_file_t * const f,
|
||||
hid_t group_id
|
||||
const hid_t group_id
|
||||
) {
|
||||
if ( group_id == 0 || group_id == -1 ) return H5_SUCCESS;
|
||||
const char *group_name = h5_get_objname( group_id );
|
||||
herr_t herr = H5Gclose ( group_id );
|
||||
if ( herr < 0 ) {
|
||||
if ( H5Gclose ( group_id ) < 0 ) {
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
@@ -54,3 +80,577 @@ _h5_close_group (
|
||||
}
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/****** D a t a s e t ********************************************************/
|
||||
/*!
|
||||
Open dataset. H5Dopen wrapper.
|
||||
|
||||
\param[in] f file handle
|
||||
\param[in] loc_id location id
|
||||
\param[in] dataset_name name of dataset to open
|
||||
*/
|
||||
hid_t
|
||||
_h5_open_dataset (
|
||||
h5_file_t * const f,
|
||||
const hid_t loc_id,
|
||||
const char * const dataset_name
|
||||
) {
|
||||
hid_t dataset_id;
|
||||
|
||||
dataset_id = H5Dopen (
|
||||
loc_id,
|
||||
dataset_name,
|
||||
H5P_DEFAULT );
|
||||
if ( dataset_id < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot open dataset \"%s\".", dataset_name );
|
||||
|
||||
return dataset_id;
|
||||
}
|
||||
|
||||
/*!
|
||||
Get dataspace of existing dataset
|
||||
|
||||
\param[in] f file handle
|
||||
\param[in] dataset_id id of dataset
|
||||
|
||||
*/
|
||||
hid_t
|
||||
_h5_get_dataset_space (
|
||||
h5_file_t * const f,
|
||||
const hid_t dataset_id
|
||||
) {
|
||||
hid_t dataspace_id = H5Dget_space ( dataset_id );
|
||||
if ( dataspace_id < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot get dataspace for dataset \"%s\".",
|
||||
h5_get_objname ( dataset_id ) );
|
||||
return dataspace_id;
|
||||
}
|
||||
|
||||
/*!
|
||||
Create new dataset
|
||||
|
||||
\param[in] f file handle
|
||||
\param[in] loc_id id of group or file
|
||||
\param[in] dataset_name name of dataset
|
||||
\param[in] type_id type used in dataset
|
||||
\param[in] dataspace_id dataspace of dataset
|
||||
\param[in] create_prop property list for dataset creation
|
||||
|
||||
*/
|
||||
hid_t
|
||||
_h5_create_dataset (
|
||||
h5_file_t * const f,
|
||||
hid_t loc_id,
|
||||
const char * dataset_name,
|
||||
const hid_t type_id,
|
||||
const hid_t dataspace_id,
|
||||
const hid_t create_proplist
|
||||
) {
|
||||
hid_t dataset_id = H5Dcreate (
|
||||
loc_id,
|
||||
dataset_name,
|
||||
type_id,
|
||||
dataspace_id,
|
||||
H5P_DEFAULT,
|
||||
create_proplist,
|
||||
H5P_DEFAULT );
|
||||
if ( dataset_id < 0 )
|
||||
return h5_error(
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot create dataset name \"%s\"",
|
||||
dataset_name );
|
||||
return dataset_id;
|
||||
}
|
||||
|
||||
/*!
|
||||
Write dataset.
|
||||
|
||||
\param[in] f file handle
|
||||
\param[in] dataset_id id of dataset
|
||||
\param[in] type_id type used in dataset
|
||||
\param[in] memspace_id id of memory space
|
||||
\param[in] diskspace_id id of disk space
|
||||
\param[in] xfer_prop transfer property list
|
||||
\param[in] buf buffer with date to write
|
||||
|
||||
*/
|
||||
herr_t
|
||||
_h5_write_dataset (
|
||||
h5_file_t * const f,
|
||||
const hid_t dataset_id,
|
||||
const hid_t type_id,
|
||||
const hid_t memspace_id,
|
||||
const hid_t diskspace_id,
|
||||
const hid_t xfer_prop,
|
||||
const void * buf
|
||||
) {
|
||||
herr_t herr = H5Dwrite (
|
||||
dataset_id,
|
||||
type_id,
|
||||
memspace_id,
|
||||
diskspace_id,
|
||||
xfer_prop,
|
||||
buf );
|
||||
if ( herr < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Write to dataset \"%s\" failed.", \
|
||||
h5_get_objname(dataset_id) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
h5_err_t
|
||||
_h5_read_dataset (
|
||||
h5_file_t * const f,
|
||||
const hid_t dataset_id,
|
||||
const hid_t type_id,
|
||||
const hid_t memspace_id,
|
||||
const hid_t diskspace_id,
|
||||
const hid_t xfer_prop,
|
||||
void * const buf ) {
|
||||
|
||||
herr_t herr = H5Dread (
|
||||
dataset_id,
|
||||
type_id,
|
||||
memspace_id,
|
||||
diskspace_id,
|
||||
xfer_prop,
|
||||
buf );
|
||||
if ( herr < 0 )
|
||||
return h5_error(
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Read from dataset \"%s\".", \
|
||||
h5_get_objname ( dataset_id ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
hid_t
|
||||
_h5_get_dataset_type (
|
||||
h5_file_t * const f,
|
||||
const hid_t dataset_id
|
||||
) {
|
||||
hid_t datatype_id = H5Dget_type ( dataset_id );
|
||||
if ( datatype_id < 0 )
|
||||
h5_error(
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot determine dataset type.");
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
/*!
|
||||
Close dataset.
|
||||
|
||||
\param[in] f file handle
|
||||
\param[in] dataset_id id of dataset to close
|
||||
*/
|
||||
herr_t
|
||||
_h5_close_dataset (
|
||||
h5_file_t * const f,
|
||||
const hid_t dataset_id
|
||||
) {
|
||||
if ( dataset_id == 0 || dataset_id == -1 ) return H5_SUCCESS;
|
||||
const char *dataset_name = h5_get_objname( dataset_id );
|
||||
|
||||
if ( H5Dclose ( dataset_id ) < 0 ) {
|
||||
return h5_error(
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Close of dataset \"%s\" failed.", dataset_name );
|
||||
}
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
/****** D a t a s p a c e ****************************************************/
|
||||
/*!
|
||||
Create dataspace for dataset. H5Screate_simple wrapper.
|
||||
|
||||
\param[in] f file handle
|
||||
\param[in] rank rank of dataspace
|
||||
\param[in] dims dimensions of dataspace
|
||||
\param[in] maxdims maximum dimensions of dataspace
|
||||
|
||||
*/
|
||||
hid_t
|
||||
_h5_create_dataset_space (
|
||||
h5_file_t * const f,
|
||||
const int rank,
|
||||
const hsize_t * dims,
|
||||
const hsize_t * maxdims
|
||||
) {
|
||||
hid_t dataspace_id = H5Screate_simple ( rank, dims, maxdims );
|
||||
if ( dataspace_id < 0 )
|
||||
h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot create dataspace with rank %d.",
|
||||
rank );
|
||||
return dataspace_id;
|
||||
}
|
||||
|
||||
/*!
|
||||
Close space.
|
||||
|
||||
\param[in] f file handle
|
||||
\param[in] dataspace_id id of space to close
|
||||
*/
|
||||
herr_t
|
||||
_h5_close_dataspace (
|
||||
h5_file_t * const f,
|
||||
const hid_t dataspace_id
|
||||
) {
|
||||
if ( dataspace_id == 0 || dataspace_id == -1 || dataspace_id == H5S_ALL )
|
||||
return H5_SUCCESS;
|
||||
|
||||
herr_t herr = H5Sclose ( dataspace_id );
|
||||
if ( herr < 0 )
|
||||
return h5_error(
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot terminate access to dataspace \"%s\".",
|
||||
h5_get_objname( dataspace_id ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
/****** D a t a t y p e ******************************************************/
|
||||
|
||||
const char*
|
||||
_h5_get_base_type_name (
|
||||
h5_file_t * const f,
|
||||
hid_t base_type_id
|
||||
) {
|
||||
if ( base_type_id == H5_INT32_T ) return "H5_INT32_T";
|
||||
if ( base_type_id == H5_INT64_T ) return "H5_INT64_T";
|
||||
if ( base_type_id == H5_FLOAT32_T ) return "H5_FLOAT32_T";
|
||||
if ( base_type_id == H5_FLOAT64_T ) return "H5_FLOAT64_T";
|
||||
|
||||
return "[unknown]";
|
||||
}
|
||||
|
||||
const char*
|
||||
_h5_get_class_type_name (
|
||||
h5_file_t * const f,
|
||||
hid_t base_type_id
|
||||
) {
|
||||
if ( base_type_id == H5_COMPOUND_T ) return "H5_COMPOUND_T";
|
||||
|
||||
return "[unknown]";
|
||||
}
|
||||
|
||||
/*!
|
||||
Create array type. Wrapper for "H5Tarray_create".
|
||||
|
||||
\param[in] f file handle
|
||||
\param[in] base_type_id base type
|
||||
\param[in] rank rank of array
|
||||
\param[in] dims dimensions
|
||||
*/
|
||||
hid_t
|
||||
_h5_create_array_type (
|
||||
h5_file_t * const f,
|
||||
hid_t base_type_id,
|
||||
int rank,
|
||||
const hsize_t *dims
|
||||
) {
|
||||
hid_t type_id = H5Tarray_create( base_type_id, rank, dims );
|
||||
if ( type_id < 0 ) {
|
||||
return h5_error(
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Can't create array datatype object with base "
|
||||
"type %s and rank %d",
|
||||
_h5_get_base_type_name ( f, base_type_id ),
|
||||
rank );
|
||||
}
|
||||
return type_id;
|
||||
}
|
||||
|
||||
hid_t
|
||||
_h5_create_type (
|
||||
h5_file_t * const f,
|
||||
H5T_class_t class,
|
||||
const size_t size
|
||||
) {
|
||||
hid_t type_id = H5Tcreate( class, size );
|
||||
if ( type_id < 0 ) {
|
||||
return h5_error(
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Can't create datatype object of class %s.",
|
||||
_h5_get_class_type_name ( f, class )
|
||||
);
|
||||
}
|
||||
return type_id;
|
||||
}
|
||||
|
||||
herr_t
|
||||
_h5_insert_type (
|
||||
h5_file_t * const f,
|
||||
hid_t dtype_id,
|
||||
const char * name,
|
||||
size_t offset,
|
||||
hid_t field_id
|
||||
) {
|
||||
herr_t herr = H5Tinsert ( dtype_id, name, offset, field_id );
|
||||
if ( herr < 0 )
|
||||
return h5_error(
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Can't insert field %s to compound datatype.",
|
||||
name );
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
herr_t
|
||||
_h5_close_type (
|
||||
h5_file_t * const f,
|
||||
hid_t dtype_id
|
||||
) {
|
||||
herr_t herr = H5Tclose ( dtype_id );
|
||||
if ( herr < 0 )
|
||||
return h5_error(
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot release datatype." );
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
/****** P r o p e r t y ******************************************************/
|
||||
|
||||
hid_t
|
||||
_h5_create_property (
|
||||
h5_file_t * const f,
|
||||
hid_t cls_id
|
||||
) {
|
||||
hid_t prop_id = H5Pcreate( cls_id );
|
||||
if ( prop_id < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot create property list." );
|
||||
return prop_id;
|
||||
}
|
||||
|
||||
herr_t
|
||||
_h5_set_chunk_property (
|
||||
h5_file_t * const f,
|
||||
hid_t plist,
|
||||
int ndims,
|
||||
const hsize_t * dim
|
||||
) {
|
||||
herr_t herr = H5Pset_chunk ( plist, ndims, dim );
|
||||
if ( herr < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot add chunking property to list." );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
h5_err_t
|
||||
_h5_close_property (
|
||||
h5_file_t * const f,
|
||||
hid_t prop
|
||||
) {
|
||||
herr_t herr = H5Pclose ( prop );
|
||||
if ( herr < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot close property." );
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
/****** F i l e **************************************************************/
|
||||
|
||||
herr_t
|
||||
_h5_close_file (
|
||||
h5_file_t * const f,
|
||||
hid_t fileid
|
||||
) {
|
||||
herr_t herr = H5Fclose ( fileid );
|
||||
if ( herr < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot close file." );
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
/****** E r r o r h a n d l i n g ********************************************/
|
||||
|
||||
herr_t
|
||||
_h5_set_errorhandler (
|
||||
h5_file_t * const f,
|
||||
hid_t estack_id,
|
||||
H5E_auto_t func,
|
||||
void *client_data
|
||||
) {
|
||||
herr_t herr = H5Eset_auto ( estack_id, func, client_data );
|
||||
if ( herr < 0 )
|
||||
return h5_error(
|
||||
f,
|
||||
H5_ERR_INIT,
|
||||
"Cannot initialize H5." );
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
/****** A t t r i b u t e ****************************************************/
|
||||
hid_t
|
||||
_h5_open_attribute_by_name (
|
||||
hid_t loc_id,
|
||||
const char *attr_name
|
||||
) {
|
||||
hid_t attr_id = H5Aopen_by_name (
|
||||
loc_id,
|
||||
attr_name,
|
||||
H5P_DEFAULT,
|
||||
H5P_DEFAULT );
|
||||
if ( attr_id < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot open attribute \"%s\" of \"%s\".",
|
||||
attr_name,
|
||||
h5_get_objname( loc_id ) );
|
||||
return attr_id;
|
||||
|
||||
hid_t
|
||||
_h5_create_attribute (
|
||||
h5_file_t * const f,
|
||||
hid_t loc_id,
|
||||
const char *attr_name,
|
||||
hid_t type_id,
|
||||
hid_t space_id,
|
||||
hid_t acpl_id,
|
||||
hid_t aapl_id
|
||||
) {
|
||||
hid_t attr_id = H5Acreate (
|
||||
loc_id,
|
||||
attr_name,
|
||||
type_id,
|
||||
space_id,
|
||||
acpl_id,
|
||||
aapl_id );
|
||||
if ( attr_id < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot create attribute \"%s\" for \"%s\".",
|
||||
attr_name,
|
||||
h5_get_objname( loc_id ) );
|
||||
return attr_id;
|
||||
}
|
||||
|
||||
herr_t
|
||||
_h5_read_attribute (
|
||||
h5_file_t * const f,
|
||||
hid_t attr_id,
|
||||
hid_t mem_type_id,
|
||||
void *buf
|
||||
) {
|
||||
herr_t herr = H5Aread ( attr_id, mem_type_id, buf );
|
||||
if ( herr < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot read attribute \"%s\".",
|
||||
h5_get_objname( attr_id ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
herr_t
|
||||
_h5_write_attribute (
|
||||
h5_file_t * const f,
|
||||
hid_t attr_id,
|
||||
hid_t mem_type_id,
|
||||
const void *buf
|
||||
) {
|
||||
herr_t herr = H5Awrite ( attr_id, mem_type_id, buf );
|
||||
if ( herr < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot write attribute \"%s\".",
|
||||
h5_get_objname( attr_id ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
_h5_get_attribute_name (
|
||||
h5_file_t * const f,
|
||||
hid_t attr_id,
|
||||
size_t buf_size,
|
||||
char *buf
|
||||
) {
|
||||
ssize_t size = H5Aget_name ( attr_id, buf_size, buf );
|
||||
if ( size < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot get attribute name." );
|
||||
return size;
|
||||
}
|
||||
|
||||
hid_t
|
||||
_h5_get_attribute_type (
|
||||
h5_file_t * const f,
|
||||
hid_t attr_id
|
||||
) {
|
||||
hid_t datatype_id = H5Aget_type ( attr_id );
|
||||
if ( datatype_id < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot get type of attribute \"%s\".",
|
||||
h5_get_objname( attr_id ) );
|
||||
return datatype_id;
|
||||
}
|
||||
|
||||
hid_t
|
||||
_h5_get_attribute_space (
|
||||
h5_file_t * const f,
|
||||
hid_t attr_id
|
||||
) {
|
||||
hid_t space_id = H5Aget_space ( attr_id );
|
||||
if ( space_id < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot get dataspace of attribute \"%s\".",
|
||||
h5_get_objname( attr_id ) );
|
||||
return space_id;
|
||||
}
|
||||
|
||||
herr_t
|
||||
_h5_close_attribute (
|
||||
h5_file_t * const f,
|
||||
hid_t attr_id
|
||||
) {
|
||||
herr_t herr = H5Aclose ( attr_id );
|
||||
if ( herr < 0 )
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot close attribute \"%s\".",
|
||||
h5_get_objname( attr_id ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
+204
-4
@@ -4,13 +4,213 @@
|
||||
hid_t
|
||||
_h5_open_group (
|
||||
h5_file_t *f,
|
||||
const hid_t parent_gid,
|
||||
const char * const grpname
|
||||
const hid_t parent_group_id,
|
||||
const char * const group_name
|
||||
);
|
||||
|
||||
h5_err_t
|
||||
_h5_close_group (
|
||||
h5_file_t *f,
|
||||
hid_t group_id
|
||||
h5_file_t * const f,
|
||||
const hid_t group_id
|
||||
);
|
||||
|
||||
hid_t
|
||||
_h5_open_dataset (
|
||||
h5_file_t * const f,
|
||||
const hid_t gid,
|
||||
const char * const dataset_name
|
||||
);
|
||||
|
||||
hid_t
|
||||
_h5_open_dataset (
|
||||
h5_file_t * const f,
|
||||
const hid_t loc_id,
|
||||
const char * const dataset_name
|
||||
);
|
||||
|
||||
hid_t
|
||||
_h5_create_dataset_space (
|
||||
h5_file_t * const f,
|
||||
const int rank,
|
||||
const hsize_t * dims,
|
||||
const hsize_t * maxdims
|
||||
);
|
||||
|
||||
hid_t
|
||||
_h5_get_dataset_space (
|
||||
h5_file_t * const f,
|
||||
const hid_t dataset_id
|
||||
);
|
||||
|
||||
herr_t
|
||||
_h5_close_dataspace (
|
||||
h5_file_t * const f,
|
||||
const hid_t dataspace_id
|
||||
);
|
||||
|
||||
hid_t
|
||||
_h5_create_dataset (
|
||||
h5_file_t * const f,
|
||||
hid_t loc_id,
|
||||
const char * dataset_name,
|
||||
const hid_t type_id,
|
||||
const hid_t dataspace_id,
|
||||
const hid_t create_proplist
|
||||
);
|
||||
|
||||
herr_t
|
||||
_h5_write_dataset (
|
||||
h5_file_t * const f,
|
||||
const hid_t dataset_id,
|
||||
const hid_t type_id,
|
||||
const hid_t memspace_id,
|
||||
const hid_t diskspace_id,
|
||||
const hid_t xfer_prop,
|
||||
const void * buf
|
||||
);
|
||||
|
||||
h5_err_t
|
||||
_h5_read_dataset (
|
||||
h5_file_t * const f,
|
||||
const hid_t dataset_id,
|
||||
const hid_t type_id,
|
||||
const hid_t memspace_id,
|
||||
const hid_t diskspace_id,
|
||||
const hid_t xfer_prop,
|
||||
void * const buf );
|
||||
|
||||
hid_t
|
||||
_h5_get_dataset_type (
|
||||
h5_file_t * const f,
|
||||
const hid_t dataset_id
|
||||
);
|
||||
|
||||
herr_t
|
||||
_h5_close_dataset (
|
||||
h5_file_t * const f,
|
||||
const hid_t dataset_id
|
||||
);
|
||||
|
||||
hid_t
|
||||
_h5_create_array_type (
|
||||
h5_file_t * const f,
|
||||
hid_t base_type_id,
|
||||
int rank,
|
||||
const hsize_t *dims
|
||||
);
|
||||
|
||||
hid_t
|
||||
_h5_create_type (
|
||||
h5_file_t * const f,
|
||||
H5T_class_t _class,
|
||||
const size_t size
|
||||
);
|
||||
|
||||
herr_t
|
||||
_h5_insert_type (
|
||||
h5_file_t * const f,
|
||||
hid_t dtype_id,
|
||||
const char * name,
|
||||
size_t offset,
|
||||
hid_t field_id
|
||||
);
|
||||
|
||||
herr_t
|
||||
_h5_close_type (
|
||||
h5_file_t * const f,
|
||||
hid_t dtype_id
|
||||
);
|
||||
|
||||
hid_t
|
||||
_h5_create_property (
|
||||
h5_file_t * const f,
|
||||
hid_t cls_id
|
||||
);
|
||||
|
||||
herr_t
|
||||
_h5_set_chunk_property (
|
||||
h5_file_t * const f,
|
||||
hid_t plist,
|
||||
int ndims,
|
||||
const hsize_t * dim
|
||||
);
|
||||
|
||||
h5_err_t
|
||||
_h5_close_property (
|
||||
h5_file_t * const f,
|
||||
hid_t prop
|
||||
);
|
||||
|
||||
herr_t
|
||||
_h5_close_file (
|
||||
h5_file_t * const f,
|
||||
hid_t fileid
|
||||
);
|
||||
|
||||
herr_t
|
||||
_h5_set_errorhandler (
|
||||
h5_file_t * const f,
|
||||
hid_t estack_id,
|
||||
H5E_auto_t func,
|
||||
void *client_data
|
||||
);
|
||||
|
||||
hid_t
|
||||
_h5_open_attribute_by_name (
|
||||
hid_t loc_id,
|
||||
const char *attr_name
|
||||
);
|
||||
|
||||
hid_t
|
||||
_h5_create_attribute (
|
||||
h5_file_t * const f,
|
||||
hid_t loc_id,
|
||||
const char *attr_name,
|
||||
hid_t type_id,
|
||||
hid_t space_id,
|
||||
hid_t acpl_id,
|
||||
hid_t aapl_id
|
||||
);
|
||||
|
||||
herr_t
|
||||
_h5_read_attribute (
|
||||
h5_file_t * const f,
|
||||
hid_t attr_id,
|
||||
hid_t mem_type_id,
|
||||
void *buf
|
||||
);
|
||||
|
||||
herr_t
|
||||
_h5_write_attribute (
|
||||
h5_file_t * const f,
|
||||
hid_t attr_id,
|
||||
hid_t mem_type_id,
|
||||
const void *buf
|
||||
);
|
||||
|
||||
ssize_t
|
||||
_h5_get_attribute_name (
|
||||
h5_file_t * const f,
|
||||
hid_t attr_id,
|
||||
size_t buf_size,
|
||||
char *buf
|
||||
);
|
||||
|
||||
hid_t
|
||||
_h5_get_attribute_type (
|
||||
h5_file_t * const f,
|
||||
hid_t attr_id
|
||||
);
|
||||
|
||||
hid_t
|
||||
_h5_get_attribute_space (
|
||||
h5_file_t * const f,
|
||||
hid_t attr_id
|
||||
);
|
||||
|
||||
herr_t
|
||||
_h5_close_attribute (
|
||||
h5_file_t * const f,
|
||||
hid_t attr_id
|
||||
);
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <hdf5.h>
|
||||
#include "h5_types.h"
|
||||
|
||||
+126
-199
@@ -50,19 +50,6 @@ _h5_error_handler (
|
||||
return 0;
|
||||
}
|
||||
|
||||
static h5_int64_t
|
||||
_init ( void ) {
|
||||
static int __init = 0;
|
||||
|
||||
herr_t r5;
|
||||
if ( ! __init ) {
|
||||
r5 = H5Eset_auto ( H5E_DEFAULT, _h5_error_handler, NULL );
|
||||
if ( r5 < 0 ) return H5_ERR_INIT;
|
||||
}
|
||||
__init = 1;
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
/*!
|
||||
\ingroup h5_private
|
||||
|
||||
@@ -76,14 +63,20 @@ static h5_int64_t
|
||||
_h5u_open_file (
|
||||
h5_file_t *f /*!< IN: file handle */
|
||||
) {
|
||||
f->shape = 0;
|
||||
f->diskshape = H5S_ALL;
|
||||
f->memshape = H5S_ALL;
|
||||
f->viewstart = -1;
|
||||
f->viewend = -1;
|
||||
f->pnparticles =
|
||||
f->u = (struct h5u_fdata*) malloc( sizeof (*f->u) );
|
||||
if ( f->u == NULL ) {
|
||||
return HANDLE_H5_NOMEM_ERR( f );
|
||||
}
|
||||
struct h5u_fdata *u = f->u;
|
||||
|
||||
u->shape = 0;
|
||||
u->diskshape = H5S_ALL;
|
||||
u->memshape = H5S_ALL;
|
||||
u->viewstart = -1;
|
||||
u->viewend = -1;
|
||||
u->pnparticles =
|
||||
(h5_int64_t*) malloc (f->nprocs * sizeof (h5_int64_t));
|
||||
if (f->pnparticles == NULL) {
|
||||
if (u->pnparticles == NULL) {
|
||||
return HANDLE_H5_NOMEM_ERR( f );
|
||||
}
|
||||
return H5_SUCCESS;
|
||||
@@ -143,43 +136,22 @@ _h5b_open_file (
|
||||
\return File handle.
|
||||
\return NULL on error.
|
||||
*/
|
||||
|
||||
h5_file_t *
|
||||
h5_open_file (
|
||||
|
||||
h5_err_t
|
||||
_h5_open_file (
|
||||
h5_file_t * const f,
|
||||
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 */
|
||||
MPI_Comm comm /*!< MPI communicator */
|
||||
) {
|
||||
|
||||
|
||||
h5_file_t *f = NULL;
|
||||
|
||||
f = (h5_file_t*) malloc( sizeof (h5_file_t) );
|
||||
if( f == NULL ) {
|
||||
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 );
|
||||
|
||||
TRY ( _h5_set_errorhandler ( f, H5E_DEFAULT, _h5_error_handler, NULL ) );
|
||||
|
||||
f->prefix_step_name = strdup ( H5PART_GROUPNAME_STEP );
|
||||
if( f->prefix_step_name == NULL ) {
|
||||
HANDLE_H5_NOMEM_ERR( f );
|
||||
goto error_cleanup;
|
||||
}
|
||||
if( f->prefix_step_name == NULL )
|
||||
return HANDLE_H5_NOMEM_ERR( f );
|
||||
|
||||
f->width_step_idx = 0;
|
||||
|
||||
f->xfer_prop = f->create_prop = f->access_prop = H5P_DEFAULT;
|
||||
@@ -189,50 +161,38 @@ h5_open_file (
|
||||
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;
|
||||
}
|
||||
f->comm = comm;
|
||||
if (MPI_Comm_size (comm, &f->nprocs) != MPI_SUCCESS) {
|
||||
return HANDLE_MPI_COMM_SIZE_ERR;
|
||||
}
|
||||
if (MPI_Comm_rank (comm, &f->myproc) != MPI_SUCCESS) {
|
||||
return HANDLE_MPI_COMM_RANK_ERR;
|
||||
}
|
||||
|
||||
|
||||
/* 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) {
|
||||
return HANDLE_H5P_SET_FAPL_MPIO_ERR;
|
||||
}
|
||||
MPI_Info_free(&info);
|
||||
|
||||
TRY ( f->access_prop = _h5_create_property ( f, H5P_FILE_ACCESS ) );
|
||||
|
||||
/*TRY ( f->create_prop = _h5_create_property ( f, H5P_FILE_CREATE) );*/
|
||||
f->create_prop = H5P_DEFAULT;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* xfer_prop: also used for parallel I/O, during actual writes
|
||||
rather than the access_prop which is for file creation. */
|
||||
TRY ( f->xfer_prop = _h5_create_property ( f, H5P_DATASET_XFER ) );
|
||||
|
||||
#ifdef COLLECTIVE_IO
|
||||
if (H5Pset_dxpl_mpio (f->xfer_prop,H5FD_MPIO_COLLECTIVE) < 0) {
|
||||
HANDLE_H5P_SET_DXPL_MPIO_ERR;
|
||||
goto error_cleanup;
|
||||
if (H5Pset_dxpl_mpio (f->xfer_prop,H5FD_MPIO_COLLECTIVE) < 0) {
|
||||
return HANDLE_H5P_SET_DXPL_MPIO_ERR;
|
||||
}
|
||||
#endif /* COLLECTIVE_IO */
|
||||
|
||||
@@ -260,19 +220,16 @@ h5_open_file (
|
||||
}
|
||||
}
|
||||
else {
|
||||
HANDLE_H5_FILE_ACCESS_TYPE_ERR ( f, flags );
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
if (f->file < 0) {
|
||||
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 ( f, "", "" );
|
||||
goto error_cleanup;
|
||||
return HANDLE_H5_FILE_ACCESS_TYPE_ERR ( f, flags );
|
||||
}
|
||||
|
||||
if (f->file < 0)
|
||||
return h5_error (
|
||||
f,
|
||||
H5_ERR_HDF5,
|
||||
"Cannot open file \"%s\" with mode \"%d\"",
|
||||
filename, flags );
|
||||
TRY ( f->root_gid = _h5_open_group ( f, f->file, "/" ) );
|
||||
f->mode = flags;
|
||||
f->step_gid = -1;
|
||||
|
||||
@@ -281,31 +238,47 @@ h5_open_file (
|
||||
"%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;
|
||||
}
|
||||
TRY ( _h5u_open_file ( f ) );
|
||||
TRY ( _h5b_open_file ( f ) );
|
||||
TRY ( _h5t_open_file ( f ) );
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
h5_file_t *
|
||||
h5_open_file (
|
||||
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 */
|
||||
) {
|
||||
|
||||
if ( _h5b_open_file ( f ) < 0 ) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
if ( _h5t_open_file ( f ) < 0 ) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
h5_file_t *f = NULL;
|
||||
|
||||
f = (h5_file_t*) malloc( sizeof (h5_file_t) );
|
||||
if( f == NULL ) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"E: %s: Can't open file %s. Not enough memory!",
|
||||
funcname,
|
||||
filename );
|
||||
return NULL;
|
||||
}
|
||||
memset (f, 0, sizeof (h5_file_t));
|
||||
f->__funcname = funcname;
|
||||
if ( _h5_open_file( f, filename, flags, comm ) < 0 ) {
|
||||
if (f != NULL ) {
|
||||
if (f->prefix_step_name) {
|
||||
free (f->prefix_step_name);
|
||||
}
|
||||
if (f->u->pnparticles != NULL) {
|
||||
free (f->u->pnparticles);
|
||||
}
|
||||
free (f);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -322,25 +295,23 @@ static h5_int64_t
|
||||
_h5u_close_file (
|
||||
h5_file_t *f /*!< file handle */
|
||||
) {
|
||||
herr_t herr;
|
||||
struct h5u_fdata *u = f->u;
|
||||
|
||||
f->__errno = H5_SUCCESS;
|
||||
if( f->shape > 0 ) {
|
||||
herr = H5Sclose( f->shape );
|
||||
if ( herr < 0 ) HANDLE_H5S_CLOSE_ERR( f );
|
||||
f->shape = 0;
|
||||
if( u->shape > 0 ) {
|
||||
TRY( _h5_close_dataspace( f, u->shape ) );
|
||||
u->shape = 0;
|
||||
}
|
||||
if( f->diskshape != H5S_ALL ) {
|
||||
herr = H5Sclose( f->diskshape );
|
||||
if ( herr < 0 ) HANDLE_H5S_CLOSE_ERR( f );
|
||||
f->diskshape = 0;
|
||||
if( u->diskshape != H5S_ALL ) {
|
||||
TRY( _h5_close_dataspace( f, u->diskshape ) );
|
||||
u->diskshape = 0;
|
||||
}
|
||||
if( f->memshape != H5S_ALL ) {
|
||||
herr = H5Sclose( f->memshape );
|
||||
if ( herr < 0 ) HANDLE_H5S_CLOSE_ERR( f );
|
||||
f->memshape = 0;
|
||||
if( u->memshape != H5S_ALL ) {
|
||||
TRY( _h5_close_dataspace( f, u->memshape ) );
|
||||
u->memshape = 0;
|
||||
}
|
||||
if( f->pnparticles ) {
|
||||
free( f->pnparticles );
|
||||
if( u->pnparticles ) {
|
||||
free( u->pnparticles );
|
||||
}
|
||||
return f->__errno;
|
||||
}
|
||||
@@ -359,30 +330,12 @@ static h5_int64_t
|
||||
_h5b_close_file (
|
||||
h5_file_t *f /*!< IN: file handle */
|
||||
) {
|
||||
|
||||
herr_t herr;
|
||||
struct h5b_fdata *b = f->b;
|
||||
|
||||
if ( b->blockgroup >= 0 ) {
|
||||
herr = H5Gclose ( b->blockgroup );
|
||||
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( f );
|
||||
b->shape = -1;
|
||||
}
|
||||
if ( b->diskshape >= 0 ) {
|
||||
herr = H5Sclose ( b->diskshape );
|
||||
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( f );
|
||||
b->memshape = -1;
|
||||
}
|
||||
TRY ( _h5_close_group( f, b->blockgroup ) );
|
||||
TRY ( _h5_close_dataspace( f, b->shape ) );
|
||||
TRY ( _h5_close_dataspace( f, b->diskshape ) );
|
||||
TRY ( _h5_close_dataspace( f, b->memshape ) );
|
||||
free ( f->b );
|
||||
f->b = NULL;
|
||||
|
||||
@@ -398,57 +351,31 @@ _h5b_close_file (
|
||||
|
||||
\return H5_SUCCESS or error code
|
||||
*/
|
||||
h5_int64_t
|
||||
h5_err_t
|
||||
h5_close_file (
|
||||
h5_file_t *f /*!< file handle */
|
||||
) {
|
||||
herr_t r = 0;
|
||||
f->__errno = H5_SUCCESS;
|
||||
|
||||
CHECK_FILEHANDLE ( f );
|
||||
|
||||
_h5_close_step ( f );
|
||||
TRY( _h5_close_step ( f ) );
|
||||
TRY( _h5u_close_file ( f ) );
|
||||
TRY( _h5b_close_file ( f ) );
|
||||
TRY( _h5t_close_file ( f ) );
|
||||
TRY( _h5_close_group( f, f->step_gid ) );
|
||||
TRY( _h5_close_property ( f, f->xfer_prop ) );
|
||||
TRY( _h5_close_property ( f, f->access_prop ) );
|
||||
TRY( _h5_close_property ( f, f->create_prop ) );
|
||||
TRY( _h5_close_group ( f, f->root_gid ) );
|
||||
TRY( _h5_close_file ( f, f->file ) );
|
||||
|
||||
_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 );
|
||||
f->step_gid = -1;
|
||||
}
|
||||
if( f->xfer_prop != H5P_DEFAULT ) {
|
||||
r = H5Pclose( 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, "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, "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 );
|
||||
f->root_gid = 0;
|
||||
}
|
||||
if ( f->file ) {
|
||||
r = H5Fclose( f->file );
|
||||
if ( r < 0 ) HANDLE_H5F_CLOSE_ERR( f );
|
||||
f->file = 0;
|
||||
}
|
||||
if (f->prefix_step_name) {
|
||||
free (f->prefix_step_name);
|
||||
}
|
||||
free( f );
|
||||
|
||||
return f->__errno;
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -20,7 +20,7 @@ h5_close_file (
|
||||
);
|
||||
|
||||
h5_int64_t
|
||||
h5_define_stepname_fmt (
|
||||
h5_set_stepname_fmt (
|
||||
h5_file_t * const f,
|
||||
const char *name,
|
||||
const h5_int64_t width
|
||||
|
||||
+124
-233
@@ -9,9 +9,13 @@
|
||||
#include "h5_core.h"
|
||||
#include "h5_core_private.h"
|
||||
|
||||
h5_int64_t
|
||||
/*
|
||||
Obsolete function - still in old H5Part code !
|
||||
*/
|
||||
|
||||
h5_err_t
|
||||
h5_write_data (
|
||||
h5_file_t *f, /*!< IN: Handle to open file */
|
||||
h5_file_t * const 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_id, /*!< IN: Type of data */
|
||||
@@ -19,104 +23,111 @@ h5_write_data (
|
||||
const hid_t memspace_id,
|
||||
const hid_t diskspace_id
|
||||
) {
|
||||
herr_t herr;
|
||||
hid_t dataset_id;
|
||||
|
||||
h5_info ( f, "Writing dataset %s/%s.", h5_get_objname(group_id), name );
|
||||
|
||||
dataset_id = H5Dcreate (
|
||||
group_id,
|
||||
name,
|
||||
type_id,
|
||||
diskspace_id,
|
||||
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT );
|
||||
if ( dataset_id < 0 )
|
||||
return HANDLE_H5D_CREATE_ERR ( f, name );
|
||||
|
||||
herr = H5Dwrite (
|
||||
dataset_id,
|
||||
type_id,
|
||||
memspace_id,
|
||||
diskspace_id,
|
||||
f->xfer_prop,
|
||||
array );
|
||||
|
||||
if ( herr < 0 ) return HANDLE_H5D_WRITE_ERR ( f, name );
|
||||
|
||||
herr = H5Dclose ( dataset_id );
|
||||
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR( f );
|
||||
TRY ( dataset_id = _h5_create_dataset (
|
||||
f,
|
||||
group_id,
|
||||
name,
|
||||
type_id,
|
||||
diskspace_id,
|
||||
H5P_DEFAULT ) );
|
||||
TRY ( _h5_write_dataset (
|
||||
f,
|
||||
dataset_id,
|
||||
type_id,
|
||||
memspace_id,
|
||||
diskspace_id,
|
||||
f->xfer_prop,
|
||||
array ) );
|
||||
TRY ( _h5_close_dataset( f, dataset_id ) );
|
||||
|
||||
f->empty = 0;
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
/*!
|
||||
Write data to dataset.
|
||||
|
||||
- Open/Create dataset
|
||||
- set hyperslabs for disk and memory via callback functions
|
||||
- Write data
|
||||
- Close dataset
|
||||
*/
|
||||
h5_err_t
|
||||
h5_write_dataset (
|
||||
h5_file_t * 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_write (
|
||||
h5_file_t * const f,
|
||||
const hid_t loc_id,
|
||||
h5_dataset_info_t *ds_info,
|
||||
hid_t (*set_memspace)(h5_file_t*,hid_t),
|
||||
hid_t (*set_diskspace)(h5_file_t*,hid_t),
|
||||
const void * const data
|
||||
) {
|
||||
h5_info ( f, "Writing dataset %s/%s.",
|
||||
h5_get_objname(group_id), dataset_name );
|
||||
h5_get_objname ( loc_id ), ds_info->name );
|
||||
|
||||
if ( f->mode == O_RDONLY )
|
||||
return _h5_handle_file_mode_error( f, 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;
|
||||
H5O_info_t obj_info;
|
||||
herr_t herr = H5Oget_info_by_name(
|
||||
group_id,
|
||||
dataset_name,
|
||||
&dataset_info,
|
||||
loc_id,
|
||||
ds_info->name,
|
||||
&obj_info,
|
||||
H5P_DEFAULT );
|
||||
|
||||
if ( (herr >= 0) && ( (f->mode==H5_O_WRONLY) || (f->mode==H5_O_APPEND) ) ) {
|
||||
h5_warn ( f,
|
||||
"Dataset %s/%s already exist.",
|
||||
h5_get_objname(group_id), dataset_name );
|
||||
h5_get_objname ( loc_id ), ds_info->name );
|
||||
return _h5_handle_file_mode_error( f, f->mode );
|
||||
}
|
||||
|
||||
/*
|
||||
open/create dataset
|
||||
*/
|
||||
hid_t dataset_id;
|
||||
hid_t dataspace_id;
|
||||
hid_t diskspace_id;
|
||||
hid_t memspace_id;
|
||||
|
||||
if ( herr >= 0 ) {
|
||||
dataset_id = H5Dopen (
|
||||
group_id,
|
||||
dataset_name,
|
||||
H5P_DEFAULT );
|
||||
if ( dataset_id < 0 )
|
||||
return HANDLE_H5D_OPEN_ERR ( f, dataset_name );
|
||||
TRY( (dataset_id = _h5_open_dataset (
|
||||
f,
|
||||
loc_id,
|
||||
ds_info->name ) ) );
|
||||
TRY( (dataspace_id = _h5_get_dataset_space (
|
||||
f,
|
||||
dataset_id ) ) );
|
||||
/*
|
||||
extend dataset?
|
||||
*/
|
||||
} 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 ( f, dataset_name );
|
||||
TRY( (dataspace_id = _h5_create_dataset_space (
|
||||
f,
|
||||
ds_info->rank,
|
||||
ds_info->dims,
|
||||
ds_info->maxdims ) ) );
|
||||
TRY( (dataset_id = _h5_create_dataset (
|
||||
f,
|
||||
loc_id,
|
||||
ds_info->name,
|
||||
*ds_info->type_id,
|
||||
dataspace_id,
|
||||
ds_info->create_prop ) ) );
|
||||
}
|
||||
herr = H5Dwrite (
|
||||
dataset_id,
|
||||
type_id,
|
||||
memspace_id,
|
||||
diskspace_id,
|
||||
f->xfer_prop,
|
||||
data );
|
||||
TRY( (memspace_id = (*set_memspace)( f, 0 ) ) );
|
||||
TRY( (diskspace_id = (*set_diskspace)( f, dataspace_id ) ) );
|
||||
|
||||
if ( herr < 0 ) return HANDLE_H5D_WRITE_ERR ( f, dataset_name );
|
||||
TRY( _h5_write_dataset (
|
||||
f,
|
||||
dataset_id,
|
||||
*ds_info->type_id,
|
||||
memspace_id,
|
||||
diskspace_id,
|
||||
f->xfer_prop,
|
||||
data ) );
|
||||
|
||||
herr = H5Dclose ( dataset_id );
|
||||
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR( f );
|
||||
TRY( _h5_close_dataset( f, dataset_id ) );
|
||||
|
||||
f->empty = 0;
|
||||
|
||||
@@ -124,131 +135,36 @@ h5_write_dataset (
|
||||
}
|
||||
|
||||
h5_err_t
|
||||
h5_read_dataset2 (
|
||||
_h5_read (
|
||||
h5_file_t * const f,
|
||||
hid_t group_id,
|
||||
const char dataset_name[],
|
||||
hid_t type_id,
|
||||
hid_t loc_id,
|
||||
h5_dataset_info_t *ds_info,
|
||||
hid_t (*set_memspace)(h5_file_t*,hid_t),
|
||||
hid_t (*set_diskspace)(h5_file_t*,hid_t),
|
||||
void * const data ) {
|
||||
void * const data
|
||||
) {
|
||||
|
||||
hid_t dataset_id = H5Dopen ( group_id, dataset_name, H5P_DEFAULT );
|
||||
if ( dataset_id < 0 ) return HANDLE_H5D_OPEN_ERR ( f, dataset_name );
|
||||
hid_t dataset_id;
|
||||
hid_t memspace_id;
|
||||
hid_t diskspace_id;
|
||||
|
||||
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 (
|
||||
TRY ( (dataset_id = _h5_open_dataset (
|
||||
f,
|
||||
loc_id,
|
||||
ds_info->name ) ) );
|
||||
TRY ( (memspace_id = (*set_memspace)( f, dataset_id ) ) );
|
||||
TRY ( (diskspace_id = (*set_diskspace)( f, dataset_id ) ) );
|
||||
TRY ( _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( f );
|
||||
herr = H5Sclose ( memspace_id );
|
||||
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR( f );
|
||||
|
||||
herr = H5Dclose ( dataset_id );
|
||||
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR( f );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
h5_err_t
|
||||
h5_read_dataset (
|
||||
h5_file_t *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 ( f, 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( f );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
h5_err_t
|
||||
_h5_read_dataset (
|
||||
h5_file_t * 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,
|
||||
*ds_info->type_id,
|
||||
memspace_id,
|
||||
diskspace_id,
|
||||
f->xfer_prop,
|
||||
data );
|
||||
if ( herr < 0 )
|
||||
return HANDLE_H5D_READ_ERR ( f, h5_get_objname ( dataset_id ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
h5_int64_t
|
||||
_create_step (
|
||||
h5_file_t * f
|
||||
) {
|
||||
h5_debug (
|
||||
f,
|
||||
"Proc[%d]: Create step #%lld for file %lld",
|
||||
f->myproc,
|
||||
(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,
|
||||
H5P_DEFAULT, H5P_DEFAULT );
|
||||
if ( f->step_gid < 0 )
|
||||
return HANDLE_H5G_CREATE_ERR ( f, f->step_name );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
h5_int64_t
|
||||
_open_step (
|
||||
h5_file_t * f
|
||||
) {
|
||||
h5_info (
|
||||
f,
|
||||
"Proc[%d]: Open step #%lld for file %lld",
|
||||
f->myproc,
|
||||
(long long)f->step_idx,
|
||||
(long long)(size_t) f );
|
||||
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, "", f->step_name );
|
||||
data ) );
|
||||
TRY ( _h5_close_dataspace ( f, diskspace_id ) );
|
||||
TRY ( _h5_close_dataspace ( f, memspace_id ) );
|
||||
TRY ( _h5_close_dataset ( f, dataset_id ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
@@ -257,8 +173,7 @@ static h5_err_t
|
||||
_init_step (
|
||||
h5_file_t * f
|
||||
) {
|
||||
h5_err_t h5err = _h5t_init_step ( f );
|
||||
if ( h5err < 0 ) return h5err;
|
||||
TRY ( _h5t_init_step ( f ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
@@ -269,19 +184,15 @@ _h5_close_step (
|
||||
) {
|
||||
|
||||
if ( f->step_gid < 0 ) return H5_SUCCESS;
|
||||
|
||||
h5_err_t h5err = _h5t_close_step ( f );
|
||||
if ( h5err < 0 ) return h5err;
|
||||
|
||||
herr_t herr = H5Gclose ( f->step_gid );
|
||||
if ( herr < 0 ) return HANDLE_H5G_CLOSE_ERR( f );
|
||||
TRY ( _h5t_close_step ( f ) );
|
||||
TRY ( _h5_close_group ( f, f->step_gid ) );
|
||||
|
||||
f->step_gid = -1;
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
h5_int64_t
|
||||
h5_err_t
|
||||
_set_step (
|
||||
h5_file_t * f,
|
||||
const h5_int64_t step_idx /*!< [in] Step to set. */
|
||||
@@ -292,24 +203,14 @@ _set_step (
|
||||
f->step_name,
|
||||
"%s#%0*lld",
|
||||
f->prefix_step_name, f->width_step_idx, (long long) f->step_idx );
|
||||
h5_info (
|
||||
f,
|
||||
"Proc[%d]: Open step #%lld for file %lld",
|
||||
f->myproc,
|
||||
(long long)f->step_idx,
|
||||
(long long)(size_t) f );
|
||||
TRY ( f->step_gid = _h5_open_group ( f, f->file, f->step_name ) );
|
||||
|
||||
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, "", 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 ( f, step_idx );
|
||||
herr = _create_step ( f );
|
||||
if ( herr < 0 ) return herr;
|
||||
} else if ( (f->mode == H5_O_RDWR) && (herr < 0) ) {
|
||||
herr = _create_step ( f );
|
||||
if ( herr < 0 ) return herr;
|
||||
} else if ( (f->mode == H5_O_RDWR) && (herr >= 0) ) {
|
||||
herr = _open_step ( f );
|
||||
if ( herr < 0 ) return herr;
|
||||
}
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -319,14 +220,9 @@ h5_set_step (
|
||||
const h5_int64_t step_idx /*!< [in] Step to set. */
|
||||
) {
|
||||
|
||||
h5_err_t h5err = _h5_close_step ( f );
|
||||
if ( h5err < 0 ) return h5err;
|
||||
|
||||
h5err = _set_step ( f, step_idx );
|
||||
if ( h5err < 0 ) return h5err;
|
||||
|
||||
h5err = _init_step ( f );
|
||||
if ( h5err < 0 ) return h5err;
|
||||
TRY ( _h5_close_step ( f ) );
|
||||
TRY ( _set_step ( f, step_idx ) );
|
||||
TRY ( _init_step ( f ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
@@ -368,19 +264,14 @@ h5_get_dataset_type(
|
||||
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 ( f, dataset_name );
|
||||
|
||||
hid_t hdf5_type = H5Dget_type ( dataset_id );
|
||||
if ( hdf5_type < 0 ) HANDLE_H5D_GET_TYPE_ERR( f );
|
||||
hid_t dataset_id;
|
||||
hid_t hdf5_type;
|
||||
|
||||
TRY( dataset_id = _h5_open_dataset ( f, group_id, dataset_name ) );
|
||||
TRY ( hdf5_type = _h5_get_dataset_type ( f, dataset_id ) );
|
||||
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( f );
|
||||
|
||||
herr = H5Dclose(dataset_id);
|
||||
if ( herr < 0 ) HANDLE_H5D_CLOSE_ERR( f );
|
||||
TRY( _h5_close_type( f, hdf5_type ) );
|
||||
TRY( _h5_close_dataset( f, dataset_id ) );
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __READWRITE_H
|
||||
#define __READWRITE_H
|
||||
#ifndef __H5_READWRITE_H
|
||||
#define __H5_READWRITE_H
|
||||
|
||||
h5_int64_t
|
||||
h5_write_data (
|
||||
@@ -12,20 +12,6 @@ h5_write_data (
|
||||
const hid_t diskspace_id
|
||||
) ;
|
||||
|
||||
h5_err_t
|
||||
h5_write_dataset (
|
||||
h5_file_t * 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
|
||||
) ;
|
||||
|
||||
|
||||
|
||||
|
||||
h5_int64_t
|
||||
h5_set_step (
|
||||
h5_file_t * const f,
|
||||
|
||||
@@ -2,12 +2,22 @@
|
||||
#define __H5_READWRITE_PRIVATE_H
|
||||
|
||||
h5_err_t
|
||||
_h5_read_dataset (
|
||||
h5_file_t * const f,
|
||||
hid_t dataset_id,
|
||||
hid_t type_id,
|
||||
hid_t memspace_id,
|
||||
hid_t diskspace_id,
|
||||
void * const data );
|
||||
_h5_write (
|
||||
h5_file_t * const f,
|
||||
hid_t loc_id,
|
||||
struct h5_dataset_info *ds_info,
|
||||
hid_t (*set_memspace)(h5_file_t*,hid_t),
|
||||
hid_t (*set_diskspace)(h5_file_t*,hid_t),
|
||||
const void * const data
|
||||
);
|
||||
|
||||
h5_err_t
|
||||
_h5_read (
|
||||
h5_file_t * const f,
|
||||
hid_t loc_id,
|
||||
h5_dataset_info_t *ds_info,
|
||||
hid_t (*set_memspace)(h5_file_t*,hid_t),
|
||||
hid_t (*set_diskspace)(h5_file_t*,hid_t),
|
||||
void * const data
|
||||
);
|
||||
#endif
|
||||
|
||||
+17
-32
@@ -1,17 +1,28 @@
|
||||
#ifndef __H5_TYPES_H
|
||||
#define __H5_TYPES_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <hdf5.h>
|
||||
|
||||
/*
|
||||
file modes:
|
||||
H5_O_RDONLY: only reading allowed
|
||||
H5_O_WRONLY: create new file, dataset must not exist
|
||||
H5_O_APPEND: allows to append a new datasets to an existing file
|
||||
H5_O_RDWR: dataset may exist
|
||||
*/
|
||||
|
||||
#define H5_O_RDWR 0
|
||||
#define H5_O_RDONLY 1
|
||||
#define H5_O_WRONLY 2
|
||||
#define H5_O_APPEND 3
|
||||
|
||||
#define H5_ID_T H5T_NATIVE_INT64
|
||||
#define H5_FLOAT64_T H5T_NATIVE_DOUBLE
|
||||
#define H5_FLOAT32_T H5T_NATIVE_FLOAT
|
||||
#define H5_INT64_T H5T_NATIVE_INT64
|
||||
#define H5_INT32_T H5T_NATIVE_INT32
|
||||
#define H5_COMPOUND_T H5T_COMPOUND
|
||||
|
||||
extern const char * const H5_O_MODES[];
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -86,32 +97,6 @@ struct h5_file {
|
||||
h5_int64_t step_idx; /* step index */
|
||||
int is_new_step;
|
||||
|
||||
/*
|
||||
BEGIN unstructured stuff,
|
||||
should be moved to 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;
|
||||
|
||||
/* END unstructured */
|
||||
|
||||
struct h5u_fdata *u;
|
||||
struct h5b_fdata *b;
|
||||
struct h5t_fdata *t;
|
||||
@@ -127,6 +112,6 @@ enum h5_oid { /* enum with number of vertices(!) */
|
||||
};
|
||||
typedef enum h5_oid h5_oid_t;
|
||||
|
||||
#define H5_MAX_VERTICES_PER_ENTITY H5_OID_TETRAHEDRON
|
||||
#define H5_MAX_VERTICES_PER_ELEM H5_OID_TETRAHEDRON
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <hdf5.h>
|
||||
|
||||
#include "h5_core/h5_core.h"
|
||||
@@ -111,42 +114,43 @@ _h5t_read_boundaryfaces (
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
boundary_t *boundary = &t->boundary;
|
||||
hid_t diskspace_id;
|
||||
|
||||
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 ( f, dataset_name );
|
||||
|
||||
hid_t diskspace_id = H5Dget_space(dataset_id);
|
||||
if ( diskspace_id < 0 ) return (hid_t)HANDLE_H5D_GET_SPACE_ERR ( f );
|
||||
hid_t dataset_id;
|
||||
TRY( dataset_id = _h5_open_dataset ( f, boundary->gid, dataset_name ) );
|
||||
TRY( diskspace_id = _h5_get_dataset_space ( f, dataset_id ) );
|
||||
|
||||
h5_id_t num_faces = H5Sget_simple_extent_npoints ( diskspace_id );
|
||||
if ( num_faces < 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 );
|
||||
|
||||
herr = H5Dclose ( dataset_id );
|
||||
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR ( f );
|
||||
TRY( _h5_close_dataspace( f, diskspace_id ) );
|
||||
TRY( _h5_close_dataset( f, dataset_id ) );
|
||||
|
||||
h5t_add_num_boundaryfaces ( f, num_faces );
|
||||
|
||||
h5_err_t h5err = _h5_read_dataset (
|
||||
TRY( _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 ( f );
|
||||
f->xfer_prop,
|
||||
boundary->faces ) );
|
||||
TRY( _h5_close_dataset( f, dataset_id ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
static hid_t
|
||||
_open_space_all (
|
||||
h5_file_t * const f,
|
||||
hid_t dataset_id
|
||||
) {
|
||||
return H5S_ALL;
|
||||
}
|
||||
|
||||
h5_err_t
|
||||
_h5t_write_boundary (
|
||||
h5_file_t * const f
|
||||
@@ -154,16 +158,13 @@ _h5t_write_boundary (
|
||||
struct h5t_fdata *t = f->t;
|
||||
boundary_t *boundary = &t->boundary;
|
||||
|
||||
hsize_t maxdim = H5S_UNLIMITED;
|
||||
|
||||
return _h5t_write_obj (
|
||||
return _h5_write (
|
||||
f,
|
||||
boundary->gid,
|
||||
boundary->num_faces[0],
|
||||
maxdim,
|
||||
H5T_NATIVE_INT32,
|
||||
(void*)boundary->faces,
|
||||
"Faces"
|
||||
&boundary->dsinfo,
|
||||
_open_space_all,
|
||||
_open_space_all,
|
||||
(void*)boundary->faces
|
||||
);
|
||||
}
|
||||
|
||||
@@ -314,7 +315,7 @@ h5t_store_boundaryface_local_id (
|
||||
switch ( t->mesh_type ) {
|
||||
case H5_OID_TETRAHEDRON: {
|
||||
h5_id_t local_tet_id = local_fid & H5_TET_MASK;
|
||||
if ( t->elems.tets[local_tet_id].parent_id != -1 ) {
|
||||
if ( t->elems.tets[local_tet_id].parent_eid != -1 ) {
|
||||
return _h5t_error_store_boundaryface_local_id (
|
||||
f,
|
||||
local_fid );
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include "h5_types.h"
|
||||
|
||||
const char * _h5t_oid_names[] = {
|
||||
"N.N.",
|
||||
"vertex",
|
||||
@@ -16,7 +18,7 @@ const char * _h5t_meshes_grpnames[] = {
|
||||
|
||||
const char *
|
||||
_h5t_map_oid2str (
|
||||
h5_id_t oid
|
||||
h5_oid_t oid
|
||||
) {
|
||||
if ( oid < 0 || oid >= sizeof(_h5t_oid_names)/sizeof(char*) ) {
|
||||
return "[invalid oid]";
|
||||
|
||||
@@ -36,7 +36,7 @@ _h5t_error_illegal_object_type (
|
||||
f, \
|
||||
H5_ERR_NOENTRY, \
|
||||
"%s with global id %lld does not exist!", \
|
||||
name, (long)id );
|
||||
name, id );
|
||||
|
||||
|
||||
#define _h5t_error_global_tet_id_nexist( f, vids ) \
|
||||
|
||||
+10
-14
@@ -11,7 +11,7 @@
|
||||
|
||||
h5_size_t
|
||||
h5t_get_num_meshes (
|
||||
h5_file_t * f,
|
||||
h5_file_t * const f,
|
||||
const enum h5_oid type
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
@@ -24,7 +24,7 @@ h5t_get_num_meshes (
|
||||
}
|
||||
TRY( t->num_meshes = (h5_size_t)hdf5_get_num_objects (
|
||||
t->topo_gid,
|
||||
_h5t_meshes_grpnames[t->mesh_type],
|
||||
_h5t_meshes_grpnames[type],
|
||||
H5G_GROUP ) );
|
||||
|
||||
return t->num_meshes;
|
||||
@@ -37,29 +37,25 @@ h5t_get_num_levels (
|
||||
h5_file_t * f
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
h5_err_t h5err;
|
||||
hid_t dataset_id;
|
||||
hid_t diskspace_id;
|
||||
|
||||
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;
|
||||
TRY( _h5t_open_mesh_group ( f ) );
|
||||
}
|
||||
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 );
|
||||
TRY( dataset_id = _h5_open_dataset ( f, t->mesh_gid, "NumVertices" ) );
|
||||
TRY( diskspace_id = _h5_get_dataset_space ( f, dataset_id ) );
|
||||
|
||||
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 );
|
||||
TRY( _h5_close_dataspace( f, diskspace_id ) );
|
||||
|
||||
t->num_levels = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
+24
-24
@@ -121,25 +121,25 @@ _get_local_vid_of_elem (
|
||||
|
||||
switch ( t->mesh_type ) {
|
||||
case H5_OID_TETRAHEDRON: {
|
||||
local_vid = t->elems_ldta.tets[local_eid].vids[ith_vertex];
|
||||
local_vid = t->elems_data.tets[local_eid].vids[ith_vertex];
|
||||
if ( local_vid == -1 ) {
|
||||
global_vid =
|
||||
t->elems.tets[local_eid].vids[ith_vertex];
|
||||
local_vid = _h5_search_idmap (
|
||||
&t->map_vertex_g2l, global_vid );
|
||||
t->elems_ldta.tets[local_eid].vids[ith_vertex] =
|
||||
t->elems_data.tets[local_eid].vids[ith_vertex] =
|
||||
local_vid;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case H5_OID_TRIANGLE: {
|
||||
local_vid = t->elems_ldta.tris[local_eid].vids[ith_vertex];
|
||||
local_vid = t->elems_data.tris[local_eid].vids[ith_vertex];
|
||||
if ( local_vid == -1 ) {
|
||||
global_vid =
|
||||
t->elems.tris[local_eid].vids[ith_vertex];
|
||||
local_vid = _h5_search_idmap (
|
||||
&t->map_vertex_g2l, global_vid );
|
||||
t->elems_ldta.tris[local_eid].vids[ith_vertex] =
|
||||
t->elems_data.tris[local_eid].vids[ith_vertex] =
|
||||
local_vid;
|
||||
}
|
||||
break;
|
||||
@@ -274,23 +274,23 @@ _h5t_sort_elems (
|
||||
int k;
|
||||
h5_id_t i;
|
||||
for ( k = 0; k < 2; k++ ) {
|
||||
TRY( _h5_alloc_smap ( f, &t->sorted_elems_ldta[k], num_elems ) );
|
||||
TRY( _h5_alloc_smap ( f, &t->sorted_elems[k], num_elems ) );
|
||||
for ( i = 0; i < num_elems; i++ ) {
|
||||
t->sorted_elems_ldta[k].items[i] = i;
|
||||
t->sorted_elems[k].items[i] = i;
|
||||
}
|
||||
t->sorted_elems_ldta[k].num_items = num_elems;
|
||||
t->sorted_elems[k].num_items = num_elems;
|
||||
}
|
||||
|
||||
_h5_qsort_r (
|
||||
t->sorted_elems_ldta[0].items,
|
||||
t->sorted_elems[0].items,
|
||||
num_elems,
|
||||
sizeof(t->sorted_elems_ldta[0].items[0]),
|
||||
sizeof(t->sorted_elems[0].items[0]),
|
||||
f,
|
||||
_qsort_cmp_elems0 );
|
||||
_h5_qsort_r (
|
||||
t->sorted_elems_ldta[1].items,
|
||||
t->sorted_elems[1].items,
|
||||
num_elems,
|
||||
sizeof(t->sorted_elems_ldta[1].items[0]),
|
||||
sizeof(t->sorted_elems[1].items[0]),
|
||||
f,
|
||||
_qsort_cmp_elems1 );
|
||||
|
||||
@@ -367,13 +367,13 @@ _search_elem (
|
||||
_h5t_sort_local_vids ( f, local_vids, t->mesh_type );
|
||||
|
||||
register h5_id_t low = 0;
|
||||
register h5_id_t high = t->sorted_elems_ldta[0].num_items - 1;
|
||||
register h5_id_t high = t->sorted_elems[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_elems_ldta[0].items[mid];
|
||||
h5_id_t *elem2 = t->elems_ldta.tets[local_eid].vids;
|
||||
h5_id_t local_eid = t->sorted_elems[0].items[mid];
|
||||
h5_id_t *elem2 = t->elems_data.tets[local_eid].vids;
|
||||
int diff = _vcmp_elems ( f, elem1, elem2 );
|
||||
if ( diff < 0 )
|
||||
high = mid - 1;
|
||||
@@ -397,7 +397,7 @@ h5t_get_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];
|
||||
return t->sorted_elems[0].items[local_eid];
|
||||
fail:
|
||||
return _h5t_handle_get_local_eid_err ( f, local_vids );
|
||||
}
|
||||
@@ -427,7 +427,7 @@ h5t_map_local_vid2global (
|
||||
|
||||
if ( local_vid < 0 || local_vid > t->num_vertices[t->num_levels-1] )
|
||||
return HANDLE_H5_OUT_OF_RANGE_ERR ( f, "vertex", local_vid );
|
||||
return t->vertices[local_vid].id;
|
||||
return t->vertices[local_vid].vid;
|
||||
}
|
||||
|
||||
h5_err_t
|
||||
@@ -464,12 +464,12 @@ h5t_map_local_eid2global (
|
||||
case H5_OID_TETRAHEDRON:
|
||||
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;
|
||||
return t->elems.tets[local_eid].eid;
|
||||
case H5_OID_TRIANGLE:
|
||||
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;
|
||||
return t->elems.tris[local_eid].eid;
|
||||
default:
|
||||
return h5_error_internal ( f, __FILE__, __func__, __LINE__ );
|
||||
}
|
||||
@@ -510,14 +510,14 @@ _search_ith_vertex_in_elem (
|
||||
struct h5t_fdata *t = f->t;
|
||||
|
||||
register h5_id_t low = 0;
|
||||
register h5_id_t high = t->sorted_elems_ldta[i].num_items - 1;
|
||||
register h5_id_t high = t->sorted_elems[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_elems_ldta[i].items[mid];
|
||||
h5_id_t local_vid2 = t->elems_ldta.tets[local_eid].vids[i];
|
||||
h5_id_t local_eid = t->sorted_elems[i].items[mid];
|
||||
h5_id_t local_vid2 = t->elems_data.tets[local_eid].vids[i];
|
||||
h5_float64_t *vertex2 = t->vertices[local_vid2].P;
|
||||
int diff = _cmp_vertices ( vertex1, vertex2 );
|
||||
|
||||
@@ -540,7 +540,7 @@ _tetm_contain_triangle (
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
|
||||
h5_id_t *local_vids_of_elem = t->elems_ldta.tets[local_eid].vids;
|
||||
h5_id_t *local_vids_of_elem = t->elems_data.tets[local_eid].vids;
|
||||
if ( i == 0 &&
|
||||
local_vids[1] == local_vids_of_elem[1] &&
|
||||
local_vids[2] == local_vids_of_elem[2]
|
||||
@@ -600,12 +600,12 @@ _tetm_search_triangle (
|
||||
|
||||
while ( idx[i] > 0 && /* get leftmost */
|
||||
local_vids[0] == _get_local_vid_of_elem (
|
||||
f, i, t->sorted_elems_ldta[0].items[idx[i]-1] ) )
|
||||
f, i, t->sorted_elems[0].items[idx[i]-1] ) )
|
||||
idx[i]--;
|
||||
|
||||
do {
|
||||
/* check whether triangle is in elem given by local id */
|
||||
local_eid[i] = t->sorted_elems_ldta[i].items[idx[i]];
|
||||
local_eid[i] = t->sorted_elems[i].items[idx[i]];
|
||||
tidx[i] = _tetm_contain_triangle (
|
||||
f, local_vids, i, local_eid[i] );
|
||||
if ( tidx[i] >= 0 ) break;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __T_MAP_H
|
||||
#define __T_MAP_H
|
||||
#ifndef __H5T_MAP_H
|
||||
#define __H5T_MAP_H
|
||||
|
||||
h5_id_t
|
||||
h5t_map_global_vid2local (
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __T_MAP_PRIVATE_H
|
||||
#define __T_MAP_PRIVATE_H
|
||||
#ifndef __H5T_MAP_PRIVATE_H
|
||||
#define __H5T_MAP_PRIVATE_H
|
||||
|
||||
h5_err_t
|
||||
_h5t_sort_global_vids (
|
||||
|
||||
+241
-176
@@ -17,35 +17,32 @@ static h5_err_t
|
||||
_create_array_types (
|
||||
h5_file_t * f
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
h5t_fdata_t *t = f->t;
|
||||
h5_dtypes_t *dtypes = &(t->dtypes);
|
||||
|
||||
hsize_t dims[1] = { 3 };
|
||||
hid_t hid = H5Tarray_create ( H5T_NATIVE_DOUBLE, 1, dims );
|
||||
if ( hid < 0 ) {
|
||||
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 ( 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 ( f, "H5T_NATIVE_INT32", 1 );
|
||||
}
|
||||
t->int32_3tuple_tid = hid;
|
||||
|
||||
TRY(
|
||||
dtypes->h5_coord3d_t = _h5_create_array_type (
|
||||
f,
|
||||
H5_FLOAT64_T,
|
||||
1,
|
||||
dims )
|
||||
);
|
||||
TRY(
|
||||
dtypes->h5_3id_t = _h5_create_array_type (
|
||||
f,
|
||||
H5_ID_T,
|
||||
1,
|
||||
dims )
|
||||
);
|
||||
dims[0] = 4;
|
||||
hid = H5Tarray_create ( H5T_NATIVE_INT32, 1, dims );
|
||||
if ( hid < 0 ) {
|
||||
return HANDLE_H5T_ARRAY_CREATE_ERR ( f, "H5T_NATIVE_INT32", 1 );
|
||||
}
|
||||
t->int32_4tuple_tid = hid;
|
||||
TRY(
|
||||
dtypes->h5_4id_t = _h5_create_array_type (
|
||||
f,
|
||||
H5_ID_T,
|
||||
1,
|
||||
dims )
|
||||
);
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
@@ -54,40 +51,27 @@ static h5_err_t
|
||||
_create_vertex_type (
|
||||
h5_file_t * f
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
h5_dtypes_t *dtypes = &f->t->dtypes;
|
||||
|
||||
hid_t hid = H5Tcreate ( H5T_COMPOUND, sizeof(struct h5_vertex) );
|
||||
if ( hid < 0 ) {
|
||||
return HANDLE_H5T_CREATE_ERR ( f, "H5T_COMPOUND", "verticies" );
|
||||
}
|
||||
t->vertex_tid = hid;
|
||||
|
||||
herr_t herr = H5Tinsert (
|
||||
t->vertex_tid,
|
||||
"id",
|
||||
HOFFSET(struct h5_vertex, id),
|
||||
H5T_NATIVE_INT32 );
|
||||
if ( herr < 0 ) {
|
||||
return HANDLE_H5T_INSERT_ERR ( f, "id", "verticies" );
|
||||
}
|
||||
|
||||
herr = H5Tinsert (
|
||||
t->vertex_tid,
|
||||
"unused",
|
||||
HOFFSET(struct h5_vertex, unused),
|
||||
H5T_NATIVE_INT32 );
|
||||
if ( herr < 0 ) {
|
||||
return HANDLE_H5T_INSERT_ERR ( f, "unused", "verticies" );
|
||||
}
|
||||
|
||||
herr = H5Tinsert (
|
||||
t->vertex_tid,
|
||||
"P",
|
||||
HOFFSET(struct h5_vertex, P),
|
||||
t->float64_3tuple_tid );
|
||||
if ( herr < 0 ) {
|
||||
return HANDLE_H5T_INSERT_ERR ( f, "P", "verticies" );
|
||||
}
|
||||
TRY(
|
||||
dtypes->h5_vertex_t = _h5_create_type (
|
||||
f,
|
||||
H5_COMPOUND_T,
|
||||
sizeof(struct h5_vertex) ) );
|
||||
TRY(
|
||||
_h5_insert_type (
|
||||
f,
|
||||
dtypes->h5_vertex_t,
|
||||
"vid",
|
||||
HOFFSET(struct h5_vertex, vid),
|
||||
H5_ID_T ) );
|
||||
TRY(
|
||||
_h5_insert_type (
|
||||
f,
|
||||
dtypes->h5_vertex_t,
|
||||
"P",
|
||||
HOFFSET(struct h5_vertex, P),
|
||||
dtypes->h5_coord3d_t ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
@@ -96,49 +80,41 @@ static h5_err_t
|
||||
_create_triangle_type (
|
||||
h5_file_t * f
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
h5_dtypes_t *dtypes = &f->t->dtypes;
|
||||
|
||||
hid_t hid = H5Tcreate ( H5T_COMPOUND, sizeof(struct h5_triangle) );
|
||||
if ( hid < 0 ) {
|
||||
return HANDLE_H5T_CREATE_ERR ( f, "H5T_COMPOUND", "triangle" );
|
||||
}
|
||||
t->triangle_tid = hid;
|
||||
|
||||
herr_t herr = H5Tinsert (
|
||||
t->triangle_tid,
|
||||
"id",
|
||||
HOFFSET(struct h5_triangle, id),
|
||||
H5T_NATIVE_INT32 );
|
||||
if ( herr < 0 ) {
|
||||
return HANDLE_H5T_INSERT_ERR ( f, "id", "triangle" );
|
||||
}
|
||||
|
||||
herr = H5Tinsert (
|
||||
t->triangle_tid,
|
||||
"parent_id",
|
||||
HOFFSET(struct h5_triangle, parent_id),
|
||||
H5T_NATIVE_INT32 );
|
||||
if ( herr < 0 ) {
|
||||
return HANDLE_H5T_INSERT_ERR ( f, "parent_id", "triangle" );
|
||||
}
|
||||
|
||||
herr = H5Tinsert (
|
||||
t->triangle_tid,
|
||||
"refined_on_level",
|
||||
HOFFSET(struct h5_triangle, refined_on_level),
|
||||
H5T_NATIVE_INT32 );
|
||||
if ( herr < 0 ) {
|
||||
return HANDLE_H5T_INSERT_ERR ( f, "refined_on_level", "triangle" );
|
||||
}
|
||||
|
||||
herr = H5Tinsert (
|
||||
t->triangle_tid,
|
||||
"vids",
|
||||
HOFFSET(struct h5_triangle, vids),
|
||||
t->int32_3tuple_tid );
|
||||
if ( herr < 0 ) {
|
||||
return HANDLE_H5T_INSERT_ERR ( f, "vids", "triangle" );
|
||||
}
|
||||
TRY(
|
||||
dtypes->h5_triangle_t = _h5_create_type (
|
||||
f,
|
||||
H5_COMPOUND_T,
|
||||
sizeof(struct h5_triangle) ) );
|
||||
TRY(
|
||||
_h5_insert_type (
|
||||
f,
|
||||
dtypes->h5_triangle_t,
|
||||
"eid",
|
||||
HOFFSET(struct h5_triangle, eid),
|
||||
H5_ID_T ) );
|
||||
TRY(
|
||||
_h5_insert_type (
|
||||
f,
|
||||
dtypes->h5_triangle_t,
|
||||
"parent_eid",
|
||||
HOFFSET(struct h5_triangle, parent_eid),
|
||||
H5_ID_T ) );
|
||||
TRY(
|
||||
_h5_insert_type (
|
||||
f,
|
||||
dtypes->h5_triangle_t,
|
||||
"refined_on_level",
|
||||
HOFFSET(struct h5_triangle, refined_on_level),
|
||||
H5_ID_T ) );
|
||||
TRY(
|
||||
_h5_insert_type (
|
||||
f,
|
||||
dtypes->h5_triangle_t,
|
||||
"vids",
|
||||
HOFFSET(struct h5_triangle, vids),
|
||||
dtypes->h5_3id_t ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
@@ -147,62 +123,61 @@ static h5_err_t
|
||||
_create_tet_type (
|
||||
h5_file_t * f
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
h5_dtypes_t *dtypes = &f->t->dtypes;
|
||||
|
||||
hid_t hid = H5Tcreate ( H5T_COMPOUND, sizeof(struct h5_tetrahedron) );
|
||||
if ( hid < 0 ) {
|
||||
return HANDLE_H5T_CREATE_ERR ( f, "H5T_COMPOUND", "tetrahedra" );
|
||||
}
|
||||
t->tet_tid = hid;
|
||||
|
||||
herr_t herr = H5Tinsert (
|
||||
t->tet_tid,
|
||||
"id",
|
||||
HOFFSET(struct h5_tetrahedron, id),
|
||||
H5T_NATIVE_INT32 );
|
||||
if ( herr < 0 ) {
|
||||
return HANDLE_H5T_INSERT_ERR ( f, "id", "tetrahedra" );
|
||||
}
|
||||
|
||||
herr = H5Tinsert (
|
||||
t->tet_tid,
|
||||
"parent_id",
|
||||
HOFFSET(struct h5_tetrahedron, parent_id),
|
||||
H5T_NATIVE_INT32 );
|
||||
if ( herr < 0 ) {
|
||||
return HANDLE_H5T_INSERT_ERR ( f, "parent_id", "tetrahedra" );
|
||||
}
|
||||
|
||||
herr = H5Tinsert (
|
||||
t->tet_tid,
|
||||
"refined_on_level",
|
||||
HOFFSET(struct h5_tetrahedron, refined_on_level),
|
||||
H5T_NATIVE_INT32 );
|
||||
if ( herr < 0 ) {
|
||||
return HANDLE_H5T_INSERT_ERR ( f, "refined_on_level", "tetrahedra" );
|
||||
}
|
||||
|
||||
herr = H5Tinsert (
|
||||
t->tet_tid,
|
||||
"unused",
|
||||
HOFFSET(struct h5_tetrahedron, unused),
|
||||
H5T_NATIVE_INT32 );
|
||||
if ( herr < 0 ) {
|
||||
return HANDLE_H5T_INSERT_ERR ( f, "unused", "tetrahedra" );
|
||||
}
|
||||
|
||||
herr = H5Tinsert (
|
||||
t->tet_tid,
|
||||
"vids",
|
||||
HOFFSET(struct h5_tetrahedron, vids),
|
||||
t->int32_4tuple_tid );
|
||||
if ( herr < 0 ) {
|
||||
return HANDLE_H5T_INSERT_ERR ( f, "vids", "tetrahedra" );
|
||||
}
|
||||
TRY(
|
||||
dtypes->h5_tet_t = _h5_create_type (
|
||||
f,
|
||||
H5_COMPOUND_T,
|
||||
sizeof(struct h5_tetrahedron) ) );
|
||||
TRY(
|
||||
_h5_insert_type (
|
||||
f,
|
||||
dtypes->h5_tet_t,
|
||||
"eid",
|
||||
HOFFSET(struct h5_tetrahedron, eid),
|
||||
H5_ID_T ) );
|
||||
TRY(
|
||||
_h5_insert_type (
|
||||
f,
|
||||
dtypes->h5_tet_t,
|
||||
"parent_eid",
|
||||
HOFFSET(struct h5_tetrahedron, parent_eid),
|
||||
H5_ID_T ) );
|
||||
TRY(
|
||||
_h5_insert_type (
|
||||
f,
|
||||
dtypes->h5_tet_t,
|
||||
"refined_on_level",
|
||||
HOFFSET(struct h5_tetrahedron, refined_on_level),
|
||||
H5T_NATIVE_INT32 ) );
|
||||
TRY(
|
||||
_h5_insert_type (
|
||||
f,
|
||||
dtypes->h5_tet_t,
|
||||
"vids",
|
||||
HOFFSET(struct h5_tetrahedron, vids),
|
||||
dtypes->h5_4id_t ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
#if 0
|
||||
h5_err_t
|
||||
_h5_set_dataset_properties (
|
||||
h5_dataset_info_t *dsinfo,
|
||||
const char *name,
|
||||
const hid_t type,
|
||||
const int rank,
|
||||
const hsize_t *dims,
|
||||
const hsize_t *maxdims,
|
||||
const hsize_t chunk_size
|
||||
) {
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
static h5_err_t
|
||||
_init_fdata (
|
||||
h5_file_t * f
|
||||
@@ -220,9 +195,93 @@ _init_fdata (
|
||||
t->topo_gid = -1;
|
||||
t->meshes_gid = -1;
|
||||
t->mesh_gid = -1;
|
||||
|
||||
t->num_boundaries = -1;
|
||||
|
||||
|
||||
/* vertices */
|
||||
strcpy( t->dsinfo_vertices.name, "Vertices" );
|
||||
t->dsinfo_vertices.rank = 1;
|
||||
t->dsinfo_vertices.dims[0] = 0;
|
||||
t->dsinfo_vertices.maxdims[0] = H5S_UNLIMITED;
|
||||
t->dsinfo_vertices.chunk_size[0] = 4096;
|
||||
t->dsinfo_vertices.type_id = &t->dtypes.h5_vertex_t;
|
||||
TRY( t->dsinfo_vertices.create_prop = _h5_create_property (
|
||||
f,
|
||||
H5P_DATASET_CREATE ) );
|
||||
TRY( _h5_set_chunk_property (
|
||||
f,
|
||||
t->dsinfo_vertices.create_prop,
|
||||
t->dsinfo_vertices.rank,
|
||||
t->dsinfo_vertices.chunk_size ) );
|
||||
t->dsinfo_vertices.access_prop = H5P_DEFAULT;
|
||||
|
||||
/* NumVertices */
|
||||
strcpy( t->dsinfo_num_vertices.name, "NumVertices" );
|
||||
t->dsinfo_num_vertices.rank = 1;
|
||||
t->dsinfo_num_vertices.dims[0] = 0;
|
||||
t->dsinfo_num_vertices.maxdims[0] = H5S_UNLIMITED;
|
||||
t->dsinfo_num_vertices.chunk_size[0] = 4096;
|
||||
t->dsinfo_num_vertices.type_id = &t->dtypes.h5_id_t;
|
||||
TRY( t->dsinfo_num_vertices.create_prop = _h5_create_property (
|
||||
f,
|
||||
H5P_DATASET_CREATE ) );
|
||||
TRY( _h5_set_chunk_property (
|
||||
f,
|
||||
t->dsinfo_num_vertices.create_prop,
|
||||
t->dsinfo_num_vertices.rank,
|
||||
t->dsinfo_num_vertices.chunk_size ) );
|
||||
t->dsinfo_num_vertices.access_prop = H5P_DEFAULT;
|
||||
|
||||
/* Elems */
|
||||
strcpy( t->dsinfo_elems.name, "Elems" );
|
||||
t->dsinfo_elems.rank = 1;
|
||||
t->dsinfo_elems.dims[0] = 0;
|
||||
t->dsinfo_elems.maxdims[0] = H5S_UNLIMITED;
|
||||
t->dsinfo_elems.chunk_size[0] = 4096;
|
||||
t->dsinfo_elems.type_id = &t->elem_tid;
|
||||
TRY( t->dsinfo_elems.create_prop = _h5_create_property (
|
||||
f,
|
||||
H5P_DATASET_CREATE ) );
|
||||
TRY( _h5_set_chunk_property (
|
||||
f,
|
||||
t->dsinfo_elems.create_prop,
|
||||
t->dsinfo_elems.rank,
|
||||
t->dsinfo_elems.chunk_size ) );
|
||||
t->dsinfo_elems.access_prop = H5P_DEFAULT;
|
||||
|
||||
/* NumElems */
|
||||
strcpy( t->dsinfo_num_elems.name, "NumElems" );
|
||||
t->dsinfo_num_elems.rank = 1;
|
||||
t->dsinfo_num_elems.dims[0] = 0;
|
||||
t->dsinfo_num_elems.maxdims[0] = H5S_UNLIMITED;
|
||||
t->dsinfo_num_elems.chunk_size[0] = 4096;
|
||||
t->dsinfo_num_elems.type_id = &t->dtypes.h5_id_t;
|
||||
TRY( t->dsinfo_num_elems.create_prop = _h5_create_property (
|
||||
f,
|
||||
H5P_DATASET_CREATE ) );
|
||||
TRY( _h5_set_chunk_property (
|
||||
f,
|
||||
t->dsinfo_num_elems.create_prop,
|
||||
t->dsinfo_num_elems.rank,
|
||||
t->dsinfo_num_elems.chunk_size ) );
|
||||
t->dsinfo_num_elems.access_prop = H5P_DEFAULT;
|
||||
|
||||
/* NumElemsOnLevel */
|
||||
strcpy( t->dsinfo_num_elems_on_level.name, "NumElemsOnLevel" );
|
||||
t->dsinfo_num_elems_on_level.rank = 1;
|
||||
t->dsinfo_num_elems_on_level.dims[0] = 0;
|
||||
t->dsinfo_num_elems_on_level.maxdims[0] = H5S_UNLIMITED;
|
||||
t->dsinfo_num_elems_on_level.chunk_size[0] = 4096;
|
||||
t->dsinfo_num_elems_on_level.type_id = &t->dtypes.h5_id_t;
|
||||
TRY( t->dsinfo_num_elems_on_level.create_prop = _h5_create_property (
|
||||
f,
|
||||
H5P_DATASET_CREATE ) );
|
||||
TRY( _h5_set_chunk_property (
|
||||
f,
|
||||
t->dsinfo_num_elems_on_level.create_prop,
|
||||
t->dsinfo_num_elems_on_level.rank,
|
||||
t->dsinfo_num_elems_on_level.chunk_size ) );
|
||||
t->dsinfo_num_elems_on_level.access_prop = H5P_DEFAULT;
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -240,13 +299,22 @@ h5_err_t
|
||||
_h5t_open_file (
|
||||
h5_file_t * f /*!< IN: file handle */
|
||||
) {
|
||||
TRY( f->t = _h5_alloc ( f, NULL, sizeof(*f->t) ) );
|
||||
TRY( _init_fdata ( f ) );
|
||||
|
||||
TRY( (f->t = _h5_alloc ( f, NULL, sizeof(*f->t) ) ) );
|
||||
struct h5t_fdata *t = f->t;
|
||||
|
||||
t->dtypes.h5_id_t = H5_INT64_T;
|
||||
t->dtypes.h5_float64_t = H5_FLOAT64_T;
|
||||
|
||||
TRY( _create_array_types ( f ) );
|
||||
TRY( _create_vertex_type ( f ) );
|
||||
TRY( _create_triangle_type ( f ) );
|
||||
TRY( _create_tet_type ( f ) );
|
||||
|
||||
|
||||
|
||||
TRY( _init_fdata ( f ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -365,14 +433,14 @@ h5t_open_mesh (
|
||||
id = t->num_meshes;
|
||||
}
|
||||
t->mesh_type = type;
|
||||
snprintf ( t->mesh_name, sizeof (t->mesh_name), "%d", id );
|
||||
snprintf ( t->mesh_name, sizeof (t->mesh_name), "%lld", id );
|
||||
|
||||
switch( type ) {
|
||||
case H5_OID_TETRAHEDRON:
|
||||
t->elem_tid = t->tet_tid;
|
||||
t->elem_tid = t->dtypes.h5_tet_t;
|
||||
break;
|
||||
case H5_OID_TRIANGLE:
|
||||
t->elem_tid = t->triangle_tid;
|
||||
t->elem_tid = t->dtypes.h5_triangle_t;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
@@ -451,24 +519,13 @@ h5_err_t
|
||||
_h5t_close_mesh (
|
||||
h5_file_t * const f /*!< file handle */
|
||||
) {
|
||||
TRY( _h5t_write_mesh ( f ) );
|
||||
TRY( _close_hdf5_objs ( f ) );
|
||||
TRY( _release_memory ( f ) );
|
||||
TRY( h5t_close_boundary ( f ) );
|
||||
TRY( _init_fdata ( f ) );
|
||||
|
||||
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 = _init_fdata ( f )) < 0 ) return h5err;
|
||||
|
||||
return h5err;
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
h5_err_t
|
||||
@@ -486,3 +543,11 @@ h5t_open_level (
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
herr_t
|
||||
_h5_set_chunk_property (
|
||||
h5_file_t * const f,
|
||||
hid_t plist,
|
||||
int ndims,
|
||||
const hsize_t * dim
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __T_OPENCLOSE_H
|
||||
#define __T_OPENCLOSE_H
|
||||
#ifndef __H5T_OPENCLOSE_H
|
||||
#define __H5T_OPENCLOSE_H
|
||||
|
||||
h5_err_t
|
||||
_h5t_open_file (
|
||||
|
||||
+87
-133
@@ -9,65 +9,51 @@
|
||||
#include "h5_core/h5_core.h"
|
||||
#include "h5_core/h5_core_private.h"
|
||||
|
||||
|
||||
h5_err_t
|
||||
_h5t_write_obj (
|
||||
h5_file_t * f,
|
||||
const hid_t group_id,
|
||||
const hsize_t current_dims,
|
||||
const hsize_t max_dims,
|
||||
const hid_t type_id,
|
||||
const void * const object,
|
||||
const char * const dataset_name
|
||||
static hid_t
|
||||
_open_space_all (
|
||||
h5_file_t * const f,
|
||||
hid_t dataset_id
|
||||
) {
|
||||
|
||||
h5_err_t h5err = (h5_err_t)h5_write_dataset (
|
||||
f,
|
||||
group_id,
|
||||
dataset_name,
|
||||
type_id,
|
||||
H5S_ALL,
|
||||
H5S_ALL,
|
||||
object );
|
||||
if ( h5err < 0 ) return h5err;
|
||||
|
||||
return H5_SUCCESS;
|
||||
return H5S_ALL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Write vertices:
|
||||
* either we write a new dataset
|
||||
* or we append data to this dataset
|
||||
* appending means, a new level has been added
|
||||
* existing vertices will never be changed!
|
||||
|
||||
*/
|
||||
static h5_err_t
|
||||
_write_vertices (
|
||||
h5_file_t * f
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
h5_err_t h5err;
|
||||
|
||||
if ( t->num_vertices <= 0 ) return H5_SUCCESS; /* ???? */
|
||||
|
||||
if ( t->mesh_gid < 0 ) {
|
||||
h5err = _h5t_open_mesh_group ( f );
|
||||
if ( h5err < 0 ) return h5err;
|
||||
TRY( _h5t_open_mesh_group ( f ) );
|
||||
}
|
||||
|
||||
hsize_t maxdim = H5S_UNLIMITED;
|
||||
h5err = _h5t_write_obj (
|
||||
f,
|
||||
t->mesh_gid,
|
||||
t->num_vertices[t->num_levels-1],
|
||||
maxdim,
|
||||
t->vertex_tid,
|
||||
(void*)t->vertices,
|
||||
"Vertices"
|
||||
);
|
||||
if ( h5err < 0 ) return h5err;
|
||||
return _h5t_write_obj (
|
||||
f,
|
||||
t->mesh_gid,
|
||||
t->num_levels,
|
||||
maxdim,
|
||||
H5T_NATIVE_INT32,
|
||||
(void*)t->num_vertices,
|
||||
"NumVertices"
|
||||
);
|
||||
TRY( _h5_write (
|
||||
f,
|
||||
t->mesh_gid,
|
||||
&t->dsinfo_vertices,
|
||||
_open_space_all,
|
||||
_open_space_all,
|
||||
t->vertices ) );
|
||||
TRY( _h5_write (
|
||||
f,
|
||||
t->mesh_gid,
|
||||
&t->dsinfo_num_vertices,
|
||||
_open_space_all,
|
||||
_open_space_all,
|
||||
t->num_vertices ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
static h5_err_t
|
||||
@@ -75,62 +61,48 @@ _write_elems (
|
||||
h5_file_t * f
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
h5_err_t h5err;
|
||||
|
||||
if ( t->num_elems <= 0 ) return H5_SUCCESS;
|
||||
|
||||
if ( t->mesh_gid < 0 ) {
|
||||
h5err = _h5t_open_mesh_group ( f );
|
||||
if ( h5err < 0 ) return h5err;
|
||||
TRY( _h5t_open_mesh_group ( f ) );
|
||||
}
|
||||
|
||||
hsize_t maxdim = H5S_UNLIMITED;
|
||||
h5err = _h5t_write_obj (
|
||||
f,
|
||||
t->mesh_gid,
|
||||
t->num_elems[t->num_levels-1],
|
||||
maxdim,
|
||||
t->elem_tid,
|
||||
(void*)t->elems.data,
|
||||
"Elems"
|
||||
);
|
||||
if ( h5err < 0 ) return h5err;
|
||||
TRY( _h5_write (
|
||||
f,
|
||||
t->mesh_gid,
|
||||
&t->dsinfo_elems,
|
||||
_open_space_all,
|
||||
_open_space_all,
|
||||
t->elems.data ) );
|
||||
|
||||
h5err = _h5t_write_obj (
|
||||
f,
|
||||
t->mesh_gid,
|
||||
t->num_levels,
|
||||
maxdim,
|
||||
H5T_NATIVE_INT32,
|
||||
(void*)t->num_elems,
|
||||
"NumElems"
|
||||
);
|
||||
if ( h5err < 0 ) return h5err;
|
||||
TRY( _h5_write (
|
||||
f,
|
||||
t->mesh_gid,
|
||||
&t->dsinfo_num_elems,
|
||||
_open_space_all,
|
||||
_open_space_all,
|
||||
t->num_elems ) );
|
||||
|
||||
return _h5t_write_obj (
|
||||
f,
|
||||
t->mesh_gid,
|
||||
t->num_levels,
|
||||
maxdim,
|
||||
H5T_NATIVE_INT32,
|
||||
(void*)t->num_elems_on_level,
|
||||
"NumElemsOnLevel"
|
||||
);
|
||||
TRY( _h5_write (
|
||||
f,
|
||||
t->mesh_gid,
|
||||
&t->dsinfo_num_elems_on_level,
|
||||
_open_space_all,
|
||||
_open_space_all,
|
||||
t->num_elems_on_level ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
h5_err_t
|
||||
_h5t_write_mesh (
|
||||
h5_file_t * f
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
h5_err_t h5err;
|
||||
if ( ! f->t->mesh_changed ) return 0;
|
||||
|
||||
if ( ! t->mesh_changed ) return 0;
|
||||
|
||||
h5err = _write_vertices( f );
|
||||
if ( h5err < 0 ) return h5err;
|
||||
h5err = _write_elems( f );
|
||||
if ( h5err < 0 ) return h5err;
|
||||
TRY( _write_vertices( f ) );
|
||||
TRY( _write_elems( f ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
@@ -148,35 +120,25 @@ _read_dataset (
|
||||
hid_t (*open_file_space)(h5_file_t*,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 ( f, dataset_name );
|
||||
hid_t dataset_id;
|
||||
hid_t mem_space_id;
|
||||
hid_t file_space_id;
|
||||
|
||||
hid_t mem_space_id = (*open_mem_space)( f, dataset_id );
|
||||
if ( mem_space_id < 0 ) return mem_space_id;
|
||||
hid_t file_space_id = (*open_file_space)( f, dataset_id );
|
||||
if ( file_space_id < 0 ) return file_space_id;
|
||||
TRY( dataset_id = _h5_open_dataset ( f, group_id, dataset_name ) );
|
||||
TRY( mem_space_id = (*open_mem_space)( f, dataset_id ) );
|
||||
TRY( file_space_id = (*open_file_space)( f, dataset_id ) );
|
||||
TRY( _h5_read_dataset (
|
||||
f,
|
||||
dataset_id,
|
||||
type_id,
|
||||
mem_space_id,
|
||||
file_space_id,
|
||||
f->xfer_prop,
|
||||
data ) );
|
||||
|
||||
herr_t herr = H5Dread (
|
||||
dataset_id,
|
||||
type_id,
|
||||
mem_space_id,
|
||||
file_space_id,
|
||||
f->xfer_prop,
|
||||
data );
|
||||
if ( herr < 0 )
|
||||
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 ( f );
|
||||
}
|
||||
|
||||
if ( mem_space_id != H5S_ALL ) {
|
||||
herr = H5Sclose ( mem_space_id );
|
||||
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
|
||||
}
|
||||
herr = H5Dclose ( dataset_id );
|
||||
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR ( f );
|
||||
TRY( _h5_close_dataspace( f, file_space_id ) );
|
||||
TRY( _h5_close_dataspace( f, mem_space_id ) );
|
||||
TRY( _h5_close_dataset( f, dataset_id ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
@@ -197,16 +159,8 @@ _open_file_space_vertices (
|
||||
return H5S_ALL;
|
||||
}
|
||||
|
||||
static hid_t
|
||||
_open_space_all (
|
||||
h5_file_t * const f,
|
||||
hid_t dataset_id
|
||||
) {
|
||||
return H5S_ALL;
|
||||
}
|
||||
|
||||
h5_err_t
|
||||
_ht5_read_num_vertices (
|
||||
_h5t_read_num_vertices (
|
||||
h5_file_t * const f
|
||||
) {
|
||||
h5_err_t h5err;
|
||||
@@ -244,7 +198,7 @@ _h5t_read_vertices (
|
||||
TRY( _h5t_open_mesh_group ( f ) );
|
||||
}
|
||||
if ( t->num_vertices == NULL ) {
|
||||
TRY( _ht5_read_num_vertices ( f ) );
|
||||
TRY( _h5t_read_num_vertices ( f ) );
|
||||
}
|
||||
|
||||
TRY( _h5t_alloc_num_vertices ( f, t->num_vertices[t->num_levels-1] ) );
|
||||
@@ -252,7 +206,7 @@ _h5t_read_vertices (
|
||||
f,
|
||||
t->mesh_gid,
|
||||
"Vertices",
|
||||
t->vertex_tid,
|
||||
t->dtypes.h5_vertex_t,
|
||||
_open_mem_space_vertices,
|
||||
_open_file_space_vertices,
|
||||
t->vertices ) );
|
||||
@@ -260,7 +214,7 @@ _h5t_read_vertices (
|
||||
h5_id_t local_vid = 0;
|
||||
for ( ; local_vid < t->num_vertices[t->num_levels-1]; local_vid++ ) {
|
||||
t->map_vertex_g2l.items[local_vid].global_id =
|
||||
t->vertices[local_vid].id;
|
||||
t->vertices[local_vid].vid;
|
||||
t->map_vertex_g2l.items[local_vid].local_id = local_vid;
|
||||
t->map_vertex_g2l.num_items++;
|
||||
}
|
||||
@@ -298,7 +252,7 @@ h5t_traverse_vertices (
|
||||
return 0;
|
||||
}
|
||||
h5_vertex_t *vertex = &t->vertices[++t->last_retrieved_vid];
|
||||
*id = vertex->id;
|
||||
*id = vertex->vid;
|
||||
memcpy ( P, &vertex->P, sizeof ( vertex->P ) );
|
||||
|
||||
return t->last_retrieved_vid;
|
||||
@@ -392,7 +346,7 @@ _h5t_read_elems (
|
||||
f,
|
||||
t->elems.tets[local_eid].vids,
|
||||
t->mesh_type,
|
||||
t->elems_ldta.tets[local_eid].vids
|
||||
t->elems_data.tets[local_eid].vids
|
||||
) );
|
||||
}
|
||||
break;
|
||||
@@ -402,7 +356,7 @@ _h5t_read_elems (
|
||||
f,
|
||||
t->elems.tris[local_eid].vids,
|
||||
t->mesh_type,
|
||||
t->elems_ldta.tris[local_eid].vids
|
||||
t->elems_data.tris[local_eid].vids
|
||||
) );
|
||||
}
|
||||
break;
|
||||
@@ -462,8 +416,8 @@ _traverse_tets (
|
||||
}
|
||||
}
|
||||
|
||||
*id = tet->id;
|
||||
*parent_id = tet->parent_id;
|
||||
*id = tet->eid;
|
||||
*parent_id = tet->parent_eid;
|
||||
memcpy ( ids, &tet->vids, sizeof ( tet->vids ) );
|
||||
|
||||
return t->last_retrieved_eid;
|
||||
@@ -541,8 +495,8 @@ _traverse_triangles (
|
||||
}
|
||||
}
|
||||
|
||||
*id = tri->id;
|
||||
*parent_id = tri->parent_id;
|
||||
*id = tri->eid;
|
||||
*parent_id = tri->parent_eid;
|
||||
memcpy ( ids, &tri->vids, sizeof ( tri->vids ) );
|
||||
|
||||
return t->last_retrieved_eid;
|
||||
@@ -587,7 +541,7 @@ _h5t_read_mesh (
|
||||
if ( h5err < 0 ) return h5err;
|
||||
}
|
||||
|
||||
if ( t->sorted_elems_ldta[0].items == NULL ) {
|
||||
if ( t->sorted_elems[0].items == NULL ) {
|
||||
_h5t_sort_elems ( f );
|
||||
}
|
||||
return H5_SUCCESS;
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
#ifndef __T_READWRITE_H
|
||||
#define __T_READWRITE_H
|
||||
#ifndef __H5T_READWRITE_H
|
||||
#define __H5T_READWRITE_H
|
||||
|
||||
h5_err_t
|
||||
_h5t_write_mesh (
|
||||
h5_file_t * f
|
||||
);
|
||||
|
||||
h5_id_t
|
||||
h5t_add_mesh (
|
||||
h5_file_t * f
|
||||
);
|
||||
|
||||
h5_err_t
|
||||
_h5t_read_vertices (
|
||||
h5_file_t * f
|
||||
|
||||
+154
-230
@@ -1,12 +1,39 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <hdf5.h>
|
||||
|
||||
#include "h5_core/h5_core.h"
|
||||
#include "h5_core/h5_types_private.h"
|
||||
#include "h5_core/h5t_types_private.h"
|
||||
#include "h5_core/h5_core_private.h"
|
||||
|
||||
/*!
|
||||
Add new mesh
|
||||
|
||||
\return mesh id
|
||||
*/
|
||||
h5_id_t
|
||||
h5t_add_mesh (
|
||||
h5_file_t * const f,
|
||||
const h5_size_t num_elems,
|
||||
const h5_oid_t mesh_type
|
||||
) {
|
||||
h5_id_t mesh_id = 0;
|
||||
|
||||
TRY( (mesh_id = h5t_open_mesh ( f, -1, mesh_type )) );
|
||||
TRY( h5t_add_level ( f, num_elems+3, num_elems ) );
|
||||
|
||||
f->t->mesh_changed = 1;
|
||||
|
||||
return mesh_id;
|
||||
}
|
||||
|
||||
|
||||
h5_id_t
|
||||
h5t_add_level (
|
||||
h5_file_t * const f
|
||||
h5_file_t * const f,
|
||||
const h5_size_t num_vertices,
|
||||
const h5_size_t num_elems
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
|
||||
@@ -20,6 +47,9 @@ h5t_add_level (
|
||||
return -1; /* not implemented */
|
||||
}
|
||||
t->cur_level = t->num_levels++;
|
||||
t->dsinfo_num_vertices.dims[0] = t->num_levels;
|
||||
t->dsinfo_num_elems.dims[0] = t->num_levels;
|
||||
t->dsinfo_num_elems_on_level.dims[0] = t->num_levels;
|
||||
|
||||
ssize_t num_bytes = t->num_levels*sizeof ( h5_size_t );
|
||||
t->num_vertices = realloc ( t->num_vertices, num_bytes );
|
||||
@@ -36,6 +66,10 @@ h5t_add_level (
|
||||
t->last_stored_vid = -1;
|
||||
t->last_stored_eid = -1;
|
||||
}
|
||||
|
||||
TRY( _h5t_add_num_vertices ( f, num_vertices ) );
|
||||
TRY( _h5t_add_num_elems ( f, num_elems ) );
|
||||
|
||||
return t->cur_level;
|
||||
}
|
||||
|
||||
@@ -72,14 +106,14 @@ _h5t_add_num_vertices (
|
||||
ssize_t num_vertices = (t->cur_level > 0 ?
|
||||
t->num_vertices[t->cur_level-1] + num : num);
|
||||
t->num_vertices[t->cur_level] = num_vertices;
|
||||
|
||||
t->dsinfo_vertices.dims[0] = num_vertices;
|
||||
return _h5t_alloc_num_vertices ( f, num_vertices );
|
||||
}
|
||||
|
||||
h5_id_t
|
||||
h5t_store_vertex (
|
||||
h5_file_t * const f, /*!< file handle */
|
||||
const h5_id_t global_id, /*!< global vertex id or -1 */
|
||||
const h5_id_t global_vid, /*!< global vertex id or -1 */
|
||||
const h5_float64_t P[3] /*!< coordinates */
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
@@ -97,26 +131,12 @@ h5t_store_vertex (
|
||||
if ( t->cur_level < 0 )
|
||||
return _h5t_error_undef_level( f );
|
||||
|
||||
/*
|
||||
check id
|
||||
*/
|
||||
if ( (t->cur_level == 0) && (
|
||||
(global_id < 0) || (global_id >= t->num_vertices[0]) ) ) {
|
||||
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( f, "vertex", global_id );
|
||||
}
|
||||
|
||||
h5_id_t local_id = ++t->last_stored_vid;
|
||||
h5_vertex_t *vertex = &t->vertices[local_id];
|
||||
vertex->id = global_id;
|
||||
vertex->vid = global_vid; /* global id from mesher not yet handled! */
|
||||
vertex->vid = local_id; /* serial case: global id == local id */
|
||||
memcpy ( &vertex->P, P, sizeof ( vertex->P ) );
|
||||
|
||||
_h5_insert_idmap ( f, &t->map_vertex_g2l, global_id, local_id );
|
||||
|
||||
return local_id;
|
||||
}
|
||||
|
||||
@@ -133,11 +153,11 @@ _h5t_alloc_num_elems (
|
||||
switch ( t->mesh_type ) {
|
||||
case H5_OID_TETRAHEDRON:
|
||||
sizeof_elem = sizeof ( t->elems.tets[0] );
|
||||
sizeof_lelem = sizeof ( t->elems_ldta.tets[0] );
|
||||
sizeof_lelem = sizeof ( t->elems_data.tets[0] );
|
||||
break;
|
||||
case H5_OID_TRIANGLE:
|
||||
sizeof_elem = sizeof ( t->elems.tris[0] );
|
||||
sizeof_lelem = sizeof ( t->elems_ldta.tris[0] );
|
||||
sizeof_lelem = sizeof ( t->elems_data.tris[0] );
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
@@ -149,13 +169,13 @@ _h5t_alloc_num_elems (
|
||||
return H5_ERR_NOMEM;
|
||||
}
|
||||
|
||||
t->elems_ldta.data = realloc (
|
||||
t->elems_ldta.data, new_num_elems*sizeof_lelem );
|
||||
if ( t->elems_ldta.data == NULL ) {
|
||||
t->elems_data.data = realloc (
|
||||
t->elems_data.data, new_num_elems*sizeof_lelem );
|
||||
if ( t->elems_data.data == NULL ) {
|
||||
return H5_ERR_NOMEM;
|
||||
}
|
||||
memset (
|
||||
t->elems_ldta.data+cur_num_elems*sizeof_lelem,
|
||||
t->elems_data.data+cur_num_elems*sizeof_lelem,
|
||||
-1,
|
||||
(new_num_elems-cur_num_elems) * sizeof_lelem );
|
||||
|
||||
@@ -163,7 +183,7 @@ _h5t_alloc_num_elems (
|
||||
}
|
||||
|
||||
h5_err_t
|
||||
_h5t_add_num_elements (
|
||||
_h5t_add_num_elems (
|
||||
h5_file_t * const f,
|
||||
const h5_size_t num
|
||||
) {
|
||||
@@ -174,6 +194,7 @@ _h5t_add_num_elements (
|
||||
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->dsinfo_elems.dims[0] = 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;
|
||||
@@ -181,23 +202,15 @@ _h5t_add_num_elements (
|
||||
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_elements ( f, num ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
/*!
|
||||
\param[in] local_parent_eid local parent id of element if level \c >0 else \c -1
|
||||
\param[in] local_vids local vertex id's defining the element
|
||||
*/
|
||||
h5_id_t
|
||||
h5t_store_element (
|
||||
h5t_store_elem (
|
||||
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 */
|
||||
const h5_id_t local_parent_eid,
|
||||
const h5_id_t local_vids[]
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
|
||||
@@ -208,194 +221,88 @@ h5t_store_element (
|
||||
/* 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),
|
||||
f, _h5t_map_oid2str(t->mesh_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_eid != -1 ) ||
|
||||
( t->cur_level > 0 && local_parent_eid < 0 ) ||
|
||||
( t->cur_level > 0
|
||||
&& local_parent_cid >= t->num_elems[t->cur_level-1] )
|
||||
&& local_parent_eid >= t->num_elems[t->cur_level-1] )
|
||||
) {
|
||||
return HANDLE_H5_PARENT_ID_ERR (
|
||||
f,
|
||||
_h5t_map_oid2str(t->type),
|
||||
local_parent_cid );
|
||||
_h5t_map_oid2str(t->mesh_type),
|
||||
local_parent_eid );
|
||||
}
|
||||
|
||||
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]--;
|
||||
}
|
||||
switch ( t->mesh_type ) {
|
||||
case H5_OID_TETRAHEDRON:
|
||||
return _h5t_store_tet ( f, local_parent_eid, local_vids );
|
||||
case H5_OID_TRIANGLE:
|
||||
return _h5t_store_triangle ( f, local_parent_eid, local_vids );
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return local_id;
|
||||
|
||||
}
|
||||
|
||||
h5_id_t
|
||||
_h5t_store_tet (
|
||||
h5_file_t * const f,
|
||||
const h5_id_t parent_id, /*!< global parent id
|
||||
const h5_id_t local_parent_eid, /*!< local parent id
|
||||
if level \c >0 else \c -1 */
|
||||
const h5_id_t vids[4] /*!< tuple with vertex id's */
|
||||
const h5_id_t vids[4] /*!< tuple with local vertex id's */
|
||||
) {
|
||||
|
||||
struct h5t_fdata *t = f->t;
|
||||
|
||||
/*
|
||||
more than allocated
|
||||
*/
|
||||
if ( t->last_stored_eid+1 >= t->num_elems[t->cur_level] )
|
||||
return HANDLE_H5_OVERFLOW_ERR(
|
||||
f, "tet", t->num_elems[t->cur_level] );
|
||||
|
||||
/*
|
||||
level not set
|
||||
*/
|
||||
if ( t->cur_level < 0 )
|
||||
return _h5t_error_undef_level( f );
|
||||
|
||||
/*
|
||||
check parent id
|
||||
*/
|
||||
if ( (t->cur_level == 0) &&
|
||||
(parent_id != -1) ) {
|
||||
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 ( f, "tet", global_id, parent_id );
|
||||
}
|
||||
if ( (t->cur_level > 0) &&
|
||||
(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_elems[0]) ) ) {
|
||||
return HANDLE_H5_OUT_OF_RANGE_ERR( f, "tet", global_id );
|
||||
}
|
||||
if ( (t->cur_level > 0) && (
|
||||
(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_eid;
|
||||
h5_tetrahedron_t *tet = &t->elems.tets[local_id];
|
||||
tet->id = global_id;
|
||||
tet->parent_id = parent_id;
|
||||
h5_id_t local_eid = ++t->last_stored_eid;
|
||||
h5_tetrahedron_t *tet = &t->elems.tets[local_eid];
|
||||
tet->eid = local_eid;
|
||||
tet->parent_eid = local_parent_eid;
|
||||
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 );
|
||||
_h5t_sort_local_vids ( f, tet->vids, 4 );
|
||||
|
||||
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 =
|
||||
if ( local_parent_eid >= 0 ) {
|
||||
if ( t->elems.tets[local_parent_eid].refined_on_level < 0 ) {
|
||||
t->elems.tets[local_parent_eid].refined_on_level =
|
||||
t->cur_level;
|
||||
t->num_elems_on_level[t->cur_level]--;
|
||||
}
|
||||
}
|
||||
return local_id;
|
||||
return local_eid;
|
||||
}
|
||||
|
||||
|
||||
h5_id_t
|
||||
h5t_store_triangle (
|
||||
_h5t_store_triangle (
|
||||
h5_file_t * const f,
|
||||
const h5_id_t parent_id, /*!< global parent id
|
||||
if level \c >0 else \c -1 */
|
||||
const h5_id_t vids[3] /*!< tuple with vertex id's */
|
||||
const h5_id_t local_parent_eid,
|
||||
const h5_id_t vids[3]
|
||||
) {
|
||||
|
||||
struct h5t_fdata *t = f->t;
|
||||
|
||||
/*
|
||||
more than allocated
|
||||
*/
|
||||
if ( t->last_stored_eid+1 >= t->num_elems[t->cur_level] )
|
||||
return HANDLE_H5_OVERFLOW_ERR(
|
||||
f, "triangle", t->num_elems[t->cur_level] );
|
||||
|
||||
/*
|
||||
missing call to add the first level
|
||||
*/
|
||||
if ( t->cur_level < 0 )
|
||||
return _h5t_error_undef_level( f );
|
||||
|
||||
/*
|
||||
check parent id
|
||||
*/
|
||||
if ( (t->cur_level == 0) && (parent_id != -1) ) {
|
||||
return HANDLE_H5_PARENT_ID_ERR (
|
||||
f, "triangle", global_id, parent_id );
|
||||
}
|
||||
if ( (t->cur_level > 0) && (parent_id < 0) ) {
|
||||
return HANDLE_H5_PARENT_ID_ERR (
|
||||
f, "triangle", global_id, parent_id );
|
||||
}
|
||||
if ( (t->cur_level>0) && (parent_id >= t->num_elems[t->cur_level-1]) ) {
|
||||
return HANDLE_H5_PARENT_ID_ERR (
|
||||
f, "triangle", global_id, parent_id );
|
||||
}
|
||||
/*
|
||||
check id
|
||||
*/
|
||||
if ( (t->cur_level == 0) && (
|
||||
(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_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_eid;
|
||||
h5_triangle_t *tri = &t->elems.tris[local_id];
|
||||
tri->id = global_id;
|
||||
tri->parent_id = parent_id;
|
||||
h5_id_t local_eid = ++t->last_stored_eid;
|
||||
h5_triangle_t *tri = &t->elems.tris[local_eid];
|
||||
tri->eid = local_eid;
|
||||
tri->parent_eid = local_parent_eid;
|
||||
tri->refined_on_level = -1;
|
||||
|
||||
memcpy ( &tri->vids, vids, sizeof ( tri->vids ) );
|
||||
|
||||
_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.tris[local_parent_id].refined_on_level < 0 ) {
|
||||
t->elems.tris[local_parent_id].refined_on_level =
|
||||
if ( local_parent_eid >= 0 ) {
|
||||
if ( t->elems.tris[local_parent_eid].refined_on_level < 0 ) {
|
||||
t->elems.tris[local_parent_eid].refined_on_level =
|
||||
t->cur_level;
|
||||
t->num_elems_on_level[t->cur_level]--;
|
||||
}
|
||||
}
|
||||
return local_id;
|
||||
return local_eid;
|
||||
}
|
||||
|
||||
|
||||
@@ -416,20 +323,14 @@ _h5t_bisect_edge (
|
||||
h5_float64_t *P0 = t->vertices[local_vid0].P;
|
||||
h5_float64_t *P1 = t->vertices[local_vid1].P;
|
||||
|
||||
/*
|
||||
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 );
|
||||
local_id = ++t->last_stored_vid;
|
||||
h5_vertex_t *vertex = &t->vertices[local_id];
|
||||
vertex->id = h5t_get_num_vertices( f, -1, -1 );
|
||||
vertex->vid = local_id;
|
||||
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 ) {
|
||||
if ( _h5t_get_local_vid( f, vertex->P ) < 0 ) {
|
||||
t->num_vertices[t->cur_level]++;
|
||||
}
|
||||
|
||||
@@ -437,45 +338,76 @@ _h5t_bisect_edge (
|
||||
}
|
||||
|
||||
/*!
|
||||
Refine tetrahedron \c global_tid
|
||||
Refine element \c local_eid
|
||||
|
||||
\return Local id of first new element or \c -1
|
||||
*/
|
||||
h5_id_t
|
||||
h5t_refine_elem (
|
||||
h5_file_t * const f,
|
||||
const h5_id_t local_eid
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
switch ( t->mesh_type ) {
|
||||
case H5_OID_TETRAHEDRON:
|
||||
return _h5t_refine_tet ( f, local_eid );
|
||||
case H5_OID_TRIANGLE:
|
||||
return _h5t_refine_triangle ( f, local_eid );
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Refine triangle \c local_eid
|
||||
|
||||
\return Local id of first new triangle or \c -1
|
||||
*/
|
||||
h5_id_t
|
||||
_h5t_refine_triangle (
|
||||
h5_file_t * const f,
|
||||
const h5_id_t local_eid
|
||||
) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*!
|
||||
Refine tetrahedron \c local_eid
|
||||
|
||||
\return Local id of first new tetrahedron or \c -1
|
||||
*/
|
||||
h5_id_t
|
||||
h5t_refine_tet (
|
||||
_h5t_refine_tet (
|
||||
h5_file_t * const f,
|
||||
const h5_id_t parent_tet_global_id
|
||||
const h5_id_t local_eid
|
||||
) {
|
||||
struct h5t_fdata *t = f->t;
|
||||
h5_id_t local_vids[6];
|
||||
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->elems_ldta.tets[parent_tet_local_id].vids[0],
|
||||
t->elems_ldta.tets[parent_tet_local_id].vids[1] );
|
||||
t->elems_data.tets[local_eid].vids[0],
|
||||
t->elems_data.tets[local_eid].vids[1] );
|
||||
local_vids[1] = _h5t_bisect_edge(
|
||||
f,
|
||||
t->elems_ldta.tets[parent_tet_local_id].vids[0],
|
||||
t->elems_ldta.tets[parent_tet_local_id].vids[2] );
|
||||
t->elems_data.tets[local_eid].vids[0],
|
||||
t->elems_data.tets[local_eid].vids[2] );
|
||||
local_vids[2] = _h5t_bisect_edge(
|
||||
f,
|
||||
t->elems_ldta.tets[parent_tet_local_id].vids[0],
|
||||
t->elems_ldta.tets[parent_tet_local_id].vids[3] );
|
||||
t->elems_data.tets[local_eid].vids[0],
|
||||
t->elems_data.tets[local_eid].vids[3] );
|
||||
local_vids[3] = _h5t_bisect_edge(
|
||||
f,
|
||||
t->elems_ldta.tets[parent_tet_local_id].vids[1],
|
||||
t->elems_ldta.tets[parent_tet_local_id].vids[2] );
|
||||
t->elems_data.tets[local_eid].vids[1],
|
||||
t->elems_data.tets[local_eid].vids[2] );
|
||||
local_vids[4] = _h5t_bisect_edge(
|
||||
f,
|
||||
t->elems_ldta.tets[parent_tet_local_id].vids[1],
|
||||
t->elems_ldta.tets[parent_tet_local_id].vids[3] );
|
||||
t->elems_data.tets[local_eid].vids[1],
|
||||
t->elems_data.tets[local_eid].vids[3] );
|
||||
local_vids[5] = _h5t_bisect_edge(
|
||||
f,
|
||||
t->elems_ldta.tets[parent_tet_local_id].vids[2],
|
||||
t->elems_ldta.tets[parent_tet_local_id].vids[3] );
|
||||
t->elems_data.tets[local_eid].vids[2],
|
||||
t->elems_data.tets[local_eid].vids[3] );
|
||||
|
||||
/*
|
||||
add new tets
|
||||
@@ -484,50 +416,46 @@ h5t_refine_tet (
|
||||
|
||||
/* 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[0] = t->elems_data.tets[local_eid].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 (
|
||||
TRY2( _h5t_store_tet (
|
||||
f,
|
||||
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[0] = t->elems_data.tets[local_eid].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 (
|
||||
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[0] = t->elems_data.tets[local_eid].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 (
|
||||
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[0] = t->elems_data.tets[local_eid].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 (
|
||||
TRY2( _h5t_store_tet (
|
||||
f,
|
||||
new_tet_local_id,
|
||||
parent_tet_global_id,
|
||||
new_tet_local_vids ), fail );
|
||||
|
||||
/* 4 */
|
||||
@@ -536,10 +464,9 @@ h5t_refine_tet (
|
||||
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 (
|
||||
TRY2( _h5t_store_tet (
|
||||
f,
|
||||
new_tet_local_id,
|
||||
parent_tet_global_id,
|
||||
new_tet_local_vids ), fail );
|
||||
|
||||
/* 5 */
|
||||
@@ -548,10 +475,9 @@ h5t_refine_tet (
|
||||
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 (
|
||||
TRY2( _h5t_store_tet (
|
||||
f,
|
||||
new_tet_local_id,
|
||||
parent_tet_global_id,
|
||||
new_tet_local_vids ), fail );
|
||||
|
||||
/* 6 */
|
||||
@@ -560,10 +486,9 @@ h5t_refine_tet (
|
||||
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 (
|
||||
TRY2( _h5t_store_tet (
|
||||
f,
|
||||
new_tet_local_id,
|
||||
parent_tet_global_id,
|
||||
new_tet_local_vids ), fail );
|
||||
|
||||
/* 7 */
|
||||
@@ -572,10 +497,9 @@ h5t_refine_tet (
|
||||
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 (
|
||||
TRY2( _h5t_store_tet (
|
||||
f,
|
||||
new_tet_local_id,
|
||||
parent_tet_global_id,
|
||||
new_tet_local_vids ), fail );
|
||||
|
||||
return H5_SUCCESS;
|
||||
|
||||
@@ -1,15 +1,24 @@
|
||||
#ifndef __H5T_STOREMESH_H
|
||||
#define __H5T_STOREMESH_H
|
||||
|
||||
h5_id_t
|
||||
h5t_add_mesh (
|
||||
h5_file_t * const f,
|
||||
const h5_size_t num_elems,
|
||||
const h5_oid_t mesh_type
|
||||
);
|
||||
|
||||
h5_id_t
|
||||
h5t_add_level (
|
||||
h5_file_t * const f
|
||||
h5_file_t * const f,
|
||||
const h5_size_t num_vertices,
|
||||
const h5_size_t num_elems
|
||||
);
|
||||
|
||||
h5_id_t
|
||||
h5t_store_vertex (
|
||||
h5_file_t * const f,
|
||||
const h5_id_t global_id,
|
||||
const h5_id_t mesher_vid,
|
||||
const h5_float64_t P[3]
|
||||
);
|
||||
|
||||
@@ -26,18 +35,41 @@ h5_add_num_triangles (
|
||||
);
|
||||
|
||||
h5_id_t
|
||||
h5t_store_tet (
|
||||
h5t_store_elem (
|
||||
h5_file_t * const f,
|
||||
const h5_id_t global_id,
|
||||
const h5_id_t parent_id,
|
||||
const h5_id_t local_parent_eid,
|
||||
const h5_id_t local_vids[]
|
||||
);
|
||||
|
||||
h5_id_t
|
||||
_h5t_store_triangle (
|
||||
h5_file_t * const f,
|
||||
const h5_id_t local_parent_eid,
|
||||
const h5_id_t vids[3]
|
||||
);
|
||||
|
||||
h5_id_t
|
||||
_h5t_store_tet (
|
||||
h5_file_t * const f,
|
||||
const h5_id_t local_parent_eid,
|
||||
const h5_id_t vids[4]
|
||||
);
|
||||
|
||||
h5_id_t
|
||||
h5t_store_triangle (
|
||||
h5t_refine_elem (
|
||||
h5_file_t * const f,
|
||||
const h5_id_t global_id,
|
||||
const h5_id_t parent_id,
|
||||
const h5_id_t vids[3]
|
||||
const h5_id_t local_eid
|
||||
);
|
||||
|
||||
h5_id_t
|
||||
_h5t_refine_triangle (
|
||||
h5_file_t * const f,
|
||||
const h5_id_t local_eid
|
||||
);
|
||||
|
||||
h5_id_t
|
||||
_h5t_refine_tet (
|
||||
h5_file_t * const f,
|
||||
const h5_id_t local_eid
|
||||
);
|
||||
#endif
|
||||
|
||||
@@ -1,54 +1,75 @@
|
||||
#ifndef __H5T_TYPES_PRIVATE_H
|
||||
#define __H5T_TYPES_PRIVATE_H
|
||||
|
||||
typedef h5_int64_t h5_3id_t[3];
|
||||
typedef h5_int64_t h5_4id_t[4];
|
||||
typedef h5_float64_t h5_coord3d_t[3];
|
||||
|
||||
struct h5_vertex {
|
||||
h5_id_t vid;
|
||||
h5_float64_t P[3];
|
||||
h5_coord3d_t P;
|
||||
};
|
||||
typedef struct h5_vertex h5_vertex_t;
|
||||
|
||||
struct h5_triangle {
|
||||
h5_id_t cid;
|
||||
h5_id_t parent_cid;
|
||||
h5_id_t eid;
|
||||
h5_id_t parent_eid;
|
||||
h5_id_t refined_on_level;
|
||||
h5_id_t vids[3];
|
||||
h5_3id_t vids;
|
||||
};
|
||||
typedef struct h5_triangle h5_triangle_t;
|
||||
|
||||
struct h5_tetrahedron {
|
||||
h5_id_t cid;
|
||||
h5_id_t parent_cid;
|
||||
h5_id_t eid;
|
||||
h5_id_t parent_eid;
|
||||
h5_id_t refined_on_level;
|
||||
h5_id_t vids[4];
|
||||
h5_4id_t vids;
|
||||
};
|
||||
|
||||
typedef struct h5_tetrahedron h5_tetrahedron_t;
|
||||
typedef struct h5_tetrahedron h5_tet_t;
|
||||
|
||||
struct h5_triangle_local {
|
||||
h5_id_t parent_cid;
|
||||
h5_id_t vids[3]; /* local(!) vertex ids */
|
||||
h5_id_t parent_eid;
|
||||
h5_3id_t vids; /* 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 */
|
||||
struct h5_tet_local {
|
||||
h5_id_t parent_eid;
|
||||
h5_4id_t vids; /* local(!) vertex ids */
|
||||
};
|
||||
typedef struct h5_tet_local h5_tet_local_t;
|
||||
|
||||
union elems {
|
||||
union h5_elems {
|
||||
h5_tet_t *tets;
|
||||
h5_triangle_t *tris;
|
||||
void *data;
|
||||
};
|
||||
typedef union h5_elems h5_elems_t;
|
||||
|
||||
union elems_local {
|
||||
h5_tet_local_t *tets;
|
||||
h5_triangle_local_t *tris;
|
||||
void *data;
|
||||
union h5_elems_data {
|
||||
h5_tet_local_t *tets;
|
||||
h5_triangle_local_t *tris;
|
||||
void *data;
|
||||
};
|
||||
typedef union h5_elems_data h5_elems_data_t;
|
||||
|
||||
/*
|
||||
information about HDF5 dataset
|
||||
*/
|
||||
struct h5_dataset_info {
|
||||
char name[256];
|
||||
int rank;
|
||||
hsize_t dims[4];
|
||||
hsize_t maxdims[4];
|
||||
hsize_t chunk_size[4];
|
||||
hid_t *type_id;
|
||||
hid_t create_prop;
|
||||
hid_t access_prop;
|
||||
};
|
||||
typedef struct h5_dataset_info h5_dataset_info_t;
|
||||
|
||||
|
||||
struct boundary {
|
||||
char name[16];
|
||||
@@ -63,24 +84,36 @@ struct boundary {
|
||||
h5_size_t *num_faces_on_level; /* real num of faces per level */
|
||||
|
||||
h5_id_t last_accessed_face;
|
||||
h5_dataset_info_t dsinfo;
|
||||
};
|
||||
typedef struct boundary boundary_t;
|
||||
|
||||
/*** type ids' for compound types ***/
|
||||
struct h5_dtypes {
|
||||
hid_t h5_id_t;
|
||||
hid_t h5_int64_t;
|
||||
hid_t h5_float64_t;
|
||||
hid_t h5_coord3d_t; /* 3-tuple of 64-bit float */
|
||||
hid_t h5_3id_t; /* 3-tuple of id's */
|
||||
hid_t h5_4id_t; /* 4-tuple of id's */
|
||||
hid_t h5_vertex_t; /* vertex structure */
|
||||
hid_t h5_triangle_t; /* triangle structure */
|
||||
hid_t h5_tet_t; /* tetrahedron structure */
|
||||
};
|
||||
typedef struct h5_dtypes h5_dtypes_t;
|
||||
|
||||
struct h5t_fdata {
|
||||
/*** book-keeping ***/
|
||||
char mesh_name[16];
|
||||
char mesh_label[256];
|
||||
enum h5_oid mesh_type;
|
||||
h5_id_t cur_mesh;
|
||||
h5_id_t mesh_changed; /* true if mesh is new or has
|
||||
been changed */
|
||||
h5_id_t num_meshes;
|
||||
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 */
|
||||
h5_size_t num_levels;
|
||||
h5_oid_t mesh_type; /* object id of element type */
|
||||
h5_id_t cur_mesh; /* id of current mesh */
|
||||
h5_id_t mesh_changed; /* true if new or has been changed */
|
||||
h5_id_t num_meshes; /* number of meshes */
|
||||
hid_t elem_tid; /* HDF5 type id: tet, triangle etc */
|
||||
h5_id_t cur_level; /* id of current level */
|
||||
h5_id_t new_level; /* idx of the first new level or -1 */
|
||||
h5_size_t num_levels; /* number of levels */
|
||||
|
||||
/*** vertices ***/
|
||||
h5_vertex_t *vertices;
|
||||
@@ -88,24 +121,31 @@ struct h5t_fdata {
|
||||
struct idmap map_vertex_g2l; /* map global id to local id */
|
||||
struct smap sorted_lvertices;
|
||||
h5_id_t last_retrieved_vid;
|
||||
h5_id_t last_stored_vid;
|
||||
|
||||
h5_id_t last_stored_vid;
|
||||
h5_dataset_info_t dsinfo_vertices;
|
||||
h5_dataset_info_t dsinfo_num_vertices;
|
||||
|
||||
|
||||
/*** Elements ***/
|
||||
union elems elems;
|
||||
union elems_local elems_ldta; /* local vertex id's of
|
||||
elems */
|
||||
h5_elems_t elems;
|
||||
h5_elems_data_t elems_data; /* local, per element data */
|
||||
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_elems_ldta[H5_MAX_VERTICES_PER_ELEM];/* sorted local entitiy ids
|
||||
[0]: 0,1,2,3 sorted
|
||||
[1]: 1,0,2,3 sorted */
|
||||
/*
|
||||
array with geometrically sorted local entitiy ids
|
||||
[0]: 0,1,2,3 sorted
|
||||
[1]: 1,0,2,3 sorted
|
||||
...
|
||||
*/
|
||||
struct smap sorted_elems[H5_MAX_VERTICES_PER_ELEM];
|
||||
|
||||
h5_id_t last_retrieved_eid;
|
||||
h5_id_t last_stored_eid;
|
||||
h5_dataset_info_t dsinfo_elems;
|
||||
h5_dataset_info_t dsinfo_num_elems;
|
||||
h5_dataset_info_t dsinfo_num_elems_on_level;
|
||||
|
||||
/*** Boundary Meshes ***/
|
||||
h5_id_t num_boundaries; /* number of boundaries */
|
||||
@@ -119,14 +159,9 @@ struct h5t_fdata {
|
||||
hid_t meshes_gid;
|
||||
hid_t mesh_gid;
|
||||
|
||||
/*** 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 */
|
||||
/*** type ids' for base & compound data types ***/
|
||||
h5_dtypes_t dtypes;
|
||||
};
|
||||
typedef struct h5t_fdata h5t_fdata_t;
|
||||
|
||||
#endif
|
||||
|
||||
+80
-141
@@ -13,7 +13,7 @@ h5_int64_t
|
||||
h5u_has_view (
|
||||
h5_file_t *f
|
||||
) {
|
||||
return ( f->viewstart >= 0 ) && ( f->viewend >= 0 );
|
||||
return ( f->u->viewstart >= 0 ) && ( f->u->viewend >= 0 );
|
||||
}
|
||||
|
||||
static hid_t
|
||||
@@ -23,9 +23,10 @@ _get_diskshape_for_reading (
|
||||
) {
|
||||
|
||||
herr_t r;
|
||||
struct h5u_fdata *u = f->u;
|
||||
|
||||
hid_t space = H5Dget_space(dataset);
|
||||
if ( space < 0 ) return (hid_t)HANDLE_H5D_GET_SPACE_ERR ( f );
|
||||
hid_t space;
|
||||
TRY( space = _h5_get_dataset_space ( f, dataset ) );
|
||||
|
||||
if ( h5u_has_view ( f ) ) {
|
||||
hsize_t stride;
|
||||
@@ -37,14 +38,14 @@ _get_diskshape_for_reading (
|
||||
#endif
|
||||
|
||||
/* so, is this selection inclusive or exclusive? */
|
||||
start = f->viewstart;
|
||||
count = f->viewend - f->viewstart; /* to be inclusive */
|
||||
start = u->viewstart;
|
||||
count = u->viewend - u->viewstart; /* to be inclusive */
|
||||
stride=1;
|
||||
|
||||
/* now we select a subset */
|
||||
if ( f->diskshape > 0 ) {
|
||||
if ( u->diskshape > 0 ) {
|
||||
r = H5Sselect_hyperslab (
|
||||
f->diskshape, H5S_SELECT_SET,
|
||||
u->diskshape, H5S_SELECT_SET,
|
||||
&start, &stride, &count, NULL);
|
||||
if ( r < 0 )
|
||||
return (hid_t)HANDLE_H5S_SELECT_HYPERSLAB_ERR ( f );
|
||||
@@ -58,7 +59,7 @@ _get_diskshape_for_reading (
|
||||
h5_debug (
|
||||
f,
|
||||
"Selection: range=%d:%d, npoints=%d s=%d",
|
||||
(int)f->viewstart,(int)f->viewend,
|
||||
(int)u->viewstart,(int)u->viewend,
|
||||
(int)H5Sget_simple_extent_npoints(space),
|
||||
(int)H5Sget_select_npoints(space) );
|
||||
}
|
||||
@@ -70,15 +71,13 @@ _get_memshape_for_reading (
|
||||
h5_file_t *f,
|
||||
hid_t dataset
|
||||
) {
|
||||
struct h5u_fdata *u = f->u;
|
||||
|
||||
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);
|
||||
if ( r < 0 ) return (hid_t)HANDLE_H5S_CREATE_SIMPLE_ERR ( f, 1 );
|
||||
return r;
|
||||
}
|
||||
else {
|
||||
hsize_t len = u->viewend - u->viewstart;
|
||||
return _h5_create_dataset_space ( f, 1, &len, &dmax );
|
||||
} else {
|
||||
return H5S_ALL;
|
||||
}
|
||||
}
|
||||
@@ -87,8 +86,6 @@ h5_int64_t
|
||||
h5u_get_num_elems (
|
||||
h5_file_t *f /*!< [in] Handle to open file */
|
||||
) {
|
||||
|
||||
h5_int64_t herr;
|
||||
hid_t space_id;
|
||||
hid_t dataset_id;
|
||||
char dataset_name[128];
|
||||
@@ -101,20 +98,14 @@ h5u_get_num_elems (
|
||||
"%s#%0*lld",
|
||||
f->prefix_step_name, f->width_step_idx, (long long) f->step_idx );
|
||||
|
||||
herr = hdf5_get_object_name (
|
||||
TRY( hdf5_get_object_name (
|
||||
f->file,
|
||||
step_name,
|
||||
H5G_DATASET,
|
||||
0,
|
||||
dataset_name, sizeof (dataset_name) );
|
||||
if ( herr < 0 ) return herr;
|
||||
|
||||
dataset_id = H5Dopen ( f->step_gid, dataset_name, H5P_DEFAULT );
|
||||
if ( dataset_id < 0 )
|
||||
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;
|
||||
dataset_name, sizeof (dataset_name) ) );
|
||||
TRY( dataset_id = _h5_open_dataset ( f, f->step_gid, dataset_name ) );
|
||||
TRY( space_id = _get_diskshape_for_reading ( f, dataset_id ) );
|
||||
|
||||
if ( h5u_has_view ( f ) ) {
|
||||
nparticles = H5Sget_select_npoints ( space_id );
|
||||
@@ -125,12 +116,8 @@ h5u_get_num_elems (
|
||||
if ( nparticles < 0 )
|
||||
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 ( f );
|
||||
}
|
||||
herr = H5Dclose ( dataset_id );
|
||||
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR ( f );
|
||||
TRY( _h5_close_dataspace( f, space_id ) );
|
||||
TRY( _h5_close_dataset( f, dataset_id ) );
|
||||
|
||||
return (h5_int64_t) nparticles;
|
||||
}
|
||||
@@ -143,46 +130,27 @@ h5u_read_elems (
|
||||
const hid_t type
|
||||
) {
|
||||
|
||||
herr_t herr;
|
||||
hid_t dataset_id;
|
||||
hid_t space_id;
|
||||
hid_t memspace_id;
|
||||
|
||||
if ( f->step_gid < 0 ) {
|
||||
h5_int64_t h5err = h5_set_step ( f, f->step_idx );
|
||||
if ( h5err < 0 ) return h5err;
|
||||
TRY( h5_set_step ( f, f->step_idx ) );
|
||||
}
|
||||
dataset_id = H5Dopen ( f->step_gid, name, H5P_DEFAULT );
|
||||
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;
|
||||
|
||||
memspace_id = _get_memshape_for_reading ( f, dataset_id );
|
||||
if ( memspace_id < 0 ) return (h5_int64_t)memspace_id;
|
||||
|
||||
herr = H5Dread (
|
||||
dataset_id,
|
||||
type,
|
||||
memspace_id, /* shape/size of data in memory (the
|
||||
complement to disk hyperslab) */
|
||||
space_id, /* shape/size of data on disk
|
||||
(get hyperslab if needed) */
|
||||
f->xfer_prop, /* ignore... its for parallel reads */
|
||||
array );
|
||||
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 ( f );
|
||||
}
|
||||
|
||||
if ( memspace_id != H5S_ALL )
|
||||
herr = H5Sclose ( memspace_id );
|
||||
if ( herr < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
|
||||
|
||||
herr = H5Dclose ( dataset_id );
|
||||
if ( herr < 0 ) return HANDLE_H5D_CLOSE_ERR ( f );
|
||||
TRY( (dataset_id = _h5_open_dataset ( f, f->step_gid, name ) ) );
|
||||
TRY( (space_id = _get_diskshape_for_reading ( f, dataset_id ) ) );
|
||||
TRY( (memspace_id = _get_memshape_for_reading ( f, dataset_id ) ) );
|
||||
TRY( _h5_read_dataset (
|
||||
f,
|
||||
dataset_id,
|
||||
type,
|
||||
memspace_id,
|
||||
space_id,
|
||||
f->xfer_prop,
|
||||
array ) );
|
||||
TRY( _h5_close_dataspace( f, space_id ) );
|
||||
TRY( _h5_close_dataspace( f, memspace_id ) );
|
||||
TRY( _h5_close_dataset ( f, dataset_id ) );
|
||||
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
@@ -192,11 +160,9 @@ h5u_set_num_elements (
|
||||
h5_file_t *f, /*!< [in] Handle to open file */
|
||||
h5_int64_t nparticles /*!< [in] Number of particles */
|
||||
) {
|
||||
|
||||
struct h5u_fdata *u = f->u;
|
||||
CHECK_FILEHANDLE( f );
|
||||
|
||||
herr_t r = 0;
|
||||
|
||||
#ifndef PARALLEL_IO
|
||||
/*
|
||||
if we are not using parallel-IO, there is enough information
|
||||
@@ -204,31 +170,23 @@ h5u_set_num_elements (
|
||||
for parallel IO, this is going to cause problems because
|
||||
we don't know if things have changed globally
|
||||
*/
|
||||
if ( f->nparticles == nparticles ) {
|
||||
if ( u->nparticles == nparticles ) {
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
if ( f->diskshape != H5S_ALL ) {
|
||||
r = H5Sclose( f->diskshape );
|
||||
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 ( f );
|
||||
f->memshape = H5S_ALL;
|
||||
}
|
||||
if( f->shape ) {
|
||||
r = H5Sclose(f->shape);
|
||||
if ( r < 0 ) return HANDLE_H5S_CLOSE_ERR ( f );
|
||||
}
|
||||
f->nparticles =(hsize_t) nparticles;
|
||||
TRY( _h5_close_dataspace( f, u->diskshape ) );
|
||||
u->diskshape = H5S_ALL;
|
||||
TRY( _h5_close_dataspace( f, u->memshape ) );
|
||||
u->memshape = H5S_ALL;
|
||||
TRY( _h5_close_dataspace( f, u->shape ) );
|
||||
u->shape = H5S_ALL;
|
||||
u->nparticles =(hsize_t) nparticles;
|
||||
#ifndef PARALLEL_IO
|
||||
f->shape = H5Screate_simple (1,
|
||||
&(f->nparticles),
|
||||
NULL);
|
||||
if ( f->shape < 0 ) HANDLE_H5S_CREATE_SIMPLE_ERR ( f, 1 );
|
||||
|
||||
TRY( u->shape = _h5_create_dataset_space (
|
||||
f,
|
||||
1,
|
||||
&(u->nparticles),
|
||||
NULL ) );
|
||||
#else /* PARALLEL_IO */
|
||||
/*
|
||||
The Gameplan here is to declare the overall size of the on-disk
|
||||
@@ -282,18 +240,14 @@ h5u_set_num_elements (
|
||||
}
|
||||
|
||||
/* declare overall datasize */
|
||||
f->shape = H5Screate_simple (1, &total, &total);
|
||||
if (f->shape < 0) return HANDLE_H5S_CREATE_SIMPLE_ERR ( 1 );
|
||||
|
||||
TRY ( f->shape = _h5_create_dataset_space ( f, 1, &total, &total ) );
|
||||
|
||||
/* 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 );
|
||||
TRY ( f->diskshape = _h5_create_dataset_space ( f, 1, &total, &total) );
|
||||
|
||||
/* declare local memory datasize */
|
||||
f->memshape = H5Screate_simple (1, &(f->nparticles), &dmax);
|
||||
if (f->memshape < 0)
|
||||
return HANDLE_H5S_CREATE_SIMPLE_ERR ( 1 );
|
||||
TRY ( f->memshape = _h5_create_dataset_space (
|
||||
f, 1, &(f->nparticles), &dmax ) );
|
||||
|
||||
count[0] = nparticles;
|
||||
r = H5Sselect_hyperslab (
|
||||
@@ -305,9 +259,7 @@ h5u_set_num_elements (
|
||||
if ( r < 0 ) return HANDLE_H5S_SELECT_HYPERSLAB_ERR;
|
||||
|
||||
if ( f->step_gid < 0 ) {
|
||||
r = h5_set_step ( f, 0 );
|
||||
if ( r < 0 ) return r;
|
||||
|
||||
TRY ( h5_set_step ( f, 0 ) );
|
||||
}
|
||||
#endif
|
||||
return H5_SUCCESS;
|
||||
@@ -324,6 +276,7 @@ h5u_write_data (
|
||||
CHECK_FILEHANDLE ( f );
|
||||
CHECK_WRITABLE_MODE( f );
|
||||
CHECK_TIMEGROUP( f );
|
||||
struct h5u_fdata *u = f->u;
|
||||
|
||||
return h5_write_data(
|
||||
f,
|
||||
@@ -331,9 +284,8 @@ h5u_write_data (
|
||||
array,
|
||||
type,
|
||||
f->step_gid,
|
||||
f->shape,
|
||||
f->memshape,
|
||||
f->diskshape );
|
||||
u->memshape,
|
||||
u->diskshape );
|
||||
}
|
||||
|
||||
h5_int64_t
|
||||
@@ -341,26 +293,17 @@ h5u_reset_view (
|
||||
h5_file_t *f
|
||||
) {
|
||||
|
||||
herr_t herr = 0;
|
||||
struct h5u_fdata *u = f->u;
|
||||
|
||||
u->viewstart = -1;
|
||||
u->viewend = -1;
|
||||
TRY( _h5_close_dataspace( f, u->shape ) );
|
||||
u->shape = H5S_ALL;
|
||||
TRY( _h5_close_dataspace( f, u->diskshape ) );
|
||||
u->diskshape = H5S_ALL;
|
||||
TRY( _h5_close_dataspace( f, u->memshape ) );
|
||||
u->memshape = H5S_ALL;
|
||||
|
||||
f->viewstart = -1;
|
||||
f->viewend = -1;
|
||||
if ( f->shape != 0 ){
|
||||
herr = H5Sclose(f->shape);
|
||||
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 ( 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 ( f );
|
||||
f->memshape=H5S_ALL;
|
||||
}
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -374,6 +317,7 @@ h5u_set_view (
|
||||
hsize_t total;
|
||||
hsize_t stride = 1;
|
||||
hsize_t dmax = H5S_UNLIMITED;
|
||||
struct h5u_fdata *u = f->u;
|
||||
|
||||
h5_debug (
|
||||
f,
|
||||
@@ -412,27 +356,22 @@ h5u_set_view (
|
||||
end = start; /* ensure that we don't have a range error */
|
||||
}
|
||||
/* setting up the new view */
|
||||
f->viewstart = start;
|
||||
f->viewend = end;
|
||||
f->nparticles = end - start + 1;
|
||||
u->viewstart = start;
|
||||
u->viewend = end;
|
||||
u->nparticles = end - start + 1;
|
||||
|
||||
/* declare overall datasize */
|
||||
f->shape = H5Screate_simple ( 1, &total, &total );
|
||||
if ( f->shape < 0 )
|
||||
return HANDLE_H5S_CREATE_SIMPLE_ERR ( f, 1 );
|
||||
TRY ( u->shape = _h5_create_dataset_space ( f, 1, &total, &total ) );
|
||||
|
||||
/* 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 ( f, 1 );
|
||||
TRY ( u->diskshape= _h5_create_dataset_space ( f, 1, &total, &total ) );
|
||||
|
||||
/* declare local memory datasize */
|
||||
f->memshape = H5Screate_simple(1,&(f->nparticles),&dmax);
|
||||
if ( f->memshape < 0 )
|
||||
return HANDLE_H5S_CREATE_SIMPLE_ERR ( f, 1 );
|
||||
TRY ( u->memshape = _h5_create_dataset_space (
|
||||
f, 1, &(u->nparticles), &dmax ) );
|
||||
|
||||
herr = H5Sselect_hyperslab (
|
||||
f->diskshape,
|
||||
u->diskshape,
|
||||
H5S_SELECT_SET,
|
||||
(hsize_t*)&start,
|
||||
&stride,
|
||||
@@ -449,15 +388,15 @@ h5u_get_view (
|
||||
h5_int64_t *start,
|
||||
h5_int64_t *end
|
||||
) {
|
||||
|
||||
struct h5u_fdata *u = f->u;
|
||||
h5_int64_t viewstart = 0;
|
||||
h5_int64_t viewend = 0;
|
||||
|
||||
if ( f->viewstart >= 0 )
|
||||
viewstart = f->viewstart;
|
||||
if ( u->viewstart >= 0 )
|
||||
viewstart = u->viewstart;
|
||||
|
||||
if ( f->viewend >= 0 ) {
|
||||
viewend = f->viewend;
|
||||
if ( u->viewend >= 0 ) {
|
||||
viewend = u->viewend;
|
||||
}
|
||||
else {
|
||||
viewend = h5u_get_num_elems ( f );
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __U_READWRITE_H
|
||||
#define __U_READWRITE_H
|
||||
#ifndef __H5U_READWRITE_H
|
||||
#define __H5U_READWRITE_H
|
||||
|
||||
h5_int64_t
|
||||
h5u_get_num_elems (
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __H5B_TYPES_PRIVATE_H
|
||||
#define __H5B_TYPES_PRIVATE_H
|
||||
#ifndef __H5U_TYPES_PRIVATE_H
|
||||
#define __H5U_TYPES_PRIVATE_H
|
||||
|
||||
struct h5u_fdata {
|
||||
hsize_t nparticles; /* -> u.nparticles */
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <string.h>
|
||||
#include <hdf5.h>
|
||||
#include "h5_core.h"
|
||||
#include "h5_core_private.h"
|
||||
@@ -103,7 +104,7 @@ hdf5_get_num_objects (
|
||||
}
|
||||
|
||||
const char *
|
||||
hdf5_get_objname (
|
||||
h5_get_objname (
|
||||
hid_t id
|
||||
) {
|
||||
static char objname[256];
|
||||
|
||||
@@ -8,6 +8,11 @@ hdf5_get_num_objects (
|
||||
const hid_t type
|
||||
);
|
||||
|
||||
const char *
|
||||
h5_get_objname (
|
||||
hid_t id
|
||||
);
|
||||
|
||||
h5_int64_t
|
||||
hdf5_get_num_objects_matching_pattern (
|
||||
hid_t group_id,
|
||||
@@ -16,11 +21,6 @@ hdf5_get_num_objects_matching_pattern (
|
||||
char * const pattern
|
||||
);
|
||||
|
||||
const char *
|
||||
hdf5_get_objname (
|
||||
hid_t id
|
||||
);
|
||||
|
||||
h5_int64_t
|
||||
hdf5_get_object_name (
|
||||
hid_t group_id,
|
||||
|
||||
Reference in New Issue
Block a user