[svn-r8074] Purpose:

added h5repack and h5diff support for copying and differences of references to dataset regions
modified the behaviour in the diff of attributes, when a difference in name is detected
in the attribute cycle (number of attributes of object), instead of exiting the
cycle, rather continue


Description:

Solution:

Platforms tested:
linux
solaris
AIX

Misc. update:
This commit is contained in:
Pedro Vicente Nunes 2004-01-16 10:31:55 -05:00
parent 5112a79d81
commit efbde3c2f3
11 changed files with 623 additions and 129 deletions

View File

@ -19,7 +19,7 @@
#include "hdf5.h"
#include "h5trav.h"
#if 1
#if 0
#define H5_REPACK_DEBUG
#endif
@ -158,20 +158,12 @@ int copy_attr(hid_t loc_in,
pack_opt_t *options
);
const char* MapIdToName(hid_t refobj_id,
trav_table_t *travt);
int do_copy_refobjs(hid_t fidin,
hid_t fidout,
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,
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);

View File

@ -233,12 +233,13 @@ int do_copy_objects(hid_t fidin,
/*-------------------------------------------------------------------------
* object references are a special case
* references are a special case
* we cannot just copy the buffers, but instead we recreate the reference
* in a second traversal of the output file
*-------------------------------------------------------------------------
*/
if ( ! H5Tequal(mtype_id, H5T_STD_REF_OBJ) )
if ( H5Tget_class(mtype_id) != H5T_REFERENCE )
{
/* the information about the object to be filtered/"layouted" */

View File

@ -20,6 +20,19 @@
#include "h5repack.h"
static const char* MapIdToName(hid_t refobj_id,
trav_table_t *travt);
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 */
);
/*-------------------------------------------------------------------------
* Function: do_copy_refobjs
*
@ -116,7 +129,12 @@ int do_copy_refobjs(hid_t fidin,
goto error;
if ((msize=H5Tget_size(mtype_id))==0)
goto error;
/*-------------------------------------------------------------------------
* test for a valid output dataset
*-------------------------------------------------------------------------
*/
dset_out = FAIL;
/*-------------------------------------------------------------------------
* object references are a special case
@ -125,13 +143,12 @@ int do_copy_refobjs(hid_t fidin,
*/
if (H5Tequal(mtype_id, H5T_STD_REF_OBJ))
{
H5G_obj_t obj_type;
hid_t refobj_id;
hobj_ref_t *refbuf;
const char* refname;
hobj_ref_t *buf;
unsigned u;
H5G_obj_t obj_type;
hid_t refobj_id;
hobj_ref_t *refbuf; /* buffer for object references */
hobj_ref_t *buf;
const char* refname;
unsigned u;
/*-------------------------------------------------------------------------
* read to memory
@ -146,7 +163,6 @@ int do_copy_refobjs(hid_t fidin,
if (H5Dread(dset_in,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0)
goto error;
if ((obj_type = H5Rget_obj_type(dset_in,H5R_OBJECT,buf))<0)
goto error;
refbuf=HDmalloc((unsigned)nelmts*msize);
@ -156,24 +172,25 @@ int do_copy_refobjs(hid_t fidin,
}
for ( u=0; u<nelmts; u++)
{
H5E_BEGIN_TRY {
if ((refobj_id = H5Rdereference(dset_in,H5R_OBJECT,&buf[u]))<0)
goto error;
/* get the name. a valid name could only occur in the
continue;
} 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))!=NULL)
{
/* create the reference */
/* create the reference, -1 parameter for objects */
if (H5Rcreate(&refbuf[u],fidout,refname,H5R_OBJECT,-1)<0)
goto error;
if (options->verbose)
printf("object <%s> reference created to <%s>\n",travt->objs[i].name,refname);
printf("object <%s> object reference created to <%s>\n",
travt->objs[i].name,
refname);
}
close_obj(obj_type,refobj_id);
}/* j */
/*-------------------------------------------------------------------------
* create/write dataset/close
@ -189,31 +206,113 @@ int do_copy_refobjs(hid_t fidin,
}/*H5T_STD_REF_OBJ*/
/*-------------------------------------------------------------------------
* dataset region references
*-------------------------------------------------------------------------
*/
else if (H5Tequal(mtype_id, H5T_STD_REF_DSETREG))
{
H5G_obj_t obj_type;
hid_t refobj_id;
hdset_reg_ref_t *refbuf; /* input buffer for region references */
hdset_reg_ref_t *buf; /* output buffer */
const char* refname;
unsigned u;
/*-------------------------------------------------------------------------
* open previously created object in 1st traversal
* read input to memory
*-------------------------------------------------------------------------
*/
buf=(void *) HDmalloc((unsigned)(nelmts*msize));
if ( buf==NULL){
printf( "cannot read into memory\n" );
goto error;
}
if (H5Dread(dset_in,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0)
goto error;
if ((obj_type = H5Rget_obj_type(dset_in,H5R_DATASET_REGION,buf))<0)
goto error;
/*-------------------------------------------------------------------------
* create output
*-------------------------------------------------------------------------
*/
refbuf=HDcalloc(sizeof(hdset_reg_ref_t),(size_t)nelmts); /*init to zero */
if ( refbuf==NULL){
printf( "cannot allocate memory\n" );
goto error;
}
for ( u=0; u<nelmts; u++)
{
H5E_BEGIN_TRY {
if ((refobj_id = H5Rdereference(dset_in,H5R_DATASET_REGION,&buf[u]))<0)
continue;
} 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))!=NULL)
{
hid_t region_id; /* region id of the referenced dataset */
if ((region_id = H5Rget_region(dset_in,H5R_DATASET_REGION,&buf[u]))<0)
goto error;
/* create the reference, we need the space_id */
if (H5Rcreate(&refbuf[u],fidout,refname,H5R_DATASET_REGION,region_id)<0)
goto error;
if (H5Sclose(region_id)<0)
goto error;
if (options->verbose)
printf("object <%s> region reference created to <%s>\n",
travt->objs[i].name,
refname);
}
close_obj(obj_type,refobj_id);
}/* u */
/*-------------------------------------------------------------------------
* create/write dataset/close
*-------------------------------------------------------------------------
*/
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;
free(buf);
free(refbuf);
} /* H5T_STD_REF_DSETREG */
/*-------------------------------------------------------------------------
* not references, open previously created object in 1st traversal
*-------------------------------------------------------------------------
*/
else
{
if ((dset_out=H5Dopen(fidout,travt->objs[i].name))<0)
goto error;
}
assert(dset_out!=FAIL);
/*-------------------------------------------------------------------------
* copy referenced objects in attributes
*-------------------------------------------------------------------------
*/
if (do_copy_refobjs_inattr(dset_in,dset_out,options,travt,fidout)<0)
/*-------------------------------------------------------------------------
* copy referenced objects in attributes
*-------------------------------------------------------------------------
*/
if (copy_refs_attr(dset_in,dset_out,options,travt,fidout)<0)
goto error;
/*-------------------------------------------------------------------------
* check for hard links
*-------------------------------------------------------------------------
*/
/*-------------------------------------------------------------------------
* check for hard links
*-------------------------------------------------------------------------
*/
if (travt->objs[i].nlinks)
{
for ( j=0; j<travt->objs[i].nlinks; j++)
@ -225,7 +324,6 @@ int do_copy_refobjs(hid_t fidin,
}
}
/*-------------------------------------------------------------------------
* close
*-------------------------------------------------------------------------
@ -243,7 +341,6 @@ int do_copy_refobjs(hid_t fidin,
goto error;
if (H5Dclose(dset_out)<0)
goto error;
break;
@ -295,7 +392,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,travt,fidout)<0)
if (copy_refs_attr(grp_in,grp_out,options,travt,fidout)<0)
goto error;
if (H5Gclose(grp_out)<0)
@ -323,9 +420,10 @@ error:
/*-------------------------------------------------------------------------
* Function: do_copy_refobjs_inattr
* Function: copy_refs_attr
*
* Purpose: copy attributes located in LOC_IN, which is obtained either from
* Purpose: duplicate all referenced HDF5 located in attributes
* relative to LOC_IN, which is obtained either from
* loc_id = H5Gopen( fid, name);
* loc_id = H5Dopen( fid, name);
* loc_id = H5Topen( fid, name);
@ -339,12 +437,12 @@ error:
*-------------------------------------------------------------------------
*/
int do_copy_refobjs_inattr(hid_t loc_in,
hid_t loc_out,
pack_opt_t *options,
trav_table_t *travt,
hid_t fidout /* for saving references */
)
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 attr_id; /* attr ID */
hid_t attr_out; /* attr ID */
@ -402,8 +500,6 @@ int do_copy_refobjs_inattr(hid_t loc_in,
if ((msize=H5Tget_size(mtype_id))==0)
goto error;
/*-------------------------------------------------------------------------
* object references are a special case
* we cannot just copy the buffers, but instead we recreate the reference
@ -418,7 +514,11 @@ int do_copy_refobjs_inattr(hid_t loc_in,
const char* refname;
hobj_ref_t *buf;
/*-------------------------------------------------------------------------
* read input to memory
*-------------------------------------------------------------------------
*/
buf=(void *) HDmalloc((unsigned)(nelmts*msize));
if ( buf==NULL){
printf( "cannot read into memory\n" );
@ -457,7 +557,7 @@ int do_copy_refobjs_inattr(hid_t loc_in,
/*-------------------------------------------------------------------------
* copy
*-------------------------------------------------------------------------
*/
*/
if ((attr_out=H5Acreate(loc_out,name,ftype_id,space_id,H5P_DEFAULT))<0)
goto error;
@ -471,6 +571,92 @@ int do_copy_refobjs_inattr(hid_t loc_in,
free(buf);
}/*H5T_STD_REF_OBJ*/
/*-------------------------------------------------------------------------
* dataset region references
*-------------------------------------------------------------------------
*/
else if (H5Tequal(mtype_id, H5T_STD_REF_DSETREG))
{
H5G_obj_t obj_type;
hid_t refobj_id;
hdset_reg_ref_t *refbuf; /* input buffer for region references */
hdset_reg_ref_t *buf; /* output buffer */
const char* refname;
unsigned u;
/*-------------------------------------------------------------------------
* read input to memory
*-------------------------------------------------------------------------
*/
buf=(void *) HDmalloc((unsigned)(nelmts*msize));
if ( buf==NULL){
printf( "cannot read into memory\n" );
goto error;
}
if (H5Aread(attr_id,mtype_id,buf)<0)
goto error;
if ((obj_type = H5Rget_obj_type(attr_id,H5R_DATASET_REGION,buf))<0)
goto error;
/*-------------------------------------------------------------------------
* create output
*-------------------------------------------------------------------------
*/
refbuf=HDcalloc(sizeof(hdset_reg_ref_t),(size_t)nelmts); /*init to zero */
if ( refbuf==NULL){
printf( "cannot allocate memory\n" );
goto error;
}
for ( u=0; u<nelmts; u++)
{
H5E_BEGIN_TRY {
if ((refobj_id = H5Rdereference(attr_id,H5R_DATASET_REGION,&buf[u]))<0)
continue;
} 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))!=NULL)
{
hid_t region_id; /* region id of the referenced dataset */
if ((region_id = H5Rget_region(attr_id,H5R_DATASET_REGION,&buf[u]))<0)
goto error;
/* create the reference, we need the space_id */
if (H5Rcreate(&refbuf[u],fidout,refname,H5R_DATASET_REGION,region_id)<0)
goto error;
if (H5Sclose(region_id)<0)
goto error;
if (options->verbose)
printf("object <%s> region reference created to <%s>\n",name,refname);
}
close_obj(obj_type,refobj_id);
}/* u */
/*-------------------------------------------------------------------------
* copy
*-------------------------------------------------------------------------
*/
if ((attr_out=H5Acreate(loc_out,name,ftype_id,space_id,H5P_DEFAULT))<0)
goto error;
if(H5Awrite(attr_out,mtype_id,refbuf)<0)
goto error;
if (H5Aclose(attr_out)<0)
goto error;
free(refbuf);
free(buf);
} /* H5T_STD_REF_DSETREG */
/*-------------------------------------------------------------------------
@ -532,33 +718,31 @@ void close_obj(H5G_obj_t obj_type, hid_t obj_id)
*-------------------------------------------------------------------------
*/
const char* MapIdToName(hid_t refobj_id,
trav_table_t *travt)
static const char* MapIdToName(hid_t refobj_id,
trav_table_t *travt)
{
hid_t id;
hid_t fid;
int i;
/* obtains the file ID given an object ID. This ID must be closed */
if ((fid = H5Iget_file_id(refobj_id))<0)
{
assert(0);
return NULL;
}
/* linear search */
for ( i=0; i<travt->nobjs; i++)
{
switch ( travt->objs[i].type )
{
/*-------------------------------------------------------------------------
* H5G_GROUP
*-------------------------------------------------------------------------
*/
default:
assert(0);
break;
case H5G_GROUP:
case H5G_TYPE:
case H5G_LINK:
break;
/*-------------------------------------------------------------------------
@ -573,49 +757,18 @@ const char* MapIdToName(hid_t refobj_id,
assert(0);
return NULL;
}
if (H5Dclose(id)<0)
{
assert(0);
return NULL;
}
if (id==refobj_id)
{
H5Fclose(fid);
return travt->objs[i].name;
}
break;
/*-------------------------------------------------------------------------
* H5G_TYPE
*-------------------------------------------------------------------------
*/
case H5G_TYPE:
break;
/*-------------------------------------------------------------------------
* H5G_LINK
*-------------------------------------------------------------------------
*/
case H5G_LINK:
break;
default:
assert(0);
break;
}
} /* switch */
} /* i */
if (H5Fclose(fid)<0)
@ -623,3 +776,4 @@ const char* MapIdToName(hid_t refobj_id,
return NULL;
}

