diff options
author | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2003-12-02 23:13:27 (GMT) |
---|---|---|
committer | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2003-12-02 23:13:27 (GMT) |
commit | 486c13d307978ccbb9c2306c85c39a674ed56b96 (patch) | |
tree | 5c5863521d8acf6dd3c7d4db3880596fecad84de /tools/lib | |
parent | 684db5595b5fa30633eb648f6e71a36d3857644a (diff) | |
download | hdf5-486c13d307978ccbb9c2306c85c39a674ed56b96.zip hdf5-486c13d307978ccbb9c2306c85c39a674ed56b96.tar.gz hdf5-486c13d307978ccbb9c2306c85c39a674ed56b96.tar.bz2 |
[svn-r7904] Purpose:
h5diff new features
Description:
added comparison for attributes
adeded comparison for all dataset datatypes
added tests for the new features
changed the output format
Solution:
Platforms tested:
linux
solaris 5.7
IRIX 6.5 (64)
Misc. update:
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/h5diff.c | 170 | ||||
-rw-r--r-- | tools/lib/h5diff.h | 52 | ||||
-rw-r--r-- | tools/lib/h5diff_array.c | 575 | ||||
-rw-r--r-- | tools/lib/h5diff_attr.c | 31 | ||||
-rw-r--r-- | tools/lib/h5diff_dset.c | 213 | ||||
-rw-r--r-- | tools/lib/h5diff_util.c | 70 |
6 files changed, 768 insertions, 343 deletions
diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c index a02af47..5b38968 100644 --- a/tools/lib/h5diff.c +++ b/tools/lib/h5diff.c @@ -14,6 +14,7 @@ #include "h5diff.h" +#include "H5private.h" #include <stdlib.h> #include <assert.h> @@ -316,11 +317,10 @@ int diff_compare( hid_t file1_id, /* objects are not the same type */ if ( info1[i].type != info2[j].type && options->verbose) { - printf("Comparison not supported\n"); - printf("<%s> is of type %s and <%s> is of type %s\n", + printf("Comparison not possible: <%s> is of type %s and <%s> is of type %s\n", obj1_name, get_type(info1[i].type), obj2_name, get_type(info2[j].type) ); - return 0; + return 1; } nfound=diff( file1_id, obj1_name, file2_id, obj2_name, options, info1[i].type ); @@ -333,6 +333,11 @@ int diff_compare( hid_t file1_id, * Function: diff * * Purpose: switch between types and choose the diff function + * TYPE is either + * H5G_LINK Object is a symbolic link + * H5G_GROUP Object is a group + * H5G_DATASET Object is a dataset + * H5G_TYPE Object is a named data type * * Return: Number of differences found * @@ -340,42 +345,163 @@ int diff_compare( hid_t file1_id, * * Date: May 9, 2003 * - * Comments: - * - * Modifications: - * *------------------------------------------------------------------------- */ -int diff( hid_t file1_id, - const char *obj1_name, - hid_t file2_id, - const char *obj2_name, +int diff( hid_t file1_id, + const char *path1, + hid_t file2_id, + const char *path2, diff_opt_t *options, - int type ) + H5G_obj_t type ) { - int nfound=0; + hid_t type1_id; + hid_t type2_id; + hid_t grp1_id; + hid_t grp2_id; + int ret; + H5G_stat_t sb1; + H5G_stat_t sb2; + char *buf1=NULL; + char *buf2=NULL; + int nfound=-1; switch ( type ) { +/*------------------------------------------------------------------------- + * H5G_DATASET + *------------------------------------------------------------------------- + */ case H5G_DATASET: - nfound=diff_dataset(file1_id,file2_id,obj1_name,obj2_name,options); + if (options->verbose) + printf( "Dataset: <%s> and <%s>\n",path1,path2); + nfound=diff_dataset(file1_id,file2_id,path1,path2,options); + break; + +/*------------------------------------------------------------------------- + * H5G_TYPE + *------------------------------------------------------------------------- + */ + case H5G_TYPE: + if (options->verbose) + printf( "Datatype: <%s> and <%s>\n",path1,path2); + + if ((type1_id = H5Topen(file1_id, path1))<0) + goto out; + if ((type2_id = H5Topen(file2_id, path2))<0) + goto out; + + if ((ret = H5Tequal(type1_id,type2_id))<0) + goto out; + + /* if H5Tequal is > 0 then the datatypes refer to the same datatype */ + nfound = (ret>0) ? 0 : 1; + + /* compare attributes */ + diff_attr(type1_id,type2_id,path1,path2,options); + + if ( H5Tclose(type1_id)<0) + goto out; + if ( H5Tclose(type2_id)<0) + goto out; + + break; + +/*------------------------------------------------------------------------- + * H5G_GROUP + *------------------------------------------------------------------------- + */ + case H5G_GROUP: + if (options->verbose) + printf( "Group: <%s> and <%s>\n",path1,path2); + + if ((grp1_id = H5Gopen(file1_id, path1))<0) + goto out; + if ((grp2_id = H5Gopen(file2_id, path2))<0) + goto out; + + ret = HDstrcmp(path1,path2); + + /* if "path1" != "path2" then the groups are "different" */ + nfound = (ret!=0) ? 1 : 0; + + /* compare attributes */ + diff_attr(grp1_id,grp2_id,path1,path2,options); + + if ( H5Gclose(grp1_id)<0) + goto out; + if ( H5Gclose(grp2_id)<0) + goto out; + + break; + + +/*------------------------------------------------------------------------- + * H5G_LINK + *------------------------------------------------------------------------- + */ + case H5G_LINK: + if (options->verbose) + printf( "Link: <%s> and <%s>\n",path1,path2); + + if (H5Gget_objinfo(file1_id,path1,FALSE,&sb1)<0) + goto out; + if (H5Gget_objinfo(file1_id,path1,FALSE,&sb2)<0) + goto out; + + buf1 = malloc(sb1.linklen); + buf2 = malloc(sb2.linklen); + + if (H5Gget_linkval(file1_id,path1,sb1.linklen,buf1)<0) + goto out; + if (H5Gget_linkval(file2_id,path2,sb1.linklen,buf2)<0) + goto out; + + ret = HDstrcmp(buf1,buf2); + + /* if "buf1" != "buf2" then the links are "different" */ + nfound = (ret!=0) ? 1 : 0; + + if (buf1) { + free(buf1); + buf1=NULL; + } + + if (buf2) { + free(buf2); + buf2=NULL; + } + break; + default: + nfound=0; if (options->verbose) { - printf("Comparison not supported\n"); - printf("<%s> is of type %s and <%s> is of type %s\n", - obj1_name, get_type(type), - obj2_name, get_type(type) ); + printf("Comparison not supported: <%s> and <%s> are of type %s\n", + path1, path2, get_type(type) ); } break; } -#if 0 - if (options->verbose) - printf("\n"); -#endif + + out: + + /* close */ + /* disable error reporting */ + H5E_BEGIN_TRY { + H5Tclose(type1_id); + H5Tclose(type2_id); + H5Gclose(grp1_id); + H5Tclose(grp2_id); + /* enable error reporting */ + } H5E_END_TRY; + + if (buf1) + free(buf1); + if (buf2) + free(buf2); + return nfound; } diff --git a/tools/lib/h5diff.h b/tools/lib/h5diff.h index 10e190d..0c52f76 100644 --- a/tools/lib/h5diff.h +++ b/tools/lib/h5diff.h @@ -29,8 +29,10 @@ *------------------------------------------------------------------------- */ -#define FFORMAT "%-15.10g %-15.10g %-15.10g\n" +#define FFORMAT "%-15f %-15f %-15f\n" #define IFORMAT "%-15d %-15d %-15d\n" +#define CFORMAT "%-16c %-17c\n" +#define SFORMAT "%-16s %-17s\n" #define UIFORMAT "%-15u %-15u %-15u\n" #define LIFORMAT "%-15ld %-15ld %-15ld\n" #define ULIFORMAT "%-15lu %-15lu %-15lu\n" @@ -57,7 +59,6 @@ typedef struct { int n; /* count */ int count; /* count value */ int verbose; /* print information */ - int attr; /* compare attributes */ } diff_opt_t; @@ -96,12 +97,18 @@ int diff_dataset( hid_t file1_id, const char *obj2_name, diff_opt_t *options ); -int diff( hid_t file1_id, - const char *obj1_name, - hid_t file2_id, - const char *obj2_name, +int diff_datasetid( hid_t dset1_id, + hid_t dset2_id, + const char *obj1_name, + const char *obj2_name, + diff_opt_t *options ); + +int diff( hid_t file1_id, + const char *path1, + hid_t file2_id, + const char *path2, diff_opt_t *options, - int type ); + H5G_obj_t type ); int diff_compare( hid_t file1_id, const char *file1_name, @@ -123,15 +130,17 @@ int diff_match( hid_t file1_id, trav_info_t *info2, diff_opt_t *options ); -int diff_array( void *buf1, - void *buf2, - hsize_t tot_cnt, +int diff_array( void *_mem1, + void *_mem2, + hsize_t nelmts, int rank, hsize_t *dims, diff_opt_t *options, - const char *obj1, - const char *obj2, - hid_t m_type ); + const char *name1, + const char *name2, + hid_t m_type, + hid_t container1_id, + hid_t container2_id); /* dataset where the reference came from*/ int diff_can_type( hid_t f_type1, /* file data type */ @@ -147,8 +156,10 @@ int diff_can_type( hid_t f_type1, /* file data type */ diff_opt_t *options ); -int diff_attr(hid_t loc1_id, - hid_t loc2_id, +int diff_attr(hid_t loc1_id, + hid_t loc2_id, + const char *path1, + const char *path2, diff_opt_t *options ); @@ -158,15 +169,20 @@ int diff_attr(hid_t loc1_id, *------------------------------------------------------------------------- */ -int diff_can( hid_t type_id ); void print_type(hid_t type); const char* diff_basename(const char *name); const char* get_type(int type); const char* get_class(H5T_class_t tclass); const char* get_sign(H5T_sign_t sign); void print_dims( int r, hsize_t *d ); -void print_pos( int *ph, int p, unsigned int curr_pos, int *acc, - int *pos, int rank, const char *obj1, const char *obj2 ); +void print_pos( int *ph, + int per, + hsize_t curr_pos, + hsize_t *acc, + hsize_t *pos, + int rank, + const char *obj1, + const char *obj2 ); #if defined (H5DIFF_DEBUG) void print_sizes( const char *obj1, const char *obj2, diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c index 0a2eb41..38f5ba9 100644 --- a/tools/lib/h5diff_array.c +++ b/tools/lib/h5diff_array.c @@ -18,57 +18,65 @@ #include <assert.h> #include <math.h> + static -int diff_array_mem( void *_mem1, - void *_mem2, - hid_t m_type, - unsigned i, - int rank, - int *acc, - int *pos, - diff_opt_t *options, - const char *obj1, - const char *obj2); +int diff_datum( void *_mem1, + void *_mem2, + hid_t m_type, + hsize_t i, + int rank, + hsize_t *acc, + hsize_t *pos, + diff_opt_t *options, + const char *obj1, + const char *obj2, + hid_t container1_id, + hid_t container2_id, + int *ph); static int diff_native_uchar(unsigned char *mem1, unsigned char *mem2, size_t type_size, - unsigned i, + hsize_t i, int rank, - int *acc, - int *pos, + hsize_t *acc, + hsize_t *pos, diff_opt_t *options, const char *obj1, const char *obj2, - int ph); + int *ph); + +static +int diff_char(unsigned char *mem1, + unsigned char *mem2, + size_t type_size, + hsize_t i, + int rank, + hsize_t *acc, + hsize_t *pos, + diff_opt_t *options, + const char *obj1, + 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); /*------------------------------------------------------------------------- * Function: diff_array * - * Purpose: compare array; - * currenttly only the NATIVE types below are supported + * Purpose: compare two memory buffers; * - * Return: number of differences found + * Return: number of differences found, -1 on error * * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu * - * Date: May 30, 2003 - * - * Modifications: October 30, 2003 - * Added support for H5T_COMPOUND types; to handle compounds a recursive - * function is called. because of this , the data is compared datum by datum - * instead of the previous cycle that compared all the array the native - * types - * Added support for - * H5T_STRING - * H5T_BITFIELD - * H5T_OPAQUE - * H5T_ENUM - * H5T_VLEN - * H5T_ARRAY - * + * Date: November 12, 2003 + * *------------------------------------------------------------------------- */ @@ -80,7 +88,9 @@ int diff_array( void *_mem1, diff_opt_t *options, const char *name1, const char *name2, - hid_t m_type ) + hid_t m_type, + hid_t container1_id, + hid_t container2_id) /* dataset where the reference came from*/ { int nfound=0; /* number of differences found */ size_t size; /* size of datum */ @@ -88,23 +98,27 @@ int diff_array( void *_mem1, unsigned char *mem2 = (unsigned char*)_mem2; unsigned char *tmp1; unsigned char *tmp2; - int acc[32]; /* accumulator and matrix position */ - int pos[32]; - unsigned i; + hsize_t acc[32]; /* accumulator position */ + hsize_t pos[32]; /* matrix position */ + int ph=1; /* print header */ + hsize_t i; int j; + acc[rank-1]=1; for(j=(rank-2); j>=0; j--) { acc[j]=acc[j+1]*(int)dims[j+1]; } + for ( j = 0; j < rank; j++) + pos[j]=0; if(H5Tis_variable_str(m_type)) { tmp1 = ((unsigned char**)mem1)[0]; tmp2 = ((unsigned char**)mem2)[0]; - nfound+=diff_array_mem( + nfound+=diff_datum( tmp1, tmp2, m_type, @@ -114,7 +128,10 @@ int diff_array( void *_mem1, pos, options, name1, - name2); + name2, + container1_id, + container2_id, + &ph); } else @@ -126,7 +143,7 @@ int diff_array( void *_mem1, for ( i = 0; i < nelmts; i++) { - nfound+=diff_array_mem( + nfound+=diff_datum( mem1 + i * size, mem2 + i * size, /* offset */ m_type, @@ -136,7 +153,10 @@ int diff_array( void *_mem1, pos, options, name1, - name2); + name2, + container1_id, + container2_id, + &ph); if (options->n && nfound>=options->count) return nfound; } @@ -148,30 +168,57 @@ int diff_array( void *_mem1, /*------------------------------------------------------------------------- - * Function: diff_array_mem + * Function: diff_datum * * Purpose: Compare the values pointed to in _MEM1 and _MEM2 of type M_TYPE * - * Return: number of differences found + * Return: number of differences found, -1 on error * * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu * * Date: October 29, 2003 * + * The compare of the 2 buffers read from the files is made datum by datum. + * + * H5T_INTEGER and H5T_FLOAT + * Copy the buffer into a compatible local datum and do a numerical + * compare of this datum + * H5T_COMPOUND + * Recursively call this function for each member + * H5T_ARRAY + * Recursively call this function for each element + * H5T_VLEN + * Recursively call this function for each element + * H5T_STRING + * compare byte by byte in a cycle from 0 to type_size. this type_size is the + * value obtained by the get_size function but it is the string lenght for + * variable sized strings + * H5T_OPAQUE + * compare byte by byte in a cycle from 0 to type_size + * H5T_BITFIELD + * compare byte by byte in a cycle from 0 to type_size + * H5T_ENUM + * for each pair of elements being compared, both bit patterns are converted to + * their corresponding enumeration constant and a string comparison is made + * H5T_REFERENCE + * Dereference the object and compare the type (basic object type). *------------------------------------------------------------------------- */ static -int diff_array_mem( void *_mem1, - void *_mem2, - hid_t m_type, - unsigned i, - int rank, - int *acc, - int *pos, - diff_opt_t *options, - const char *obj1, - const char *obj2) +int diff_datum( void *_mem1, + void *_mem2, + hid_t m_type, + hsize_t i, + int rank, + hsize_t *acc, + hsize_t *pos, + diff_opt_t *options, + const char *obj1, + const char *obj2, + hid_t container1_id, + hid_t container2_id, /*where the reference came from*/ + int *ph) /*print header */ { char fmt_llong[255], fmt_ullong[255]; char fmt_llongp[255], fmt_ullongp[255]; @@ -187,8 +234,15 @@ int diff_array_mem( void *_mem1, hsize_t nelmts; hsize_t ndims; size_t size; - static int ph=1; /* print header */ - int nfound=0; /* differences found */ + int iszero1; + int iszero2; + H5G_obj_t obj1_type; + H5G_obj_t obj2_type; + hid_t obj1_id; + hid_t obj2_id; + H5G_stat_t sb1; + H5G_stat_t sb2; + int nfound=0; /* differences found */ /* Build default formats for long long types */ sprintf(fmt_llong, "%%%sd %%%sd %%%sd\n", @@ -200,11 +254,8 @@ int diff_array_mem( void *_mem1, sprintf(fmt_ullongp, "%%%su %%%su %%%su %%%su\n", H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH); - - /* Get the size. */ type_size = H5Tget_size( m_type ); - switch (H5Tget_class(m_type)) { default: @@ -213,9 +264,7 @@ int diff_array_mem( void *_mem1, case H5T_TIME: assert(0); break; - case H5T_REFERENCE: - assert(0); - break; + /*------------------------------------------------------------------------- * H5T_COMPOUND *------------------------------------------------------------------------- @@ -226,7 +275,7 @@ int diff_array_mem( void *_mem1, { offset = H5Tget_member_offset(m_type, j); memb_type = H5Tget_member_type(m_type, j); - nfound+=diff_array_mem( + nfound+=diff_datum( mem1+offset, mem2+offset, memb_type, @@ -236,7 +285,10 @@ int diff_array_mem( void *_mem1, pos, options, obj1, - obj2); + obj2, + container1_id, + container2_id, + ph); H5Tclose(memb_type); } break; @@ -248,16 +300,16 @@ int diff_array_mem( void *_mem1, case H5T_STRING: if(H5Tis_variable_str(m_type)) - type_size = HDstrlen(mem1); + type_size = HDstrlen((char*)mem1); else type_size = H5Tget_size(m_type); for (u=0; u<type_size; u++) - nfound+=diff_native_uchar( + nfound+=diff_char( mem1 + u, mem2 + u, /* offset */ type_size, - u, + i, /* index position */ rank, acc, pos, @@ -281,7 +333,7 @@ int diff_array_mem( void *_mem1, mem1 + u, mem2 + u, /* offset */ type_size, - u, + i, /* index position */ rank, acc, pos, @@ -304,7 +356,7 @@ int diff_array_mem( void *_mem1, mem1 + u, mem2 + u, /* offset */ type_size, - u, + i, /* index position */ rank, acc, pos, @@ -331,30 +383,44 @@ int diff_array_mem( void *_mem1, char enum_name1[1024]; char enum_name2[1024]; - if ((H5Tenum_nameof(m_type, mem1, enum_name1, sizeof enum_name1) >= 0) && - (H5Tenum_nameof(m_type, mem2, enum_name2, sizeof enum_name2) >= 0)) - { - if (HDstrcmp(enum_name1,enum_name2)!=0) - nfound=1; - } - else - { - for (u=0; u<type_size; u++) - nfound+=diff_native_uchar( - mem1 + u, - mem2 + u, /* offset */ - type_size, - u, - rank, - acc, - pos, - options, - obj1, - obj2, - ph); + /* disable error reporting */ + H5E_BEGIN_TRY { - } + if ((H5Tenum_nameof(m_type, mem1, enum_name1, sizeof enum_name1) >= 0) && + (H5Tenum_nameof(m_type, mem2, enum_name2, sizeof enum_name2) >= 0)) + { + if (HDstrcmp(enum_name1,enum_name2)!=0) + { + nfound=1; + if ( options->r==0 ) + { + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(SFORMAT,enum_name1,enum_name2); + } + } + } + else + { + for (u=0; u<type_size; u++) + nfound+=diff_native_uchar( + mem1 + u, + mem2 + u, /* offset */ + type_size, + i, /* index position */ + rank, + acc, + pos, + options, + obj1, + obj2, + ph); + } + + /* enable error reporting */ + } H5E_END_TRY; } + break; /*------------------------------------------------------------------------- @@ -373,17 +439,20 @@ int diff_array_mem( void *_mem1, for (u = 0, nelmts = 1; u <ndims; u++) nelmts *= dims[u]; for (u = 0; u < nelmts; u++) - nfound+=diff_array_mem( + nfound+=diff_datum( mem1 + u * size, mem2 + u * size, /* offset */ memb_type, - u, + i, /* index position */ rank, acc, pos, options, obj1, - obj2); + obj2, + container1_id, + container2_id, + ph); H5Tclose(memb_type); break; @@ -401,21 +470,119 @@ int diff_array_mem( void *_mem1, nelmts = ((hvl_t *)mem1)->len; for (j = 0; j < nelmts; j++) - nfound+=diff_array_mem( + nfound+=diff_datum( ((char *)(((hvl_t *)mem1)->p)) + j * size, ((char *)(((hvl_t *)mem2)->p)) + j * size, /* offset */ memb_type, - j, + i, /* index position */ rank, acc, pos, options, obj1, - obj2); + obj2, + container1_id, + container2_id, + ph); H5Tclose(memb_type); break; + + + case H5T_REFERENCE: + + iszero1=is_zero(_mem1, H5Tget_size(m_type)); + iszero2=is_zero(_mem2, H5Tget_size(m_type)); + if (iszero1==1 && iszero2==1) + return 0; + else if (iszero1!=iszero2) + return 1; + else + { + +/*------------------------------------------------------------------------- + * H5T_STD_REF_DSETREG + * Dataset region reference + *------------------------------------------------------------------------- + */ + + if (H5Tequal(m_type, H5T_STD_REF_DSETREG)) + { + if ((obj1_id = H5Rdereference(container1_id, H5R_DATASET_REGION, _mem1))<0) + return -1; + if ((obj2_id = H5Rdereference(container2_id, H5R_DATASET_REGION, _mem2))<0) + return -1; + if (H5Gget_objinfo(obj1_id, ".", FALSE, &sb1)<0) + return -1; + if (H5Gget_objinfo(obj2_id, ".", FALSE, &sb2)<0) + return -1; + + /* compare OID */ + if (sb1.objno!=sb2.objno) + { + printf("Different OIDs in reference: <%s, %d> and <%s, %d>", + obj1, sb1.objno, obj2, sb2.objno); + nfound = 1; + } + close_obj(H5G_DATASET,obj1_id); + close_obj(H5G_DATASET,obj2_id); + + }/*dataset reference*/ + + +/*------------------------------------------------------------------------- + * H5T_STD_REF_OBJ + * Object references. get the type and OID of the referenced object + *------------------------------------------------------------------------- + */ + else if (H5Tequal(m_type, H5T_STD_REF_OBJ)) + { + + if ((obj1_type = H5Rget_obj_type(container1_id, H5R_OBJECT, _mem1))<0) + return -1; + if ((obj2_type = H5Rget_obj_type(container2_id, H5R_OBJECT, _mem2))<0) + return -1; + + /* check object type */ + if (obj1_type!=obj2_type) + { + printf("Different object types referenced: <%s> and <%s>", obj1, obj2); + return 1; + } + + if ((obj1_id = H5Rdereference(container1_id, H5R_OBJECT, _mem1))<0) + return -1; + if ((obj2_id = H5Rdereference(container2_id, H5R_OBJECT, _mem2))<0) + return -1; + + + /*deep compare */ + switch (obj1_type) { + case H5G_DATASET: + nfound=diff_datasetid(obj1_id, + obj2_id, + NULL, + NULL, + options); + break; + default: + printf("Warning: Comparison not possible of object types referenced: <%s> and <%s>", + obj1, obj2); + break; + } + + close_obj(obj1_type,obj1_id); + close_obj(obj2_type,obj2_id); + + }/*object reference*/ + + }/*is zero*/ + + + break; + + case H5T_INTEGER: @@ -437,7 +604,7 @@ int diff_array_mem( void *_mem1, { if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IFORMAT,temp1_char,temp2_char,abs(temp1_char-temp2_char)); } @@ -451,7 +618,7 @@ int diff_array_mem( void *_mem1, { if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IPFORMAT,temp1_char,temp2_char,abs(temp1_char-temp2_char), abs(1-temp2_char/temp1_char)); @@ -467,7 +634,7 @@ int diff_array_mem( void *_mem1, { if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IPFORMAT,temp1_char,temp2_char,abs(temp1_char-temp2_char), abs(1-temp2_char/temp1_char)); @@ -479,7 +646,7 @@ int diff_array_mem( void *_mem1, { if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IFORMAT,temp1_char,temp2_char,abs(temp1_char-temp2_char)); } @@ -507,7 +674,7 @@ int diff_array_mem( void *_mem1, { if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IFORMAT,temp1_uchar,temp2_uchar,abs(temp1_uchar-temp2_uchar)); } @@ -521,7 +688,7 @@ int diff_array_mem( void *_mem1, { if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IPFORMAT,temp1_uchar,temp2_uchar,abs(temp1_uchar-temp2_uchar), abs(1-temp2_uchar/temp1_uchar)); @@ -537,7 +704,7 @@ int diff_array_mem( void *_mem1, { if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IPFORMAT,temp1_uchar,temp2_uchar,abs(temp1_uchar-temp2_uchar), abs(1-temp2_uchar/temp1_uchar)); @@ -549,7 +716,7 @@ int diff_array_mem( void *_mem1, { if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IFORMAT,temp1_uchar,temp2_uchar,abs(temp1_uchar-temp2_uchar)); } @@ -579,7 +746,7 @@ int diff_array_mem( void *_mem1, { if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IFORMAT,temp1_short,temp2_short,abs(temp1_short-temp2_short)); } @@ -593,7 +760,7 @@ int diff_array_mem( void *_mem1, { if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IPFORMAT,temp1_short,temp2_short,abs(temp1_short-temp2_short), abs(1-temp2_short/temp1_short)); @@ -609,7 +776,7 @@ int diff_array_mem( void *_mem1, { if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IPFORMAT,temp1_short,temp2_short,abs(temp1_short-temp2_short), abs(1-temp2_short/temp1_short)); @@ -621,7 +788,7 @@ int diff_array_mem( void *_mem1, { if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IFORMAT,temp1_short,temp2_short,abs(temp1_short-temp2_short)); } @@ -652,7 +819,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IFORMAT,temp1_ushort,temp2_ushort,abs(temp1_ushort-temp2_ushort)); } @@ -667,7 +834,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IPFORMAT,temp1_ushort,temp2_ushort,abs(temp1_ushort-temp2_ushort), abs(1-temp2_ushort/temp1_ushort)); @@ -684,7 +851,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IPFORMAT,temp1_ushort,temp2_ushort,abs(temp1_ushort-temp2_ushort), abs(1-temp2_ushort/temp1_ushort)); @@ -697,7 +864,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IFORMAT,temp1_ushort,temp2_ushort,abs(temp1_ushort-temp2_ushort)); } @@ -729,7 +896,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IFORMAT,temp1_int,temp2_int,abs(temp1_int-temp2_int)); } @@ -744,7 +911,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IPFORMAT,temp1_int,temp2_int,abs(temp1_int-temp2_int), abs(1-temp2_int/temp1_int)); @@ -761,7 +928,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IPFORMAT,temp1_int,temp2_int,abs(temp1_int-temp2_int), abs(1-temp2_int/temp1_int)); @@ -774,7 +941,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IFORMAT,temp1_int,temp2_int,abs(temp1_int-temp2_int)); } @@ -806,7 +973,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(UIFORMAT,temp1_uint,temp2_uint,abs((int)(temp1_uint-temp2_uint))); } @@ -821,7 +988,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(UIPFORMAT,temp1_uint,temp2_uint,abs((int)(temp1_uint-temp2_uint)), abs((int)(1-temp2_uint/temp1_uint))); @@ -838,7 +1005,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(UIPFORMAT,temp1_uint,temp2_uint,abs((int)(temp1_uint-temp2_uint)), abs((int)(1-temp2_uint/temp1_uint))); @@ -851,7 +1018,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(UIFORMAT,temp1_uint,temp2_uint,abs((int)(temp1_uint-temp2_uint))); } @@ -884,7 +1051,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(LIFORMAT,temp1_long,temp2_long,labs(temp1_long-temp2_long)); } @@ -899,7 +1066,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(LPIFORMAT,temp1_long,temp2_long,labs(temp1_long-temp2_long), labs(1-temp2_long/temp1_long)); @@ -916,7 +1083,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(LPIFORMAT,temp1_long,temp2_long,labs(temp1_long-temp2_long), labs(1-temp2_long/temp1_long)); @@ -929,7 +1096,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(LIFORMAT,temp1_long,temp2_long,labs(temp1_long-temp2_long)); } @@ -961,7 +1128,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(ULIFORMAT,temp1_ulong,temp2_ulong,labs((long)(temp1_ulong-temp2_ulong))); } @@ -976,7 +1143,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(ULPIFORMAT,temp1_ulong,temp2_ulong,labs((long)(temp1_ulong-temp2_ulong)), labs((long)(1-temp2_ulong/temp1_ulong))); @@ -993,7 +1160,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(ULPIFORMAT,temp1_ulong,temp2_ulong,labs((long)(temp1_ulong-temp2_ulong)), labs((long)(1-temp2_ulong/temp1_ulong))); @@ -1006,7 +1173,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(ULIFORMAT,temp1_ulong,temp2_ulong,labs((long)(temp1_ulong-temp2_ulong))); } @@ -1037,7 +1204,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(fmt_llong,temp1_llong,temp2_llong,(long_long)labs((long)(temp1_llong-temp2_llong))); } @@ -1052,7 +1219,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(fmt_llongp,temp1_llong,temp2_llong,(long_long)labs((long)(temp1_llong-temp2_llong)), (long_long)labs((long)(1-temp2_llong/temp1_llong))); @@ -1069,7 +1236,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(fmt_llongp,temp1_llong,temp2_llong,(long_long)labs((long)(temp1_llong-temp2_llong)), (long_long)labs((long)(1-temp2_llong/temp1_llong))); @@ -1082,7 +1249,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(fmt_llong,temp1_llong,temp2_llong,(long_long)labs((long)(temp1_llong-temp2_llong))); } @@ -1113,7 +1280,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(fmt_ullong,temp1_ullong,temp2_ullong, (unsigned long_long)labs((long)(temp1_ullong-temp2_ullong))); @@ -1129,7 +1296,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(fmt_ullongp,temp1_ullong,temp2_ullong, (unsigned long_long)labs((long)(temp1_ullong-temp2_ullong)), @@ -1147,7 +1314,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(fmt_ullongp,temp1_ullong,temp2_ullong, (unsigned long_long)labs((long)(temp1_ullong-temp2_ullong)), @@ -1161,7 +1328,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(fmt_ullong,temp1_ullong,temp2_ullong, (unsigned long_long)labs((long)(temp1_ullong-temp2_ullong))); @@ -1198,7 +1365,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(FFORMAT,temp1_float,temp2_float,fabs(temp1_float-temp2_float)); } @@ -1213,7 +1380,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(FPFORMAT,temp1_float,temp2_float,fabs(temp1_float-temp2_float), fabs(1-temp2_float/temp1_float)); @@ -1230,7 +1397,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(FPFORMAT,temp1_float,temp2_float,fabs(temp1_float-temp2_float), fabs(1-temp2_float/temp1_float)); @@ -1243,7 +1410,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(FFORMAT,temp1_float,temp2_float,fabs(temp1_float-temp2_float)); } @@ -1273,7 +1440,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(FFORMAT,temp1_double,temp2_double,fabs(temp1_double-temp2_double)); } @@ -1288,7 +1455,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(FPFORMAT,temp1_double,temp2_double,fabs(temp1_double-temp2_double), fabs(1-temp2_double/temp1_double)); @@ -1305,7 +1472,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(FPFORMAT,temp1_double,temp2_double,fabs(temp1_double-temp2_double), fabs(1-temp2_double/temp1_double)); @@ -1318,7 +1485,7 @@ int diff_array_mem( void *_mem1, if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(FFORMAT,temp1_double,temp2_double,fabs(temp1_double-temp2_double)); } @@ -1341,7 +1508,7 @@ int diff_array_mem( void *_mem1, /*------------------------------------------------------------------------- * Function: diff_native_uchar * - * Purpose: do a byte-by-byte comparison + * Purpose: do a byte-by-byte comparison and print in numerical format * * Return: number of differences found * @@ -1352,25 +1519,23 @@ int diff_array_mem( void *_mem1, *------------------------------------------------------------------------- */ - static int diff_native_uchar(unsigned char *mem1, unsigned char *mem2, size_t type_size, - unsigned i, + hsize_t i, int rank, - int *acc, - int *pos, + hsize_t *acc, + hsize_t *pos, diff_opt_t *options, const char *obj1, const char *obj2, - int ph) + int *ph) { int nfound=0; /* differences found */ unsigned char temp1_uchar; unsigned char temp2_uchar; - memcpy(&temp1_uchar, mem1, sizeof(unsigned char)); memcpy(&temp2_uchar, mem2, sizeof(unsigned char)); @@ -1381,7 +1546,7 @@ int diff_native_uchar(unsigned char *mem1, { if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IFORMAT,temp1_uchar,temp2_uchar,abs(temp1_uchar-temp2_uchar)); } @@ -1395,7 +1560,7 @@ int diff_native_uchar(unsigned char *mem1, { if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IPFORMAT,temp1_uchar,temp2_uchar,abs(temp1_uchar-temp2_uchar), abs(1-temp2_uchar/temp1_uchar)); @@ -1411,7 +1576,7 @@ int diff_native_uchar(unsigned char *mem1, { if ( options->r==0 ) { - print_pos(&ph,1,i,acc,pos,rank,obj1,obj2); + print_pos(ph,1,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IPFORMAT,temp1_uchar,temp2_uchar,abs(temp1_uchar-temp2_uchar), abs(1-temp2_uchar/temp1_uchar)); @@ -1423,7 +1588,7 @@ int diff_native_uchar(unsigned char *mem1, { if ( options->r==0 ) { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); printf(SPACES); printf(IFORMAT,temp1_uchar,temp2_uchar,abs(temp1_uchar-temp2_uchar)); } @@ -1432,3 +1597,105 @@ int diff_native_uchar(unsigned char *mem1, return nfound; } + + +/*------------------------------------------------------------------------- + * Function: diff_char + * + * Purpose: do a byte-by-byte comparison and print in char format + * + * Return: number of differences found + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: October 29, 2003 + * + *------------------------------------------------------------------------- + */ + +static +int diff_char(unsigned char *mem1, + unsigned char *mem2, + size_t type_size, + hsize_t i, + int rank, + hsize_t *acc, + hsize_t *pos, + diff_opt_t *options, + const char *obj1, + const char *obj2, + int *ph) +{ + int nfound=0; /* differences found */ + unsigned char temp1_uchar; + unsigned char temp2_uchar; + + memcpy(&temp1_uchar, mem1, sizeof(unsigned char)); + memcpy(&temp2_uchar, mem2, sizeof(unsigned char)); + + if (temp1_uchar != temp2_uchar) + { + if ( options->r==0 ) + { + print_pos(ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(CFORMAT,temp1_uchar,temp2_uchar); + } + nfound++; + } + + return nfound; +} + + + + +/*------------------------------------------------------------------------- + * Function: is_zero + * + * Purpose: Determines if memory is initialized to all zero bytes. + * + * Return: TRUE if all bytes are zero; FALSE otherwise + * + *------------------------------------------------------------------------- + */ +static hbool_t +is_zero(const void *_mem, size_t size) +{ + const unsigned char *mem = (const unsigned char *)_mem; + + while (size-- > 0) + if (mem[size]) + return FALSE; + + return TRUE; +} + +/*------------------------------------------------------------------------- + * Function: close_obj + * + * Purpose: Auxialiary function to close an object + * + *------------------------------------------------------------------------- + */ + +static +void close_obj(H5G_obj_t obj_type, hid_t obj_id) +{ + + switch (obj_type) { + case H5G_GROUP: + H5Gclose(obj_id); + break; + case H5G_DATASET: + H5Dclose(obj_id); + break; + case H5G_TYPE: + H5Tclose(obj_id); + break; + default: + assert(0); + break; + } +} + diff --git a/tools/lib/h5diff_attr.c b/tools/lib/h5diff_attr.c index 2fbb2a4..c2e36ef 100644 --- a/tools/lib/h5diff_attr.c +++ b/tools/lib/h5diff_attr.c @@ -20,7 +20,7 @@ /*------------------------------------------------------------------------- * Function: diff_attr * - * Purpose: diff attributes located in LOC1_ID and LOC2_ID, which are + * Purpose: compare attributes located in LOC1_ID and LOC2_ID, which are * obtained either from * loc_id = H5Gopen( fid, name); * loc_id = H5Dopen( fid, name); @@ -38,8 +38,10 @@ *------------------------------------------------------------------------- */ -int diff_attr(hid_t loc1_id, - hid_t loc2_id, +int diff_attr(hid_t loc1_id, + hid_t loc2_id, + const char *path1, + const char *path2, diff_opt_t *options ) { @@ -92,7 +94,7 @@ int diff_attr(hid_t loc1_id, /* get name */ if (H5Aget_name( attr1_id, 255, name1 )<0) goto error; - if (H5Aget_name( attr1_id, 255, name2 )<0) + if (H5Aget_name( attr2_id, 255, name2 )<0) goto error; if (HDstrcmp(name1,name2)!=0) @@ -179,10 +181,23 @@ int diff_attr(hid_t loc1_id, */ if (options->verbose) - printf( "Comparing <%s> with <%s>\n", name1, name2 ); - nfound = diff_array(buf1,buf2,nelmts1,rank1,dims1,options,name1,name2,mtype1_id); - if (options->verbose) - printf("%d attribute differences found\n", nfound ); + printf( "Attribute: <%s> and <%s>\n",name1,name2); + sprintf(name1,"%s of <%s>",name1,path1); + sprintf(name2,"%s of <%s>",name2,path2); + nfound = diff_array(buf1, + buf2, + nelmts1, + rank1, + dims1, + options, + name1, + name2, + mtype1_id, + attr1_id, + attr2_id); + if (options->verbose && nfound) + printf("%d differences found\n", nfound ); + /*------------------------------------------------------------------------- * close diff --git a/tools/lib/h5diff_dset.c b/tools/lib/h5diff_dset.c index 32ca66d..13dfe5f 100644 --- a/tools/lib/h5diff_dset.c +++ b/tools/lib/h5diff_dset.c @@ -28,9 +28,6 @@ * * Date: May 9, 2003 * - * Modifications: November 3, 2003 - * - * *------------------------------------------------------------------------- */ int diff_dataset( hid_t file1_id, @@ -41,29 +38,7 @@ int diff_dataset( hid_t file1_id, { hid_t dset1_id =-1; hid_t dset2_id =-1; - hid_t space1_id =-1; - hid_t space2_id =-1; - hid_t f_type1=-1, f_type2=-1; /* file data type */ - hid_t m_type1=-1, m_type2=-1; /* memory data type */ - size_t m_size1, m_size2; /* size of type in memory */ - H5T_sign_t sign1, sign2; /* sign of type */ - int rank1, rank2; - void *buf1=NULL, *buf2=NULL; - hsize_t tot_cnt1, tot_cnt2; - hsize_t dims1[H5S_MAX_RANK]; - hsize_t dims2[H5S_MAX_RANK]; - hsize_t maxdim1[H5S_MAX_RANK]; - hsize_t maxdim2[H5S_MAX_RANK]; - int nfound=0; /* number of differences found */ - const char *name1=NULL; /* relative names */ - const char *name2=NULL; - int maxdim_diff=0; /* maximum dimensions are different */ - int dim_diff=0; /* current dimensions are different */ - int can1, can2; /* supported diff */ - hsize_t storage_size1; - hsize_t storage_size2; - int i, gout=0; - + int gout=0, nfound; /* disable error reporting */ H5E_BEGIN_TRY { @@ -89,6 +64,77 @@ int diff_dataset( hid_t file1_id, if (gout) goto out; + nfound=diff_datasetid(dset1_id, + dset2_id, + obj1_name, + obj2_name, + options); + + + +/*------------------------------------------------------------------------- + * close + *------------------------------------------------------------------------- + */ + +out: + + /* disable error reporting */ + H5E_BEGIN_TRY { + H5Dclose(dset1_id); + H5Dclose(dset2_id); + /* enable error reporting */ + } H5E_END_TRY; + + return nfound; + +} + + + + +/*------------------------------------------------------------------------- + * Function: diff_datasetid + * + * Purpose: check for comparable datasets and read into a compatible + * memory type + * + * Return: Number of differences found + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: May 9, 2003 + * + *------------------------------------------------------------------------- + */ +int diff_datasetid( hid_t dset1_id, + hid_t dset2_id, + const char *obj1_name, + const char *obj2_name, + diff_opt_t *options ) +{ + hid_t space1_id =-1; + hid_t space2_id =-1; + hid_t f_type1=-1, f_type2=-1; /* file data type */ + hid_t m_type1=-1, m_type2=-1; /* memory data type */ + size_t m_size1, m_size2; /* size of type in memory */ + H5T_sign_t sign1, sign2; /* sign of type */ + int rank1, rank2; + void *buf1=NULL, *buf2=NULL; + hsize_t nelmts1, nelmts2; + hsize_t dims1[H5S_MAX_RANK]; + hsize_t dims2[H5S_MAX_RANK]; + hsize_t maxdim1[H5S_MAX_RANK]; + hsize_t maxdim2[H5S_MAX_RANK]; + int nfound=0; /* number of differences found */ + const char *name1=NULL; /* relative names */ + const char *name2=NULL; + int maxdim_diff=0; /* maximum dimensions are different */ + int dim_diff=0; /* current dimensions are different */ + hsize_t storage_size1; + hsize_t storage_size2; + int i, gout=0; + /* Get the dataspace handle */ if ( (space1_id = H5Dget_space(dset1_id)) < 0 ) goto out; @@ -136,7 +182,7 @@ int diff_dataset( hid_t file1_id, storage_size2=H5Dget_storage_size(dset2_id); if (storage_size1<=0 && storage_size2<=0) { - if (options->verbose) + if (options->verbose && obj1_name && obj2_name) printf("<%s> and <%s> are empty datasets\n", obj1_name, obj2_name); goto out; } @@ -167,26 +213,26 @@ int diff_dataset( hid_t file1_id, *------------------------------------------------------------------------- */ - tot_cnt1 = 1; + nelmts1 = 1; for (i = 0; i < rank1; i++) { - tot_cnt1 *= dims1[i]; + nelmts1 *= dims1[i]; } - tot_cnt2 = 1; + nelmts2 = 1; for (i = 0; i < rank2; i++) { - tot_cnt2 *= dims2[i]; + nelmts2 *= dims2[i]; } - assert(tot_cnt1==tot_cnt2); + assert(nelmts1==nelmts2); /*------------------------------------------------------------------------- * check for equal file datatype; warning only *------------------------------------------------------------------------- */ - if ( (H5Tequal(f_type1, f_type2)==0) && options->verbose) + if ( (H5Tequal(f_type1, f_type2)==0) && options->verbose && obj1_name) { printf("Warning: Different storage datatype\n"); printf("<%s> has file datatype ", obj1_name); @@ -209,29 +255,11 @@ int diff_dataset( hid_t file1_id, m_size2 = H5Tget_size( m_type2 ); #if defined (H5DIFF_DEBUG) - print_sizes(obj1_name,obj2_name,f_type1,f_type2,m_type1,m_type2); + if (obj1_name) + print_sizes(obj1_name,obj2_name,f_type1,f_type2,m_type1,m_type2); #endif /*------------------------------------------------------------------------- - * check for the comparable types in diff_array - *------------------------------------------------------------------------- - */ - - can1=diff_can(m_type1); - can2=diff_can(m_type2); - if ( (can1==0 || can2==0)) - { - if (options->verbose) { - printf("Comparison not supported\n"); - if ( can1==0 ) - printf("<%s> type is not supported\n", obj1_name); - if ( can2==0 ) - printf("<%s> type is not supported\n", obj2_name); - } - goto out; - } - -/*------------------------------------------------------------------------- * check for different signed/unsigned types *------------------------------------------------------------------------- */ @@ -240,15 +268,13 @@ int diff_dataset( hid_t file1_id, sign2=H5Tget_sign(m_type2); if ( sign1 != sign2 ) { - if (options->verbose) { - printf("Comparison not supported\n"); - printf("<%s> has sign %s\n", obj1_name, get_sign(sign1)); - printf("<%s> has sign %s", obj2_name, get_sign(sign2)); + if (options->verbose && obj1_name) { + printf("Comparison not supported: <%s> has sign %s ", obj1_name, get_sign(sign1)); + printf("and <%s> has sign %s\n", obj2_name, get_sign(sign2)); } goto out; } - /*------------------------------------------------------------------------- * "upgrade" the smaller memory size *------------------------------------------------------------------------- @@ -270,13 +296,14 @@ int diff_dataset( hid_t file1_id, } #if defined (H5DIFF_DEBUG) printf("WARNING: Size was upgraded\n"); + if (obj1_name) print_sizes(obj1_name,obj2_name,f_type1,f_type2,m_type1,m_type2); #endif } assert(m_size1==m_size2); - buf1 = (void *) HDmalloc((unsigned) (tot_cnt1*m_size1)); - buf2 = (void *) HDmalloc((unsigned) (tot_cnt2*m_size2)); + buf1 = (void *) HDmalloc((unsigned) (nelmts1*m_size1)); + buf2 = (void *) HDmalloc((unsigned) (nelmts2*m_size2)); if ( buf1 == NULL || buf2 == NULL ) { @@ -299,12 +326,23 @@ int diff_dataset( hid_t file1_id, * array compare *------------------------------------------------------------------------- */ - if (options->verbose) - printf( "Comparing <%s> with <%s>\n", obj1_name, obj2_name ); - name1=diff_basename(obj1_name); - name2=diff_basename(obj2_name); - nfound = diff_array(buf1,buf2,tot_cnt1,rank1,dims1,options,name1,name2,m_type1); - if (options->verbose) + if (obj1_name) + name1=diff_basename(obj1_name); + if (obj2_name) + name2=diff_basename(obj2_name); + nfound = diff_array(buf1, + buf2, + nelmts1, + rank1, + dims1, + options, + name1, + name2, + m_type1, + dset1_id, + dset2_id); + + if (options->verbose && nfound) printf("%d differences found\n", nfound ); /*------------------------------------------------------------------------- @@ -312,10 +350,7 @@ int diff_dataset( hid_t file1_id, *------------------------------------------------------------------------- */ - if (options->attr) - diff_attr(dset1_id,dset1_id,options); - - + diff_attr(dset1_id,dset2_id,obj1_name,obj2_name,options); /*------------------------------------------------------------------------- * close @@ -330,8 +365,6 @@ out: /* close */ /* disable error reporting */ H5E_BEGIN_TRY { - H5Dclose(dset1_id); - H5Dclose(dset2_id); H5Sclose(space1_id); H5Sclose(space2_id); H5Tclose(f_type1); @@ -345,6 +378,9 @@ out: } + + + /*------------------------------------------------------------------------- * Function: diff_can_type * @@ -398,9 +434,8 @@ int diff_can_type( hid_t f_type1, /* file data type */ if ( tclass1 != tclass2 ) { - if (options->verbose) { - printf("Comparison not supported\n"); - printf("<%s> is of class %s and <%s> is of class %s\n", + if (options->verbose && obj1_name) { + printf("Comparison not possible: <%s> is of class %s and <%s> is of class %s\n", obj1_name, get_class(tclass1), obj2_name, get_class(tclass2) ); } @@ -424,16 +459,14 @@ int diff_can_type( hid_t f_type1, /* file data type */ case H5T_OPAQUE: case H5T_ENUM: case H5T_VLEN: - return 1; + case H5T_REFERENCE: - default: /*H5T_TIME, H5T_REFERENCE */ - if (options->verbose ) { - printf("Comparison not supported\n"); - printf("<%s> is of class %s and <%s> is of class %s\n", - obj1_name, get_class(tclass1), - obj2_name, get_class(tclass2) ); - } + break; + default: /*H5T_TIME */ + if (options->verbose && obj1_name ) + printf("Comparison not supported: <%s> and <%s> are of class %s\n", + obj1_name,obj2_name,get_class(tclass2) ); return 0; } @@ -442,7 +475,7 @@ int diff_can_type( hid_t f_type1, /* file data type */ *------------------------------------------------------------------------- */ - if ( (H5Tequal(f_type1, f_type2)==0) && options->verbose) + if ( (H5Tequal(f_type1, f_type2)==0) && options->verbose && obj1_name) { printf("Warning: Different storage datatype\n"); printf("<%s> has file datatype ", obj1_name); @@ -460,9 +493,8 @@ int diff_can_type( hid_t f_type1, /* file data type */ if ( rank1 != rank2 ) { - if (options->verbose) { - printf("Comparison not supported\n"); - printf("<%s> has rank %d, dimensions ", obj1_name, rank1); + if (options->verbose && obj1_name) { + printf("Comparison not supported: <%s> has rank %d, dimensions ", obj1_name, rank1); print_dims(rank1,dims1); printf(", max dimensions "); print_dims(rank1,maxdim1); @@ -499,9 +531,8 @@ int diff_can_type( hid_t f_type1, /* file data type */ if (dim_diff==1) { - if (options->verbose) { - printf("Comparison not supported\n"); - printf("<%s> has rank %d, dimensions ", obj1_name, rank1); + if (options->verbose && obj1_name) { + printf("Comparison not supported: <%s> has rank %d, dimensions ", obj1_name, rank1); print_dims(rank1,dims1); if (maxdim1 && maxdim2) { printf(", max dimensions "); @@ -520,7 +551,7 @@ int diff_can_type( hid_t f_type1, /* file data type */ * maximum dimensions; just give a warning *------------------------------------------------------------------------- */ - if (maxdim1 && maxdim2 && maxdim_diff==1) + if (maxdim1 && maxdim2 && maxdim_diff==1 && obj1_name ) { if (options->verbose) { printf( "Warning: Different maximum dimensions\n"); diff --git a/tools/lib/h5diff_util.c b/tools/lib/h5diff_util.c index 3340e2d..673b67f 100644 --- a/tools/lib/h5diff_util.c +++ b/tools/lib/h5diff_util.c @@ -16,47 +16,6 @@ #include <assert.h> - -/*------------------------------------------------------------------------- - * Function: diff_can - * - * Purpose: Check if TYPE_ID is supported; only the listed types are - * supported in the current version - * Date: May 30, 2003 - * - * Modifications: October 29, 2003 - * Added support for H5T_COMPOUND, H5T_STRING, H5T_ARRAY types; - * - *------------------------------------------------------------------------- - */ -int diff_can(hid_t type_id) -{ - int ret=0; - - if ( ((H5Tget_class(type_id) == H5T_COMPOUND)==1)|| /* get class */ - ((H5Tget_class(type_id) == H5T_STRING)==1)|| /* get class */ - ((H5Tget_class(type_id) == H5T_ARRAY)==1)|| /* get class */ - - (H5Tequal(type_id, H5T_NATIVE_FLOAT)==1)|| - (H5Tequal(type_id, H5T_NATIVE_DOUBLE)==1)|| - (H5Tequal(type_id, H5T_NATIVE_INT)==1)|| - (H5Tequal(type_id, H5T_NATIVE_UINT)==1)|| - (H5Tequal(type_id, H5T_NATIVE_SCHAR)==1)|| - (H5Tequal(type_id, H5T_NATIVE_UCHAR)==1)|| - (H5Tequal(type_id, H5T_NATIVE_SHORT)==1)|| - (H5Tequal(type_id, H5T_NATIVE_USHORT)==1)|| - (H5Tequal(type_id, H5T_NATIVE_LONG)==1)|| - (H5Tequal(type_id, H5T_NATIVE_ULONG)==1)|| - (H5Tequal(type_id, H5T_NATIVE_LLONG)==1)|| - (H5Tequal(type_id, H5T_NATIVE_ULLONG)==1) - ) - ret=1; - return ret; -} - - - - /*------------------------------------------------------------------------- * Function: print_pos * @@ -70,8 +29,14 @@ int diff_can(hid_t type_id) * *------------------------------------------------------------------------- */ -void print_pos( int *ph, int p, unsigned int curr_pos, int *acc, - int *pos, int rank, const char *obj1, const char *obj2 ) +void print_pos( int *ph, + int per, + hsize_t curr_pos, + hsize_t *acc, + hsize_t *pos, + int rank, + const char *obj1, + const char *obj2 ) { int i; @@ -79,23 +44,28 @@ void print_pos( int *ph, int p, unsigned int curr_pos, int *acc, if ( *ph==1 ) { *ph=0; - if (p) + if (per) { - printf("%-15s %-15s %-15s %-15s %-15s\n", "position", obj1, obj2, "difference", + printf("%-15s %-15s %-15s %-15s %-15s\n", + "position", + (obj1!=NULL) ? obj1 : " ", + (obj2!=NULL) ? obj2 : " ", + "difference", "relative"); printf("------------------------------------------------------------------------\n"); } else { - printf("%-15s %-15s %-15s %-20s\n", "position", obj1, obj2, "difference"); + printf("%-15s %-15s %-15s %-20s\n", + "position", + (obj1!=NULL) ? obj1 : " ", + (obj2!=NULL) ? obj2 : " ", + "difference"); printf("------------------------------------------------------------\n"); } } for ( i = 0; i < rank; i++) - pos[i]=0; - - for ( i = 0; i < rank; i++) { pos[i] = curr_pos/acc[i]; curr_pos -= acc[i]*pos[i]; @@ -105,7 +75,7 @@ void print_pos( int *ph, int p, unsigned int curr_pos, int *acc, printf("[ " ); for ( i = 0; i < rank; i++) { - printf("%d ", pos[i] ); + HDfprintf(stdout,"%Hu ", pos[i] ); } printf("]" ); } |