summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2003-12-18 16:18:09 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2003-12-18 16:18:09 (GMT)
commit8f65e4252d4f8eea059fcdbe5efc14546175c864 (patch)
treeade9d7df10060156d25aa6a5d0e5c6581eaf8cbc
parent1f0ca5b200c1e20050265d40d26f9bc29333fb74 (diff)
downloadhdf5-8f65e4252d4f8eea059fcdbe5efc14546175c864.zip
hdf5-8f65e4252d4f8eea059fcdbe5efc14546175c864.tar.gz
hdf5-8f65e4252d4f8eea059fcdbe5efc14546175c864.tar.bz2
[svn-r7969] Purpose:
h5repack new features Description: addded the copy routines for hard links changed the traversal structure to store information about the hard links added tests Solution: Platforms tested: linux solaris IRIX Misc. update:
-rw-r--r--tools/h5repack/h5repack.h62
-rw-r--r--tools/h5repack/h5repack_copy.c132
-rw-r--r--tools/h5repack/h5repack_refs.c76
-rw-r--r--tools/h5repack/testh5repack_filters.c160
-rw-r--r--tools/h5repack/testh5repack_main.c29
-rw-r--r--tools/lib/h5diff.c6
-rw-r--r--tools/lib/h5trav.c133
-rw-r--r--tools/lib/h5trav.h29
-rw-r--r--tools/lib/h5trav_table.c76
9 files changed, 474 insertions, 229 deletions
diff --git a/tools/h5repack/h5repack.h b/tools/h5repack/h5repack.h
index 546ae3a..a372a6f 100644
--- a/tools/h5repack/h5repack.h
+++ b/tools/h5repack/h5repack.h
@@ -134,52 +134,39 @@ void print_objlist(const char *filename,
int do_copy_file(hid_t fidin,
hid_t fidout,
- int nobjects,
- trav_info_t *info,
+ trav_table_t *travt,
pack_opt_t *options);
int copy_attr(hid_t loc_in,
hid_t loc_out,
pack_opt_t *options,
- int nobjects, /* number of objects */
- trav_info_t *travi, /* array of object names */
- hid_t fidout /*for saving references */
+ trav_table_t *travt,
+ hid_t fidout /* for saving references */
);
-
-void read_info(const char *filename,pack_opt_t *options);
-
-
-void close_obj(H5G_obj_t obj_type, hid_t obj_id);
-
const char* MapIdToName(hid_t refobj_id,
- int nobjects, /* number of objects */
- trav_info_t *travi, /* array of object names */
+ trav_table_t *travt,
pack_opt_t *options) /* repack options */;
-
-
int do_copy_refobjs(hid_t fidin,
hid_t fidout,
- int nobjects, /* number of objects */
- trav_info_t *travi, /* array of object names */
+ trav_table_t *travt,
pack_opt_t *options); /* repack options */
int do_copy_refobjs_inattr(hid_t loc_in,
hid_t loc_out,
pack_opt_t *options,
- int nobjects, /* number of objects */
- trav_info_t *travi, /* array of object names */
+ trav_table_t *travt,
hid_t fidout /* for saving references */
);
+void read_info(const char *filename,pack_opt_t *options);
+void close_obj(H5G_obj_t obj_type, hid_t obj_id);
/*-------------------------------------------------------------------------
* options table
*-------------------------------------------------------------------------
*/
-
-
int options_table_init( pack_opttbl_t **tbl );
int options_table_free( pack_opttbl_t *table );
int options_add_chunk ( obj_list_t *obj_list,
@@ -194,9 +181,6 @@ int options_add_comp ( obj_list_t *obj_list,
pack_info_t* options_get_object( const char *path,
pack_opttbl_t *table);
-
-
-
/*-------------------------------------------------------------------------
* parse functions
*-------------------------------------------------------------------------
@@ -217,46 +201,36 @@ int parse_number(char *str);
*-------------------------------------------------------------------------
*/
-
-#define FNAME1 "testcopy.h5"
-#define FNAME1OUT "testcopyout.h5"
-#define FNAME2 "testfilters.h5"
-#define FNAME2OUT "testfiltersout.h5"
-
-
-
-#define FNAME1 "testcopy.h5"
-#define FNAME1OUT "testcopyout.h5"
-#define FNAME2 "testfilters.h5"
-#define FNAME2OUT "testfiltersout.h5"
-
+#define FNAME1 "test1.h5"
+#define FNAME1OUT "test1out.h5"
+#define FNAME2 "test2.h5"
+#define FNAME2OUT "test2out.h5"
+#define FNAME3 "test3.h5"
+#define FNAME3OUT "test3out.h5"
+#define FNAME4 "test4.h5"
+#define FNAME4OUT "test4out.h5"
int make_testfiles(void);
-
int make_all_objects(hid_t fid);
-
+int make_attributes(hid_t fid);
+int make_special_objects(hid_t loc_id);
int make_attr(hid_t fid);
-
int write_dset( hid_t loc_id,
int rank,
hsize_t *dims,
const char *dset_name,
hid_t type_id,
void *buf );
-
int write_attr(hid_t loc_id,
int rank,
hsize_t *dims,
const char *attr_name,
hid_t type_id,
void *buf);
-
-
void write_attr_in(hid_t loc_id,
const char* dset_name, /* for saving reference to dataset*/
hid_t fid, /* for reference create */
int make_diffs /* flag to modify data buffers */);
-
void write_dset_in(hid_t loc_id,
const char* dset_name, /* for saving reference to dataset*/
hid_t file_id,
diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c
index f7d5016..2afc94b 100644
--- a/tools/h5repack/h5repack_copy.c
+++ b/tools/h5repack/h5repack_copy.c
@@ -37,10 +37,10 @@ int copy_file(const char* fnamein,
const char* fnameout,
pack_opt_t *options)
{
- hid_t fidin;
- hid_t fidout;
- int nobjects;
- trav_info_t *travi=NULL;
+ hid_t fidin;
+ hid_t fidout;
+ int nobjects=0;
+ trav_table_t *travt=NULL;
/*-------------------------------------------------------------------------
* open the files
@@ -67,65 +67,66 @@ int copy_file(const char* fnamein,
printf("Making file <%s>...\n",fnameout);
-/*-------------------------------------------------------------------------
- * get the number of objects in the file
- *-------------------------------------------------------------------------
- */
+ /* init table */
+ trav_table_init(&travt);
- if ((nobjects = h5trav_getinfo(fidin, NULL ))<0) {
- printf("h5repack: <%s>: Could not obtain object list\n", fnamein );
- return -1;
- }
+ /* get the list of objects in the file */
+ if (h5trav_gettable(fidin,travt)<0)
+ goto out;
-/*-------------------------------------------------------------------------
- * get the list of objects in the file
- *-------------------------------------------------------------------------
- */
-
- if ((travi = (trav_info_t*) malloc( nobjects * sizeof(trav_info_t)))==NULL){
- printf("h5repack: <%s>: Could not allocate object list\n", fnamein );
- return -1;
- }
- if (h5trav_getinfo(fidin, travi )<0) {
- printf("h5repack: <%s>: Could not obtain object list\n", fnamein );
- return -1;
- }
+#if defined (H5_REPACK_DEBUG)
+ h5trav_printtable(travt);
+#endif
/*-------------------------------------------------------------------------
* do the copy
*-------------------------------------------------------------------------
*/
- if(do_copy_file(fidin,fidout,nobjects,travi,options)<0) {
+ if(do_copy_file(fidin,fidout,travt,options)<0) {
printf("h5repack: <%s>: Could not copy data to: %s\n", fnamein, fnameout);
- return -1;
+ goto out;
}
/*-------------------------------------------------------------------------
* do the copy of referenced objects
+ * and create hard links
*-------------------------------------------------------------------------
*/
- if(do_copy_refobjs(fidin,fidout,nobjects,travi,options)<0) {
+ if(do_copy_refobjs(fidin,fidout,travt,options)<0) {
printf("h5repack: <%s>: Could not copy data to: %s\n", fnamein, fnameout);
- return -1;
+ goto out;
}
-#if defined (H5_REPACK_DEBUG)
- h5trav_printinfo(nobjects,travi);
-#endif
-
+ /* free table */
+ trav_table_free(travt);
/*-------------------------------------------------------------------------
- * free
+ * close
*-------------------------------------------------------------------------
*/
+
H5Fclose(fidin);
H5Fclose(fidout);
- h5trav_freeinfo(travi,nobjects);
return 0;
+
+/*-------------------------------------------------------------------------
+ * out
+ *-------------------------------------------------------------------------
+ */
+
+out:
+ H5E_BEGIN_TRY {
+ H5Fclose(fidin);
+ H5Fclose(fidout);
+ trav_table_free(travt);
+ } H5E_END_TRY;
+
+ return -1;
}
+
/*-------------------------------------------------------------------------
* Function: do_copy_file
*
@@ -142,8 +143,7 @@ int copy_file(const char* fnamein,
int do_copy_file(hid_t fidin,
hid_t fidout,
- int nobjects, /* number of objects */
- trav_info_t *travi, /* array of object names */
+ trav_table_t *travt,
pack_opt_t *options) /* repack options */
{
hid_t grp_in; /* group ID */
@@ -168,10 +168,10 @@ int do_copy_file(hid_t fidin,
*-------------------------------------------------------------------------
*/
- for ( i = 0; i < nobjects; i++)
+ for ( i = 0; i < travt->nobjs; i++)
{
- switch ( travi[i].type )
+ switch ( travt->objs[i].type )
{
/*-------------------------------------------------------------------------
* H5G_GROUP
@@ -179,19 +179,19 @@ int do_copy_file(hid_t fidin,
*/
case H5G_GROUP:
if (options->verbose)
- printf(" %-10s %s\n", "group",travi[i].name );
+ printf(" %-10s %s\n", "group",travt->objs[i].name );
- if ((grp_out=H5Gcreate(fidout,travi[i].name, 0))<0)
+ if ((grp_out=H5Gcreate(fidout,travt->objs[i].name, 0))<0)
goto error;
- if((grp_in = H5Gopen (fidin,travi[i].name))<0)
+ if((grp_in = H5Gopen (fidin,travt->objs[i].name))<0)
goto error;
-/*-------------------------------------------------------------------------
- * copy attrs
- *-------------------------------------------------------------------------
- */
- if (copy_attr(grp_in,grp_out,options,nobjects,travi,fidout)<0)
+ /*-------------------------------------------------------------------------
+ * copy attrs
+ *-------------------------------------------------------------------------
+ */
+ if (copy_attr(grp_in,grp_out,options,travt,fidout)<0)
goto error;
if (H5Gclose(grp_out)<0)
@@ -199,6 +199,7 @@ int do_copy_file(hid_t fidin,
if (H5Gclose(grp_in)<0)
goto error;
+
break;
/*-------------------------------------------------------------------------
@@ -207,9 +208,9 @@ int do_copy_file(hid_t fidin,
*/
case H5G_DATASET:
if (options->verbose)
- printf(" %-10s %s\n", "dataset",travi[i].name );
+ printf(" %-10s %s\n", "dataset",travt->objs[i].name );
- if ((dset_in=H5Dopen(fidin,travi[i].name))<0)
+ if ((dset_in=H5Dopen(fidin,travt->objs[i].name))<0)
goto error;
if ((space_id=H5Dget_space(dset_in))<0)
goto error;
@@ -256,7 +257,7 @@ int do_copy_file(hid_t fidin,
* create/write dataset/close
*-------------------------------------------------------------------------
*/
- if ((dset_out=H5Dcreate(fidout,travi[i].name,ftype_id,space_id,dcpl_id))<0)
+ if ((dset_out=H5Dcreate(fidout,travt->objs[i].name,ftype_id,space_id,dcpl_id))<0)
goto error;
if (H5Dwrite(dset_out,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0)
goto error;
@@ -264,8 +265,8 @@ int do_copy_file(hid_t fidin,
/*-------------------------------------------------------------------------
* copy attrs
*-------------------------------------------------------------------------
- */
- if (copy_attr(dset_in,dset_out,options,nobjects,travi,fidout)<0)
+ */
+ if (copy_attr(dset_in,dset_out,options,travt,fidout)<0)
goto error;
/*close */
@@ -274,6 +275,7 @@ int do_copy_file(hid_t fidin,
if (buf)
free(buf);
+
}/*H5T_STD_REF_OBJ*/
@@ -293,8 +295,6 @@ int do_copy_file(hid_t fidin,
goto error;
if (H5Dclose(dset_in)<0)
goto error;
-
-
break;
@@ -304,20 +304,20 @@ int do_copy_file(hid_t fidin,
*/
case H5G_TYPE:
- if ((type_in = H5Topen (fidin,travi[i].name))<0)
+ if ((type_in = H5Topen (fidin,travt->objs[i].name))<0)
goto error;
if ((type_out = H5Tcopy(type_in))<0)
goto error;
- if ((H5Tcommit(fidout,travi[i].name,type_out))<0)
+ if ((H5Tcommit(fidout,travt->objs[i].name,type_out))<0)
goto error;
/*-------------------------------------------------------------------------
* copy attrs
*-------------------------------------------------------------------------
*/
- if (copy_attr(type_in,type_out,options,nobjects,travi,fidout)<0)
+ if (copy_attr(type_in,type_out,options,travt,fidout)<0)
goto error;
if (H5Tclose(type_in)<0)
@@ -326,7 +326,7 @@ int do_copy_file(hid_t fidin,
goto error;
if (options->verbose)
- printf(" %-10s %s\n","datatype",travi[i].name );
+ printf(" %-10s %s\n","datatype",travt->objs[i].name );
break;
@@ -343,32 +343,32 @@ int do_copy_file(hid_t fidin,
H5G_stat_t statbuf;
char *targbuf=NULL;
- if (H5Gget_objinfo(fidin,travi[i].name,FALSE,&statbuf)<0)
+ if (H5Gget_objinfo(fidin,travt->objs[i].name,FALSE,&statbuf)<0)
goto error;
targbuf = malloc(statbuf.linklen);
- if (H5Gget_linkval(fidin,travi[i].name,statbuf.linklen,targbuf)<0)
+ if (H5Gget_linkval(fidin,travt->objs[i].name,statbuf.linklen,targbuf)<0)
goto error;
if (H5Glink(fidout,
H5G_LINK_SOFT,
targbuf, /* current name of object */
- travi[i].name /* new name of object */
+ travt->objs[i].name /* new name of object */
)<0)
goto error;
free(targbuf);
if (options->verbose)
- printf(" %-10s %s\n","link",travi[i].name );
+ printf(" %-10s %s\n","link",travt->objs[i].name );
}
break;
default:
if (options->verbose)
- printf(" %-10s %s\n","User defined object",travi[i].name);
+ printf(" %-10s %s\n","User defined object",travt->objs[i].name);
break;
}
}
@@ -389,7 +389,7 @@ int do_copy_file(hid_t fidin,
if ((grp_in = H5Gopen(fidin,"/"))<0)
goto error;
- if (copy_attr(grp_in,grp_out,options,nobjects,travi,fidout)<0)
+ if (copy_attr(grp_in,grp_out,options,travt,fidout)<0)
goto error;
if (H5Gclose(grp_out)<0)
@@ -439,8 +439,7 @@ error:
int copy_attr(hid_t loc_in,
hid_t loc_out,
pack_opt_t *options,
- int nobjects, /* number of objects */
- trav_info_t *travi, /* array of object names */
+ trav_table_t *travt,
hid_t fidout /* for saving references */
)
{
@@ -577,4 +576,3 @@ error:
return -1;
}
-
diff --git a/tools/h5repack/h5repack_refs.c b/tools/h5repack/h5repack_refs.c
index cd5fe80..81bafab 100644
--- a/tools/h5repack/h5repack_refs.c
+++ b/tools/h5repack/h5repack_refs.c
@@ -24,6 +24,7 @@
* Function: do_copy_refobjs
*
* Purpose: duplicate all referenced HDF5 objects in the file
+ * and create hard links
*
* Return: 0, ok, -1 no
*
@@ -36,8 +37,7 @@
int do_copy_refobjs(hid_t fidin,
hid_t fidout,
- int nobjects, /* number of objects */
- trav_info_t *travi, /* array of object names */
+ trav_table_t *travt,
pack_opt_t *options) /* repack options */
{
hid_t grp_in; /* group ID */
@@ -62,22 +62,32 @@ int do_copy_refobjs(hid_t fidin,
*-------------------------------------------------------------------------
*/
- for ( i = 0; i < nobjects; i++)
+ for ( i = 0; i < travt->nobjs; i++)
{
- switch ( travi[i].type )
+ switch ( travt->objs[i].type )
{
/*-------------------------------------------------------------------------
* H5G_GROUP
*-------------------------------------------------------------------------
*/
case H5G_GROUP:
-
- if((grp_in = H5Gopen (fidin,travi[i].name))<0)
- goto error;
+
+ /*-------------------------------------------------------------------------
+ * check for hard links
+ *-------------------------------------------------------------------------
+ */
- if (H5Gclose(grp_in)<0)
- goto error;
+ if (travt->objs[i].nlinks)
+ {
+ for ( j=0; j<travt->objs[i].nlinks; j++)
+ {
+ H5Glink(fidout,
+ H5G_LINK_HARD,
+ travt->objs[i].name,
+ travt->objs[i].links[j].new_name);
+ }
+ }
break;
@@ -87,7 +97,7 @@ int do_copy_refobjs(hid_t fidin,
*/
case H5G_DATASET:
- if ((dset_in=H5Dopen(fidin,travi[i].name))<0)
+ if ((dset_in=H5Dopen(fidin,travt->objs[i].name))<0)
goto error;
if ((space_id=H5Dget_space(dset_in))<0)
goto error;
@@ -149,14 +159,14 @@ 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,nobjects,travi,options))!=NULL)
+ if ((refname=MapIdToName(refobj_id,travt,options))!=NULL)
{
/* create the reference */
if (H5Rcreate(&refbuf[j],fidout,refname,H5R_OBJECT,-1)<0)
goto error;
if (options->verbose)
- printf("object <%s> reference created to <%s>\n",travi[i].name,refname);
+ printf("object <%s> reference created to <%s>\n",travt->objs[i].name,refname);
}
close_obj(obj_type,refobj_id);
}/* j */
@@ -167,7 +177,7 @@ int do_copy_refobjs(hid_t fidin,
* create/write dataset/close
*-------------------------------------------------------------------------
*/
- if ((dset_out=H5Dcreate(fidout,travi[i].name,ftype_id,space_id,dcpl_id))<0)
+ if ((dset_out=H5Dcreate(fidout,travt->objs[i].name,ftype_id,space_id,dcpl_id))<0)
goto error;
if (H5Dwrite(dset_out,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,refbuf)<0)
goto error;
@@ -185,7 +195,7 @@ int do_copy_refobjs(hid_t fidin,
else
{
- if ((dset_out=H5Dopen(fidout,travi[i].name))<0)
+ if ((dset_out=H5Dopen(fidout,travt->objs[i].name))<0)
goto error;
}
@@ -194,8 +204,24 @@ int do_copy_refobjs(hid_t fidin,
*-------------------------------------------------------------------------
*/
- if (do_copy_refobjs_inattr(dset_in,dset_out,options,nobjects,travi,fidout)<0)
+ if (do_copy_refobjs_inattr(dset_in,dset_out,options,travt,fidout)<0)
goto error;
+
+
+ /*-------------------------------------------------------------------------
+ * check for hard links
+ *-------------------------------------------------------------------------
+ */
+ if (travt->objs[i].nlinks)
+ {
+ for ( j=0; j<travt->objs[i].nlinks; j++)
+ {
+ H5Glink(fidout,
+ H5G_LINK_HARD,
+ travt->objs[i].name,
+ travt->objs[i].links[j].new_name);
+ }
+ }
/*-------------------------------------------------------------------------
@@ -225,7 +251,7 @@ int do_copy_refobjs(hid_t fidin,
*/
case H5G_TYPE:
- if ((type_in = H5Topen (fidin,travi[i].name))<0)
+ if ((type_in = H5Topen (fidin,travt->objs[i].name))<0)
goto error;
if (H5Tclose(type_in)<0)
@@ -267,7 +293,7 @@ int do_copy_refobjs(hid_t fidin,
if ((grp_in = H5Gopen(fidin,"/"))<0)
goto error;
- if (do_copy_refobjs_inattr(grp_in,grp_out,options,nobjects,travi,fidout)<0)
+ if (do_copy_refobjs_inattr(grp_in,grp_out,options,travt,fidout)<0)
goto error;
if (H5Gclose(grp_out)<0)
@@ -314,8 +340,7 @@ error:
int do_copy_refobjs_inattr(hid_t loc_in,
hid_t loc_out,
pack_opt_t *options,
- int nobjects, /* number of objects */
- trav_info_t *travi, /* array of object names */
+ trav_table_t *travt,
hid_t fidout /* for saving references */
)
{
@@ -414,7 +439,7 @@ int do_copy_refobjs_inattr(hid_t loc_in,
/* get the name. a valid name could only occur in the
second traversal of the file */
- if ((refname=MapIdToName(refobj_id,nobjects,travi,options))!=NULL)
+ if ((refname=MapIdToName(refobj_id,travt,options))!=NULL)
{
/* create the reference */
if (H5Rcreate(&refbuf[i],fidout,refname,H5R_OBJECT,-1)<0)
@@ -506,8 +531,7 @@ static void close_obj(H5G_obj_t obj_type, hid_t obj_id)
*/
const char* MapIdToName(hid_t refobj_id,
- int nobjects, /* number of objects */
- trav_info_t *travi, /* array of object names */
+ trav_table_t *travt,
pack_opt_t *options) /* repack options */
{
hid_t id;
@@ -521,9 +545,9 @@ const char* MapIdToName(hid_t refobj_id,
}
- for ( i=0; i<nobjects; i++)
+ for ( i=0; i<travt->nobjs; i++)
{
- switch ( travi[i].type )
+ switch ( travt->objs[i].type )
{
/*-------------------------------------------------------------------------
@@ -543,7 +567,7 @@ const char* MapIdToName(hid_t refobj_id,
case H5G_DATASET:
- if ((id = H5Dopen(fid,travi[i].name))<0)
+ if ((id = H5Dopen(fid,travt->objs[i].name))<0)
{
assert(0);
return NULL;
@@ -558,7 +582,7 @@ const char* MapIdToName(hid_t refobj_id,
if (id==refobj_id)
{
H5Fclose(fid);
- return travi[i].name;
+ return travt->objs[i].name;
}
diff --git a/tools/h5repack/testh5repack_filters.c b/tools/h5repack/testh5repack_filters.c
index 36abc06..dd72813 100644
--- a/tools/h5repack/testh5repack_filters.c
+++ b/tools/h5repack/testh5repack_filters.c
@@ -22,12 +22,6 @@
*
* Purpose: make a dataset using DEFLATE (GZIP) compression in FID
*
- * Return: Success: zero
- * Failure: 1
- *
- * Programmer: Pedro Vicente <pvn@ncsa.uiuc.edu>
- * September, 19, 2003
- *
*-------------------------------------------------------------------------
*/
static int
@@ -82,12 +76,6 @@ error:
*
* Purpose: make a dataset using SZIP compression in FID
*
- * Return: Success: zero
- * Failure: 1
- *
- * Programmer: Pedro Vicente <pvn@ncsa.uiuc.edu>
- * September, 19, 2003
- *
*-------------------------------------------------------------------------
*/
static int
@@ -152,12 +140,6 @@ error:
* Purpose: make a test file with all types of HDF5 objects,
* datatypes and filters
*
- * Return: Success: zero
- * Failure: 1
- *
- * Programmer: Pedro Vicente <pvn@ncsa.uiuc.edu>
- * September, 19, 2003
- *
*-------------------------------------------------------------------------
*/
int make_testfiles(void)
@@ -167,23 +149,35 @@ int make_testfiles(void)
TESTING(" generating datasets");
- /* create a file for the copy test */
+ /* create a file for general copy test */
if((fid = H5Fcreate(FNAME1,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0)
TEST_ERROR;
-
nerrors += make_all_objects(fid);
+ /* close */
+ if(H5Fclose(fid)<0)
+ TEST_ERROR;
+ /* create a file for attributes copy test */
+ if((fid = H5Fcreate(FNAME2,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0)
+ TEST_ERROR;
+ nerrors += make_attributes(fid);
/* close */
if(H5Fclose(fid)<0)
TEST_ERROR;
+ /* create a file for special items test */
+ if((fid = H5Fcreate(FNAME3,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0)
+ TEST_ERROR;
+ nerrors += make_special_objects(fid);
+ /* close */
+ if(H5Fclose(fid)<0)
+ TEST_ERROR;
+
/* create a file for the filters test */
- if((fid = H5Fcreate(FNAME2,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0)
+ if((fid = H5Fcreate(FNAME4,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0)
TEST_ERROR;
-
nerrors += make_deflate(fid);
nerrors += make_szip(fid);
-
/* close */
if(H5Fclose(fid)<0)
TEST_ERROR;
@@ -199,20 +193,11 @@ error:
}
-
-
-
/*-------------------------------------------------------------------------
* Function: make_all_objects
*
* Purpose: make a test file with all types of HDF5 objects, datatypes
*
- * Return: Success: zero
- * Failure: 1
- *
- * Programmer: Pedro Vicente <pvn@ncsa.uiuc.edu>
- * September, 19, 2003
- *
*-------------------------------------------------------------------------
*/
int make_all_objects(hid_t fid)
@@ -267,22 +252,63 @@ int make_all_objects(hid_t fid)
H5Glink(fid, H5G_LINK_SOFT, "dset", "link");
/*-------------------------------------------------------------------------
- * write a series of attributes on the dataset, group, and root group
+ * write a series of datasetes on the group, and root group
*-------------------------------------------------------------------------
*/
- write_attr_in(dset_id,"dset_ref",fid,0);
- write_attr_in(group_id,"dset_ref",fid,0);
- write_attr_in(root_id,"dset_ref",fid,0);
+ write_dset_in(root_id,"dset_ref",fid,0);
+ write_dset_in(group_id,"dset_ref",fid,0);
+
+
+ /* Close */
+ H5Dclose(dset_id);
+ H5Gclose(group_id);
+ H5Gclose(root_id);
+
+ return 0;
+
+}
+
/*-------------------------------------------------------------------------
- * write a series of datasetes on the group, and root group
+ * Function: make_attributes
+ *
+ * Purpose: make a test file with all types of attributes
+ *
+ *-------------------------------------------------------------------------
+ */
+int make_attributes(hid_t fid)
+{
+ hid_t dset_id;
+ hid_t group_id;
+ hid_t root_id;
+ hid_t space_id;
+ hsize_t dims[1]={2};
+
+/*-------------------------------------------------------------------------
+ * H5G_DATASET
*-------------------------------------------------------------------------
*/
- write_dset_in(root_id,"dset_ref",fid,0);
- write_dset_in(group_id,"dset_ref",fid,0);
+ space_id = H5Screate_simple(1,dims,NULL);
+ dset_id = H5Dcreate(fid,"dset",H5T_NATIVE_INT,space_id,H5P_DEFAULT);
+ H5Sclose(space_id);
+
+/*-------------------------------------------------------------------------
+ * H5G_GROUP
+ *-------------------------------------------------------------------------
+ */
+ group_id = H5Gcreate(fid,"g1",0);
+ root_id = H5Gopen(fid, "/");
+
+/*-------------------------------------------------------------------------
+ * write a series of attributes on the dataset, group, and root group
+ *-------------------------------------------------------------------------
+ */
+ write_attr_in(dset_id,"dset",fid,0);
+ write_attr_in(group_id,"dset",fid,0);
+ write_attr_in(root_id,"dset",fid,0);
/* Close */
H5Dclose(dset_id);
@@ -293,3 +319,59 @@ int make_all_objects(hid_t fid)
}
+
+
+/*-------------------------------------------------------------------------
+ * Function: make_special_objects
+ *
+ * Purpose: make a test file with non common items
+ *
+ *-------------------------------------------------------------------------
+ */
+int make_special_objects(hid_t loc_id)
+{
+ hid_t group1_id;
+ hid_t group2_id;
+ hid_t group3_id;
+ hsize_t dims[1]={2};
+ int buf[2]= {1,2};
+
+
+/*-------------------------------------------------------------------------
+ * create a dataset and some hard links to it
+ *-------------------------------------------------------------------------
+ */
+
+ if (write_dset(loc_id,1,dims,"dset",H5T_NATIVE_INT,buf)<0)
+ return -1;
+ if (H5Glink(loc_id, H5G_LINK_HARD, "dset", "link1 to dset")<0)
+ return -1;
+ if (H5Glink(loc_id, H5G_LINK_HARD, "dset", "link2 to dset")<0)
+ return -1;
+ if (H5Glink(loc_id, H5G_LINK_HARD, "dset", "link3 to dset")<0)
+ return -1;
+
+/*-------------------------------------------------------------------------
+ * create a group and some hard links to it
+ *-------------------------------------------------------------------------
+ */
+
+ if ((group1_id = H5Gcreate(loc_id,"g1",0))<0)
+ return -1;
+ if ((group2_id = H5Gcreate(group1_id,"g2",0))<0)
+ return -1;
+ if ((group3_id = H5Gcreate(group2_id,"g3",0))<0)
+ return -1;
+ if (H5Glink(loc_id, H5G_LINK_HARD, "g1", "link1 to g1")<0)
+ return -1;
+ if (H5Glink(loc_id, H5G_LINK_HARD, "g1", "link2 to g1")<0)
+ return -1;
+
+
+ H5Gclose(group1_id);
+ H5Gclose(group2_id);
+
+ return 0;
+
+}
+
diff --git a/tools/h5repack/testh5repack_main.c b/tools/h5repack/testh5repack_main.c
index 0acd632..83b9b77 100644
--- a/tools/h5repack/testh5repack_main.c
+++ b/tools/h5repack/testh5repack_main.c
@@ -42,7 +42,6 @@ test_copy(void)
memset(&diff_options, 0, sizeof (diff_opt_t));
TESTING(" copy with no filters");
-
if (h5repack_init (&pack_options, 0)<0)
TEST_ERROR;
if (h5repack(FNAME1,FNAME1OUT,&pack_options)<0)
@@ -51,8 +50,30 @@ test_copy(void)
TEST_ERROR;
if (h5diff(FNAME1,FNAME1OUT,NULL,NULL,&diff_options) == 1)
TEST_ERROR;
+ PASSED();
+
+ TESTING(" copy of attributes");
+ if (h5repack_init (&pack_options, 0)<0)
+ TEST_ERROR;
+ if (h5repack(FNAME2,FNAME2OUT,&pack_options)<0)
+ TEST_ERROR;
+ if (h5repack_end (&pack_options)<0)
+ TEST_ERROR;
+ if (h5diff(FNAME2,FNAME2OUT,NULL,NULL,&diff_options) == 1)
+ TEST_ERROR;
+ PASSED();
+
+ TESTING(" copy of hardlinks");
+ if (h5repack_init (&pack_options, 0)<0)
+ TEST_ERROR;
+ if (h5repack(FNAME3,FNAME3OUT,&pack_options)<0)
+ TEST_ERROR;
+ if (h5repack_end (&pack_options)<0)
+ TEST_ERROR;
+ if (h5diff(FNAME3,FNAME3OUT,NULL,NULL,&diff_options) == 1)
+ TEST_ERROR;
+ PASSED();
- PASSED();
return 0;
error:
@@ -97,11 +118,11 @@ test_filter_deflate(void)
TEST_ERROR;
if (h5repack_addchunk("dset_gzip:5x4",&pack_options)<0)
TEST_ERROR;
- if (h5repack(FNAME2,FNAME2OUT,&pack_options)<0)
+ if (h5repack(FNAME4,FNAME4OUT,&pack_options)<0)
TEST_ERROR;
if (h5repack_end (&pack_options)<0)
TEST_ERROR;
- if (h5diff(FNAME2,FNAME2OUT,NULL,NULL,&diff_options) == 1)
+ if (h5diff(FNAME4,FNAME4OUT,NULL,NULL,&diff_options) == 1)
TEST_ERROR;
PASSED();
diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c
index 3b59b0e..eeabd8c 100644
--- a/tools/lib/h5diff.c
+++ b/tools/lib/h5diff.c
@@ -239,7 +239,7 @@ int diff_match( hid_t file1_id,
{
c1 = (table->objs[i].flags[0]) ? 'x' : ' ';
c2 = (table->objs[i].flags[1]) ? 'x' : ' ';
- printf("%5c %6c %-15s\n", c1, c2, table->objs[i].objname);
+ printf("%5c %6c %-15s\n", c1, c2, table->objs[i].name);
}
printf("\n");
}
@@ -254,9 +254,9 @@ int diff_match( hid_t file1_id,
{
if ( table->objs[i].flags[0] && table->objs[i].flags[1] )
nfound+=diff( file1_id,
- table->objs[i].objname,
+ table->objs[i].name,
file2_id,
- table->objs[i].objname,
+ table->objs[i].name,
options,
table->objs[i].type );
}
diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c
index fc64fc7..e065e28 100644
--- a/tools/lib/h5trav.c
+++ b/tools/lib/h5trav.c
@@ -25,7 +25,7 @@ int traverse( hid_t loc_id,
trav_info_t *info,
int *idx );
-herr_t get_nobjects( hid_t loc_id,
+herr_t get_nnames( hid_t loc_id,
const char *group_name );
herr_t get_name_type( hid_t loc_id,
@@ -40,7 +40,7 @@ herr_t get_name_type( hid_t loc_id,
* Purpose: get an array of "trav_info_t" , containing the name and type of
* objects in the file
*
- * Return: number of objects in file
+ * Return: number of object names in file
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
@@ -53,19 +53,46 @@ int h5trav_getinfo( hid_t file_id, trav_info_t *info )
{
trav_table_t *table=NULL;
- int nobjects=0;
+ int nnames=0;
/* init table */
trav_table_init( &table );
/* iterate starting on the root group */
- if (( nobjects = traverse( file_id, "/", table, info, &nobjects )) < 0 )
+ if (( nnames = traverse( file_id, "/", table, info, &nnames )) < 0 )
return -1;
/* free table */
trav_table_free( table );
- return nobjects;
+ return nnames;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: h5trav_gettable
+ *
+ * Purpose: get the trav_table_t struct
+ *
+ * Return: 0, -1 on error
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: December 17, 2003
+ *
+ *-------------------------------------------------------------------------
+ */
+
+int h5trav_gettable(hid_t fid, trav_table_t *travt)
+{
+ int nnames=0;
+
+ /* iterate starting on the root group */
+ if (( nnames = traverse(fid,"/",travt,NULL,&nnames))<0)
+ return -1;
+
+ return 0;
}
@@ -131,7 +158,7 @@ void h5trav_freeinfo( trav_info_t *info, int nobjs )
/*-------------------------------------------------------------------------
- * Function: count_objects
+ * Function: count_names
*
* Purpose: operator function
*
@@ -146,7 +173,7 @@ void h5trav_freeinfo( trav_info_t *info, int nobjs )
*-------------------------------------------------------------------------
*/
-static herr_t count_objects( hid_t loc_id, const char *name, void *op_data)
+static herr_t count_names( hid_t loc_id, const char *name, void *op_data)
{
H5G_stat_t statbuf;
@@ -161,9 +188,9 @@ static herr_t count_objects( hid_t loc_id, const char *name, void *op_data)
}
/*-------------------------------------------------------------------------
- * Function: get_nobjects
+ * Function: get_nnames
*
- * Purpose: Counts the number of objects in the group GROUP_NAME
+ * Purpose: Counts the number of names in the group GROUP_NAME
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
@@ -181,12 +208,12 @@ static herr_t count_objects( hid_t loc_id, const char *name, void *op_data)
*-------------------------------------------------------------------------
*/
-herr_t get_nobjects( hid_t loc_id, const char *group_name )
+herr_t get_nnames( hid_t loc_id, const char *group_name )
{
int nobjs = 0;
- if ( H5Giterate( loc_id, group_name, NULL, count_objects, (void *)&nobjs ) < 0 )
+ if ( H5Giterate( loc_id, group_name, NULL, count_names, (void *)&nobjs ) < 0 )
return -1;
return nobjs;
@@ -287,17 +314,18 @@ int traverse( hid_t loc_id,
char *name=NULL;
H5G_obj_t type;
- int nobjs;
- int i;
+ int n_names;
char *path=NULL;
H5G_stat_t statbuf;
int inserted_objs=0;
- int j;
+ int i, j;
+
- if (( nobjs = get_nobjects( loc_id, group_name )) < 0 )
+ /* get the number of names */
+ if (( n_names = get_nnames( loc_id, group_name )) < 0 )
return -1;
- for ( i = 0; i < nobjs; i++)
+ for ( i = 0; i < n_names; i++)
{
if (get_name_type( loc_id, group_name, i, &name, &type ) < 0 )
@@ -365,8 +393,9 @@ int traverse( hid_t loc_id,
else
{
#if defined (H5_TRAV_DEBUG)
- printf("%s %s\n", "HARDLINK", table->objs[j].objname);
+ printf("<%s> HARDLINK to <%s>\n", path, table->objs[j].name);
#endif
+ trav_table_addlink(table,j,path);
}
}
@@ -404,11 +433,11 @@ int traverse( hid_t loc_id,
else
{
#if defined (H5_TRAV_DEBUG)
- printf("%s %s\n", "HARDLINK", table->objs[j].objname);
+ printf("<%s> HARDLINK to <%s>\n", path, table->objs[j].name);
#endif
- }
-
- }
+ trav_table_addlink(table,j,path);
+ } /* displayed==1 */
+ } /* nlink>1 */
break;
@@ -442,7 +471,10 @@ int traverse( hid_t loc_id,
/* increment */
inserted_objs++;
-
+
+ /* add object to table */
+ trav_table_add(statbuf.objno, path, H5G_LINK, table );
+
break;
@@ -471,9 +503,9 @@ int traverse( hid_t loc_id,
/*-------------------------------------------------------------------------
- * Function: diff_list
+ * Function: h5trav_printinfo
*
- * Purpose: print list of objects in file
+ * Purpose: print list of names in file
*
* Return: void
*
@@ -481,10 +513,6 @@ int traverse( hid_t loc_id,
*
* Date: May 9, 2003
*
- * Comments:
- *
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
void h5trav_printinfo(int nobjs, trav_info_t *travi)
@@ -515,3 +543,52 @@ void h5trav_printinfo(int nobjs, trav_info_t *travi)
+/*-------------------------------------------------------------------------
+ * Function: h5trav_printtable
+ *
+ * Purpose: print list of objects in file
+ *
+ * Return: void
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: May 9, 2003
+ *
+ *-------------------------------------------------------------------------
+ */
+void h5trav_printtable(trav_table_t *table)
+{
+ int i, j;
+
+ for ( i = 0; i < table->nobjs; i++)
+ {
+ switch ( table->objs[i].type )
+ {
+ case H5G_GROUP:
+ printf(" %-10s %s\n", "group", table->objs[i].name );
+ break;
+ case H5G_DATASET:
+ printf(" %-10s %s\n", "dataset", table->objs[i].name );
+ break;
+ case H5G_TYPE:
+ printf(" %-10s %s\n", "datatype", table->objs[i].name );
+ break;
+ case H5G_LINK:
+ printf(" %-10s %s\n", "link", table->objs[i].name );
+ break;
+ default:
+ printf(" %-10s %s\n", "User defined object", table->objs[i].name );
+ break;
+ }
+
+ if (table->objs[i].nlinks)
+ {
+ for ( j=0; j<table->objs[i].nlinks; j++)
+ {
+ printf(" %-10s %s\n", " hardlink", table->objs[i].links[j] );
+ }
+ }
+
+ }
+}
+
diff --git a/tools/lib/h5trav.h b/tools/lib/h5trav.h
index 1f826bb..cedbc54 100644
--- a/tools/lib/h5trav.h
+++ b/tools/lib/h5trav.h
@@ -40,16 +40,28 @@ typedef struct trav_info_t {
/*-------------------------------------------------------------------------
+ * keep record of hard link information
+ *-------------------------------------------------------------------------
+ */
+typedef struct trav_link_t {
+ char *new_name;
+} trav_link_t;
+
+
+/*-------------------------------------------------------------------------
* struct to store basic info needed for the h5trav table traversal algorythm
*-------------------------------------------------------------------------
*/
typedef struct trav_obj_t {
- haddr_t objno;
- unsigned flags[2];
- char *objname;
- int displayed;
- H5G_obj_t type;
+ haddr_t objno; /* object number from H5Gget_objinfo */
+ unsigned flags[2]; /* h5diff.object is present or not in both files*/
+ char *name; /* name */
+ int displayed; /* hard link already traversed once */
+ H5G_obj_t type; /* type of object */
+ trav_link_t *links; /* array of possible link names */
+ int sizelinks; /* size of links array */
+ int nlinks; /* number of links */
} trav_obj_t;
@@ -78,7 +90,7 @@ int h5trav_getinfo( hid_t file_id, trav_info_t *info );
int h5trav_getindex( const char *obj, int nobjs, trav_info_t *info );
void h5trav_freeinfo( trav_info_t *info, int nobjs );
void h5trav_printinfo(int nobjs, trav_info_t *info);
-
+int h5trav_gettable(hid_t fid, trav_table_t *travt);
#ifdef __cplusplus
@@ -107,6 +119,11 @@ void trav_table_addflags(unsigned *flags,
H5G_obj_t type,
trav_table_t *table);
+void h5trav_printtable(trav_table_t *table);
+
+void trav_table_addlink(trav_table_t *table,
+ int j /* the object index */,
+ char *path );
#endif /* H5TRAV_H__ */
diff --git a/tools/lib/h5trav_table.c b/tools/lib/h5trav_table.c
index bbbe2d6..0071559 100644
--- a/tools/lib/h5trav_table.c
+++ b/tools/lib/h5trav_table.c
@@ -57,7 +57,7 @@ int trav_table_search(haddr_t objno, trav_table_t *table )
*/
void trav_table_add(haddr_t objno,
- char *objname,
+ char *name,
H5G_obj_t type,
trav_table_t *table)
{
@@ -73,16 +73,21 @@ void trav_table_add(haddr_t objno,
table->objs[i].flags[0] = table->objs[i].flags[1] = 0;
table->objs[i].displayed = 0;
table->objs[i].type = H5G_UNKNOWN;
- table->objs[i].objname = NULL;
+ table->objs[i].name = NULL;
+ table->objs[i].links = NULL;
+ table->objs[i].nlinks = 0;
+ table->objs[i].sizelinks = 0;
}
}
i = table->nobjs++;
table->objs[i].objno = objno;
table->objs[i].flags[0] = table->objs[i].flags[1] = 0;
- HDfree(table->objs[i].objname);
- table->objs[i].objname = (char *)HDstrdup(objname);
+ HDfree(table->objs[i].name);
+ table->objs[i].name = (char *)HDstrdup(name);
table->objs[i].type = type;
+ table->objs[i].links = NULL;
+ table->objs[i].nlinks = 0;
}
@@ -101,7 +106,7 @@ void trav_table_add(haddr_t objno,
*/
void trav_table_addflags(unsigned *flags,
- char *objname,
+ char *name,
H5G_obj_t type,
trav_table_t *table)
{
@@ -117,7 +122,10 @@ void trav_table_addflags(unsigned *flags,
table->objs[i].flags[0] = table->objs[i].flags[1] = 0;
table->objs[i].displayed = 0;
table->objs[i].type = H5G_UNKNOWN;
- table->objs[i].objname = NULL;
+ table->objs[i].name = NULL;
+ table->objs[i].links = NULL;
+ table->objs[i].nlinks = 0;
+ table->objs[i].sizelinks = 0;
}
}
@@ -125,9 +133,11 @@ void trav_table_addflags(unsigned *flags,
table->objs[i].objno = 0;
table->objs[i].flags[0] = flags[0];
table->objs[i].flags[1] = flags[1];
- HDfree(table->objs[i].objname);
- table->objs[i].objname = (char *)HDstrdup(objname);
+ HDfree(table->objs[i].name);
+ table->objs[i].name = (char *)HDstrdup(name);
table->objs[i].type = type;
+ table->objs[i].links = NULL;
+ table->objs[i].nlinks = 0;
}
@@ -160,7 +170,10 @@ void trav_table_init( trav_table_t **tbl )
table->objs[i].flags[0] = table->objs[i].flags[1] = 0;
table->objs[i].displayed = 0;
table->objs[i].type = H5G_UNKNOWN;
- table->objs[i].objname = NULL;
+ table->objs[i].name = NULL;
+ table->objs[i].links = NULL;
+ table->objs[i].nlinks = 0;
+ table->objs[i].sizelinks = 0;
}
*tbl = table;
@@ -184,14 +197,53 @@ void trav_table_init( trav_table_t **tbl )
void trav_table_free( trav_table_t *table )
{
- int i;
+ int i, j;
for ( i = 0; i < table->nobjs; i++)
- HDfree( table->objs[i].objname );
-
+ {
+ HDfree( table->objs[i].name );
+ if (table->objs[i].nlinks)
+ {
+ for ( j=0; j<table->objs[i].nlinks; j++)
+ HDfree( table->objs[i].links[j].new_name );
+
+ HDfree(table->objs[i].links);
+ }
+ }
HDfree(table->objs);
HDfree(table);
}
+/*-------------------------------------------------------------------------
+ * Function: trav_table_addlink
+ *
+ * Purpose: Add a hardlink name to the object
+ *
+ * Return: void
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: December 17, 2003
+ *
+ *-------------------------------------------------------------------------
+ */
+
+void trav_table_addlink(trav_table_t *table,
+ int j /* the object index */,
+ char *path )
+{
+ int k;
+ /* store the link information */
+ if (table->objs[j].nlinks == table->objs[j].sizelinks) {
+ table->objs[j].sizelinks += 2;
+ table->objs[j].links =
+ (trav_link_t*)HDrealloc(table->objs[j].links,
+ table->objs[j].sizelinks * sizeof(trav_link_t));
+ }
+ k = table->objs[j].nlinks++;
+ table->objs[j].links[k].new_name = (char*)HDstrdup(path);
+}
+
+