View File

@ -213,14 +213,15 @@ void write_attr_in(hid_t loc_id,
* H5T_REFERENCE
*-------------------------------------------------------------------------
*/
/* Create references to dataset */
/* object references ( H5R_OBJECT */
if (dset_name)
{
status=H5Rcreate(&buf4[0],fid,dset_name,H5R_OBJECT,-1);
status=H5Rcreate(&buf4[1],fid,dset_name,H5R_OBJECT,-1);
write_attr(loc_id,1,dims,"reference",H5T_STD_REF_OBJ,buf4);
write_attr(loc_id,1,dims,"reference to object",H5T_STD_REF_OBJ,buf4);
}
/*-------------------------------------------------------------------------
* H5T_ENUM
*-------------------------------------------------------------------------

View File

@ -16,7 +16,8 @@
#include "h5test.h"
#include "h5repack.h"
static void make_dset_reg_ref(hid_t loc_id);
static void read_dset_reg_ref(hid_t loc_id);
/*-------------------------------------------------------------------------
@ -232,14 +233,20 @@ void write_dset_in(hid_t loc_id,
* H5T_REFERENCE
*-------------------------------------------------------------------------
*/
/* Create references to dataset */
/* object references ( H5R_OBJECT ) */
if (dset_name)
{
status=H5Rcreate(&buf4[0],file_id,dset_name,H5R_OBJECT,-1);
status=H5Rcreate(&buf4[1],file_id,dset_name,H5R_OBJECT,-1);
write_dset(loc_id,1,dims,"reference",H5T_STD_REF_OBJ,buf4);
write_dset(loc_id,1,dims,"reference to object ",H5T_STD_REF_OBJ,buf4);
}
/* Dataset region reference ( H5R_DATASET_REGION ) */
make_dset_reg_ref(loc_id);
#if defined(H5_REPACK_DEBUG)
read_dset_reg_ref(loc_id);
#endif
/*-------------------------------------------------------------------------
* H5T_ENUM
*-------------------------------------------------------------------------
@ -392,7 +399,7 @@ void write_dset_in(hid_t loc_id,
status=H5Rcreate(&buf42[i][j],file_id,dset_name,H5R_OBJECT,-1);
}
}
write_dset(loc_id,2,dims2,"reference2D",H5T_STD_REF_OBJ,buf42);
write_dset(loc_id,2,dims2,"reference to object 2D",H5T_STD_REF_OBJ,buf42);
}
/*-------------------------------------------------------------------------
@ -578,7 +585,7 @@ void write_dset_in(hid_t loc_id,
status=H5Rcreate(&buf43[i][j][k],file_id,dset_name,H5R_OBJECT,-1);
}
}
write_dset(loc_id,3,dims3,"reference3D",H5T_STD_REF_OBJ,buf43);
write_dset(loc_id,3,dims3,"reference to object 3D",H5T_STD_REF_OBJ,buf43);
}
/*-------------------------------------------------------------------------
@ -673,3 +680,208 @@ void write_dset_in(hid_t loc_id,
write_dset(loc_id,3,dims3,"float3D",H5T_NATIVE_FLOAT,buf83);
}
/*-------------------------------------------------------------------------
* Function: make_dset_reg_ref
*
* Purpose: write dataset region references
*
*-------------------------------------------------------------------------
*/
#define SPACE1_RANK 1
#define SPACE1_DIM1 4
#define SPACE2_RANK 2
#define SPACE2_DIM1 10
#define SPACE2_DIM2 10
#define NPOINTS 10
static void make_dset_reg_ref(hid_t loc_id)
{
hid_t dset1; /* Dataset ID */
hid_t dset2; /* Dereferenced dataset ID */
hid_t sid1; /* Dataspace ID #1 */
hid_t sid2; /* Dataspace ID #2 */
hsize_t dims1[] = {SPACE1_DIM1};
hsize_t dims2[] = {SPACE2_DIM1, SPACE2_DIM2};
hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */
hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */
hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */
hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */
hssize_t coord1[NPOINTS][SPACE2_RANK]; /* Coordinates for point selection */
hdset_reg_ref_t *wbuf; /* buffer to write to disk */
int *dwbuf; /* Buffer for writing numeric data to disk */
int i; /* counting variables */
herr_t ret; /* Generic return value */
/* Allocate write & read buffers */
wbuf=calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1);
dwbuf=malloc(sizeof(int)*SPACE2_DIM1*SPACE2_DIM2);
/* Create dataspace for datasets */
sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL);
/* Create a dataset */
dset2=H5Dcreate(loc_id,"dset referenced region",H5T_STD_U8LE,sid2,H5P_DEFAULT);
for(i=0; i<SPACE2_DIM1*SPACE2_DIM2; i++)
dwbuf[i]=i*3;
/* Write selection to disk */
ret=H5Dwrite(dset2,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,dwbuf);
/* Close Dataset */
ret = H5Dclose(dset2);
/* Create dataspace for the reference dataset */
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
/* Create a dataset */
dset1=H5Dcreate(loc_id,"region reference",H5T_STD_REF_DSETREG,sid1,H5P_DEFAULT);
/* Create references */
/* Select 6x6 hyperslab for first reference */
start[0]=2; start[1]=2;
stride[0]=1; stride[1]=1;
count[0]=6; count[1]=6;
block[0]=1; block[1]=1;
ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block);
/* Store first dataset region */
ret = H5Rcreate(&wbuf[0],loc_id,"dset referenced region",H5R_DATASET_REGION,sid2);
/* Select sequence of ten points for second reference */
coord1[0][0]=6; coord1[0][1]=9;
coord1[1][0]=2; coord1[1][1]=2;
coord1[2][0]=8; coord1[2][1]=4;
coord1[3][0]=1; coord1[3][1]=6;
coord1[4][0]=2; coord1[4][1]=8;
coord1[5][0]=3; coord1[5][1]=2;
coord1[6][0]=0; coord1[6][1]=4;
coord1[7][0]=9; coord1[7][1]=0;
coord1[8][0]=7; coord1[8][1]=1;
coord1[9][0]=3; coord1[9][1]=3;
ret = H5Sselect_elements(sid2,H5S_SELECT_SET,NPOINTS,(const hssize_t **)coord1);
/* Store second dataset region */
ret = H5Rcreate(&wbuf[1],loc_id,"dset referenced region",H5R_DATASET_REGION,sid2);
/* Write selection to disk */
ret=H5Dwrite(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
/* Close all objects */
ret = H5Sclose(sid1);
ret = H5Dclose(dset1);
ret = H5Sclose(sid2);
free(wbuf);
free(dwbuf);
}
/*-------------------------------------------------------------------------
* Function: read_dset_reg_ref
*
* Purpose: read dataset region references
*
*-------------------------------------------------------------------------
*/
static void read_dset_reg_ref(hid_t loc_id)
{
hid_t dset1; /* Dataset ID */
hid_t dset2; /* Dereferenced dataset ID */
hid_t sid1; /* Dataspace ID #1 */
hid_t sid2; /* Dataspace ID #2 */
hsize_t *coords; /* Coordinate buffer */
hssize_t low[SPACE2_RANK]; /* Selection bounds */
hssize_t high[SPACE2_RANK]; /* Selection bounds */
hdset_reg_ref_t *rbuf; /* buffer to read from disk */
int *drbuf; /* Buffer for reading numeric data from disk */
int i, j; /* counting variables */
herr_t ret; /* Generic return value */
/* Allocate write & read buffers */
rbuf=malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1);
drbuf=calloc(sizeof(int),SPACE2_DIM1*SPACE2_DIM2);
/* Open the dataset */
dset1=H5Dopen(loc_id,"region reference");
/* Read selection from disk */
ret=H5Dread(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf);
/* Try to open objects */
dset2 = H5Rdereference(dset1,H5R_DATASET_REGION,&rbuf[0]);
/* Check information in referenced dataset */
sid1 = H5Dget_space(dset2);
ret=(herr_t)H5Sget_simple_extent_npoints(sid1);
printf(" Number of elements in the dataset is : %d\n",ret);
/* Read from disk */
ret=H5Dread(dset2,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,drbuf);
for(i=0; i<SPACE2_DIM1; i++) {
for (j=0; j<SPACE2_DIM2; j++) printf (" %d ", drbuf[i*SPACE2_DIM2+j]);
printf("\n"); }
/* Get the hyperslab selection */
sid2=H5Rget_region(dset1,H5R_DATASET_REGION,&rbuf[0]);
/* Verify correct hyperslab selected */
ret = (herr_t)H5Sget_select_npoints(sid2);
printf(" Number of elements in the hyperslab is : %d \n", ret);
ret = (herr_t)H5Sget_select_hyper_nblocks(sid2);
/* allocate space for the hyperslab blocks */
coords=malloc((size_t)ret*SPACE2_RANK*sizeof(hsize_t)*2);
ret = H5Sget_select_hyper_blocklist(sid2,0,ret,coords);
printf(" Hyperslab coordinates are : \n");
printf (" ( %lu , %lu ) ( %lu , %lu ) \n",
(unsigned long)coords[0],
(unsigned long)coords[1],
(unsigned long)coords[2],
(unsigned long)coords[3]);
free(coords);
ret = H5Sget_select_bounds(sid2,low,high);
/* Close region space */
ret = H5Sclose(sid2);
/* Get the element selection */
sid2=H5Rget_region(dset1,H5R_DATASET_REGION,&rbuf[1]);
/* Verify correct elements selected */
ret = (herr_t)H5Sget_select_elem_npoints(sid2);
printf(" Number of selected elements is : %d\n", ret);
/* Allocate space for the element points */
coords= malloc(ret*SPACE2_RANK*sizeof(hsize_t));
ret = H5Sget_select_elem_pointlist(sid2,0,ret,coords);
printf(" Coordinates of selected elements are : \n");
for (i=0; i<2*NPOINTS; i=i+2)
printf(" ( %lu , %lu ) \n",
(unsigned long)coords[i],
(unsigned long)coords[i+1]);
free(coords);
ret = H5Sget_select_bounds(sid2,low,high);
/* Close region space */
ret = H5Sclose(sid2);
/* Close first space */
ret = H5Sclose(sid1);
/* Close dereferenced Dataset */
ret = H5Dclose(dset2);
/* Close Dataset */
ret = H5Dclose(dset1);
/* Free memory buffers */
free(rbuf);
free(drbuf);
}

