Commit c26d6a84 authored by gsell's avatar gsell

adapted to new/changed function:

h5priv_open_group(): open existing group
h5priv_create_group(): create or open existing group
h5priv_open_group_with_intermediates(): open existing group
h5priv_create_group_with_intermediates(): create or open existing group
parent 54ccc3b5
......@@ -50,10 +50,18 @@ h5_set_step (
"Open step #%lld for file %lld",
(long long)f->step_idx,
(long long)(size_t) f);
TRY (f->step_gid = h5priv_open_group (is_writable(f),
f->file,
f->step_name));
h5_err_t exists;
TRY (exists = hdf5_link_exists (f->file, f->step_name));
if (exists) {
TRY (f->step_gid = h5priv_open_group (
f->file,
f->step_name));
} else if (is_writable (f)) {
TRY (f->step_gid = h5priv_create_group (
f->file,
f->step_name));
}
H5_RETURN (H5_SUCCESS);
}
......
......@@ -86,7 +86,7 @@ h5t_get_num_mtagsets (
if (!exists) H5_LEAVE (0);
hid_t loc_id;
TRY (loc_id = h5priv_open_group (0, m->mesh_gid, "Tags"));
TRY (loc_id = h5priv_open_group (m->mesh_gid, "Tags"));
TRY (num_mtagsets = hdf5_get_num_groups (loc_id));
TRY (hdf5_close_group (loc_id));
......@@ -402,8 +402,9 @@ read_tagset (
hid_t loc_id = 0;
// open HDF5 group
TRY (loc_id = h5priv_open_group (0, tagset->parent_gid, "Tags", tagset->name));
TRY (loc_id = h5priv_open_group_with_intermediates (
tagset->parent_gid,
"Tags", tagset->name, NULL));
// read datasets:
......@@ -614,11 +615,9 @@ write_tagset (
tagset->num_values = entity->idx = val_idx;
// write data
TRY (group_id = h5priv_open_group (
1,
TRY (group_id = h5priv_create_group_with_intermediates (
tagset->parent_gid,
"Tags",
tagset->name));
"Tags", tagset->name, NULL));
h5_dsinfo_t dsinfo;
memset (&dsinfo, 0, sizeof(dsinfo));
dsinfo.rank = 1;
......@@ -664,9 +663,9 @@ write_tagset (
open_space_all, open_space_all,
values));
h5_int64_t scope = tagset->scope.min_level;
TRY (h5priv_write_attrib (group_id, "__scope_min__", H5_INT64_T, &scope, 1, 1));
TRY (h5priv_write_attrib (group_id, "__scope_min__", H5_INT64_T, &scope, 1));
scope = tagset->scope.max_level;
TRY (h5priv_write_attrib (group_id, "__scope_max__", H5_INT64_T, &scope, 1, 1));
TRY (h5priv_write_attrib (group_id, "__scope_max__", H5_INT64_T, &scope, 1));
TRY (hdf5_close_group (group_id));
TRY (h5_free (elems));
......
......@@ -52,41 +52,6 @@ h5priv_link_exists_ (
H5_RETURN (1);
}
h5_err_t
h5priv_open_group_ (
int create_intermediate,
const hid_t loc_id,
const char const* path[],
size_t size
) {
H5_PRIV_FUNC_ENTER (h5_err_t,
"create_intermediate=%d, loc_id=%lld, (%s), path=%s, ...",
create_intermediate, (long long int)loc_id, hdf5_get_objname (loc_id),
path[0]);
hid_t hid = loc_id;
hid_t hid2 = 0;
h5_err_t exists;
for (size_t i=0; i < size; i++) {
TRY (exists = hdf5_link_exists (hid, path[i]));
if (exists) {
TRY (hid2 = hdf5_open_group (hid, path[i]));
} else if (create_intermediate) {
TRY (hid2 = hdf5_create_group (hid, path[i]));
} else {
H5_RETURN_ERROR (
H5_ERR_HDF5,
"No such group '%s/%s'.",
hdf5_get_objname (hid),
path[i]);
}
if (hid != loc_id) {
TRY (hdf5_close_group (hid));
}
hid = hid2;
}
H5_RETURN (hid);
}
typedef struct op_data {
int queried_idx;
......
......@@ -160,15 +160,6 @@ hdf5_create_group (
H5_RETURN (group_id);
}
h5_err_t
h5priv_open_group_ (int, hid_t, const char const*[], size_t);
#define h5priv_open_group(create_intermediate, loc_id, ...) \
(h5priv_open_group_ (create_intermediate, \
loc_id, \
(const char const*[]) {__VA_ARGS__}, \
PP_NARG(__VA_ARGS__)))
h5_err_t
h5priv_link_exists_ (
const hid_t loc_id,
......@@ -201,6 +192,106 @@ hdf5_close_group (
H5_RETURN (H5_SUCCESS);
}
static inline hid_t
h5priv_create_group (
const hid_t loc_id,
const char const* group_name
) {
H5_PRIV_FUNC_ENTER (hid_t,
"loc_id=%lld, (%s), group_name=%s",
(long long int)loc_id, hdf5_get_objname (loc_id),
group_name);
h5_err_t exists;
TRY (exists = hdf5_link_exists (loc_id, group_name));
if (exists) {
TRY (ret_value = hdf5_open_group (loc_id, group_name));
} else {
TRY (ret_value = hdf5_create_group (loc_id, group_name));
}
H5_RETURN (ret_value);
}
static inline hid_t
h5priv_open_group (
const hid_t loc_id,
const char const* group_name
) {
H5_PRIV_FUNC_ENTER (hid_t,
"loc_id=%lld, (%s), group_name=%s",
(long long int)loc_id, hdf5_get_objname (loc_id),
group_name);
h5_err_t exists;
TRY (exists = hdf5_link_exists (loc_id, group_name));
if (exists) {
TRY (ret_value = hdf5_open_group (loc_id, group_name));
} else {
H5_RETURN_ERROR (
H5_ERR_HDF5,
"Group does not exist: '%s/%s'.",
hdf5_get_objname (loc_id),
group_name);
}
H5_RETURN (ret_value);
}
static inline hid_t
h5priv_create_group_with_intermediates (
const hid_t loc_id,
...
) {
va_list ap;
va_start(ap, loc_id);
char* group_name = va_arg(ap, char*);
H5_PRIV_FUNC_ENTER (hid_t,
"loc_id=%lld (%s), "
"group_name=%s, ...",
(long long int)loc_id, hdf5_get_objname (loc_id),
group_name);
hid_t parent_id = loc_id;
while (group_name != NULL) {
TRY (ret_value = h5priv_create_group (
parent_id,
group_name));
if (parent_id != loc_id) {
// close intermediate groups
TRY (hdf5_close_group (parent_id));
}
group_name = va_arg(ap, char*);
parent_id = ret_value;
}
va_end (ap);
H5_RETURN (ret_value);
}
static inline hid_t
h5priv_open_group_with_intermediates (
const hid_t loc_id,
...
) {
va_list ap;
va_start(ap, loc_id);
char* group_name = va_arg(ap, char*);
H5_PRIV_FUNC_ENTER (hid_t,
"loc_id=%lld (%s), "
"group_name=%s, ...",
(long long int)loc_id, hdf5_get_objname (loc_id),
group_name);
hid_t parent_id = loc_id;
while (group_name != NULL) {
TRY (ret_value = h5priv_open_group (
parent_id,
group_name));
if (parent_id != loc_id) {
// close intermediate groups
TRY (hdf5_close_group (parent_id));
}
group_name = va_arg(ap, char*);
parent_id = ret_value;
}
va_end(ap);
H5_RETURN (ret_value);
}
static inline h5_ssize_t
hdf5_get_num_objs_in_group (
const hid_t group_id
......
......@@ -47,11 +47,9 @@ h5t_open_tetrahedral_mesh_by_idx (
hid_t ctn_hid;
char name[1024];
TRY (ctn_hid = h5priv_open_group (
0,
TRY (ctn_hid = h5priv_open_group_with_intermediates (
f->root_gid,
H5T_CONTAINER_GRPNAME,
TETRAHEDRAL_MESHES_GRPNAME));
H5T_CONTAINER_GRPNAME, TETRAHEDRAL_MESHES_GRPNAME, NULL));
TRY (hdf5_get_name_of_group_by_idx (ctn_hid, idx, name, sizeof (name)));
TRY (hdf5_close_group (ctn_hid));
......@@ -68,12 +66,11 @@ h5t_open_tetrahedral_mesh (
H5_CORE_API_ENTER (h5_err_t, "f=%p, name=%s, mesh=%p", f, name, mesh);
hid_t mesh_hid;
TRY (mesh_hid = h5priv_open_group (
0, // do not create intermediate groups
TRY (mesh_hid = h5priv_open_group_with_intermediates (
f->root_gid,
H5T_CONTAINER_GRPNAME,
TETRAHEDRAL_MESHES_GRPNAME,
name));
name, NULL));
TRY (*mesh = h5_calloc (1, sizeof(**mesh)));
h5t_mesh_t* m = *mesh;
......@@ -106,12 +103,11 @@ h5t_open_tetrahedral_mesh_part (
H5_CORE_API_ENTER (h5_err_t, "f=%p, name=%s, mesh=%p", f, name, mesh);
hid_t mesh_hid;
TRY (mesh_hid = h5priv_open_group (
0,
TRY (mesh_hid = h5priv_open_group_with_intermediates (
f->root_gid,
H5T_CONTAINER_GRPNAME,
TRIANGLE_MESHES_GRPNAME,
name));
name, NULL));
TRY (*mesh = h5_calloc (1, sizeof(**mesh)));
h5t_mesh_t* m = *mesh;
......@@ -157,12 +153,11 @@ h5t_add_tetrahedral_mesh (
name);
}
hid_t mesh_hid;
TRY (mesh_hid = h5priv_open_group (
1, // create intermediate groups in path
TRY (mesh_hid = h5priv_create_group_with_intermediates (
f->root_gid,
H5T_CONTAINER_GRPNAME,
TETRAHEDRAL_MESHES_GRPNAME,
name));
name, NULL));
TRY (*mesh = h5_calloc (1, sizeof(**mesh)));
h5t_mesh_t* m = *mesh;
......@@ -214,12 +209,11 @@ h5t_add_chunked_tetrahedral_mesh (
name);
}
hid_t mesh_hid;
TRY (mesh_hid = h5priv_open_group (
1, // create intermediate groups in path
TRY (mesh_hid = h5priv_create_group_with_intermediates (
f->root_gid,
H5T_CONTAINER_GRPNAME,
TETRAHEDRAL_MESHES_GRPNAME,
name));
name, NULL));
TRY (*mesh = h5_calloc (1, sizeof(**mesh)));
h5t_mesh_t* m = *mesh;
......
......@@ -46,11 +46,10 @@ h5t_open_triangle_mesh_by_idx (
hid_t ctn_hid;
char name[1024];
TRY (ctn_hid = h5priv_open_group (
0,
TRY (ctn_hid = h5priv_open_group_with_intermediates (
f->root_gid,
H5T_CONTAINER_GRPNAME,
TRIANGLE_MESHES_GRPNAME));
TRIANGLE_MESHES_GRPNAME, NULL));
TRY (hdf5_get_name_of_group_by_idx (ctn_hid, idx, name, sizeof (name)));
TRY (hdf5_close_group (ctn_hid));
......@@ -73,12 +72,11 @@ h5t_open_triangle_mesh (
double start = MPI_Wtime();
#endif
hid_t mesh_hid;
TRY (mesh_hid = h5priv_open_group (
0,
TRY (mesh_hid = h5priv_open_group_with_intermediates (
f->root_gid,
H5T_CONTAINER_GRPNAME,
TRIANGLE_MESHES_GRPNAME,
name));
name, NULL));
TRY (*mesh = h5_calloc (1, sizeof(**mesh)));
h5t_mesh_t* m = *mesh;
......@@ -119,12 +117,11 @@ h5t_open_triangle_mesh_part (
MPI_Barrier (f->props->comm);
double start = MPI_Wtime();
#endif
TRY (mesh_hid = h5priv_open_group (
0,
TRY (mesh_hid = h5priv_open_group_with_intermediates (
f->root_gid,
H5T_CONTAINER_GRPNAME,
TRIANGLE_MESHES_GRPNAME,
name));
name, NULL));
TRY (*mesh = h5_calloc (1, sizeof(**mesh)));
h5t_mesh_t* m = *mesh;
......@@ -176,12 +173,11 @@ h5t_add_triangle_mesh (
name);
}
hid_t mesh_hid;
TRY (mesh_hid = h5priv_open_group (
1, // create intermediate groups in path
TRY (mesh_hid = h5priv_create_group_with_intermediates (
f->root_gid,
H5T_CONTAINER_GRPNAME,
TRIANGLE_MESHES_GRPNAME,
name));
name, NULL));
TRY (*mesh = h5_calloc (1, sizeof(**mesh)));
h5t_mesh_t* m = *mesh;
......@@ -240,12 +236,11 @@ h5t_add_chunked_triangle_mesh(
name);
}
hid_t mesh_hid;
TRY (mesh_hid = h5priv_open_group (
1, // create intermediate groups in path
TRY (mesh_hid = h5priv_create_group_with_intermediates (
f->root_gid,
H5T_CONTAINER_GRPNAME,
TRIANGLE_MESHES_GRPNAME,
name));
name, NULL));
TRY (*mesh = h5_calloc (1, sizeof(**mesh)));
h5t_mesh_t* m = *mesh;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment