src/h5/t_openclose.c

src/h5/t_readwrite.c
* added
This commit is contained in:
2008-01-20 10:58:56 +00:00
parent ee30cb6123
commit 1caf5a3a04
3 changed files with 280 additions and 0 deletions
+2
View File
@@ -60,6 +60,8 @@ src/h5/openclose.c -text
src/h5/openclose.h -text
src/h5/readwrite.c -text
src/h5/readwrite.h -text
src/h5/t_openclose.c -text
src/h5/t_readwrite.c -text
src/h5/u_readwrite.c -text
src/h5/u_readwrite.h -text
test/Bench.c -text
+112
View File
@@ -0,0 +1,112 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h> /* va_arg - System dependent ?! */
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <hdf5.h>
#include "H5PartTypes.h"
#include "H5BlockTypes.h"
#include "H5Part.h"
#include "H5Block.h"
#include "H5PartPrivate.h"
#include "H5BlockPrivate.h"
#include "H5PartErrors.h"
#include "H5BlockErrors.h"
#include "H5.h"
extern h5part_error_handler _err_handler;
extern h5part_int64_t _h5part_errno;
extern unsigned _debug;
static h5_err_t
_create_array_types (
h5_file * f
) {
hsize_t dims[1] = { 3 };
t->float64_3tuple_tid = H5Tarray_create ( H5T_NATIVE_DOUBLE, 1, dims,NULL);
dims[0] = 2;
t->int32_2tuple_tid = H5Tarray_create ( H5T_NATIVE_INT32, 1, dims, NULL );
dims[0] = 3;
t->int32_3tuple_tid = H5Tarray_create ( H5T_NATIVE_INT32, 1, dims, NULL );
dims[0] = 4;
t->int32_4tuple_tid = H5Tarray_create ( H5T_NATIVE_INT32, 1, dims, NULL );
return H5_SUCCESS;
}
static h5_err_t
_create_vertex_type (
h5_file * f
) {
t->vertex_tid = H5Tcreate ( H5T_COMPOUND, sizeof(struct h5_vertex) );
H5Tinsert (
t->vertex_tid,
"id",
HOFFSET(struct h5_vertex, id),
H5T_NATIVE_INT32 );
H5Tinsert (
t->vertex_tid,
"unused",
HOFFSET(struct h5_vertex, unused),
H5T_NATIVE_INT32 );
H5Tinsert (
t->vertex_tid,
"P",
HOFFSET(struct h5_vertex, P),
t->float64_3tuple_tid );
return H5_SUCCESS;
}
static h5_err_t
_create_tet_type (
h5_file * f
) {
t->tet_tid = H5Tcreate ( H5T_COMPOUND, sizeof(struct h5_tetrahedron) );
H5Tinsert (
t->tet_tid,
"id",
HOFFSET(struct h5_tet, id),
H5T_NATIVE_INT32 );
H5Tinsert (
t->tet_tid,
"parent_id",
HOFFSET(struct h5_tet, parent_id),
H5T_NATIVE_INT32 );
H5Tinsert (
t->tet_tid,
"vertex_ids",
HOFFSET(struct h5_tet, vertex_ids),
t->int32_4tuple_tid );
return H5_SUCCESS;
/*!
\ingroup h5_private
\internal
Initialize H5Block internal structure.
\return H5_SUCCESS or error code
*/
h5_err_t
_h5t_open_file (
h5_file * f /*!< IN: file handle */
) {
h5_err_t h5err = H5_SUCCESS;;
struct h5t_fdata * t = &fh->t;
t->num_levels = -1;
levels = NULL;
if (h5err = _create_array_types ( f )) < 0 ) return herr;
if (h5err = _create_vertex_type ( f )) < 0 ) return herr;
if (h5err = _create_tet_type ( f )) < 0 ) return herr;
return H5_SUCCESS;
}
+166
View File
@@ -0,0 +1,166 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h> /* va_arg - System dependent ?! */
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <hdf5.h>
#include "H5PartTypes.h"
#include "H5BlockTypes.h"
#include "H5Part.h"
#include "H5Block.h"
#include "H5PartPrivate.h"
#include "H5BlockPrivate.h"
#include "H5PartErrors.h"
#include "H5BlockErrors.h"
#include "H5.h"
/*
Initialize required data structures only!
*/
h5_err_t
_h5t_init_step (
h5_file * f
) {
memset ( f->t, 0, sizeof(f->t) );
f->t.mesh_gid = -1;
f->t.num_levels = f->is_new_step ? 0 : -1;
f->t.cur_level = -1;
return H5_SUCCESS;
}
static h5_err_t
_open_topo_group (
h5_file * f
) {
herr_t herr = H5Gget_objinfo( f->step_gid, "Topo", 1, NULL );
if ( herr => 0 ) {
f->t.mesh_gid = H5Gopen ( f->step_gid, "Topo" );
} else {
f->t.mesh_gid = H5Gcreate ( f->step_gid, "Topo", 0 );
}
if ( f->t.mesh_gid < 0 )
return HANDLE_H5G_OPEN_ERR ( "Topo" );
}
/*
store vertices -> Topo.VERTICES_COORD3D
levels -> TOPO.VERTICES_LEVELS3D
*/
static h5_err_t
_write_vertices (
h5_file * f
) {
h5t_fdata t &f->t;
herr_t herr;
if ( t->coord3d_gid < 0 ) {
h5err = _open_coord3d_group ( f );
if ( h5err < 0 ) return h5err;
}
if ( t->num_levels == 0 ) return 0;
if ( t->num_levels < 0 ) return -1;
hsize_t current_dims[1];
current_dims[0] = t->levels[t->num_levels-1].num_vertices;
t->coord3d_sid = H5Screate_simple (
1,
current_dims,
H5S_UNLIMITED
);
if ( t->coord3d_sid < 0 ) return -1;
t->coord3d_did = H5Dcreate (
coord3d_gid,
"COORD3D",
t->vertex_tid,
t->coord3d_sid,
H5P_DEFAULT);
if ( t->coord3d_did < 0 ) return -1;
herr = H5Dwrite (
coord3d,
t->vertex_tid,
H5S_ALL, H5S_ALL, H5P_DEFAULT,
t->vertices );
if ( herr < 0 ) return -1;
return H5_SUCCESS;
}
static h5_err_t
_write_tets (
h5_file * f
) {
return -1;
}
/*
determine new levels
foreach Object
- create HDF5 groups
- write data
*/
static h5_err_t
_write_data (
h5_file * f
) {
struct h5t_fdata *t = &f->t;
h5_err_t h5err;
if ( t->topo_gid < 0 ) {
h5err = _open_topo_group ( f );
if ( h5err < 0 ) return h5err;
}
h5err = _write_vertices( f );
if ( h5err < 0 ) return h5err;
h5err = _write_tets( f );
if ( h5err < 0 ) return h5err;
return -1;
}
static h5_err_t
_close_hdf5_objs (
h5_file * f
) {
return -1;
}
static h5_err_t
_release_memory (
h5_file * f
) {
return -1;
}
/*
- write data
- close HDF5 objects we cannot reuse
- free memory
*/
h5_err_t
_h5t_close_step (
h5_file * f
) {
h5_err_t h5err = _write_data ( f );
if ( h5err < 0 ) return h5err;
h5_err_t h5err = _close_hdf5_objs ( f );
if ( h5err < 0 ) return h5err;
h5_err_t h5err = _release_memory ( f );
if ( h5err < 0 ) return h5err;
return H5_SUCCESS;
}