View File

@ -41,9 +41,16 @@ test_copy(void)
diff_opt_t diff_options;
memset(&diff_options, 0, sizeof (diff_opt_t));
TESTING(" copy with no filters");
if (h5repack_init (&pack_options, 0)<0)
TEST_ERROR;
#if defined(H5_REPACK_DEBUG)
diff_options.verbose=1;
pack_options.verbose=1;
#endif
if (h5repack(FNAME1,FNAME1OUT,&pack_options)<0)
TEST_ERROR;
if (h5diff(FNAME1,FNAME1OUT,NULL,NULL,&diff_options) == 1)

View File

@ -126,7 +126,7 @@ int make_all_objects(hid_t loc_id)
*/
space_id = H5Screate_simple(1,dims,NULL);
dset_id = H5Dcreate(loc_id,"dset_ref",H5T_NATIVE_INT,space_id,H5P_DEFAULT);
dset_id = H5Dcreate(loc_id,"dset_referenced",H5T_NATIVE_INT,space_id,H5P_DEFAULT);
H5Sclose(space_id);
/*-------------------------------------------------------------------------
@ -161,8 +161,8 @@ int make_all_objects(hid_t loc_id)
*-------------------------------------------------------------------------
*/
write_dset_in(root_id,"dset_ref",loc_id,0);
write_dset_in(group_id,"dset_ref",loc_id,0);
write_dset_in(root_id,"dset_referenced",loc_id,0);
write_dset_in(group_id,"dset_referenced",loc_id,0);
/* Close */

