summaryrefslogtreecommitdiffstats
path: root/tools/h5repack/h5repack_refs.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/h5repack/h5repack_refs.c')
-rw-r--r--tools/h5repack/h5repack_refs.c80
1 files changed, 37 insertions, 43 deletions
diff --git a/tools/h5repack/h5repack_refs.c b/tools/h5repack/h5repack_refs.c
index 1035a06..4d57b44 100644
--- a/tools/h5repack/h5repack_refs.c
+++ b/tools/h5repack/h5repack_refs.c
@@ -20,19 +20,16 @@
#include "h5repack.h"
static const char* MapIdToName(hid_t refobj_id,
- trav_table_t *travt,
- const char* fname);
+ trav_table_t *travt);
-static void close_obj(H5G_obj_t obj_type, hid_t obj_id);
+static void close_obj(H5G_obj_t1 obj_type, hid_t obj_id);
static int copy_refs_attr(hid_t loc_in,
hid_t loc_out,
pack_opt_t *options,
trav_table_t *travt,
- hid_t fidout, /* for saving references */
- hid_t fidin,
- const char *fname
+ hid_t fidout /* for saving references */
);
/*-------------------------------------------------------------------------
@@ -53,18 +50,17 @@ static int copy_refs_attr(hid_t loc_in,
int do_copy_refobjs(hid_t fidin,
hid_t fidout,
trav_table_t *travt,
- pack_opt_t *options, /* repack options */
- const char *fnamein)
+ pack_opt_t *options) /* repack options */
{
- hid_t grp_in; /* group ID */
- hid_t grp_out; /* group ID */
- hid_t dset_in; /* read dataset ID */
- hid_t dset_out; /* write dataset ID */
- hid_t type_in; /* named type ID */
- hid_t dcpl_id; /* dataset creation property list ID */
- hid_t space_id; /* space ID */
- hid_t ftype_id; /* file data type ID */
- hid_t mtype_id; /* memory data type ID */
+ hid_t grp_in=-1; /* group ID */
+ hid_t grp_out=-1; /* group ID */
+ hid_t dset_in=-1; /* read dataset ID */
+ hid_t dset_out=-1; /* write dataset ID */
+ hid_t type_in=-1; /* named type ID */
+ hid_t dcpl_id=-1; /* dataset creation property list ID */
+ hid_t space_id=-1; /* space ID */
+ hid_t ftype_id=-1; /* file data type ID */
+ hid_t mtype_id=-1; /* memory data type ID */
size_t msize; /* memory size of memory type */
hsize_t nelmts; /* number of elements in dataset */
int rank; /* rank of dataset */
@@ -153,7 +149,7 @@ int do_copy_refobjs(hid_t fidin,
*/
if (H5Tequal(mtype_id, H5T_STD_REF_OBJ))
{
- H5G_obj_t obj_type;
+ H5G_obj_t1 obj_type;
hid_t refobj_id;
hobj_ref_t *refbuf=NULL; /* buffer for object references */
hobj_ref_t *buf=NULL;
@@ -190,7 +186,7 @@ int do_copy_refobjs(hid_t fidin,
} H5E_END_TRY;
/* get the name. a valid name could only occur in the
second traversal of the file */
- if ((refname=MapIdToName(refobj_id,travt,fnamein))!=NULL)
+ if ((refname=MapIdToName(refobj_id,travt))!=NULL)
{
/* create the reference, -1 parameter for objects */
if (H5Rcreate(&refbuf[u],fidout,refname,H5R_OBJECT,-1)<0)
@@ -228,7 +224,7 @@ int do_copy_refobjs(hid_t fidin,
*/
else if (H5Tequal(mtype_id, H5T_STD_REF_DSETREG))
{
- H5G_obj_t obj_type;
+ H5G_obj_t1 obj_type;
hid_t refobj_id;
hdset_reg_ref_t *refbuf=NULL; /* input buffer for region references */
hdset_reg_ref_t *buf=NULL; /* output buffer */
@@ -270,7 +266,7 @@ int do_copy_refobjs(hid_t fidin,
/* get the name. a valid name could only occur in the
second traversal of the file */
- if ((refname=MapIdToName(refobj_id,travt,fnamein))!=NULL)
+ if ((refname=MapIdToName(refobj_id,travt))!=NULL)
{
hid_t region_id; /* region id of the referenced dataset */
if ((region_id = H5Rget_region(dset_in,H5R_DATASET_REGION,&buf[u]))<0)
@@ -323,7 +319,7 @@ int do_copy_refobjs(hid_t fidin,
* copy referenced objects in attributes
*-------------------------------------------------------------------------
*/
- if (copy_refs_attr(dset_in,dset_out,options,travt,fidout,fidin,fnamein)<0)
+ if (copy_refs_attr(dset_in,dset_out,options,travt,fidout)<0)
goto error;
@@ -410,7 +406,7 @@ int do_copy_refobjs(hid_t fidin,
if ((grp_in = H5Gopen(fidin,"/"))<0)
goto error;
- if (copy_refs_attr(grp_in,grp_out,options,travt,fidout,fidin,fnamein)<0)
+ if (copy_refs_attr(grp_in,grp_out,options,travt,fidout)<0)
goto error;
if (H5Gclose(grp_out)<0)
@@ -459,16 +455,14 @@ static int copy_refs_attr(hid_t loc_in,
hid_t loc_out,
pack_opt_t *options,
trav_table_t *travt,
- hid_t fidout, /* for saving references */
- hid_t fidin,
- const char *fnamein
+ hid_t fidout /* for saving references */
)
{
- hid_t attr_id; /* attr ID */
- hid_t attr_out; /* attr ID */
- hid_t space_id; /* space ID */
- hid_t ftype_id; /* file data type ID */
- hid_t mtype_id; /* memory data type ID */
+ hid_t attr_id=-1; /* attr ID */
+ hid_t attr_out=-1; /* attr ID */
+ hid_t space_id=-1; /* space ID */
+ hid_t ftype_id=-1; /* file data type ID */
+ hid_t mtype_id=-1; /* memory data type ID */
size_t msize; /* memory size of type */
hsize_t nelmts; /* number of elements in dataset */
int rank; /* rank of dataset */
@@ -527,7 +521,7 @@ static int copy_refs_attr(hid_t loc_in,
*/
if (H5Tequal(mtype_id, H5T_STD_REF_OBJ))
{
- H5G_obj_t obj_type;
+ H5G_obj_t1 obj_type;
hid_t refobj_id;
hobj_ref_t *refbuf=NULL;
unsigned k;
@@ -564,7 +558,7 @@ static int copy_refs_attr(hid_t loc_in,
} H5E_END_TRY;
/* get the name. a valid name could only occur in the
second traversal of the file */
- if ((refname=MapIdToName(refobj_id,travt,fnamein))!=NULL)
+ if ((refname=MapIdToName(refobj_id,travt))!=NULL)
{
/* create the reference */
if (H5Rcreate(&refbuf[k],fidout,refname,H5R_OBJECT,-1)<0)
@@ -604,7 +598,7 @@ static int copy_refs_attr(hid_t loc_in,
*/
else if (H5Tequal(mtype_id, H5T_STD_REF_DSETREG))
{
- H5G_obj_t obj_type;
+ H5G_obj_t1 obj_type;
hid_t refobj_id;
hdset_reg_ref_t *refbuf=NULL; /* input buffer for region references */
hdset_reg_ref_t *buf=NULL; /* output buffer */
@@ -646,7 +640,7 @@ static int copy_refs_attr(hid_t loc_in,
} H5E_END_TRY;
/* get the name. a valid name could only occur in the
second traversal of the file */
- if ((refname=MapIdToName(refobj_id,travt,fnamein))!=NULL)
+ if ((refname=MapIdToName(refobj_id,travt))!=NULL)
{
hid_t region_id; /* region id of the referenced dataset */
if ((region_id = H5Rget_region(attr_id,H5R_DATASET_REGION,&buf[k]))<0)
@@ -714,7 +708,7 @@ error:
*-------------------------------------------------------------------------
*/
-static void close_obj(H5G_obj_t obj_type, hid_t obj_id)
+static void close_obj(H5G_obj_t1 obj_type, hid_t obj_id)
{
H5E_BEGIN_TRY
{
@@ -744,17 +738,16 @@ static void close_obj(H5G_obj_t obj_type, hid_t obj_id)
*/
static const char* MapIdToName(hid_t refobj_id,
- trav_table_t *travt,
- const char* fname)
+ trav_table_t *travt)
{
hid_t id;
hid_t fid;
int i;
- /* open */
- if ((fid=H5Fopen(fname,H5F_ACC_RDONLY,H5P_DEFAULT))<0 ){
- printf("h5repack: <%s>: %s\n", fname, H5FOPENERROR );
- exit(1);
+ /* obtains the file ID given an object ID. This ID must be closed */
+ if ((fid = H5Iget_file_id(refobj_id))<0)
+ {
+ return NULL;
}
/* linear search */
@@ -785,7 +778,8 @@ static const char* MapIdToName(hid_t refobj_id,
} /* switch */
} /* i */
- H5Fclose(fid);
+ if (H5Fclose(fid)<0)
+ return NULL;
return NULL;
}