diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/h5diff/Makefile.in | 12 | ||||
-rw-r--r-- | tools/h5diff/h5diff.c | 986 | ||||
-rw-r--r-- | tools/h5diff/h5difftst.c | 438 | ||||
-rw-r--r-- | tools/h5diff/h5trav.c | 594 | ||||
-rw-r--r-- | tools/h5diff/h5trav.h | 50 |
5 files changed, 1462 insertions, 618 deletions
diff --git a/tools/h5diff/Makefile.in b/tools/h5diff/Makefile.in index 9995cd8..0f71c62 100644 --- a/tools/h5diff/Makefile.in +++ b/tools/h5diff/Makefile.in @@ -19,14 +19,14 @@ CPPFLAGS=-I. -I$(srcdir) -I$(top_builddir)/src -I$(top_srcdir)/src \ ## Test programs and scripts. ## TEST_PROGS= -TEST_SCRIPTS=$(srcdir)/testh5diff.sh +TEST_SCRIPTS= ## These are our main targets: library and tools. ## LIBHDF5=$(top_builddir)/src/libhdf5.la PUB_PROGS=h5diff -PROGS=$(PUB_PROGS) $(TEST_PROGS) h5difftst +PROGS= ## Source and object files for the library; do not install ## @@ -36,7 +36,7 @@ PUB_LIB= ## Source and object files for programs... ## -PROG_SRC=h5diff.c h5difftst.c +PROG_SRC=h5diff.c h5trav.c PROG_OBJ=$(PROG_SRC:.c=.lo) PRIVATE_HDR= @@ -55,10 +55,8 @@ check test _test: $(PROGS) ## $(PROGS): $(LIBTOOLS) $(LIBHDF5) -h5diff: h5diff.lo - @$(LT_LINK_EXE) $(CFLAGS) -o $@ h5diff.lo $(LIBTOOLS) $(LIBHDF5) $(LDFLAGS) $(LIBS) +h5diff: h5diff.lo h5trav.lo + @$(LT_LINK_EXE) $(CFLAGS) -o $@ h5diff.lo h5trav.lo $(LIBTOOLS) $(LIBHDF5) $(LDFLAGS) $(LIBS) -h5difftst: h5difftst.lo - @$(LT_LINK_EXE) $(CFLAGS) -o $@ h5difftst.lo $(LIBTOOLS) $(LIBHDF5) $(LDFLAGS) $(LIBS) @CONCLUDE@ diff --git a/tools/h5diff/h5diff.c b/tools/h5diff/h5diff.c index 15f7ac6..4980eeb 100644 --- a/tools/h5diff/h5diff.c +++ b/tools/h5diff/h5diff.c @@ -2,25 +2,67 @@ #include <stdio.h> #include <stdlib.h> +#include <math.h> + +#include <assert.h> + #include "hdf5.h" +#include "h5trav.h" + + +/* + +Example 1 +dset1 dset2 h5diff_test1.h5 h5diff_test2.h5 +Example 2 +dset1 dset2 -v h5diff_test1.h5 h5diff_test2.h5 +Example 3 +-v h5diff_test1.h5 h5diff_test2.h5 +Example 4 +-v -r h5diff_test1.h5 h5diff_test2.h5 +Example 5 +dset1 dset2 -n 2 h5diff_test1.h5 h5diff_test2.h5 +Example 6 +dset3 dset4 -m 0.01 h5diff_test1.h5 h5diff_test2.h5 +Example 7 +dset5 dset6 -p 0.05 h5diff_test1.h5 h5diff_test2.h5 + +*/ #ifndef FALSE -#define FALSE 0 +#define FALSE 0 #endif #ifndef TRUE -#define TRUE 1 +#define TRUE 1 #endif -int do_test_files(); -int h5diff_dataset( hid_t file1_id, hid_t file2_id, const char *dset_name ); -void array_diff( void *buf1, void *buf2, hsize_t tot_cnt, hid_t type_id ); -herr_t get_ndsets( hid_t loc_id, const char *group_name ); -herr_t count_dsets( hid_t loc_id, const char *name, void *op_data); +typedef struct options_t +{ + int d_; + int g_; + int t_; + int r_; /* report only what objects differ */ + int m_; + double m_limit; + int p_; + double p_percent; + int n_; + int n_number_count; + int a_; + int v_; /* verbose */ +} options_t; +int do_test_files(); + +int diff_dataset( hid_t file1_id, hid_t file2_id, const char *obj1_name, + const char *obj2_name, options_t options ); +int array_diff( void *buf1, void *buf2, hsize_t tot_cnt, hid_t type_id, int rank, + hsize_t *dims, options_t options ); +void print_pos( hsize_t curr_pos, hsize_t *acc, hsize_t *pos, int rank ); @@ -46,12 +88,19 @@ herr_t count_dsets( hid_t loc_id, const char *name, void *op_data); void usage( const char *progname ) { #define USAGE "\ - [-d dset] The name of the dataset to compare\n\ + [-m ] Print a basic help message\n\ + [-v ] Print a verbose output message\n\ + [-r ] Print only what objects differ \n\ + [-d ] Compare only datasets\n\ + [-g ] Compare only groups\n\ + [-n count] Print difference up to count number for each variable\n\ + [-m delta] Print difference when it is greater than limit delta\n\ + [-p percent] Print differences which are within a certain percent value\n\ file1 File name of the first HDF5 file\n\ file2 File name of the second HDF5 file\n" fprintf(stderr, - "%s [-d] file1 file2\n%s", + "%s [-d delta] file1 file2\n%s", progname, USAGE); exit(EXIT_FAILURE); @@ -80,15 +129,30 @@ int main(int argc, const char *argv[]) { const char *progname = argv[0]; - int dset_only = FALSE; - int argno; - const char *s = NULL; - const char *file1_name = NULL; - const char *file2_name = NULL; - const char *dset_name = NULL; - hid_t file1_id, file2_id; - herr_t status; - int ndsets; + int dset_only = FALSE; + int have_group = FALSE; + int argno, i, j; + const char *s = NULL; + const char *file1_name = NULL; + const char *file2_name = NULL; + char *obj1_name = NULL; + char *obj2_name = NULL; + hid_t file1_id, file2_id; + herr_t status; + int nobjects1, nobjects2; + info_t *info1=NULL; + info_t *info2=NULL; + char *attr1_name = NULL; + char *attr2_name = NULL; + options_t options = {0,0,0,0,0,0,0,0,0,0,0,0}; + + + /* string compare */ + char *pdest; + int result; + int len; + + do_test_files(); @@ -98,15 +162,15 @@ int main(int argc, const char *argv[]) *------------------------------------------------------------------------- */ - if (argc < 4) { + if (argc < 2) { usage( progname ); exit(EXIT_FAILURE); } - /* parse command line options */ - for (argno=1; argno<argc ; argno++) + /* last 2 items are the file names */ + for (argno=1; argno<argc-2 ; argno++) { - + /* get the single-letter switches */ if ( '-'==argv[argno][0] ) { @@ -117,54 +181,354 @@ int main(int argc, const char *argv[]) case 'h': usage(progname); exit(EXIT_SUCCESS); - case 'd': - dset_only = TRUE; - dset_name = argv[argno+1]; + case 'v': + options.v_ = 1; + break; + case 'd': + options.d_ = 1; + break; + case 'g': + options.g_ = 1; + break; + case 't': + options.t_ = 1; + break; + case 'r': + options.r_ = 1; + break; + case 'a': + options.a_ = 1; + break; + case 'm': + /* if it is not another option */ + if ( '-' !=argv[argno+1][0] ) + { + options.m_ = 1; + options.m_limit = atof(argv[argno+1]); + } + break; + case 'p': + if ( '-' !=argv[argno+1][0] ) + { + options.p_ = 1; + options.p_percent = atof(argv[argno+1]); + } + break; + case 'n': + if ( '-' !=argv[argno+1][0] ) + { + options.n_ = 1; + options.n_number_count = atoi(argv[argno+1]); + } break; } /*switch*/ } /*for*/ } /*if*/ - + + else + + { + + /* 2 last args are the file names, and it is not a -switch parameter */ + if ( argno < argc-2 && '-' !=argv[argno-1][0] ) + { + if ( obj1_name == NULL ) + obj1_name = argv[argno]; + + if ( obj2_name == NULL ) + { + + /* check if we have a second object name */ + if ( '-' !=argv[argno+1][0] ) + /* yes */ + obj2_name = argv[argno+1]; + else + /* no */ + obj2_name = obj1_name; + } + } + + } + }/*for*/ - + /*------------------------------------------------------------------------- * process the files *------------------------------------------------------------------------- */ - file1_name = argv[argno-2]; - file2_name = argv[argno-1]; + file1_name = argv[argc-2]; + file2_name = argv[argc-1]; /* Open the files */ if ((file1_id=H5Fopen(file1_name,H5F_ACC_RDONLY,H5P_DEFAULT))<0 || (file2_id=H5Fopen(file2_name,H5F_ACC_RDONLY,H5P_DEFAULT))<0) exit(EXIT_FAILURE); - /* Get the number of datasets */ - ndsets = get_ndsets( file1_id, "." ); - if ( dset_only ) +/*------------------------------------------------------------------------- + * get the number of objects in the files + *------------------------------------------------------------------------- + */ + + nobjects1 = H5get_object_info( file1_id, NULL ); + nobjects2 = H5get_object_info( file2_id, NULL ); + +/*------------------------------------------------------------------------- + * get the list of objects in the files + *------------------------------------------------------------------------- + */ + + info1 = (info_t*) malloc( nobjects1 * sizeof(info_t)); + info2 = (info_t*) malloc( nobjects2 * sizeof(info_t)); + + H5get_object_info( file1_id, info1 ); + H5get_object_info( file2_id, info2 ); + + if ( options.v_ ) { + printf("File 1: # of entries = %d\n", nobjects1); + for ( i = 0; i < nobjects1; i++) + { + switch ( info1[i].type ) + { + case H5G_GROUP: + printf("%s \t %s\n", info1[i].name, "group" ); + break; + case H5G_DATASET: + printf("%s \t %s\n", info1[i].name, "dataset" ); + break; + case H5G_TYPE: + printf("%s \t %s\n", info1[i].name, "datatype" ); + break; + } + } + + printf("File 2: # of entries = %d\n", nobjects2); + for ( i = 0; i < nobjects2; i++) + { + switch ( info2[i].type ) + { + case H5G_GROUP: + printf("%s \t %s\n", info2[i].name, "group" ); + break; + case H5G_DATASET: + printf("%s \t %s\n", info2[i].name, "dataset" ); + break; + case H5G_TYPE: + printf("%s \t %s\n", info2[i].name, "datatype" ); + break; + } + } + printf("\n"); + } + + - h5diff_dataset(file1_id,file2_id,dset_name); + +/*------------------------------------------------------------------------- + * object name was supplied + *------------------------------------------------------------------------- + */ + + /* object name was supplied, find obj1_name */ + if ( obj1_name ) + { + + for ( i = 0; i < nobjects1; i++) + { + + pdest = strstr( info1[i].name, obj1_name ); + result = pdest - info1[i].name; + len = strlen(obj1_name); + + /* found at position result */ + if( pdest != NULL && + /* check if it is not a substring */ + info1[i].name[result-1] == '/' && + /* check if it is the last or in the middle */ + (info1[i].name[result+len]=='/' || + info1[i].name[result+len]=='\0') ) + { + if ( options.v_ ) + printf( "%s found in file %s\n\n", info1[i].name, file1_name); + + /* go to second file and find obj2_name */ + for ( j = 0; j < nobjects2; j++) + { + + pdest = strstr( info2[j].name, obj2_name ); + result = pdest - info2[j].name; + + len = strlen(obj2_name); + + /* found at position result */ + if( pdest != NULL && + /* check if it is not a substring */ + info2[j].name[result-1] == '/' && + /* check if it is the last or in the middle */ + (info2[j].name[result+len]=='/' || info2[j].name[result+len]=='\0') && + /* objects are the same type */ + info1[i].type == info2[j].type ) + { + + switch ( info1[i].type ) + { + + /*------------------------------------------------------------------------- + * H5G_GROUP + *------------------------------------------------------------------------- + */ + + case H5G_GROUP: + + if ( options.d_==1 || options.t_==1 ) break; + printf( "%s found in file %s, %s found in file %s\n", info1[i].name, file1_name, + info2[j].name, file2_name ); + + + break; + + /*------------------------------------------------------------------------- + * H5G_DATASET + *------------------------------------------------------------------------- + */ + + case H5G_DATASET: + if ( options.g_==1 || options.t_==1 ) break; + if ( options.v_ ) + printf( "%s found in file %s\n\n", info2[j].name, file2_name); + if ( options.r_==1 ) break; + /* compare with the absolute name */ + diff_dataset(file1_id,file2_id,info1[i].name,info2[j].name,options); + printf("\n"); + break; + + /*------------------------------------------------------------------------- + * H5G_TYPE + *------------------------------------------------------------------------- + */ + + case H5G_TYPE: + + break; + + } /* switch */ + + } + + } /* j */ + + } + + } /* i */ } + + + +/*------------------------------------------------------------------------- + * compare all datasets + *------------------------------------------------------------------------- + */ + else + + { + for ( i = 0; i < nobjects1; i++) + { + obj1_name = info1[i].name; + len = strlen(obj1_name); + + for ( j = 0; j < nobjects2; j++) + { + /* find an object in file2 with same name as in file 1 */ + + pdest = strstr( info2[j].name, obj1_name ); + result = pdest - info2[j].name; + + /* found at position result */ + if( pdest != NULL && + /* check if it is not a substring */ + info2[j].name[result] == '/' && + /* check if it is the last or in the middle */ + (info2[j].name[result+len]=='/' || info2[j].name[result+len]=='\0') && + /* objects are the same type */ + info1[i].type == info2[j].type ) + { + + switch ( info1[i].type ) + { + + /*------------------------------------------------------------------------- + * H5G_GROUP + *------------------------------------------------------------------------- + */ + + case H5G_GROUP: + + if ( options.d_==1 || options.t_==1 ) break; + printf( "%s found in file %s, %s found in file %s\n", info1[i].name, file1_name, + info2[j].name, file2_name ); + + break; + + /*------------------------------------------------------------------------- + * H5G_DATASET + *------------------------------------------------------------------------- + */ + + case H5G_DATASET: + + if ( options.g_==1 || options.t_==1 ) break; + if ( options.v_ ) + printf( "%s found in file %s, %s found in file %s\n", info1[i].name, file1_name, + info2[j].name, file2_name ); + if ( options.r_==1 ) break; + /* compare with the absolute name */ + diff_dataset(file1_id,file2_id,info1[i].name,info2[j].name,options); + printf("\n"); + break; + + /*------------------------------------------------------------------------- + * H5G_TYPE + *------------------------------------------------------------------------- + */ + + case H5G_TYPE: + + break; + + } + + } + + } /* j */ + } /* i */ + + } - /* Close */ - status = H5Fclose(file1_id); - status = H5Fclose(file2_id); + /* close */ + status = H5Fclose(file1_id); + status = H5Fclose(file2_id); + if ( info1 ) + free(info1); + if ( info2 ) + free(info2); + return 0; - return 0; } + + + /*------------------------------------------------------------------------- - * Function: h5diff_dataset + * Function: diff_dataset * * Purpose: * @@ -183,40 +547,41 @@ int main(int argc, const char *argv[]) -int h5diff_dataset( hid_t file1_id, hid_t file2_id, const char *dset_name ) +int diff_dataset( hid_t file1_id, hid_t file2_id, const char *obj1_name, + const char *obj2_name, options_t options ) { - hid_t dset1_id, dset2_id; - hid_t space1_id, space2_id; - hid_t type1_id, type2_id; - hid_t rank1, rank2; - void *buf1, *buf2; - hsize_t tot_cnt, tot_cnt1, tot_cnt2; - hsize_t dims1[32], dims2[32]; - int i; - herr_t status; + hid_t dset1_id, dset2_id; + hid_t space1_id, space2_id; + hid_t type1_id, type2_id; + hid_t rank1, rank2; + void *buf1, *buf2; + hsize_t tot_cnt, tot_cnt1, tot_cnt2; + hsize_t dims1[32], dims2[32]; + int i; + herr_t status; /*------------------------------------------------------------------------- * open the handles *------------------------------------------------------------------------- */ - /* Open the datasets */ - if ( (dset1_id = H5Dopen(file1_id,dset_name)) < 0 ) + /* Open the datasets */ + if ( (dset1_id = H5Dopen(file1_id,obj1_name)) < 0 ) return -1; - if ( (dset2_id = H5Dopen(file2_id,dset_name)) < 0 ) + if ( (dset2_id = H5Dopen(file2_id,obj2_name)) < 0 ) return -1; - /* Get the datatype */ + /* Get the datatype */ if ( (type1_id = H5Dget_type(dset1_id)) < 0 ) goto out; - /* Get the datatype */ + /* Get the datatype */ if ( (type2_id = H5Dget_type(dset2_id)) < 0 ) goto out; - /* Get the dataspace handle */ + /* Get the dataspace handle */ if ( (space1_id = H5Dget_space(dset1_id)) < 0 ) return -1; @@ -224,7 +589,7 @@ int h5diff_dataset( hid_t file1_id, hid_t file2_id, const char *dset_name ) if ( (rank1 = H5Sget_simple_extent_ndims(space1_id)) < 0 ) return -1; - /* Get the dataspace handle */ + /* Get the dataspace handle */ if ( (space2_id = H5Dget_space(dset2_id)) < 0 ) return -1; @@ -232,11 +597,11 @@ int h5diff_dataset( hid_t file1_id, hid_t file2_id, const char *dset_name ) if ( (rank2 = H5Sget_simple_extent_ndims(space2_id)) < 0 ) return -1; - /* Get dimensions */ + /* Get dimensions */ if ( H5Sget_simple_extent_dims(space1_id,dims1,NULL) < 0 ) goto out; - /* Get dimensions */ + /* Get dimensions */ if ( H5Sget_simple_extent_dims(space2_id,dims2,NULL) < 0 ) goto out; @@ -245,13 +610,13 @@ int h5diff_dataset( hid_t file1_id, hid_t file2_id, const char *dset_name ) * compare *------------------------------------------------------------------------- */ - - printf("Dataset Name: %s .... Comparing\n", dset_name); - - if ( rank1 != rank2 ) - { + + if ( rank1 != rank2 ) + { goto out; - } + } + + printf("Dataset Names: %s and %s .... Comparing\n", obj1_name, obj2_name); tot_cnt1 = 1; for (i = 0; i < rank1; i++) @@ -265,14 +630,14 @@ int h5diff_dataset( hid_t file1_id, hid_t file2_id, const char *dset_name ) tot_cnt2 *= dims2[i]; } - buf1 = (void *) malloc((unsigned) (tot_cnt1*H5Tget_size(type1_id))); + buf1 = (void *) malloc((unsigned) (tot_cnt1*H5Tget_size(type1_id))); buf2 = (void *) malloc((unsigned) (tot_cnt2*H5Tget_size(type2_id))); if ( H5Dread(dset1_id,type1_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf1) < 0 ) goto out; - if ( H5Dread(dset2_id,type2_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf2) < 0 ) + if ( H5Dread(dset2_id,type2_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf2) < 0 ) goto out; if (tot_cnt1 > tot_cnt2) @@ -280,11 +645,25 @@ int h5diff_dataset( hid_t file1_id, hid_t file2_id, const char *dset_name ) else tot_cnt = tot_cnt1; - array_diff(buf1,buf2,tot_cnt,type1_id); + if ( array_diff(buf1,buf2,tot_cnt,type1_id,rank1,dims1,options) == 0 ) + printf("No differences found\n" ); - free((char *) buf1); + free((char *) buf1); free((char *) buf2); + +/*------------------------------------------------------------------------- + * attributes + *------------------------------------------------------------------------- + */ + + if ( options.a_==1 ) + { + + + + } + /*------------------------------------------------------------------------- * close @@ -294,15 +673,15 @@ int h5diff_dataset( hid_t file1_id, hid_t file2_id, const char *dset_name ) out: - /* Close */ - status = H5Dclose(dset1_id); - status = H5Dclose(dset2_id); - status = H5Sclose(space1_id); - status = H5Sclose(space2_id); - status = H5Tclose(type1_id); - status = H5Tclose(type2_id); + /* Close */ + status = H5Dclose(dset1_id); + status = H5Dclose(dset2_id); + status = H5Sclose(space1_id); + status = H5Sclose(space2_id); + status = H5Tclose(type1_id); + status = H5Tclose(type2_id); - return 0; + return 0; } @@ -327,23 +706,31 @@ out: */ -void array_diff( void *buf1, void *buf2, hsize_t tot_cnt, hid_t type_id ) +int array_diff( void *buf1, void *buf2, hsize_t tot_cnt, hid_t type_id, int rank, + hsize_t *dims, options_t options ) { - -#if 0 char *i1ptr1, *i1ptr2; short *i2ptr1, *i2ptr2; + int *i4ptr1, *i4ptr2; float *fptr1, *fptr2; double *dptr1, *dptr2; -#endif + int found = 0; - int *i4ptr1, *i4ptr2; - int i; + /* accumulator and matrix position */ + hsize_t acc[32]; + hsize_t pos[32]; + int i; + + H5T_class_t type_class; + size_t type_size; - H5T_class_t type_class; - size_t type_size; + acc[rank-1]=1; + for(i=(rank-2); i>=0; i--) + { + acc[i]=acc[i+1]*dims[i+1]; + } - /* Get the class. */ + /* Get the class. */ type_class = H5Tget_class( type_id ); /* Get the size. */ @@ -355,172 +742,423 @@ void array_diff( void *buf1, void *buf2, hsize_t tot_cnt, hid_t type_id ) case H5T_INTEGER: - switch(type_size) - { - case 4: + switch(type_size) + { - i4ptr1 = (int *) buf1; - i4ptr2 = (int *) buf2; - for ( i = 0; i < tot_cnt; i++) - { - if (*i4ptr1 != *i4ptr2) - { - printf("Index: %d, File1: %d, File2: %d\n", i, *i4ptr1, *i4ptr2); - } - i4ptr1++; i4ptr2++; - } + /*------------------------------------------------------------------------- + * H5T_INTEGER 1 + *------------------------------------------------------------------------- + */ + + case 1: + i1ptr1 = (char *) buf1; + i1ptr2 = (char *) buf2; + + break; + + /*------------------------------------------------------------------------- + * H5T_INTEGER 2 + *------------------------------------------------------------------------- + */ + + case 2: + i2ptr1 = (short *) buf1; + i2ptr2 = (short *) buf2; + + break; + + /*------------------------------------------------------------------------- + * H5T_INTEGER 4 + *------------------------------------------------------------------------- + */ + + case 4: + i4ptr1 = (int *) buf1; + i4ptr2 = (int *) buf2; + for ( i = 0; i < tot_cnt; i++) + { + + if (*i4ptr1 != *i4ptr2) + { + print_pos( i, acc, pos, rank ); + printf(" %d, %d\n", *i4ptr1, *i4ptr2); + found++; + + if ( options.n_ && found>options.n_number_count-1) + return found; + } + i4ptr1++; i4ptr2++; + } + break; + + + } /*switch*/ + + break; /* H5T_INTEGER */ - break; + case H5T_FLOAT: - } /*switch*/ + switch(type_size) + { - - break; /* H5T_INTEGER */ + /*------------------------------------------------------------------------- + * H5T_FLOAT 4 + *------------------------------------------------------------------------- + */ + case 4: + fptr1 = (float *) buf1; + fptr2 = (float *) buf2; + + for ( i = 0; i < tot_cnt; i++) + { + if ( options.n_ && i>options.n_number_count-1) + return found; + + /* delta but not percentage */ + if ( options.m_ && !options.p_ ) + { + if ( fabs(*fptr1 - *fptr2) > options.m_limit ) + { + print_pos( i, acc, pos, rank ); + printf(" %f, %f\n", *fptr1, *fptr2); + found=1; + } + } + + /* percentage but not delta */ + else if ( !options.m_ && options.p_ ) + { + if ( 1 - *fptr1 / *fptr2 > options.p_percent ) + { + print_pos( i, acc, pos, rank ); + printf(" %f, %f\n", *fptr1, *fptr2); + found=1; + } + } + + /* percentage and delta */ + else if ( options.m_ && options.p_ ) + { + if ( 1 - *fptr1 / *fptr2 > options.p_percent && + fabs(*fptr1 - *fptr2) > options.m_limit ) + { + print_pos( i, acc, pos, rank ); + printf(" %f, %f\n", *fptr1, *fptr2); + found=1; + } + } + + else + + if (*fptr1 != *fptr2) + { + print_pos( i, acc, pos, rank ); + printf(" %f, %f\n", *fptr1, *fptr2); + found=1; + } + fptr1++; fptr2++; + } + break; + + /*------------------------------------------------------------------------- + * H5T_FLOAT 8 + *------------------------------------------------------------------------- + */ + + case 8: + dptr1 = (double *) buf1; + dptr2 = (double *) buf2; + - - } /*switch*/ + break; + + } /*switch*/ + + + + break; /* H5T_FLOAT */ + + } /*switch*/ - + return found; } - - /*------------------------------------------------------------------------- - * Function: get_ndsets + * Function: print_pos + * + * Purpose: conver an array index position to matrix notation * - * Purpose: Counts the number of datasets in the group GROUP_NAME + * Return: pos matrix array * * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu * - * Date: October 10, 2002 + * Date: December 19, 2002 * - * Return: - * Success: The return value of the first operator that - * returns non-zero, or zero if all members were - * processed with no operator returning non-zero. + * Comments: * - * Failure: Negative if something goes wrong within the - * library, or the negative value returned by one - * of the operators. + * Modifications: * *------------------------------------------------------------------------- */ -herr_t get_ndsets( hid_t loc_id, const char *group_name ) + + +void print_pos( hsize_t curr_pos, hsize_t *acc, hsize_t *pos, int rank ) { + int i; - int ndsets = 0; + 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]; + } + assert( curr_pos == 0 ); + + printf("[ " ); + for ( i = 0; i < rank; i++) + { + printf("%d ", pos[i]+1 ); + } + printf("] :" ); - if ( H5Giterate( loc_id, group_name, NULL, count_dsets, (void *)&ndsets ) < 0 ) - return -1; - return ndsets; } /*------------------------------------------------------------------------- - * Function: count_dsets - * - * Purpose: operator function used by get_ndsets - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: October 10, 2002 - * - * Comments: - * - * Modifications: - * + * do some test files *------------------------------------------------------------------------- */ -static herr_t count_dsets( hid_t loc_id, const char *name, void *op_data) +int do_test_files() { - H5G_stat_t statbuf; + hid_t file1_id, file2_id; + hid_t dataset_id; + hid_t space_id; + hid_t group_id, group2_id; + hsize_t dims [1] = { 7 }; + hsize_t dims2 [2] = { 3,2 }; + int data1[7] = {1,1,1,1,1,1,1}; + int data2[7] = {1,1,1,4,5,6,7}; + float data3[7] = {1,1,3,4,5,6,7}; + float data4[7] = {1,1,3.02f,4.002f,5.00002f,6,7}; + float data5[3][2] = {1,1,3,4,5,6}; + float data6[3][2] = {1,1.1f,3.02f,4.002f,5.00002f,6}; + + /* attribute */ + size_t size_attr = 5; + float attr_data1[5] = {1,2,3,4,5}; + float attr_data2[5] = {1,2.1f,3.01f,4.001f,5.00001f}; + herr_t status; - if (H5Gget_objinfo( loc_id, name, FALSE, &statbuf) < 0 ) - return -1; +/*------------------------------------------------------------------------- + * Create two files + *------------------------------------------------------------------------- + */ + + /* Create a file */ + file1_id = H5Fcreate ("h5diff_test1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); - if ( statbuf.type == H5G_DATASET ) - (*(int *)op_data)++; + /* Create a file */ + file2_id = H5Fcreate ("h5diff_test2.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); - /* Define a default zero value for return. This will cause the iterator to continue */ - return 0; -} +/*------------------------------------------------------------------------- + * Make dataset "dset1" on file1 + *------------------------------------------------------------------------- + */ + /* Create a data space */ + space_id = H5Screate_simple(1,dims,NULL); + /* Create a dataset "dset1" */ + dataset_id = H5Dcreate(file1_id,"dset1",H5T_NATIVE_INT,space_id,H5P_DEFAULT); + + /* Write the data */ + status = H5Dwrite(dataset_id,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data1); + /* Close */ + status = H5Dclose(dataset_id); + status = H5Sclose(space_id); /*------------------------------------------------------------------------- - * do some test files + * Make dataset "dset3" on file1 *------------------------------------------------------------------------- */ -int do_test_files() -{ + /* Create a data space */ + space_id = H5Screate_simple(1,dims,NULL); + + /* Create a dataset "dset3" */ + dataset_id = H5Dcreate(file1_id,"dset3",H5T_NATIVE_FLOAT,space_id,H5P_DEFAULT); + + /* Write the data */ + status = H5Dwrite(dataset_id,H5T_NATIVE_FLOAT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data3); + + /* Close */ + status = H5Dclose(dataset_id); + status = H5Sclose(space_id); + +/*------------------------------------------------------------------------- + * Make group "g1" on file1 + *------------------------------------------------------------------------- + */ + + /* Create a group. */ + group_id = H5Gcreate(file1_id, "g1", 0); + + /* Close */ + status = H5Gclose(group_id); + + +/*------------------------------------------------------------------------- + * Make dataset "dset1" on file2 + *------------------------------------------------------------------------- + */ + + /* Create a data space */ + space_id = H5Screate_simple(1,dims,NULL); + + /* Create a dataset "dset1" */ + dataset_id = H5Dcreate(file2_id,"dset1",H5T_NATIVE_INT,space_id,H5P_DEFAULT); + + /* Write the data */ + status = H5Dwrite(dataset_id,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data2); + + /* Close */ + status = H5Dclose(dataset_id); + status = H5Sclose(space_id); + + + /*------------------------------------------------------------------------- + * Make dataset "dset2" on file2 + *------------------------------------------------------------------------- + */ + + /* Create a data space */ + space_id = H5Screate_simple(1,dims,NULL); + + /* Create a dataset "dset1" */ + dataset_id = H5Dcreate(file2_id,"dset2",H5T_NATIVE_INT,space_id,H5P_DEFAULT); + + /* Write the data */ + status = H5Dwrite(dataset_id,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data2); + + /* Close */ + status = H5Dclose(dataset_id); + status = H5Sclose(space_id); - hid_t file_id; - hid_t dataset_id; - hid_t space_id; - hsize_t dims1[1] = { 5 }; - int data1[5] = {1,1,1,1,1}; - hsize_t dims2[1] = { 5 }; - int data2[5] = {1,1,1,2,2}; - herr_t status; /*------------------------------------------------------------------------- - * Create one file + * Make dataset "g1/dset1" on file2 *------------------------------------------------------------------------- */ + + /* Create a data space */ + space_id = H5Screate_simple(1,dims,NULL); + + /* Create a group. */ + group_id = H5Gcreate(file2_id, "g1", 0); + + /* Create a dataset "g1/dset1" */ + dataset_id = H5Dcreate(group_id,"dset1",H5T_NATIVE_INT,space_id,H5P_DEFAULT); - /* Create a file */ - file_id = H5Fcreate ("h5diff_test1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + /* Write the data */ + status = H5Dwrite(dataset_id,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data2); + + /* Close */ + status = H5Dclose(dataset_id); + status = H5Gclose(group_id); + status = H5Sclose(space_id); + +/*------------------------------------------------------------------------- + * Make group "g2/g1" on file2 + *------------------------------------------------------------------------- + */ + + /* Create a group. */ + group_id = H5Gcreate(file2_id, "g2", 0); + group2_id = H5Gcreate(group_id, "g1", 0); + + /* Close */ + status = H5Gclose(group_id); + status = H5Gclose(group2_id); + +/*------------------------------------------------------------------------- + * Make dataset "dset4" on file2 + *------------------------------------------------------------------------- + */ /* Create a data space */ - space_id = H5Screate_simple(1,dims1,NULL); + space_id = H5Screate_simple(1,dims,NULL); /* Create a dataset "dset" */ - dataset_id = H5Dcreate(file_id,"dset",H5T_NATIVE_INT,space_id,H5P_DEFAULT); + dataset_id = H5Dcreate(file2_id,"dset4",H5T_NATIVE_FLOAT,space_id,H5P_DEFAULT); /* Write the data */ - status = H5Dwrite(dataset_id,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data1); + status = H5Dwrite(dataset_id,H5T_NATIVE_FLOAT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data4); - /* Close */ - status = H5Dclose(dataset_id); + /* Close */ + status = H5Dclose(dataset_id); status = H5Sclose(space_id); - status = H5Fclose(file_id); /*------------------------------------------------------------------------- - * Create another file + * Make dataset "dset5" on file1 *------------------------------------------------------------------------- */ - /* Create a file */ - file_id = H5Fcreate ("h5diff_test2.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); - /* Create a data space */ - space_id = H5Screate_simple(1,dims2,NULL); + space_id = H5Screate_simple(2,dims2,NULL); /* Create a dataset "dset" */ - dataset_id = H5Dcreate(file_id,"dset",H5T_NATIVE_INT,space_id,H5P_DEFAULT); + dataset_id = H5Dcreate(file1_id,"dset5",H5T_NATIVE_FLOAT,space_id,H5P_DEFAULT); + + /* Write the data */ + status = H5Dwrite(dataset_id,H5T_NATIVE_FLOAT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data5); - /* Write the data */ - status = H5Dwrite(dataset_id,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data2); + /* Close */ + status = H5Dclose(dataset_id); + status = H5Sclose(space_id); - /* Close */ - status = H5Dclose(dataset_id); +/*------------------------------------------------------------------------- + * Make dataset "dset6" on file2 + *------------------------------------------------------------------------- + */ + + /* Create a data space */ + space_id = H5Screate_simple(2,dims2,NULL); + + /* Create a dataset "dset" */ + dataset_id = H5Dcreate(file2_id,"dset6",H5T_NATIVE_FLOAT,space_id,H5P_DEFAULT); + + /* Write the data */ + status = H5Dwrite(dataset_id,H5T_NATIVE_FLOAT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data6); + + /* Close */ + status = H5Dclose(dataset_id); status = H5Sclose(space_id); - status = H5Fclose(file_id); + +/*------------------------------------------------------------------------- + * Close files + *------------------------------------------------------------------------- + */ + status = H5Fclose(file1_id); + status = H5Fclose(file2_id); - return 0; + return 0; } + + + diff --git a/tools/h5diff/h5difftst.c b/tools/h5diff/h5difftst.c index e0065f7..b839511 100644 --- a/tools/h5diff/h5difftst.c +++ b/tools/h5diff/h5difftst.c @@ -6,447 +6,11 @@ #include "hdf5.h" -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE 1 -#endif - -int do_test_files(); -int h5diff_dataset( hid_t file1_id, hid_t file2_id, const char *dset_name ); -void array_diff( void *buf1, void *buf2, hsize_t tot_cnt, hid_t type_id ); - - - - -/*------------------------------------------------------------------------- - * Function: usage - * - * Purpose: print a usage message - * - * Return: void - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: October 8, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ - -void usage( const char *progname ) -{ -#define USAGE "\ - [-d dset] Compare only the specified dataset(s)\n\ - file1 File name of the first HDF5 file\n\ - file2 File name of the second HDF5 file\n" - - fprintf(stderr, - "%s [-d] file1 file2\n%s", - progname, - USAGE); - exit(EXIT_FAILURE); -} - - -/*------------------------------------------------------------------------- - * Function: main - * - * Purpose: H5diff - * - * Return: Success: 0, Failure: 1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: October 8, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ int main(int argc, const char *argv[]) { - const char *progname = argv[0]; - int dset_only = FALSE; - int argno; - const char *s = NULL; - const char *file1_name = NULL; - const char *file2_name = NULL; - const char *dset_name = NULL; - hid_t file1_id, file2_id; - herr_t status; - - do_test_files(); - - -/*------------------------------------------------------------------------- - * parse command line options - *------------------------------------------------------------------------- - */ - - if (argc < 2) { - usage( progname ); - exit(EXIT_FAILURE); - } - - /* parse command line options */ - for (argno=1; argno<argc ; argno++) - { - - /* get the single-letter switches */ - if ( '-'==argv[argno][0] ) - { - - for (s=argv[argno]+1; *s; s++) - { - switch (*s) { - case 'h': - usage(progname); - exit(EXIT_SUCCESS); - case 'd': - dset_only = TRUE; - dset_name = argv[argno+1]; - break; - } /*switch*/ - } /*for*/ - } /*if*/ - - }/*for*/ - - -/*------------------------------------------------------------------------- - * process the files - *------------------------------------------------------------------------- - */ - - file1_name = argv[argno-2]; - file2_name = argv[argno-1]; - - /* Open the files */ - if ((file1_id=H5Fopen(file1_name,H5F_ACC_RDONLY,H5P_DEFAULT))<0 || - (file2_id=H5Fopen(file2_name,H5F_ACC_RDONLY,H5P_DEFAULT))<0) - exit(EXIT_FAILURE); - - if ( dset_only ) - { - - h5diff_dataset(file1_id,file2_id,dset_name); - - } - - - /* Close */ - status = H5Fclose(file1_id); - status = H5Fclose(file2_id); - - - + return 0; } - -/*------------------------------------------------------------------------- - * Function: h5diff_dataset - * - * Purpose: - * - * Return: Success: 0, Failure: -11 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: October 8, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ - - - -int h5diff_dataset( hid_t file1_id, hid_t file2_id, const char *dset_name ) -{ - - hid_t dset1_id, dset2_id; - hid_t space1_id, space2_id; - hid_t type1_id, type2_id; - hid_t rank1, rank2; - void *buf1, *buf2; - hsize_t tot_cnt, tot_cnt1, tot_cnt2; - hsize_t dims1[32], dims2[32]; - int i; - herr_t status; - -/*------------------------------------------------------------------------- - * open the handles - *------------------------------------------------------------------------- - */ - - /* Open the datasets */ - if ( (dset1_id = H5Dopen(file1_id,dset_name)) < 0 ) - return -1; - - if ( (dset2_id = H5Dopen(file2_id,dset_name)) < 0 ) - return -1; - - /* Get the datatype */ - if ( (type1_id = H5Dget_type(dset1_id)) < 0 ) - goto out; - - /* Get the datatype */ - if ( (type2_id = H5Dget_type(dset2_id)) < 0 ) - goto out; - - /* Get the dataspace handle */ - if ( (space1_id = H5Dget_space(dset1_id)) < 0 ) - return -1; - - /* Get rank */ - if ( (rank1 = H5Sget_simple_extent_ndims(space1_id)) < 0 ) - return -1; - - /* Get the dataspace handle */ - if ( (space2_id = H5Dget_space(dset2_id)) < 0 ) - return -1; - - /* Get rank */ - if ( (rank2 = H5Sget_simple_extent_ndims(space2_id)) < 0 ) - return -1; - - /* Get dimensions */ - if ( H5Sget_simple_extent_dims(space1_id,dims1,NULL) < 0 ) - goto out; - - /* Get dimensions */ - if ( H5Sget_simple_extent_dims(space2_id,dims2,NULL) < 0 ) - goto out; - - -/*------------------------------------------------------------------------- - * compare - *------------------------------------------------------------------------- - */ - - - printf("\n---------------------------\n"); - printf("Dataset Name: %s .... Comparing\n", dset_name); - - if ( rank1 != rank2 ) - { - goto out; - } - - tot_cnt1 = 1; - for (i = 0; i < rank1; i++) - { - tot_cnt1 *= dims1[i]; - } - - tot_cnt2 = 1; - for (i = 0; i < rank2; i++) - { - tot_cnt2 *= dims2[i]; - } - - buf1 = (void *) malloc((unsigned) (tot_cnt1*H5Tget_size(type1_id))); - buf2 = (void *) malloc((unsigned) (tot_cnt2*H5Tget_size(type2_id))); - - - if ( H5Dread(dset1_id,type1_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf1) < 0 ) - goto out; - - if ( H5Dread(dset2_id,type2_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf2) < 0 ) - goto out; - - if (tot_cnt1 > tot_cnt2) - tot_cnt = tot_cnt2; - else - tot_cnt = tot_cnt1; - - array_diff(buf1,buf2,tot_cnt,type1_id); - - - free((char *) buf1); - free((char *) buf2); - -/*------------------------------------------------------------------------- - * close - *------------------------------------------------------------------------- - */ - - -out: - - /* Close */ - status = H5Dclose(dset1_id); - status = H5Dclose(dset2_id); - status = H5Sclose(space1_id); - status = H5Sclose(space2_id); - status = H5Tclose(type1_id); - status = H5Tclose(type2_id); - - return 0; - -} - - - -/*------------------------------------------------------------------------- - * Function: array_diff - * - * Purpose: - * - * Return: Success: 0, Failure: -11 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: October 8, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ - - -void array_diff( void *buf1, void *buf2, hsize_t tot_cnt, hid_t type_id ) -{ - -#if 0 - char *i1ptr1, *i1ptr2; - short *i2ptr1, *i2ptr2; - float *fptr1, *fptr2; - double *dptr1, *dptr2; -#endif - - int *i4ptr1, *i4ptr2; - int i; - - H5T_class_t type_class; - size_t type_size; - - /* Get the class. */ - type_class = H5Tget_class( type_id ); - - /* Get the size. */ - type_size = H5Tget_size( type_id ); - - - switch(type_class) - { - case H5T_INTEGER: - - - switch(type_size) - { - case 4: - - i4ptr1 = (int *) buf1; - i4ptr2 = (int *) buf2; - for ( i = 0; i < tot_cnt; i++) - { - if (*i4ptr1 != *i4ptr2) - { - printf("Index: %d, File1: %d, File2: %d\n", i, *i4ptr1, *i4ptr2); - } - i4ptr1++; i4ptr2++; - } - - - - break; - - } /*switch*/ - - - - break; /* H5T_INTEGER */ - - - - } /*switch*/ - - - -} - - - - - -/*------------------------------------------------------------------------- - * do some test files - *------------------------------------------------------------------------- - */ - -int do_test_files() -{ - - hid_t file_id; - hid_t dataset_id; - hid_t space_id; - hsize_t dims1[1] = { 5 }; - int data1[5] = {1,2,3,4,5}; - hsize_t dims2[1] = { 5 }; - int data2[5] = {6,7,8,9,10}; - herr_t status; - -/*------------------------------------------------------------------------- - * Create one file - *------------------------------------------------------------------------- - */ - - /* Create a file */ - file_id = H5Fcreate ("h5diff_test1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); - - /* Create a data space */ - space_id = H5Screate_simple(1,dims1,NULL); - - /* Create a dataset "dset" */ - dataset_id = H5Dcreate(file_id,"dset",H5T_NATIVE_INT,space_id,H5P_DEFAULT); - - /* Write the data */ - status = H5Dwrite(dataset_id,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data1); - - /* Close */ - status = H5Dclose(dataset_id); - status = H5Sclose(space_id); - status = H5Fclose(file_id); - -/*------------------------------------------------------------------------- - * Create another file - *------------------------------------------------------------------------- - */ - - /* Create a file */ - file_id = H5Fcreate ("h5diff_test2.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); - - /* Create a data space */ - space_id = H5Screate_simple(1,dims2,NULL); - - /* Create a dataset "dset" */ - dataset_id = H5Dcreate(file_id,"dset",H5T_NATIVE_INT,space_id,H5P_DEFAULT); - - /* Write the data */ - status = H5Dwrite(dataset_id,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data2); - - /* Close */ - status = H5Dclose(dataset_id); - status = H5Sclose(space_id); - status = H5Fclose(file_id); - - - return 0; - - -} diff --git a/tools/h5diff/h5trav.c b/tools/h5diff/h5trav.c new file mode 100644 index 0000000..dad344d --- /dev/null +++ b/tools/h5diff/h5trav.c @@ -0,0 +1,594 @@ + +#include <stdio.h> +#include <stdlib.h> + +#include "hdf5.h" +#include "h5trav.h" + + + +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FAIL +#define FAIL -1 +#endif + + + +/* functions for traversal */ +int traverse( hid_t loc_id, const char *group_name, table_t *table, info_t *info, int *idx ); +herr_t get_nobjects( hid_t loc_id, const char *group_name ); +herr_t get_name_type( hid_t loc_id, const char *group_name, int idx, char **name, int *type ); + +/* table methods */ +void table_init( table_t **table ); +void table_free( table_t *table ); +int table_search(unsigned long *objno, table_t *table ); +void table_add(unsigned long *objno, char *objname, table_t *table ); + + + + +/*------------------------------------------------------------------------- + * Function: H5get_object_info + * + * Purpose: + * + * Return: Success: 0, Failure: -11 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 6, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +int H5get_object_info( hid_t file_id, info_t *info ) +{ + + table_t *table=NULL; + int nobjects=0; + + /* init table */ + table_init( &table ); + + /* iterate starting on the root group */ + if (( nobjects = traverse( file_id, "/", table, info, &nobjects )) < 0 ) + return -1; + + /* free table */ + table_free( table ); + + return nobjects; + +} + + + + +/*------------------------------------------------------------------------- + * Function: count_objects + * + * Purpose: operator function + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: October 10, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +static herr_t count_objects( hid_t loc_id, const char *name, void *op_data) +{ + + H5G_stat_t statbuf; + + if (H5Gget_objinfo( loc_id, name, FALSE, &statbuf) < 0 ) + return 1; + + (*(int *)op_data)++; + + /* Define a default zero value for return. This will cause the iterator to continue */ + return 0; +} + + + + +/*------------------------------------------------------------------------- + * Function: get_nobjects + * + * Purpose: Counts the number of objects in the group GROUP_NAME + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: October 10, 2002 + * + * Return: + * Success: The return value of the first operator that + * returns non-zero, or zero if all members were + * processed with no operator returning non-zero. + * + * Failure: Negative if something goes wrong within the + * library, or the negative value returned by one + * of the operators. + * + *------------------------------------------------------------------------- + */ + +herr_t get_nobjects( hid_t loc_id, const char *group_name ) +{ + + int nobjs = 0; + + if ( H5Giterate( loc_id, group_name, NULL, count_objects, (void *)&nobjs ) < 0 ) + return -1; + + return nobjs; +} + + + +/*------------------------------------------------------------------------- + * Function: opget_info + * + * Purpose: operator function + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: October 10, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +static herr_t opget_info( hid_t loc_id, const char *name, void *op_data) +{ + + H5G_stat_t statbuf; + + if (H5Gget_objinfo( loc_id, name, FALSE, &statbuf) < 0 ) + return 1; + + ((info_t *)op_data)->type = statbuf.type; + ((info_t *)op_data)->name = (char *)strdup(name); + + /* Define 1 for return. This will cause the iterator to stop */ + return 1; +} + + +/*------------------------------------------------------------------------- + * Function: get_name_type + * + * Purpose: + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: October 10, 2002 + * + * Return: + * Success: The return value of the first operator that + * returns non-zero, or zero if all members were + * processed with no operator returning non-zero. + * + * Failure: Negative if something goes wrong within the + * library, or the negative value returned by one + * of the operators. + * + *------------------------------------------------------------------------- + */ + +herr_t get_name_type( hid_t loc_id, const char *group_name, int idx, char **name, int *type ) +{ + + info_t info; + + if (H5Giterate( loc_id, group_name, &idx, opget_info, (void *)&info) < 0 ) + return -1; + + *name = info.name; + *type = info.type; + + return 0; +} + + + + + + + +/*------------------------------------------------------------------------- + * Function: traverse + * + * Purpose: + * + * Return: Success: 0, Failure: -11 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 4, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + + + +int traverse( hid_t loc_id, const char *group_name, table_t *table, info_t *info, int *idx ) +{ + + char *name=NULL; + int type; + int nobjs; + int i; + char *path=NULL; + H5G_stat_t statbuf; + int inserted_objs=0; + int j; + void *edata; + hid_t (*func)(void*); + + if (( nobjs = get_nobjects( loc_id, group_name )) < 0 ) + return -1; + + for ( i = 0; i < nobjs; i++) + { + + if (get_name_type( loc_id, group_name, i, &name, &type ) < 0 ) + return -1; + + /* allocate path buffer */ + path = (char*) malloc(strlen(group_name) + strlen(name) + 2); + + /* initialize path */ + strcpy( path, group_name ); + if ( strcmp(group_name,"/")!=0 ) + strcat( path, "/" ); + strcat( path, name ); + + + + /* disable error reporting */ + H5Eget_auto(&func, &edata); + H5Eset_auto(NULL, NULL); + + /* get info */ + H5Gget_objinfo( loc_id, path, TRUE, &statbuf); + H5Eset_auto(func, edata); + + /* add to array */ + if ( info ) + { + info[*idx].name = strdup(path); + info[*idx].type = type; + (*idx)++; + } + + + switch ( type ) + { + + /*------------------------------------------------------------------------- + * H5G_GROUP + *------------------------------------------------------------------------- + */ + + case H5G_GROUP: + + /* increment */ + inserted_objs++; + + /* nlink is number of hard links to object */ + if (statbuf.nlink > 0 && table_search(statbuf.objno, table ) == FAIL) + { + /* add object to table */ + table_add(statbuf.objno, path, table ); + + /* recurse with the absolute name */ + inserted_objs += traverse( loc_id, path, table, info, idx ); + } + + /* search table + group with more than one link to it */ + if (statbuf.nlink > 1) + { + if ((j = table_search(statbuf.objno, table )) < 0 ) + return -1; + + if ( table->objs[j].displayed == 0 ) + { + table->objs[j].displayed = 1; + } + else + { + printf("%s %s\n", "HARDLINK", table->objs[j].objname); + } + + } + + + + + + break; + + /*------------------------------------------------------------------------- + * H5G_DATASET + *------------------------------------------------------------------------- + */ + + case H5G_DATASET: + + + + /* increment */ + inserted_objs++; + + /* nlink is number of hard links to object */ + if (statbuf.nlink > 0 && table_search(statbuf.objno, table ) == FAIL) + { + /* add object to table */ + table_add(statbuf.objno, path, table ); + + } + + /* search table + dataset with more than one link to it */ + if (statbuf.nlink > 1) + { + if ((j = table_search(statbuf.objno, table )) < 0 ) + return -1; + + if ( table->objs[j].displayed == 0 ) + { + table->objs[j].displayed = 1; + } + else + { + printf("%s %s\n", "HARDLINK", table->objs[j].objname); + } + + } + + + break; + + /*------------------------------------------------------------------------- + * H5G_TYPE + *------------------------------------------------------------------------- + */ + + case H5G_TYPE: + + + + /* increment */ + inserted_objs++; + + /* nlink is number of hard links to object */ + if (statbuf.nlink > 0 && table_search(statbuf.objno, table ) == FAIL) + { + /* add object to table */ + table_add(statbuf.objno, path, table ); + + } + + break; + + + /*------------------------------------------------------------------------- + * H5G_LINK + *------------------------------------------------------------------------- + */ + + case H5G_LINK: + + + + /* increment */ + inserted_objs++; + + break; + + + default: + break; + + } + + /*------------------------------------------------------------------------- + * end switch + *------------------------------------------------------------------------- + */ + + if ( name ) + free( name ); + + if ( path ) + free( path ); + + } /* i */ + + + + return inserted_objs; +} + + + +/*------------------------------------------------------------------------- + * Function: table_search + * + * Purpose: + * + * Return: Success: 0, Failure: -11 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 4, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +int table_search(unsigned long *objno, table_t *table ) +{ + int i; + + for (i = 0; i < table->nobjs; i++) + if (table->objs[i].objno[0] == *objno && table->objs[i].objno[1] == *(objno + 1)) + return i; + + return FAIL; +} + + +/*------------------------------------------------------------------------- + * Function: table_add + * + * Purpose: + * + * Return: Success: 0, Failure: -11 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 4, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + + + +void table_add(unsigned long *objno, char *objname, table_t *table) +{ + int i; + + if (table->nobjs == table->size) { + table->size *= 2; + table->objs = (obj_t*)realloc(table->objs, table->size * sizeof(obj_t)); + + for (i = table->nobjs; i < table->size; i++) { + table->objs[i].objno[0] = table->objs[i].objno[1] = 0; + table->objs[i].displayed = 0; + table->objs[i].recorded = 0; + table->objs[i].objname = NULL; + } + } + + i = table->nobjs++; + table->objs[i].objno[0] = objno[0]; + table->objs[i].objno[1] = objno[1]; + free(table->objs[i].objname); + table->objs[i].objname = strdup(objname); + + +} + + +/*------------------------------------------------------------------------- + * Function: table_init + * + * Purpose: + * + * Return: Success: 0, Failure: -11 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 4, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +void table_init( table_t **tbl ) +{ + int i; + table_t* table = (table_t*) malloc(sizeof(table_t)); + + table->size = 20; + table->nobjs = 0; + table->objs = (obj_t*) malloc(table->size * sizeof(obj_t)); + + for (i = 0; i < table->size; i++) { + table->objs[i].objno[0] = table->objs[i].objno[1] = 0; + table->objs[i].displayed = 0; + table->objs[i].recorded = 0; + table->objs[i].objname = NULL; + } + + *tbl = table; +} + + + +/*------------------------------------------------------------------------- + * Function: table_free + * + * Purpose: + * + * Return: Success: 0, Failure: -11 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 4, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +void table_free( table_t *table ) +{ + + int i; + + +#if 0 + printf("Table: # of entries = %d\n", table->nobjs); + for ( i = 0; i < table->nobjs; i++) + printf("%lu %lu %s %d %d\n", table->objs[i].objno[0], + table->objs[i].objno[1], + table->objs[i].objname, + table->objs[i].displayed, table->objs[i].recorded); +#endif + + for ( i = 0; i < table->nobjs; i++) + free( table->objs[i].objname ); + + free(table->objs); + free(table); + +} diff --git a/tools/h5diff/h5trav.h b/tools/h5diff/h5trav.h new file mode 100644 index 0000000..2255b7f --- /dev/null +++ b/tools/h5diff/h5trav.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2001 National Center for Supercomputing Applications + * All rights reserved. + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * Monday, 4. November 2002 + */ +#ifndef H5TRAV_H__ +#define H5TRAV_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*struct to store name and type of an object */ +typedef struct info_t { + char *name; + int type; +} info_t; + + +/* public methods */ +int H5get_object_info( hid_t file_id, info_t *info ); + + + +/*struct to store basic info about an object */ +typedef struct obj_t { + unsigned long objno[2]; + char *objname; + int displayed; + int recorded; +} obj_t; + +/*struct that stores all objects, excluding shared objects */ +typedef struct table_t { + int size; + int nobjs; + obj_t *objs; +} table_t; + + +#ifdef __cplusplus +} +#endif + + +#endif /* H5TRAV_H__ */ |