View File

@ -58,12 +58,12 @@ int h5diff(const char *fname1,
/* Open the files */
if ((file1_id=H5Fopen(fname1,H5F_ACC_RDONLY,H5P_DEFAULT))<0 )
{
printf("h5diff: %s: No such file or directory\n", fname1 );
printf("h5diff: <%s>: unable to open file\n", fname1 );
nfound = -1;
}
if ((file2_id=H5Fopen(fname2,H5F_ACC_RDONLY,H5P_DEFAULT))<0 )
{
printf("h5diff: %s: No such file or directory\n", fname2 );
printf("h5diff: <%s>: unable to open file\n", fname2 );
nfound = -1;
}
/* enable error reporting */

View File

@ -19,8 +19,7 @@
#include <math.h>
static
int diff_datum( void *_mem1,
static int diff_datum(void *_mem1,
void *_mem2,
hid_t m_type,
hsize_t i,
@ -34,8 +33,7 @@ int diff_datum( void *_mem1,
hid_t container2_id,
int *ph);
static
int diff_native_uchar(unsigned char *mem1,
static int diff_native_uchar(unsigned char *mem1,
unsigned char *mem2,
size_t type_size,
hsize_t i,
@ -47,8 +45,7 @@ int diff_native_uchar(unsigned char *mem1,
const char *obj2,
int *ph);
static
int diff_char(unsigned char *mem1,
static int diff_char(unsigned char *mem1,
unsigned char *mem2,
size_t type_size,
hsize_t i,
@ -60,10 +57,10 @@ int diff_char(unsigned char *mem1,
const char *obj2,
int *ph);
static
hbool_t is_zero(const void *_mem, size_t size);
static
void close_obj(H5G_obj_t obj_type, hid_t obj_id);
static hbool_t is_zero(const void *_mem, size_t size);
static void close_obj(H5G_obj_t obj_type, hid_t obj_id);
static int diff_region(hid_t region1_id, hid_t region2_id);
/*-------------------------------------------------------------------------
@ -509,6 +506,9 @@ int diff_datum( void *_mem1,
if (H5Tequal(m_type, H5T_STD_REF_DSETREG))
{
hid_t region1_id;
hid_t region2_id;
if ((obj1_id = H5Rdereference(container1_id, H5R_DATASET_REGION, _mem1))<0)
return -1;
if ((obj2_id = H5Rdereference(container2_id, H5R_DATASET_REGION, _mem2))<0)
@ -517,17 +517,21 @@ int diff_datum( void *_mem1,
return -1;
if (H5Gget_objinfo(obj2_id, ".", FALSE, &sb2)<0)
return -1;
if ((region1_id = H5Rget_region(container1_id, H5R_DATASET_REGION, _mem1))<0)
return -1;
if ((region2_id = H5Rget_region(container2_id, H5R_DATASET_REGION, _mem2))<0)
return -1;
/* compare OID */
if (sb1.objno!=sb2.objno)
if (diff_region(region1_id,region2_id))
{
HDfprintf(stdout,"Different OIDs in reference: <%s, %Hu> and <%s, %Hu>",
obj1, sb1.objno, obj2, sb2.objno);
nfound = 1;
printf("Different region referenced\n");
}
close_obj(H5G_DATASET,obj1_id);
close_obj(H5G_DATASET,obj2_id);
H5Sclose(region1_id);
H5Sclose(region2_id);
}/*dataset reference*/
@ -1699,3 +1703,124 @@ void close_obj(H5G_obj_t obj_type, hid_t obj_id)
}
}
/*-------------------------------------------------------------------------
* Function: diff_region
*
* Purpose: diff a dataspace region
*
* Return: 0, diff not found, 1 found
*
*-------------------------------------------------------------------------
*/
static int diff_region(hid_t region1_id, hid_t region2_id)
{
hssize_t nblocks1, npoints1;
hssize_t nblocks2, npoints2;
hsize_t alloc_size;
hsize_t *ptdata1;
hsize_t *ptdata2;
int ndims1 = H5Sget_simple_extent_ndims(region1_id);
int ndims2 = H5Sget_simple_extent_ndims(region2_id);
int ret=0;
#if defined (H5DIFF_DEBUG)
int i;
#endif
/*
* These two functions fail if the region does not have blocks or points,
* respectively. They do not currently know how to translate from one to
* the other.
*/
H5E_BEGIN_TRY {
nblocks1 = H5Sget_select_hyper_nblocks(region1_id);
nblocks2 = H5Sget_select_hyper_nblocks(region2_id);
npoints1 = H5Sget_select_elem_npoints(region1_id);
npoints2 = H5Sget_select_elem_npoints(region2_id);
} H5E_END_TRY;
if (nblocks1!=nblocks2 || npoints1!=npoints2 || ndims1!=ndims2)
return 1;
/* compare block information */
if (nblocks1 > 0)
{
alloc_size = nblocks1 * ndims1 * 2 * sizeof(ptdata1[0]);
assert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/
ptdata1 = malloc((size_t)alloc_size);
H5_CHECK_OVERFLOW(nblocks1, hssize_t, hsize_t);
H5Sget_select_hyper_blocklist(region1_id, (hsize_t)0, (hsize_t)nblocks1, ptdata1);
ptdata2 = malloc((size_t)alloc_size);
H5_CHECK_OVERFLOW(nblocks2, hssize_t, hsize_t);
H5Sget_select_hyper_blocklist(region2_id, (hsize_t)0, (hsize_t)nblocks2, ptdata2);
ret=HDmemcmp(ptdata1,ptdata2,(size_t)alloc_size);
#if defined (H5DIFF_DEBUG)
for (i = 0; i < nblocks1; i++)
{
int j;
/* start coordinates and opposite corner */
for (j = 0; j < ndims1; j++)
printf("%s%lu", j ? "," : "(",
(unsigned long)ptdata1[i * 2 * ndims1 + j]);
for (j = 0; j < ndims1; j++)
printf("%s%lu", j ? "," : ")-(",
(unsigned long)ptdata1[i * 2 * ndims1 + j + ndims1]);
printf(")\n");
}
#endif
HDfree(ptdata1);
HDfree(ptdata2);
}
/* Print point information */
if (npoints1 > 0)
{
alloc_size = npoints1 * ndims1 * sizeof(ptdata1[0]);
assert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/
ptdata1 = malloc((size_t)alloc_size);
H5_CHECK_OVERFLOW(npoints1,hssize_t,hsize_t);
H5Sget_select_elem_pointlist(region1_id, (hsize_t)0, (hsize_t)npoints1, ptdata1);
ptdata2 = malloc((size_t)alloc_size);
H5_CHECK_OVERFLOW(npoints1,hssize_t,hsize_t);
H5Sget_select_elem_pointlist(region2_id, (hsize_t)0, (hsize_t)npoints2, ptdata2);
ret=HDmemcmp(ptdata1,ptdata2,(size_t)alloc_size);
#if defined (H5DIFF_DEBUG)
for (i = 0; i < npoints1; i++)
{
int j;
printf("%sPt%lu: " ,
i ? "," : "",
(unsigned long)i);
for (j = 0; j < ndims1; j++)
printf("%s%lu", j ? "," : "(",
(unsigned long)(ptdata1[i * ndims1 + j]));
printf(")");
}
#endif
HDfree(ptdata1);
HDfree(ptdata2);
}
return ret;
}

View File

@ -65,6 +65,7 @@ int diff_attr(hid_t loc1_id,
char name1[255];
char name2[255];
int n1, n2, i, j, nfound;
int ret=0;
if ((n1 = H5Aget_num_attrs(loc1_id))<0)
goto error;
@ -105,7 +106,8 @@ int diff_attr(hid_t loc1_id,
}
H5Aclose(attr1_id);
H5Aclose(attr2_id);
return 1;
ret=1;
continue;
}
/* get the file datatype */
@ -218,7 +220,7 @@ int diff_attr(hid_t loc1_id,
HDfree(buf2);
} /* i */
return 0;
return ret;
error:
H5E_BEGIN_TRY {

View File

@ -1,6 +1,6 @@
#############################
Expected output for 'h5diff file1.h6 file2.h6'
#############################
h5diff: file1.h6: No such file or directory
h5diff: file2.h6: No such file or directory
h5diff: <file1.h6>: unable to open file
h5diff: <file2.h6>: unable to open file