From f2b52777f461e1f9e9fcdf9d1dc2520b96746382 Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Tue, 28 Oct 2003 12:40:05 -0500 Subject: [svn-r7769] Purpose: moved h5diff "public API" routines to tools/lib folder Platforms tested: linux solaris 2.7 IRIX Misc. update: --- MANIFEST | 17 +- tools/h5diff/Makefile.in | 13 +- tools/h5diff/h5diff.c | 420 ------------- tools/h5diff/h5diff.h | 134 ----- tools/h5diff/h5diff_array.c | 1101 ---------------------------------- tools/h5diff/h5diff_dset.c | 405 ------------- tools/h5diff/h5diff_util.c | 421 ------------- tools/h5diff/h5trav.c | 459 --------------- tools/h5diff/h5trav.h | 89 --- tools/h5diff/h5trav_table.c | 210 ------- tools/h5repack/Makefile.in | 17 +- tools/h5repack/h5repack.c | 19 +- tools/h5repack/h5repack.h | 20 +- tools/h5repack/h5repack_list.c | 44 +- tools/h5repack/h5repack_list.h | 10 +- tools/h5repack/h5repack_main.c | 2 +- tools/h5repack/h5repack_opttable.c | 12 +- tools/h5repack/h5repack_opttable.h | 10 +- tools/h5repack/test_h5repack_add.c | 2 +- tools/h5repack/test_h5repack_main.c | 18 +- tools/lib/Makefile.in | 4 +- tools/lib/h5diff.c | 424 ++++++++++++++ tools/lib/h5diff.h | 162 +++++ tools/lib/h5diff_array.c | 1107 +++++++++++++++++++++++++++++++++++ tools/lib/h5diff_dset.c | 408 +++++++++++++ tools/lib/h5diff_util.c | 409 +++++++++++++ tools/lib/h5trav.c | 461 +++++++++++++++ tools/lib/h5trav.h | 94 +++ tools/lib/h5trav_table.c | 193 ++++++ 29 files changed, 3351 insertions(+), 3334 deletions(-) delete mode 100644 tools/h5diff/h5diff.c delete mode 100644 tools/h5diff/h5diff.h delete mode 100644 tools/h5diff/h5diff_array.c delete mode 100644 tools/h5diff/h5diff_dset.c delete mode 100644 tools/h5diff/h5diff_util.c delete mode 100644 tools/h5diff/h5trav.c delete mode 100644 tools/h5diff/h5trav.h delete mode 100644 tools/h5diff/h5trav_table.c create mode 100644 tools/lib/h5diff.c create mode 100644 tools/lib/h5diff.h create mode 100644 tools/lib/h5diff_array.c create mode 100644 tools/lib/h5diff_dset.c create mode 100644 tools/lib/h5diff_util.c create mode 100644 tools/lib/h5trav.c create mode 100644 tools/lib/h5trav.h create mode 100644 tools/lib/h5trav_table.c diff --git a/MANIFEST b/MANIFEST index 775bec2..473f086 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1111,15 +1111,7 @@ ./tools/h5diff/Dependencies ./tools/h5diff/Makefile.in -./tools/h5diff/h5diff.c -./tools/h5diff/h5diff_array.c -./tools/h5diff/h5diff_dset.c ./tools/h5diff/h5diff_main.c -./tools/h5diff/h5diff_util.c -./tools/h5diff/h5trav.c -./tools/h5diff/h5trav_table.c -./tools/h5diff/h5trav.h -./tools/h5diff/h5diff.h ./tools/h5diff/test_h5diff.c ./tools/h5diff/testh5diff.sh @@ -1153,7 +1145,14 @@ ./tools/lib/h5tools_str.h ./tools/lib/h5tools_utils.c ./tools/lib/h5tools_utils.h -./tools/lib/talign.c +./tools/lib/h5diff.c +./tools/lib/h5diff_array.c +./tools/lib/h5diff_dset.c +./tools/lib/h5diff_util.c +./tools/lib/h5trav.c +./tools/lib/h5trav_table.c +./tools/lib/h5trav.h +./tools/lib/h5diff.h ./tools/misc/Dependencies ./tools/misc/Makefile.in diff --git a/tools/h5diff/Makefile.in b/tools/h5diff/Makefile.in index ae5b212..3726718 100644 --- a/tools/h5diff/Makefile.in +++ b/tools/h5diff/Makefile.in @@ -32,6 +32,7 @@ TEST_SCRIPTS=$(srcdir)/testh5diff.sh ## These are our main targets: library and tools. ## LIBHDF5=$(top_builddir)/src/libhdf5.la +LIBTOOLS=../lib/libh5tools.la PUB_PROGS=h5diff PROGS=$(PUB_PROGS) $(TEST_PROGS) @@ -48,11 +49,11 @@ MOSTLYCLEAN=*.h5 ## Source and object files for programs... ## -PROG_SRC=h5diff.c h5diff_array.c h5diff_dset.c h5diff_main.c h5diff_util.c h5trav.c h5trav_table.c test_h5diff.c +PROG_SRC= h5diff_main.c test_h5diff.c PROG_OBJ=$(PROG_SRC:.c=.lo) -OBJS=h5diff.lo h5diff_array.lo h5diff_dset.lo h5diff_main.lo h5diff_util.lo h5trav.lo h5trav_table.lo +OBJS= h5diff_main.lo -PRIVATE_HDR=h5trav.h h5diff.h +PRIVATE_HDR= ## Source and object files for the tests ## @@ -66,13 +67,13 @@ check test _test: $(PROGS) ## How to build the programs...They all depend on the hdf5 library and ## the tools library compiled in this directory. ## -$(PROGS): $(LIBHDF5) +$(PROGS): $(LIBTOOLS) $(LIBHDF5) h5diff: $(OBJS) - @$(LT_LINK_EXE) $(CFLAGS) -o $@ $(OBJS) $(LIBHDF5) $(LDFLAGS) $(LIBS) + @$(LT_LINK_EXE) $(CFLAGS) -o $@ $(OBJS) $(LIBTOOLS) $(LIBHDF5) $(LDFLAGS) $(LIBS) h5difftst: test_h5diff.lo - @$(LT_LINK_EXE) $(CFLAGS) -o $@ test_h5diff.lo $(LIBHDF5) $(LDFLAGS) $(LIBS) + @$(LT_LINK_EXE) $(CFLAGS) -o $@ test_h5diff.lo $(LIBTOOLS) $(LIBHDF5) $(LDFLAGS) $(LIBS) @CONCLUDE@ diff --git a/tools/h5diff/h5diff.c b/tools/h5diff/h5diff.c deleted file mode 100644 index 9ea7423..0000000 --- a/tools/h5diff/h5diff.c +++ /dev/null @@ -1,420 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - - -#include "h5diff.h" -#include -#include - - - -/*------------------------------------------------------------------------- - * Function: h5diff - * - * Purpose: public function, can be called in an applicattion program. - * return differences between 2 HDF5 files - * - * Return: An exit status of 0 means no differences were found, 1 means some - * differences were found. - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: October 22, 2003 - * - *------------------------------------------------------------------------- - */ - -int h5diff(const char *fname1, - const char *fname2, - const char *objname1, - const char *objname2, - options_t options) -{ - int nobjects1, nobjects2; - info_t *info1=NULL; - info_t *info2=NULL; - hid_t file1_id, file2_id; - int nfound; - - -/*------------------------------------------------------------------------- - * open the files first; if they are not valid, no point in continuing - *------------------------------------------------------------------------- - */ - - /* disable error reporting */ - H5E_BEGIN_TRY { - - /* Open the files */ - if ((file1_id=H5Fopen(fname1,H5F_ACC_RDONLY,H5P_DEFAULT))<0 ) - { - printf("h5diff: %s: No such file or directory\n", fname1 ); - exit(1); - } - if ((file2_id=H5Fopen(fname2,H5F_ACC_RDONLY,H5P_DEFAULT))<0 ) - { - printf("h5diff: %s: No such file or directory\n", fname2 ); - exit(1); - } - /* enable error reporting */ - } H5E_END_TRY; - - -/*------------------------------------------------------------------------- - * 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)); - if (info1==NULL || info2==NULL) - return 0; - - H5get_object_info( file1_id, info1 ); - H5get_object_info( file2_id, info2 ); - -/*------------------------------------------------------------------------- - * object name was supplied - *------------------------------------------------------------------------- - */ - - if ( objname1 ) - { - assert(objname2); - nfound=compare(file1_id,fname1,objname1,nobjects1,info1, - file2_id,fname2,objname2,nobjects2,info2,options); - } - -/*------------------------------------------------------------------------- - * compare all - *------------------------------------------------------------------------- - */ - - else - { - nfound=match(file1_id,nobjects1,info1, - file2_id,nobjects2,info2,options); - } - - - info_free(info1,nobjects1); - info_free(info2,nobjects2); - /* close */ - assert( (H5Fclose(file1_id)) >=0); - assert( (H5Fclose(file2_id)) >=0); - - return nfound; -} - - - -/*------------------------------------------------------------------------- - * Function: match - * - * Purpose: Find common objects; the algorithm used for this search is the - * cosequential match algorithm and is described in - * Folk, Michael; Zoellick, Bill. (1992). File Structures. Addison-Wesley. - * - * Return: Number of differences found - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: May 9, 2003 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -int match( hid_t file1_id, int nobjects1, info_t *info1, - hid_t file2_id, int nobjects2, info_t *info2, - options_t options ) -{ - int cmp; - int more_names_exist = (nobjects1>0 && nobjects2>0) ? 1 : 0; - int curr1=0; - int curr2=0; - int i; - /*build a common list */ - table_t *table=NULL; - unsigned infile[2]; - char c1, c2; - int nfound=0; - -/*------------------------------------------------------------------------- - * build the list - *------------------------------------------------------------------------- - */ - table_init( &table ); - - - while ( more_names_exist ) - { - /* criteria is string compare */ - cmp = strcmp( info1[curr1].name, info2[curr2].name ); - if ( cmp == 0 ) - { - infile[0]=1; infile[1]=1; - table_add_flags(infile, info1[curr1].name, info1[curr1].type, table ); - - curr1++; - curr2++; - } - else if ( cmp < 0 ) - { - infile[0]=1; infile[1]=0; - table_add_flags(infile, info1[curr1].name, info1[curr1].type, table ); - curr1++; - } - else - { - infile[0]=0; infile[1]=1; - table_add_flags(infile, info2[curr2].name, info2[curr2].type, table ); - curr2++; - } - - more_names_exist = (curr1nobjs; i++) - { - c1 = (table->objs[i].flags[0]) ? 'x' : ' '; - c2 = (table->objs[i].flags[1]) ? 'x' : ' '; - printf("%5c %6c %-15s\n", c1, c2, table->objs[i].objname); - } - printf("\n"); - } - - -/*------------------------------------------------------------------------- - * do the diff for common objects - *------------------------------------------------------------------------- - */ - - for (i = 0; i < table->nobjs; i++) - { - if ( table->objs[i].flags[0] && table->objs[i].flags[1] ) - nfound+=diff( file1_id, table->objs[i].objname, - file2_id, table->objs[i].objname, - options, table->objs[i].type ); - } - - /* free table */ - table_free(table); - return nfound; -} - - -/*------------------------------------------------------------------------- - * Function: compare - * - * Purpose: get objects form list, and check for the same type - * - * Return: Number of differences found - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: May 9, 2003 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ - -int compare( hid_t file1_id, const char *file1_name, const char *obj1_name, - int nobjects1, info_t *info1, - hid_t file2_id, const char *file2_name, const char *obj2_name, - int nobjects2, info_t *info2, - options_t options ) -{ - - int f1=0, f2=0; - int nfound=0; - - int i = info_getindex( obj1_name, nobjects1, info1 ); - int j = info_getindex( obj2_name, nobjects2, info2 ); - - if ( i == -1 ) - { - printf( "Object <%s> could not be found in <%s>\n", obj1_name, file1_name ); - f1=1; - } - if ( j == -1 ) - { - printf( "Object <%s> could not be found in <%s>\n", obj2_name, file2_name ); - f2=1; - } - if ( f1 || f2 ) - return -1; - - /* use the name with "/" first, as obtained by iterator function */ - obj1_name=info1[i].name; - obj2_name=info2[j].name; - - /* objects are not the same type */ - if ( info1[i].type != info2[j].type ) - { - printf("Comparison not supported\n"); - printf("<%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; - } - - nfound=diff( file1_id, obj1_name, file2_id, obj2_name, options, info1[i].type ); - - return nfound; -} - - -/*------------------------------------------------------------------------- - * Function: diff - * - * Purpose: switch between types and choose the diff function - * - * Return: Number of differences found - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: May 9, 2003 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ - -int diff( hid_t file1_id, const char *obj1_name, hid_t file2_id, const char *obj2_name, - options_t options, int type ) -{ - int nfound=0; - - switch ( type ) - { - case H5G_DATASET: - nfound=diff_dataset(file1_id,file2_id,obj1_name,obj2_name,options); - break; - - default: - 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) ); - break; - } - - if (options.verbose) - printf("\n"); - return nfound; -} - - -/*------------------------------------------------------------------------- - * Function: list - * - * Purpose: print list of objects in file - * - * Return: void - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: May 9, 2003 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -#ifdef NOT_YET -void list( const char *filename, int nobjects, info_t *info ) -{ - int i; - - printf("File <%s>: # of entries = %d\n", filename, nobjects ); - for ( i = 0; i < nobjects; i++) - { - switch ( info[i].type ) - { - case H5G_GROUP: - printf("%s %20s\n", info[i].name, "group" ); - break; - case H5G_DATASET: - printf("%s %20s\n", info[i].name, "dataset" ); - break; - case H5G_TYPE: - printf("%s %20s\n", info[i].name, "datatype" ); - break; - case H5G_LINK: - printf("%s %20s\n", info[i].name, "link" ); - break; - default: - printf("%s %20s\n", info[i].name, "User defined object" ); - break; - } - } - -} -#endif - - - - - diff --git a/tools/h5diff/h5diff.h b/tools/h5diff/h5diff.h deleted file mode 100644 index 6a244e8..0000000 --- a/tools/h5diff/h5diff.h +++ /dev/null @@ -1,134 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#ifndef H5DIFF_H__ -#define H5DIFF_H__ - -#include "hdf5.h" -#include "h5trav.h" - - -#if 0 -#define H5DIFF_DEBUG -#endif - - -/*------------------------------------------------------------------------- - * printf formatting - *------------------------------------------------------------------------- - */ - -#define FFORMAT "%-15.10g %-15.10g %-15.10g\n" -#define IFORMAT "%-15d %-15d %-15d\n" -#define UIFORMAT "%-15u %-15u %-15u\n" -#define LIFORMAT "%-15ld %-15ld %-15ld\n" -#define ULIFORMAT "%-15lu %-15lu %-15lu\n" -/* with -p option */ -#define FPFORMAT "%-15.10g %-15.10g %-15.10g %-14.10g\n" -#define IPFORMAT "%-15d %-15d %-15d %-14d\n" -#define UIPFORMAT "%-15u %-15u %-15u %-14u\n" -#define LPIFORMAT "%-15ld %-15ld %-15ld %-14ld\n" -#define ULPIFORMAT "%-15lu %-15lu %-15lu %-14lu\n" -#define SPACES " " - - -/*------------------------------------------------------------------------- - * command line options - *------------------------------------------------------------------------- - */ - -typedef struct { - int r; /* report only what objects differ */ - int d; /* delta */ - double delta; /* delta value */ - int p; /* relative error */ - double percent; /* relative error value */ - int n; /* count */ - int count; /* count value */ - int verbose; /* print information */ -} options_t; - - - -/*------------------------------------------------------------------------- - * public functions - *------------------------------------------------------------------------- - */ - -#ifdef __cplusplus -extern "C" { -#endif - -int h5diff(const char *fname1, - const char *fname2, - const char *objname1, - const char *objname2, - options_t options); - - -#ifdef __cplusplus -} -#endif - - - -/*------------------------------------------------------------------------- - * private functions - *------------------------------------------------------------------------- - */ - - -int diff_dataset( hid_t file1_id, hid_t file2_id, const char *obj1_name, - const char *obj2_name, options_t options ); -int diff( hid_t file1_id, const char *obj1_name, hid_t file2_id, const char *obj2_name, - options_t options, int type ); -int compare( hid_t file1_id, const char *file1_name, const char *obj1_name, - int nobjects1, info_t *info1, - hid_t file2_id, const char *file2_name, const char *obj2_name, - int nobjects2, info_t *info2, - options_t options ); -int match( hid_t file1_id, int nobjects1, info_t *info1, - hid_t file2_id, int nobjects2, info_t *info2, options_t options ); -int array_diff( void *buf1, void *buf2, hsize_t tot_cnt, int rank, hsize_t *dims, - options_t options, const char *obj1, const char *obj2, - hid_t m_type ); - -/*------------------------------------------------------------------------- - * utility functions - *------------------------------------------------------------------------- - */ - -int h5diff_can_diff( hid_t type_id ); -void print_datatype(hid_t type); -const char* h5diff_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 ); - -#if defined (H5DIFF_DEBUG) -void print_sizes( const char *obj1, const char *obj2, - hid_t f_type1, hid_t f_type2, - hid_t m_type1, hid_t m_type2 ); -#endif - -#ifdef NOT_YET -void list( const char *filename, int nobjects, info_t *info ); -#endif /* NOT_YET */ - - - -#endif /* H5DIFF_H__ */ diff --git a/tools/h5diff/h5diff_array.c b/tools/h5diff/h5diff_array.c deleted file mode 100644 index 807cecf..0000000 --- a/tools/h5diff/h5diff_array.c +++ /dev/null @@ -1,1101 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - - -#include "h5diff.h" -#include "H5private.h" -#include -#include - - - -/*------------------------------------------------------------------------- - * Function: array_diff - * - * Purpose: compare array; - * currenttly only the NATIVE types below are supported - * - * Return: number of differences found - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: May 30, 2003 - * - *------------------------------------------------------------------------- - */ -int array_diff( void *buf1, void *buf2, hsize_t tot_cnt, int rank, hsize_t *dims, - options_t options, const char *obj1, const char *obj2, - hid_t m_type ) -{ - char fmt_llong[255], fmt_ullong[255]; - char fmt_llongp[255], fmt_ullongp[255]; - size_t type_size;/* just check */ - int nfound=0; /* number of differences found */ - int ph=1; /* print header */ - int acc[32]; /* accumulator and matrix position */ - int pos[32]; - unsigned i; - int j; - char *_buf1 = (char*)buf1; - char *_buf2 = (char*)buf2; - - - /* Build default formats for long long types */ - sprintf(fmt_llong, "%%%sd %%%sd %%%sd\n", - H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH); - sprintf(fmt_ullong, "%%%su %%%su %%%su\n", - H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH); - sprintf(fmt_llongp, "%%%sd %%%sd %%%sd %%%sd\n", - H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH); - sprintf(fmt_ullongp, "%%%su %%%su %%%su %%%su\n", - H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH); - - - acc[rank-1]=1; - for(j=(rank-2); j>=0; j--) - { - acc[j]=acc[j+1]*(int)dims[j+1]; - } - - /* Get the size. */ - type_size = H5Tget_size( m_type ); - -/*------------------------------------------------------------------------- - * H5T_NATIVE_SCHAR - *------------------------------------------------------------------------- - */ - if (H5Tequal(m_type, H5T_NATIVE_SCHAR)) - { - char temp1_char; - char temp2_char; - assert(type_size==sizeof(char)); - for ( i = 0; i < tot_cnt; i++) - { - memcpy(&temp1_char, _buf1, sizeof(char)); - memcpy(&temp2_char, _buf2, sizeof(char)); - /* -d and !-p */ - if (options.d && !options.p) - { - if (abs(temp1_char-temp2_char) > options.delta) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(IFORMAT,temp1_char,temp2_char,abs(temp1_char-temp2_char)); - } - nfound++; - } - } - /* !-d and -p */ - else if (!options.d && options.p) - { - if ( temp1_char!=0 && abs(1-temp2_char/temp1_char) > options.percent ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - /* -d and -p */ - else if ( options.d && options.p) - { - if ( temp1_char!=0 && abs(1-temp2_char/temp1_char) > options.percent && - abs(temp1_char-temp2_char) > options.delta ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - else if (temp1_char != temp2_char) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(IFORMAT,temp1_char,temp2_char,abs(temp1_char-temp2_char)); - } - nfound++; - } - - _buf1+=sizeof(char); - _buf2+=sizeof(char); - }/* i */ - - } /*H5T_NATIVE_SCHAR*/ - - -/*------------------------------------------------------------------------- - * H5T_NATIVE_UCHAR - *------------------------------------------------------------------------- - */ - else if (H5Tequal(m_type, H5T_NATIVE_UCHAR)) - { - unsigned char temp1_uchar; - unsigned char temp2_uchar; - assert(type_size==sizeof(unsigned char)); - for ( i = 0; i < tot_cnt; i++) - { - memcpy(&temp1_uchar, _buf1, sizeof(unsigned char)); - memcpy(&temp2_uchar, _buf2, sizeof(unsigned char)); - /* -d and !-p */ - if (options.d && !options.p) - { - if (abs(temp1_uchar-temp2_uchar) > options.delta) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(IFORMAT,temp1_uchar,temp2_uchar,abs(temp1_uchar-temp2_uchar)); - } - nfound++; - } - } - /* !-d and -p */ - else if (!options.d && options.p) - { - if ( temp1_uchar!=0 && abs(1-temp2_uchar/temp1_uchar) > options.percent ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - /* -d and -p */ - else if ( options.d && options.p) - { - if ( temp1_uchar!=0 && abs(1-temp2_uchar/temp1_uchar) > options.percent && - abs(temp1_uchar-temp2_uchar) > options.delta ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - else if (temp1_uchar != temp2_uchar) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(IFORMAT,temp1_uchar,temp2_uchar,abs(temp1_uchar-temp2_uchar)); - } - nfound++; - } - - _buf1+=sizeof(unsigned char); - _buf2+=sizeof(unsigned char); - }/* i */ - - } /*H5T_NATIVE_UCHAR*/ - - -/*------------------------------------------------------------------------- - * H5T_NATIVE_SHORT - *------------------------------------------------------------------------- - */ - - else if (H5Tequal(m_type, H5T_NATIVE_SHORT)) - { - short temp1_short; - short temp2_short; - assert(type_size==sizeof(short)); - for ( i = 0; i < tot_cnt; i++) - { - memcpy(&temp1_short, _buf1, sizeof(short)); - memcpy(&temp2_short, _buf2, sizeof(short)); - /* -d and !-p */ - if (options.d && !options.p) - { - if (abs(temp1_short-temp2_short) > options.delta) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(IFORMAT,temp1_short,temp2_short,abs(temp1_short-temp2_short)); - } - nfound++; - } - } - /* !-d and -p */ - else if (!options.d && options.p) - { - if ( temp1_short!=0 && abs(1-temp2_short/temp1_short) > options.percent ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - /* -d and -p */ - else if ( options.d && options.p) - { - if ( temp1_short!=0 && abs(1-temp2_short/temp1_short) > options.percent && - abs(temp1_short-temp2_short) > options.delta ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - else if (temp1_short != temp2_short) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(IFORMAT,temp1_short,temp2_short,abs(temp1_short-temp2_short)); - } - nfound++; - } - - _buf1+=sizeof(short); - _buf2+=sizeof(short); - }/* i */ - - } /*H5T_NATIVE_SHORT*/ - -/*------------------------------------------------------------------------- - * H5T_NATIVE_USHORT - *------------------------------------------------------------------------- - */ - - else if (H5Tequal(m_type, H5T_NATIVE_USHORT)) - { - unsigned short temp1_ushort; - unsigned short temp2_ushort; - assert(type_size==sizeof(short)); - for ( i = 0; i < tot_cnt; i++) - { - memcpy(&temp1_ushort, _buf1, sizeof(unsigned short)); - memcpy(&temp2_ushort, _buf2, sizeof(unsigned short)); - /* -d and !-p */ - if (options.d && !options.p) - { - if (abs(temp1_ushort-temp2_ushort) > options.delta) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(IFORMAT,temp1_ushort,temp2_ushort,abs(temp1_ushort-temp2_ushort)); - } - nfound++; - } - } - /* !-d and -p */ - else if (!options.d && options.p) - { - if ( temp1_ushort!=0 && abs(1-temp2_ushort/temp1_ushort) > options.percent ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - /* -d and -p */ - else if ( options.d && options.p) - { - if ( temp1_ushort!=0 && abs(1-temp2_ushort/temp1_ushort) > options.percent && - abs(temp1_ushort-temp2_ushort) > options.delta ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - else if (temp1_ushort != temp2_ushort) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(IFORMAT,temp1_ushort,temp2_ushort,abs(temp1_ushort-temp2_ushort)); - } - nfound++; - } - - _buf1+=sizeof(unsigned short); - _buf2+=sizeof(unsigned short); - }/* i */ - - } /*H5T_NATIVE_USHORT*/ - - -/*------------------------------------------------------------------------- - * H5T_NATIVE_INT - *------------------------------------------------------------------------- - */ - - else if (H5Tequal(m_type, H5T_NATIVE_INT)) - { - int temp1_int; - int temp2_int; - assert(type_size==sizeof(int)); - for ( i = 0; i < tot_cnt; i++) - { - memcpy(&temp1_int, _buf1, sizeof(int)); - memcpy(&temp2_int, _buf2, sizeof(int)); - /* -d and !-p */ - if (options.d && !options.p) - { - if (abs(temp1_int-temp2_int) > options.delta) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(IFORMAT,temp1_int,temp2_int,abs(temp1_int-temp2_int)); - } - nfound++; - } - } - /* !-d and -p */ - else if (!options.d && options.p) - { - if ( temp1_int!=0 && abs(1-temp2_int/temp1_int) > options.percent ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - /* -d and -p */ - else if ( options.d && options.p) - { - if ( temp1_int!=0 && abs(1-temp2_int/temp1_int) > options.percent && - abs(temp1_int-temp2_int) > options.delta ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - else if (temp1_int != temp2_int) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(IFORMAT,temp1_int,temp2_int,abs(temp1_int-temp2_int)); - } - nfound++; - } - - _buf1+=sizeof(int); - _buf2+=sizeof(int); - }/* i */ - - } /*H5T_NATIVE_INT*/ - - -/*------------------------------------------------------------------------- - * H5T_NATIVE_UINT - *------------------------------------------------------------------------- - */ - - else if (H5Tequal(m_type, H5T_NATIVE_UINT)) - { - unsigned int temp1_uint; - unsigned int temp2_uint; - assert(type_size==sizeof(int)); - for ( i = 0; i < tot_cnt; i++) - { - memcpy(&temp1_uint, _buf1, sizeof(unsigned int)); - memcpy(&temp2_uint, _buf2, sizeof(unsigned int)); - /* -d and !-p */ - if (options.d && !options.p) - { - if (abs((int)(temp1_uint-temp2_uint)) > options.delta) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(UIFORMAT,temp1_uint,temp2_uint,abs((int)(temp1_uint-temp2_uint))); - } - nfound++; - } - } - /* !-d and -p */ - else if (!options.d && options.p) - { - if ( temp1_uint!=0 && abs((int)(1-temp2_uint/temp1_uint)) > options.percent ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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))); - } - nfound++; - } - } - /* -d and -p */ - else if ( options.d && options.p) - { - if ( temp1_uint!=0 && abs((int)(1-temp2_uint/temp1_uint)) > options.percent && - abs((int)(temp1_uint-temp2_uint)) > options.delta ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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))); - } - nfound++; - } - } - else if (temp1_uint != temp2_uint) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(UIFORMAT,temp1_uint,temp2_uint,abs((int)(temp1_uint-temp2_uint))); - } - nfound++; - } - - _buf1+=sizeof(unsigned int); - _buf2+=sizeof(unsigned int); - }/* i */ - - } /*H5T_NATIVE_UINT*/ - - -/*------------------------------------------------------------------------- - * H5T_NATIVE_LONG - *------------------------------------------------------------------------- - */ - - else if (H5Tequal(m_type, H5T_NATIVE_LONG)) - { - long temp1_long; - long temp2_long; - assert(type_size==sizeof(long)); - for ( i = 0; i < tot_cnt; i++) - { - memcpy(&temp1_long, _buf1, sizeof(long)); - memcpy(&temp2_long, _buf2, sizeof(long)); - /* -d and !-p */ - if (options.d && !options.p) - { - if (labs(temp1_long-temp2_long) > (long)options.delta) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(LIFORMAT,temp1_long,temp2_long,labs(temp1_long-temp2_long)); - } - nfound++; - } - } - /* !-d and -p */ - else if (!options.d && options.p) - { - if ( temp1_long!=0 && labs(1-temp2_long/temp1_long) > (long)options.percent ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - /* -d and -p */ - else if ( options.d && options.p) - { - if ( temp1_long!=0 && labs(1-temp2_long/temp1_long) > (long)options.percent && - labs(temp1_long-temp2_long) > (long)options.delta ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - else if (temp1_long != temp2_long) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(LIFORMAT,temp1_long,temp2_long,labs(temp1_long-temp2_long)); - } - nfound++; - } - - _buf1+=sizeof(long); - _buf2+=sizeof(long); - }/* i */ - - } /*H5T_NATIVE_LONG*/ - -/*------------------------------------------------------------------------- - * H5T_NATIVE_ULONG - *------------------------------------------------------------------------- - */ - - else if (H5Tequal(m_type, H5T_NATIVE_ULONG)) - { - unsigned long temp1_ulong; - unsigned long temp2_ulong; - assert(type_size==sizeof(unsigned long)); - for ( i = 0; i < tot_cnt; i++) - { - memcpy(&temp1_ulong, _buf1, sizeof(unsigned long)); - memcpy(&temp2_ulong, _buf2, sizeof(unsigned long)); - /* -d and !-p */ - if (options.d && !options.p) - { - if (labs((long)(temp1_ulong-temp2_ulong)) > (long)options.delta) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(ULIFORMAT,temp1_ulong,temp2_ulong,labs((long)(temp1_ulong-temp2_ulong))); - } - nfound++; - } - } - /* !-d and -p */ - else if (!options.d && options.p) - { - if ( temp1_ulong!=0 && labs((long)(1-temp2_ulong/temp1_ulong)) > (long)options.percent ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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))); - } - nfound++; - } - } - /* -d and -p */ - else if ( options.d && options.p) - { - if ( temp1_ulong!=0 && labs((long)(1-temp2_ulong/temp1_ulong)) > (long)options.percent && - labs((long)(temp1_ulong-temp2_ulong)) > (long)options.delta ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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))); - } - nfound++; - } - } - else if (temp1_ulong != temp2_ulong) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(ULIFORMAT,temp1_ulong,temp2_ulong,labs((long)(temp1_ulong-temp2_ulong))); - } - nfound++; - } - - _buf1+=sizeof(unsigned long); - _buf2+=sizeof(unsigned long); - }/* i */ - - } /*H5T_NATIVE_ULONG*/ - -/*------------------------------------------------------------------------- - * H5T_NATIVE_LLONG - *------------------------------------------------------------------------- - */ - - else if (H5Tequal(m_type, H5T_NATIVE_LLONG)) - { - long_long temp1_llong; - long_long temp2_llong; - assert(type_size==sizeof(long_long)); - for ( i = 0; i < tot_cnt; i++) - { - memcpy(&temp1_llong, _buf1, sizeof(long_long)); - memcpy(&temp2_llong, _buf2, sizeof(long_long)); - /* -d and !-p */ - if (options.d && !options.p) - { - if (labs((long)(temp1_llong-temp2_llong)) > (long)options.delta) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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))); - } - nfound++; - } - } - /* !-d and -p */ - else if (!options.d && options.p) - { - if ( temp1_llong!=0 && labs((long)(1-temp2_llong/temp1_llong)) > (long)options.percent ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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))); - } - nfound++; - } - } - /* -d and -p */ - else if ( options.d && options.p) - { - if ( temp1_llong!=0 && labs((long)(1-temp2_llong/temp1_llong)) > (long)options.percent && - labs((long)(temp1_llong-temp2_llong)) > (long)options.delta ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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))); - } - nfound++; - } - } - else if (temp1_llong != temp2_llong) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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))); - } - nfound++; - } - - _buf1+=sizeof(long_long); - _buf2+=sizeof(long_long); - }/* i */ - - } /*H5T_NATIVE_LLONG*/ - -/*------------------------------------------------------------------------- - * H5T_NATIVE_ULLONG - *------------------------------------------------------------------------- - */ - - else if (H5Tequal(m_type, H5T_NATIVE_ULLONG)) - { - unsigned long_long temp1_ullong; - unsigned long_long temp2_ullong; - assert(type_size==sizeof(unsigned long_long)); - for ( i = 0; i < tot_cnt; i++) - { - memcpy(&temp1_ullong, _buf1, sizeof(unsigned long_long)); - memcpy(&temp2_ullong, _buf2, sizeof(unsigned long_long)); - /* -d and !-p */ - if (options.d && !options.p) - { - if (labs((long)(temp1_ullong-temp2_ullong)) > (long)options.delta) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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))); - } - nfound++; - } - } - /* !-d and -p */ - else if (!options.d && options.p) - { - if ( temp1_ullong!=0 && labs((long)(1-temp2_ullong/temp1_ullong)) > (long)options.percent ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)), - (unsigned long_long)labs((long)(1-temp2_ullong/temp1_ullong))); - } - nfound++; - } - } - /* -d and -p */ - else if ( options.d && options.p) - { - if ( temp1_ullong!=0 && labs((long)(1-temp2_ullong/temp1_ullong)) > (long)options.percent && - labs((long)(temp1_ullong-temp2_ullong)) > (long)options.delta ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)), - (unsigned long_long)labs((long)(1-temp2_ullong/temp1_ullong))); - } - nfound++; - } - } - else if (temp1_ullong != temp2_ullong) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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))); - } - nfound++; - } - - _buf1+=sizeof(unsigned long_long); - _buf2+=sizeof(unsigned long_long); - }/* i */ - - } /*H5T_NATIVE_ULLONG*/ - -/*------------------------------------------------------------------------- - * H5T_NATIVE_FLOAT - *------------------------------------------------------------------------- - */ - - else if (H5Tequal(m_type, H5T_NATIVE_FLOAT)) - { - float temp1_float; - float temp2_float; - assert(type_size==sizeof(float)); - for ( i = 0; i < tot_cnt; i++) - { - memcpy(&temp1_float, _buf1, sizeof(float)); - memcpy(&temp2_float, _buf2, sizeof(float)); - /* -d and !-p */ - if (options.d && !options.p) - { - if (fabs(temp1_float-temp2_float) > options.delta) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(FFORMAT,temp1_float,temp2_float,fabs(temp1_float-temp2_float)); - } - nfound++; - } - } - /* !-d and -p */ - else if (!options.d && options.p) - { - if ( temp1_float!=0 && fabs(1-temp2_float/temp1_float) > options.percent ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - /* -d and -p */ - else if ( options.d && options.p) - { - if ( temp1_float!=0 && fabs(1-temp2_float/temp1_float) > options.percent && - fabs(temp1_float-temp2_float) > options.delta ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - else if (temp1_float != temp2_float) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(FFORMAT,temp1_float,temp2_float,fabs(temp1_float-temp2_float)); - } - nfound++; - } - - _buf1+=sizeof(float); - _buf2+=sizeof(float); - }/* i */ - - } /*H5T_NATIVE_FLOAT*/ - -/*------------------------------------------------------------------------- - * H5T_NATIVE_DOUBLE - *------------------------------------------------------------------------- - */ - - else if (H5Tequal(m_type, H5T_NATIVE_DOUBLE)) - { - double temp1_double; - double temp2_double; - assert(type_size==sizeof(double)); - for ( i = 0; i < tot_cnt; i++) - { - memcpy(&temp1_double, _buf1, sizeof(double)); - memcpy(&temp2_double, _buf2, sizeof(double)); - /* -d and !-p */ - if (options.d && !options.p) - { - if (fabs(temp1_double-temp2_double) > options.delta) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(FFORMAT,temp1_double,temp2_double,fabs(temp1_double-temp2_double)); - } - nfound++; - } - } - /* !-d and -p */ - else if (!options.d && options.p) - { - if ( temp1_double!=0 && fabs(1-temp2_double/temp1_double) > options.percent ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - /* -d and -p */ - else if ( options.d && options.p) - { - if ( temp1_double!=0 && fabs(1-temp2_double/temp1_double) > options.percent && - fabs(temp1_double-temp2_double) > options.delta ) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - 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)); - } - nfound++; - } - } - else if (temp1_double != temp2_double) - { - if (options.n && nfound>=options.count) - return nfound; - if ( options.r==0 ) - { - print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); - printf(SPACES); - printf(FFORMAT,temp1_double,temp2_double,fabs(temp1_double-temp2_double)); - } - nfound++; - } - - _buf1+=sizeof(double); - _buf2+=sizeof(double); - }/* i */ - - } /*H5T_NATIVE_DOUBLE*/ - -/*------------------------------------------------------------------------- - * no more - *------------------------------------------------------------------------- - */ - else - { - assert(0); - } - - return nfound; -} - - diff --git a/tools/h5diff/h5diff_dset.c b/tools/h5diff/h5diff_dset.c deleted file mode 100644 index 1ecfb2a..0000000 --- a/tools/h5diff/h5diff_dset.c +++ /dev/null @@ -1,405 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#include "h5diff.h" -#include "H5private.h" -#include - - - -/*------------------------------------------------------------------------- - * Function: diff_dataset - * - * 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 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -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 =-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[32], dims2[32]; - hsize_t maxdim1[32], maxdim2[32]; - H5T_class_t tclass1; - H5T_class_t tclass2; - 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 */ - int i; - - - /* disable error reporting */ - H5E_BEGIN_TRY { - -/*------------------------------------------------------------------------- - * open the handles - *------------------------------------------------------------------------- - */ - - /* Open the datasets */ - if ( (dset1_id = H5Dopen(file1_id,obj1_name)) < 0 ) - { - printf("Cannot open dataset <%s>\n", obj1_name ); - goto out; - } - if ( (dset2_id = H5Dopen(file2_id,obj2_name)) < 0 ) - { - printf("Cannot open dataset <%s>\n", obj2_name ); - goto out; - } - /* enable error reporting */ - } H5E_END_TRY; - - /* Get the dataspace handle */ - if ( (space1_id = H5Dget_space(dset1_id)) < 0 ) - goto out; - - /* Get rank */ - if ( (rank1 = H5Sget_simple_extent_ndims(space1_id)) < 0 ) - goto out; - - /* Get the dataspace handle */ - if ( (space2_id = H5Dget_space(dset2_id)) < 0 ) - goto out; - - /* Get rank */ - if ( (rank2 = H5Sget_simple_extent_ndims(space2_id)) < 0 ) - goto out; - - /* Get dimensions */ - if ( H5Sget_simple_extent_dims(space1_id,dims1,maxdim1) < 0 ) - goto out; - - /* Get dimensions */ - if ( H5Sget_simple_extent_dims(space2_id,dims2,maxdim2) < 0 ) - goto out; - -/*------------------------------------------------------------------------- - * Get the file data type - *------------------------------------------------------------------------- - */ - - /* Get the data type */ - if ( (f_type1 = H5Dget_type(dset1_id)) < 0 ) - goto out; - - /* Get the data type */ - if ( (f_type2 = H5Dget_type(dset2_id)) < 0 ) - goto out; - - -/*------------------------------------------------------------------------- - * check for the same class - *------------------------------------------------------------------------- - */ - - if ((tclass1=H5Tget_class(f_type1))<0) - goto out; - - if ((tclass2=H5Tget_class(f_type2))<0) - goto out; - - if ( tclass1 != tclass2 ) - { - 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) ); - goto out; - } - -/*------------------------------------------------------------------------- - * check for non supported classes - *------------------------------------------------------------------------- - */ - - assert(tclass1==tclass2); - switch (tclass1) - { - case H5T_TIME: - case H5T_STRING: - case H5T_BITFIELD: - case H5T_OPAQUE: - case H5T_COMPOUND: - case H5T_REFERENCE: - case H5T_ENUM: - case H5T_VLEN: - case H5T_ARRAY: - 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) ); - goto out; - default: - break; - } - -/*------------------------------------------------------------------------- - * check for the same rank - *------------------------------------------------------------------------- - */ - - if ( rank1 != rank2 ) - { - printf("Comparison not supported\n"); - printf("<%s> has rank %d, dimensions ", obj1_name, rank1); - print_dims(rank1,dims1); - printf(", max dimensions "); - print_dims(rank1,maxdim1); - printf("\n" ); - printf("<%s> has rank %d, dimensions ", obj2_name, rank2); - print_dims(rank2,dims2); - printf(", max dimensions "); - print_dims(rank2,maxdim2); - goto out; - } - -/*------------------------------------------------------------------------- - * check for different dimensions - *------------------------------------------------------------------------- - */ - - assert(rank1==rank2); - for ( i=0; i has rank %d, dimensions ", obj1_name, rank1); - print_dims(rank1,dims1); - printf(", max dimensions "); - print_dims(rank1,maxdim1); - printf("\n" ); - printf("<%s> has rank %d, dimensions ", obj2_name, rank2); - print_dims(rank2,dims2); - printf(", max dimensions "); - print_dims(rank2,maxdim2); - goto out; - } - -/*------------------------------------------------------------------------- - * maximum dimensions; just give a warning - *------------------------------------------------------------------------- - */ - if (maxdim_diff==1) - { - printf( "Warning: Different maximum dimensions\n"); - printf("<%s> has max dimensions ", obj1_name); - print_dims(rank1,maxdim1); - printf("\n"); - printf("<%s> has max dimensions ", obj2_name); - print_dims(rank2,maxdim2); - printf("\n"); - } - -/*------------------------------------------------------------------------- - * get number of elements - *------------------------------------------------------------------------- - */ - - 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]; - } - - assert(tot_cnt1==tot_cnt2); - -/*------------------------------------------------------------------------- - * check for equal file datatype; warning only - *------------------------------------------------------------------------- - */ - - if ( (H5Tequal(f_type1, f_type2)==0) ) - { - printf("Warning: Different storage datatype\n"); - printf("<%s> has file datatype ", obj1_name); - print_datatype(f_type1); - printf("\n"); - printf("<%s> has file datatype ", obj2_name); - print_datatype(f_type2); - printf("\n"); - } - -/*------------------------------------------------------------------------- - * memory type and sizes - *------------------------------------------------------------------------- - */ - - m_type1 = H5Tget_native_type( f_type1 , H5T_DIR_DEFAULT); - m_type2 = H5Tget_native_type( f_type2 , H5T_DIR_DEFAULT); - - m_size1 = H5Tget_size( m_type1 ); - m_size2 = H5Tget_size( m_type2 ); - -#if defined (H5DIFF_DEBUG) - print_sizes(obj1_name,obj2_name,f_type1,f_type2,m_type1,m_type2); -#endif - -/*------------------------------------------------------------------------- - * check for the comparable types in array_diff - *------------------------------------------------------------------------- - */ - - can1=h5diff_can_diff(m_type1); - can2=h5diff_can_diff(m_type2); - if ( can1==0 || can2==0 ) - { - 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 - *------------------------------------------------------------------------- - */ - - sign1=H5Tget_sign(m_type1); - sign2=H5Tget_sign(m_type2); - if ( sign1 != sign2 ) - { - 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)); - goto out; - } - - -/*------------------------------------------------------------------------- - * "upgrade" the smaller memory size - *------------------------------------------------------------------------- - */ - - if ( m_size1 != m_size2 ) - { - if ( m_size1 < m_size2 ) - { - assert( (H5Tclose(m_type1)) >=0); - m_type1 = H5Tget_native_type( f_type2 , H5T_DIR_DEFAULT); - m_size1 = H5Tget_size( m_type1 ); - } - else - { - assert( (H5Tclose(m_type2)) >=0); - m_type2 = H5Tget_native_type( f_type1 , H5T_DIR_DEFAULT); - m_size2 = H5Tget_size( m_type2 ); - } -#if defined (H5DIFF_DEBUG) - printf("WARNING: Size was upgraded\n"); - 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)); - - if ( buf1 == NULL || buf2 == NULL ) - { - printf( "cannot read into memory\n" ); - goto out; - } - -/*------------------------------------------------------------------------- - * read - *------------------------------------------------------------------------- - */ - - if ( H5Dread(dset1_id,m_type1,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf1) < 0 ) - goto out; - - if ( H5Dread(dset2_id,m_type2,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf2) < 0 ) - goto out; - -/*------------------------------------------------------------------------- - * array compare - *------------------------------------------------------------------------- - */ - if (options.verbose) - printf( "Comparing <%s> with <%s>\n", obj1_name, obj2_name ); - name1=h5diff_basename(obj1_name); - name2=h5diff_basename(obj2_name); - nfound = array_diff(buf1,buf2,tot_cnt1,rank1,dims1,options,name1,name2,m_type1); - if (options.verbose) - printf("%d differences found\n", nfound ); - -/*------------------------------------------------------------------------- - * close - *------------------------------------------------------------------------- - */ - -out: - - if ( buf1) HDfree(buf1); - if ( buf2) HDfree(buf2); - - /* Close */ - if ( dset1_id!=-1 ) assert( (H5Dclose(dset1_id)) >=0); - if ( dset2_id!=-1 ) assert( (H5Dclose(dset2_id)) >=0); - if ( space1_id!=-1 ) assert( (H5Sclose(space1_id)) >=0); - if ( space2_id!=-1 ) assert( (H5Sclose(space2_id)) >=0); - if ( f_type1!=-1 ) assert( (H5Tclose(f_type1)) >=0); - if ( f_type2!=-1 ) assert( (H5Tclose(f_type2)) >=0); - if ( m_type1!=-1 ) assert( (H5Tclose(m_type1)) >=0); - if ( m_type2!=-1 ) assert( (H5Tclose(m_type2)) >=0); - - return nfound; - -} - diff --git a/tools/h5diff/h5diff_util.c b/tools/h5diff/h5diff_util.c deleted file mode 100644 index 6ecd988..0000000 --- a/tools/h5diff/h5diff_util.c +++ /dev/null @@ -1,421 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#include "h5diff.h" -#include - - - -/*------------------------------------------------------------------------- - * Function: h5diff_can_diff - * - * Purpose: Check if TYPE_ID is supported; only the listed types are - * supported in the current version - * - *------------------------------------------------------------------------- - */ -int h5diff_can_diff(hid_t type_id) -{ - int ret=0; - if ( (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 - * - * Purpose: convert an array index position to matrix notation - * - * Return: pos matrix array - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: May 9, 2003 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -void print_pos( int *ph, int p, unsigned int curr_pos, int *acc, - int *pos, int rank, const char *obj1, const char *obj2 ) -{ - int i; - - /* print header */ - if ( *ph==1 ) - { - *ph=0; - if (p) - { - printf("%-15s %-15s %-15s %-15s %-15s\n", "position", obj1, obj2, "difference", - "relative"); - printf("------------------------------------------------------------------------\n"); - } - else - { - printf("%-15s %-15s %-15s %-20s\n", "position", obj1, 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]; - } - assert( curr_pos == 0 ); - - printf("[ " ); - for ( i = 0; i < rank; i++) - { - printf("%d ", pos[i] ); - } - printf("]" ); -} - -/*------------------------------------------------------------------------- - * Function: print_dims - * - * Purpose: print dimensions - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: May 9, 2003 - * - * Comments: - * - *------------------------------------------------------------------------- - */ -void print_dims( int r, hsize_t *d ) -{ - int i; - printf("[ " ); - for ( i=0; i0 && '/'==name[i-1]) - --i; - - /* Skip backward over base name */ - while (i>0 && '/'!=name[i-1]) - --i; - - return(name+i); -} - -/*------------------------------------------------------------------------- - * Function: get_type - * - * Purpose: Returns the type as a string - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: May 9, 2003 - * - * Comments: - * - *------------------------------------------------------------------------- - */ -const char* -get_type(int type) -{ - switch (type) - { - case H5G_DATASET: - return("H5G_DATASET"); - case H5G_GROUP: - return("H5G_GROUP"); - case H5G_TYPE: - return("H5G_TYPE"); - case H5G_LINK: - return("H5G_LINK"); - default: - return("user defined type"); - } -} - -/*------------------------------------------------------------------------- - * Function: get_sign - * - * Purpose: Returns the sign as a string - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: May 9, 2003 - * - * Comments: - * - *------------------------------------------------------------------------- - */ -const char* -get_sign(H5T_sign_t sign) -{ - switch (sign) - { - default: - return("H5T_SGN_ERROR"); - case H5T_SGN_NONE: - return("H5T_SGN_NONE"); - case H5T_SGN_2: - return("H5T_SGN_2"); - } -} - - -/*------------------------------------------------------------------------- - * Function: get_class - * - * Purpose: Returns the class as a string - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: May 9, 2003 - * - * Comments: - * - *------------------------------------------------------------------------- - */ -const char* -get_class(H5T_class_t tclass) -{ - switch (tclass) - { - default: - return("Invalid class"); - case H5T_TIME: - return("H5T_TIME"); - case H5T_INTEGER: - return("H5T_INTEGER"); - case H5T_FLOAT: - return("H5T_FLOAT"); - case H5T_STRING: - return("H5T_STRING"); - case H5T_BITFIELD: - return("H5T_BITFIELD"); - case H5T_OPAQUE: - return("H5T_OPAQUE"); - case H5T_COMPOUND: - return("H5T_COMPOUND"); - case H5T_REFERENCE: - return("H5T_REFERENCE"); - case H5T_ENUM: - return("H5T_ENUM"); - case H5T_VLEN: - return("H5T_VLEN"); - case H5T_ARRAY: - return("H5T_ARRAY"); - } -} - - -/*------------------------------------------------------------------------- - * Function: print_sizes - * - * Purpose: Print datatype sizes - * - *------------------------------------------------------------------------- - */ -#if defined (H5DIFF_DEBUG) -void print_sizes( const char *obj1, const char *obj2, - hid_t f_type1, hid_t f_type2, - hid_t m_type1, hid_t m_type2 ) -{ - size_t f_size1, f_size2; /* size of type in file */ - size_t m_size1, m_size2; /* size of type in memory */ - - f_size1 = H5Tget_size( f_type1 ); - f_size2 = H5Tget_size( f_type2 ); - m_size1 = H5Tget_size( m_type1 ); - m_size2 = H5Tget_size( m_type2 ); - - printf("\n"); - printf("------------------\n"); - printf("sizeof(char) %u\n", sizeof(char) ); - printf("sizeof(short) %u\n", sizeof(short) ); - printf("sizeof(int) %u\n", sizeof(int) ); - printf("sizeof(long) %u\n", sizeof(long) ); - printf("<%s> ------------------\n", obj1); - printf("type on file "); - print_datatype(f_type1); - printf("\n"); - printf("size on file %u\n", f_size1 ); - - printf("type on memory "); - print_datatype(m_type1); - printf("\n"); - printf("size on memory %u\n", m_size1 ); - - printf("<%s> ------------------\n", obj2); - printf("type on file "); - print_datatype(f_type2); - printf("\n"); - printf("size on file %u\n", f_size2 ); - - printf("type on memory "); - print_datatype(m_type2); - printf("\n"); - printf("size on memory %u\n", m_size2 ); - printf("\n"); -} -#endif /* H5DIFF_DEBUG */ - - diff --git a/tools/h5diff/h5trav.c b/tools/h5diff/h5trav.c deleted file mode 100644 index f64bd37..0000000 --- a/tools/h5diff/h5trav.c +++ /dev/null @@ -1,459 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - - -#include "h5trav.h" -#include "H5private.h" - - - -/* 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 ); - -/*------------------------------------------------------------------------- - * Function: H5get_object_info - * - * Purpose: - * - * Return: - * - * 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: info_getindex - * - * Purpose: get index of OBJ in list - * - * Return: index, -1 if not found - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: May 9, 2003 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ - -int info_getindex( const char *obj, int nobjs, info_t *info ) -{ - char *pdest; - int result; - int i; - - for ( i = 0; i < nobjs; i++) - { - if ( strcmp(obj,info[i].name)==0 ) - return i; - - pdest = strstr( info[i].name, obj ); - result = (int)(pdest - info[i].name); - - /* found at position 1, meaning without '/' */ - if( pdest != NULL && result==1 ) - return i; - } - return -1; -} - - - -/*------------------------------------------------------------------------- - * Function: info_free - * - * Purpose: free info memory - * - *------------------------------------------------------------------------- - */ - -void info_free( info_t *info, int nobjs ) -{ - int i; - if ( info ) - { - for ( i = 0; i < nobjs; i++) - { - if (info[i].name) - HDfree( info[i].name ); - } - HDfree(info); - } -} - - -/*------------------------------------------------------------------------- - * 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, 0, &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, 0, &statbuf) < 0 ) - return -1; - - ((info_t *)op_data)->type = statbuf.type; - ((info_t *)op_data)->name = (char *)HDstrdup(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: - * - * 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; - - 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*) HDmalloc(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 */ - H5E_BEGIN_TRY { - - /* get info */ - H5Gget_objinfo( loc_id, path, 1, &statbuf); - } H5E_END_TRY; - - /* add to array */ - if ( info ) - { - info[*idx].name = (char *)HDstrdup(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_obj(statbuf.objno, table ) == -1) - { - /* add object to table */ - table_add_obj(statbuf.objno, path, H5G_GROUP, 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_obj(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_obj(statbuf.objno, table ) == -1) - { - /* add object to table */ - table_add_obj(statbuf.objno, path, H5G_DATASET, table ); - } - - /* search table - dataset with more than one link to it */ - if (statbuf.nlink > 1) - { - if ((j = table_search_obj(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_obj(statbuf.objno, table ) == -1) - { - /* add object to table */ - table_add_obj(statbuf.objno, path, H5G_TYPE, table ); - } - - break; - - - /*------------------------------------------------------------------------- - * H5G_LINK - *------------------------------------------------------------------------- - */ - - case H5G_LINK: - - /* increment */ - inserted_objs++; - - break; - - - default: - break; - - } - - /*------------------------------------------------------------------------- - * end switch - *------------------------------------------------------------------------- - */ - - if ( name ) - HDfree( name ); - - if ( path ) - HDfree( path ); - - } /* i */ - - - - return inserted_objs; -} - diff --git a/tools/h5diff/h5trav.h b/tools/h5diff/h5trav.h deleted file mode 100644 index 250e0c3..0000000 --- a/tools/h5diff/h5trav.h +++ /dev/null @@ -1,89 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#ifndef H5TRAV_H__ -#define H5TRAV_H__ - -#include "hdf5.h" - - -/*------------------------------------------------------------------------- - * struct to store name and type of an object - *------------------------------------------------------------------------- - */ - -typedef struct info_t { - char *name; - int type; -} info_t; - - - -/*------------------------------------------------------------------------- - * struct to store basic info about an object - *------------------------------------------------------------------------- - */ - -typedef struct obj_t { - haddr_t objno; - unsigned flags[2]; - char *objname; - int displayed; - int type; -} obj_t; - - -/*------------------------------------------------------------------------- - * struct that stores all objects, excluding shared objects - *------------------------------------------------------------------------- - */ - -typedef struct table_t { - int size; - int nobjs; - obj_t *objs; -} table_t; - - -/*------------------------------------------------------------------------- - * "info" public functions - *------------------------------------------------------------------------- - */ - -#ifdef __cplusplus -extern "C" { -#endif - -int H5get_object_info( hid_t file_id, info_t *info ); -int info_getindex( const char *obj, int nobjs, info_t *info ); -void info_free(info_t *info, int nobjs); - -#ifdef __cplusplus -} -#endif - -/*------------------------------------------------------------------------- - * table private functions - *------------------------------------------------------------------------- - */ - -void table_init(table_t **table); -void table_free(table_t *table); -int table_search_obj(haddr_t objno, table_t *table ); -void table_add_obj(haddr_t objno, char *objname, int type, table_t *table); -void table_add_flags(unsigned *flags, char *objname, int type, table_t *table); - - - -#endif /* H5TRAV_H__ */ diff --git a/tools/h5diff/h5trav_table.c b/tools/h5diff/h5trav_table.c deleted file mode 100644 index a6943bc..0000000 --- a/tools/h5diff/h5trav_table.c +++ /dev/null @@ -1,210 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - - -#include "h5diff.h" -#include "H5private.h" - -/*------------------------------------------------------------------------- - * Function: table_search_obj - * - * Purpose: - * - * Return: - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 4, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ - -int table_search_obj(haddr_t objno, table_t *table ) -{ - int i; - - for (i = 0; i < table->nobjs; i++) - if (table->objs[i].objno == objno) - return i; - - return -1; -} - - -/*------------------------------------------------------------------------- - * Function: table_add_obj - * - * Purpose: - * - * Return: - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 4, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ - -void -table_add_obj(haddr_t objno, char *objname, int type, table_t *table) -{ - int i; - - if (table->nobjs == table->size) { - table->size *= 2; - table->objs = (obj_t*)HDrealloc(table->objs, table->size * sizeof(obj_t)); - - for (i = table->nobjs; i < table->size; i++) { - table->objs[i].objno = 0; - table->objs[i].flags[0] = table->objs[i].flags[1] = 0; - table->objs[i].displayed = 0; - table->objs[i].type = H5G_UNKNOWN; - table->objs[i].objname = NULL; - } - } - - i = table->nobjs++; - table->objs[i].objno = objno; - table->objs[i].flags[0] = table->objs[i].flags[1] = 0; - HDfree(table->objs[i].objname); - table->objs[i].objname = (char *)HDstrdup(objname); - table->objs[i].type = type; -} - - -/*------------------------------------------------------------------------- - * Function: table_add_flags - * - * Purpose: - * - * Return: - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 4, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ - -void -table_add_flags(unsigned *flags, char *objname, int type, table_t *table) -{ - int i; - - if (table->nobjs == table->size) { - table->size *= 2; - table->objs = (obj_t*)HDrealloc(table->objs, table->size * sizeof(obj_t)); - - for (i = table->nobjs; i < table->size; i++) { - table->objs[i].objno = 0; - table->objs[i].flags[0] = table->objs[i].flags[1] = 0; - table->objs[i].displayed = 0; - table->objs[i].type = H5G_UNKNOWN; - table->objs[i].objname = NULL; - } - } - - i = table->nobjs++; - table->objs[i].objno = 0; - table->objs[i].flags[0] = flags[0]; - table->objs[i].flags[1] = flags[1]; - HDfree(table->objs[i].objname); - table->objs[i].objname = (char *)HDstrdup(objname); - table->objs[i].type = type; -} - - -/*------------------------------------------------------------------------- - * Function: table_init - * - * Purpose: - * - * Return: - * - * 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*) HDmalloc(sizeof(table_t)); - - table->size = 20; - table->nobjs = 0; - table->objs = (obj_t*) HDmalloc(table->size * sizeof(obj_t)); - - for (i = 0; i < table->size; i++) { - table->objs[i].objno = 0; - table->objs[i].flags[0] = table->objs[i].flags[1] = 0; - table->objs[i].displayed = 0; - table->objs[i].type = H5G_UNKNOWN; - table->objs[i].objname = NULL; - } - - *tbl = table; -} - - - -/*------------------------------------------------------------------------- - * Function: table_free - * - * Purpose: free table memory - * - * Return: - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 4, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ - -void table_free( table_t *table ) -{ - int i; - - for ( i = 0; i < table->nobjs; i++) - HDfree( table->objs[i].objname ); - - HDfree(table->objs); - HDfree(table); - -} - - diff --git a/tools/h5repack/Makefile.in b/tools/h5repack/Makefile.in index 8768d36..7ea6e23 100644 --- a/tools/h5repack/Makefile.in +++ b/tools/h5repack/Makefile.in @@ -21,11 +21,9 @@ srcdir=@srcdir@ ## Add include directory to the C preprocessor flags, add -lh5tools and ## -lhdf5 to the list of libraries. ## Add also the test include directory for #defines -## Add include for H5DIFF CPPFLAGS=-I. -I$(srcdir) -I$(top_builddir)/src -I$(top_srcdir)/src \ -I$(top_srcdir)/test \ - -I$(top_srcdir)/tools/lib @CPPFLAGS@ \ - -I$(top_srcdir)/tools/h5diff + -I$(top_srcdir)/tools/lib @CPPFLAGS@ ## Test programs and scripts. ## @@ -35,6 +33,7 @@ TEST_SCRIPTS=$(srcdir)/h5repack.sh ## These are our main targets: library and tools. ## LIBHDF5=$(top_builddir)/src/libhdf5.la +LIBTOOLS=../lib/libh5tools.la PUB_PROGS=h5repack PROGS=$(PUB_PROGS) $(TEST_PROGS) @@ -51,10 +50,10 @@ MOSTLYCLEAN=*.h5 ## Source and object files for programs... ## -PROG_SRC=h5repack.c h5repack_list.c h5repack_main.c h5repack_opttable.c h5repack_parse.c ../h5diff/h5trav.c ../h5diff/h5trav_table.c test_h5repack_add.c test_h5repack_main.c +PROG_SRC=h5repack.c h5repack_list.c h5repack_main.c h5repack_opttable.c h5repack_parse.c test_h5repack_add.c test_h5repack_main.c PROG_OBJ=$(PROG_SRC:.c=.lo) -OBJS=h5repack.lo h5repack_list.lo h5repack_main.lo h5repack_opttable.lo h5repack_parse.lo ../h5diff/h5trav.lo ../h5diff/h5trav_table.lo -TEST_OBJS=../h5diff/h5diff.lo ../h5diff/h5diff_array.lo ../h5diff/h5diff_dset.lo ../h5diff/h5diff_util.lo h5repack.lo h5repack_list.lo h5repack_opttable.lo h5repack_parse.lo ../h5diff/h5trav.lo ../h5diff/h5trav_table.lo test_h5repack_add.lo test_h5repack_main.lo +OBJS=h5repack.lo h5repack_list.lo h5repack_main.lo h5repack_opttable.lo h5repack_parse.lo +TEST_OBJS=h5repack.lo h5repack_list.lo h5repack_opttable.lo h5repack_parse.lo test_h5repack_add.lo test_h5repack_main.lo PRIVATE_HDR= @@ -70,13 +69,13 @@ check test _test: $(PROGS) ## How to build the programs...They all depend on the hdf5 library and ## the tools library compiled in this directory. ## -$(PROGS): $(LIBHDF5) +$(PROGS): $(LIBTOOLS) $(LIBHDF5) h5repack: $(OBJS) - @$(LT_LINK_EXE) $(CFLAGS) -o $@ $(OBJS) $(LIBHDF5) $(LDFLAGS) $(LIBS) + @$(LT_LINK_EXE) $(CFLAGS) -o $@ $(OBJS) $(LIBTOOLS) $(LIBHDF5) $(LDFLAGS) $(LIBS) h5repacktst: $(TEST_OBJS) - @$(LT_LINK_EXE) $(CFLAGS) -o $@ $(TEST_OBJS) $(LIBHDF5) $(LDFLAGS) $(LIBS) + @$(LT_LINK_EXE) $(CFLAGS) -o $@ $(TEST_OBJS) $(LIBTOOLS) $(LIBHDF5) $(LDFLAGS) $(LIBS) @CONCLUDE@ diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c index d88196c..fa66ae4 100644 --- a/tools/h5repack/h5repack.c +++ b/tools/h5repack/h5repack.c @@ -21,7 +21,7 @@ -static void print_options(packoptions_t *options); +static void print_options(pack_opt_t *options); /*------------------------------------------------------------------------- * Function: h5repack @@ -44,7 +44,7 @@ static void print_options(packoptions_t *options); */ int h5repack(char* infile, char* outfile, - packoptions_t *options) + pack_opt_t *options) { options->trip=0; @@ -80,10 +80,10 @@ int h5repack(char* infile, *------------------------------------------------------------------------- */ -int h5repack_init (packoptions_t *options, +int h5repack_init (pack_opt_t *options, int verbose) { - memset(options,0,sizeof(packoptions_t)); + memset(options,0,sizeof(pack_opt_t)); options->threshold = 1024; options->verbose = verbose; return (options_table_init(&(options->op_tbl))); @@ -97,7 +97,7 @@ int h5repack_init (packoptions_t *options, *------------------------------------------------------------------------- */ -int h5repack_end (packoptions_t *options) +int h5repack_end (pack_opt_t *options) { return options_table_free(options->op_tbl); } @@ -114,7 +114,7 @@ int h5repack_end (packoptions_t *options) */ int h5repack_addcomp(char* str, - packoptions_t *options) + pack_opt_t *options) { obj_list_t *obj_list=NULL; /*one object list for the -t and -c option entry */ comp_info_t comp; /*compression info for the current -t option entry */ @@ -167,7 +167,7 @@ int h5repack_addcomp(char* str, int h5repack_addchunk(char* str, - packoptions_t *options) + pack_opt_t *options) { obj_list_t *obj_list=NULL; /*one object list for the -t and -c option entry */ @@ -227,7 +227,7 @@ int h5repack_addchunk(char* str, *------------------------------------------------------------------------- */ static -void print_options(packoptions_t *options) +void print_options(pack_opt_t *options) { int i, k, j, has_cp=0, has_ck=0; @@ -339,7 +339,8 @@ void print_options(packoptions_t *options) *------------------------------------------------------------------------- */ -void read_info(char *filename,packoptions_t *options) +void read_info(char *filename, + pack_opt_t *options) { char stype[10]; char comp_info[1024]; diff --git a/tools/h5repack/h5repack.h b/tools/h5repack/h5repack.h index 17c2b52..a661e76 100644 --- a/tools/h5repack/h5repack.h +++ b/tools/h5repack/h5repack.h @@ -62,12 +62,12 @@ typedef struct { chunk_info_t chunk; /* chunk information */ } pack_info_t; -/* store a list of all objects */ +/* store a table of all objects */ typedef struct { int size; int nelems; pack_info_t *objs; -} options_table_t; +} pack_opttbl_t; /*------------------------------------------------------------------------- @@ -77,7 +77,7 @@ typedef struct { /* all the above, ready to go to the hrepack call */ typedef struct { - options_table_t *op_tbl; /*table with all -c and -t options */ + pack_opttbl_t *op_tbl; /*table with all -c and -t options */ int all_chunk; /*chunk all objects, input of "*" */ int all_comp; /*comp all objects, input of "*" */ comp_info_t comp_g; /*global compress INFO for the ALL case */ @@ -86,7 +86,7 @@ typedef struct { int trip; /*which cycle are we in */ int threshold; /*minimum size to compress, in bytes */ -} packoptions_t; +} pack_opt_t; @@ -99,11 +99,11 @@ typedef struct { extern "C" { #endif -int h5repack (char* infile, char* outfile, packoptions_t *options); -int h5repack_addcomp (char* str, packoptions_t *options); -int h5repack_addchunk(char* str, packoptions_t *options); -int h5repack_init (packoptions_t *options, int verbose); -int h5repack_end (packoptions_t *options); +int h5repack (char* infile, char* outfile, pack_opt_t *options); +int h5repack_addcomp (char* str, pack_opt_t *options); +int h5repack_addchunk(char* str, pack_opt_t *options); +int h5repack_init (pack_opt_t *options, int verbose); +int h5repack_end (pack_opt_t *options); #ifdef __cplusplus } @@ -115,7 +115,7 @@ int h5repack_end (packoptions_t *options); */ -void read_info(char *filename,packoptions_t *options); +void read_info(char *filename,pack_opt_t *options); diff --git a/tools/h5repack/h5repack_list.c b/tools/h5repack/h5repack_list.c index 138cb5b..f444218 100644 --- a/tools/h5repack/h5repack_list.c +++ b/tools/h5repack/h5repack_list.c @@ -37,11 +37,11 @@ */ -int get_objlist(char* fname, packoptions_t *options) +int get_objlist(char* fname, pack_opt_t *options) { - hid_t fid; - int nobjects, i; - info_t *info=NULL; + hid_t fid; + int nobjects, i; + trav_info_t *info=NULL; /*------------------------------------------------------------------------- * open the file @@ -65,7 +65,7 @@ int get_objlist(char* fname, packoptions_t *options) *------------------------------------------------------------------------- */ - if ((nobjects = H5get_object_info(fid, NULL ))<0) { + if ((nobjects = h5trav_getinfo(fid, NULL ))<0) { printf("h5repack: <%s>: Could not obtain object list\n", fname ); return -1; } @@ -75,11 +75,11 @@ int get_objlist(char* fname, packoptions_t *options) *------------------------------------------------------------------------- */ - if ((info = (info_t*) malloc( nobjects * sizeof(info_t)))==NULL){ + if ((info = (trav_info_t*) malloc( nobjects * sizeof(trav_info_t)))==NULL){ printf("h5repack: <%s>: Could not allocate object list\n", fname ); return -1; } - if (H5get_object_info(fid, info )<0) { + if (h5trav_getinfo(fid, info )<0) { printf("h5repack: <%s>: Could not obtain object list\n", fname ); return -1; } @@ -99,12 +99,12 @@ int get_objlist(char* fname, packoptions_t *options) printf(PFORMAT1,"","",obj_name); /* the input object names are present in the file and are valid */ - if (info_getindex(obj_name,nobjects,info)<0) + if (h5trav_getindex(obj_name,nobjects,info)<0) { printf("\nError: Could not find <%s> in file <%s>. Exiting...\n", obj_name,fname); H5Fclose(fid); - info_free(info,nobjects); + h5trav_freeinfo(info,nobjects); exit(1); } if (options->verbose) @@ -118,7 +118,7 @@ int get_objlist(char* fname, packoptions_t *options) *------------------------------------------------------------------------- */ H5Fclose(fid); - info_free(info,nobjects); + h5trav_freeinfo(info,nobjects); return 0; } @@ -141,12 +141,12 @@ int get_objlist(char* fname, packoptions_t *options) int copy_file(char* fnamein, char* fnameout, - packoptions_t *options) + pack_opt_t *options) { - hid_t fidin; - hid_t fidout; - int nobjects; - info_t *info=NULL; + hid_t fidin; + hid_t fidout; + int nobjects; + trav_info_t *info=NULL; /*------------------------------------------------------------------------- * open the files @@ -174,7 +174,7 @@ int copy_file(char* fnamein, *------------------------------------------------------------------------- */ - if ((nobjects = H5get_object_info(fidin, NULL ))<0) { + if ((nobjects = h5trav_getinfo(fidin, NULL ))<0) { printf("h5repack: <%s>: Could not obtain object list\n", fnamein ); return -1; } @@ -184,11 +184,11 @@ int copy_file(char* fnamein, *------------------------------------------------------------------------- */ - if ((info = (info_t*) malloc( nobjects * sizeof(info_t)))==NULL){ + if ((info = (trav_info_t*) malloc( nobjects * sizeof(trav_info_t)))==NULL){ printf("h5repack: <%s>: Could not allocate object list\n", fnamein ); return -1; } - if (H5get_object_info(fidin, info )<0) { + if (h5trav_getinfo(fidin, info )<0) { printf("h5repack: <%s>: Could not obtain object list\n", fnamein ); return -1; } @@ -209,7 +209,7 @@ int copy_file(char* fnamein, */ H5Fclose(fidin); H5Fclose(fidout); - info_free(info,nobjects); + h5trav_freeinfo(info,nobjects); return 0; } @@ -231,7 +231,7 @@ int copy_file(char* fnamein, */ void print_objlist(char *filename, int nobjects, - info_t *info ) + trav_info_t *info ) { int i; @@ -278,8 +278,8 @@ void print_objlist(char *filename, int do_copy_file(hid_t fidin, hid_t fidout, int nobjects, - info_t *info, - packoptions_t *options) + trav_info_t *info, + pack_opt_t *options) { hid_t grp_id; /* group ID */ hid_t dset_in; /* read dataset ID */ diff --git a/tools/h5repack/h5repack_list.h b/tools/h5repack/h5repack_list.h index 36f1907..905057e 100644 --- a/tools/h5repack/h5repack_list.h +++ b/tools/h5repack/h5repack_list.h @@ -28,21 +28,21 @@ int get_objlist(char* infname, - packoptions_t *options); + pack_opt_t *options); int copy_file(char* fnamein, char* fnameout, - packoptions_t *options); + pack_opt_t *options); void print_objlist(char *filename, int nobjects, - info_t *info ); + trav_info_t *info ); int do_copy_file(hid_t fidin, hid_t fidout, int nobjects, - info_t *info, - packoptions_t *options); + trav_info_t *info, + pack_opt_t *options); diff --git a/tools/h5repack/h5repack_main.c b/tools/h5repack/h5repack_main.c index 2956adb..39f18f8 100644 --- a/tools/h5repack/h5repack_main.c +++ b/tools/h5repack/h5repack_main.c @@ -31,7 +31,7 @@ int main(int argc, char **argv) { char *infile = NULL; char *outfile = NULL; - packoptions_t options; /*the global options */ + pack_opt_t options; /*the global options */ int i; /* initialize options */ diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c index cd0e7a2..b7019eb 100644 --- a/tools/h5repack/h5repack_opttable.c +++ b/tools/h5repack/h5repack_opttable.c @@ -28,10 +28,10 @@ *------------------------------------------------------------------------- */ -int options_table_init( options_table_t **tbl ) +int options_table_init( pack_opttbl_t **tbl ) { int i; - options_table_t* table = (options_table_t*) malloc(sizeof(options_table_t)); + pack_opttbl_t* table = (pack_opttbl_t*) malloc(sizeof(pack_opttbl_t)); if (table==NULL) { printf("Error: not enough memory for options table\n"); return -1; @@ -66,7 +66,7 @@ int options_table_init( options_table_t **tbl ) *------------------------------------------------------------------------- */ -int options_table_free( options_table_t *table ) +int options_table_free( pack_opttbl_t *table ) { free(table->objs); free(table); @@ -88,7 +88,7 @@ int options_add_chunk( obj_list_t *obj_list, int n_objs, hsize_t *chunk_lengths, int chunk_rank, - options_table_t *table ) + pack_opttbl_t *table ) { int i, j, k, I, added=0, found=0; @@ -185,7 +185,7 @@ int options_add_chunk( obj_list_t *obj_list, int options_add_comp( obj_list_t *obj_list, int n_objs, comp_info_t comp, - options_table_t *table ) + pack_opttbl_t *table ) { int i, j, I, added=0, found=0; @@ -273,7 +273,7 @@ int options_add_comp( obj_list_t *obj_list, */ pack_info_t* options_get_object( char *path, - options_table_t *table ) + pack_opttbl_t *table ) { int i; diff --git a/tools/h5repack/h5repack_opttable.h b/tools/h5repack/h5repack_opttable.h index 9122ea7..0bb1292 100644 --- a/tools/h5repack/h5repack_opttable.h +++ b/tools/h5repack/h5repack_opttable.h @@ -25,19 +25,19 @@ extern "C" { #endif -int options_table_init( options_table_t **tbl ); -int options_table_free( options_table_t *table ); +int options_table_init( pack_opttbl_t **tbl ); +int options_table_free( pack_opttbl_t *table ); int options_add_chunk ( obj_list_t *obj_list, int n_objs, hsize_t *chunk_lengths, int chunk_rank, - options_table_t *table ); + pack_opttbl_t *table ); int options_add_comp ( obj_list_t *obj_list, int n_objs, comp_info_t comp, - options_table_t *table ); + pack_opttbl_t *table ); pack_info_t* options_get_object( char *path, - options_table_t *table); + pack_opttbl_t *table); #ifdef __cplusplus diff --git a/tools/h5repack/test_h5repack_add.c b/tools/h5repack/test_h5repack_add.c index b357220..faaa9c3 100644 --- a/tools/h5repack/test_h5repack_add.c +++ b/tools/h5repack/test_h5repack_add.c @@ -177,7 +177,7 @@ int make_dsets() TEST_ERROR; nerrors += make_deflate(fid); -#if 0 +#if 1 nerrors += make_szip(fid); #endif diff --git a/tools/h5repack/test_h5repack_main.c b/tools/h5repack/test_h5repack_main.c index 9ec780a..828bc3a 100644 --- a/tools/h5repack/test_h5repack_main.c +++ b/tools/h5repack/test_h5repack_main.c @@ -44,29 +44,27 @@ static int test() { - packoptions_t options; - options_t diff_options; - memset(&diff_options, 0, sizeof (options_t)); - + pack_opt_t pack_options; + diff_opt_t diff_options; + memset(&diff_options, 0, sizeof (diff_opt_t)); TESTING(" deflate filter"); - if (h5repack_init (&options, 0)<0) + if (h5repack_init (&pack_options, 0)<0) TEST_ERROR; - if (h5repack_addcomp("dset1:GZIP 9",&options)<0) + if (h5repack_addcomp("dset1:GZIP 9",&pack_options)<0) TEST_ERROR; - if (h5repack_addchunk("dset1:5x4",&options)<0) + if (h5repack_addchunk("dset1:5x4",&pack_options)<0) TEST_ERROR; - if (h5repack(FILENAME,FILENAME_OUT,&options)<0) + if (h5repack(FILENAME,FILENAME_OUT,&pack_options)<0) TEST_ERROR; - if (h5repack_end (&options)<0) + if (h5repack_end (&pack_options)<0) TEST_ERROR; if (h5diff(FILENAME,FILENAME,NULL,NULL,diff_options) == 1) TEST_ERROR; PASSED(); return 0; - error: return 1; diff --git a/tools/lib/Makefile.in b/tools/lib/Makefile.in index 6918d32..aed2411 100644 --- a/tools/lib/Makefile.in +++ b/tools/lib/Makefile.in @@ -41,7 +41,7 @@ PROGS=$(PUB_PROGS) $(TEST_PROGS) ## Source and object files for the library; do not install ## -LIB_SRC=h5tools.c h5tools_str.c h5tools_utils.c +LIB_SRC=h5tools.c h5tools_str.c h5tools_utils.c h5diff.c h5diff_array.c h5diff_dset.c h5diff_util.c h5trav.c h5trav_table.c LIB_OBJ=$(LIB_SRC:.c=.lo) PUB_LIB= AUX_LIB=$(LIB) @@ -49,7 +49,7 @@ AUX_LIB=$(LIB) TEST_SRC=talign.c TEST_OBJ=$(TEST_SRC:.c=.lo) -PRIVATE_HDR=h5tools.h h5tools_str.h +PRIVATE_HDR=h5tools.h h5tools_str.h h5diff.h h5trav.h ## Programs have to be built before they can be tested! ## diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c new file mode 100644 index 0000000..8a013c7 --- /dev/null +++ b/tools/lib/h5diff.c @@ -0,0 +1,424 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + +#include "h5diff.h" +#include +#include + + + +/*------------------------------------------------------------------------- + * Function: h5diff + * + * Purpose: public function, can be called in an applicattion program. + * return differences between 2 HDF5 files + * + * Return: An exit status of 0 means no differences were found, 1 means some + * differences were found. + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: October 22, 2003 + * + *------------------------------------------------------------------------- + */ + +int h5diff(const char *fname1, + const char *fname2, + const char *objname1, + const char *objname2, + diff_opt_t options) +{ + int nobjects1, nobjects2; + trav_info_t *info1=NULL; + trav_info_t *info2=NULL; + hid_t file1_id, file2_id; + int nfound; + + +/*------------------------------------------------------------------------- + * open the files first; if they are not valid, no point in continuing + *------------------------------------------------------------------------- + */ + + /* disable error reporting */ + H5E_BEGIN_TRY { + + /* Open the files */ + if ((file1_id=H5Fopen(fname1,H5F_ACC_RDONLY,H5P_DEFAULT))<0 ) + { + printf("h5diff: %s: No such file or directory\n", fname1 ); + exit(1); + } + if ((file2_id=H5Fopen(fname2,H5F_ACC_RDONLY,H5P_DEFAULT))<0 ) + { + printf("h5diff: %s: No such file or directory\n", fname2 ); + exit(1); + } + /* enable error reporting */ + } H5E_END_TRY; + + +/*------------------------------------------------------------------------- + * get the number of objects in the files + *------------------------------------------------------------------------- + */ + + nobjects1 = h5trav_getinfo( file1_id, NULL ); + nobjects2 = h5trav_getinfo( file2_id, NULL ); + +/*------------------------------------------------------------------------- + * get the list of objects in the files + *------------------------------------------------------------------------- + */ + + info1 = (trav_info_t*) malloc( nobjects1 * sizeof(trav_info_t)); + info2 = (trav_info_t*) malloc( nobjects2 * sizeof(trav_info_t)); + if (info1==NULL || info2==NULL) + return 0; + + h5trav_getinfo( file1_id, info1 ); + h5trav_getinfo( file2_id, info2 ); + +/*------------------------------------------------------------------------- + * object name was supplied + *------------------------------------------------------------------------- + */ + + if ( objname1 ) + { + assert(objname2); + nfound=diff_compare(file1_id,fname1,objname1,nobjects1,info1, + file2_id,fname2,objname2,nobjects2,info2,options); + } + +/*------------------------------------------------------------------------- + * compare all + *------------------------------------------------------------------------- + */ + + else + { + nfound=diff_match(file1_id,nobjects1,info1, + file2_id,nobjects2,info2,options); + } + + + h5trav_freeinfo(info1,nobjects1); + h5trav_freeinfo(info2,nobjects2); + /* close */ + assert( (H5Fclose(file1_id)) >=0); + assert( (H5Fclose(file2_id)) >=0); + + return nfound; +} + + + +/*------------------------------------------------------------------------- + * Function: diff_match + * + * Purpose: Find common objects; the algorithm used for this search is the + * cosequential match algorithm and is described in + * Folk, Michael; Zoellick, Bill. (1992). File Structures. Addison-Wesley. + * + * Return: Number of differences found + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: May 9, 2003 + * + *------------------------------------------------------------------------- + */ +int diff_match( hid_t file1_id, + int nobjects1, + trav_info_t *info1, + hid_t file2_id, + int nobjects2, + trav_info_t *info2, + diff_opt_t options ) +{ + int more_names_exist = (nobjects1>0 && nobjects2>0) ? 1 : 0; + trav_table_t *table=NULL; + int cmp; + int curr1=0; + int curr2=0; + unsigned infile[2]; + char c1, c2; + int nfound=0, i; + +/*------------------------------------------------------------------------- + * build the list + *------------------------------------------------------------------------- + */ + trav_table_init( &table ); + + + while ( more_names_exist ) + { + /* criteria is string compare */ + cmp = strcmp( info1[curr1].name, info2[curr2].name ); + if ( cmp == 0 ) + { + infile[0]=1; infile[1]=1; + trav_table_addflags(infile, info1[curr1].name, info1[curr1].type, table ); + + curr1++; + curr2++; + } + else if ( cmp < 0 ) + { + infile[0]=1; infile[1]=0; + trav_table_addflags(infile, info1[curr1].name, info1[curr1].type, table ); + curr1++; + } + else + { + infile[0]=0; infile[1]=1; + trav_table_addflags(infile, info2[curr2].name, info2[curr2].type, table ); + curr2++; + } + + more_names_exist = (curr1nobjs; i++) + { + c1 = (table->objs[i].flags[0]) ? 'x' : ' '; + c2 = (table->objs[i].flags[1]) ? 'x' : ' '; + printf("%5c %6c %-15s\n", c1, c2, table->objs[i].objname); + } + printf("\n"); + } + + +/*------------------------------------------------------------------------- + * do the diff for common objects + *------------------------------------------------------------------------- + */ + + for (i = 0; i < table->nobjs; i++) + { + if ( table->objs[i].flags[0] && table->objs[i].flags[1] ) + nfound+=diff( file1_id, table->objs[i].objname, + file2_id, table->objs[i].objname, + options, table->objs[i].type ); + } + + /* free table */ + trav_table_free(table); + return nfound; +} + + +/*------------------------------------------------------------------------- + * Function: diff_compare + * + * Purpose: get objects from list, and check for the same type + * + * Return: Number of differences found + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: May 9, 2003 + * + *------------------------------------------------------------------------- + */ + +int diff_compare( hid_t file1_id, + const char *file1_name, + const char *obj1_name, + int nobjects1, + trav_info_t *info1, + hid_t file2_id, + const char *file2_name, + const char *obj2_name, + int nobjects2, + trav_info_t *info2, + diff_opt_t options ) +{ + + int f1=0, f2=0; + int nfound=0; + + int i = h5trav_getindex( obj1_name, nobjects1, info1 ); + int j = h5trav_getindex( obj2_name, nobjects2, info2 ); + + if ( i == -1 ) + { + printf( "Object <%s> could not be found in <%s>\n", obj1_name, file1_name ); + f1=1; + } + if ( j == -1 ) + { + printf( "Object <%s> could not be found in <%s>\n", obj2_name, file2_name ); + f2=1; + } + if ( f1 || f2 ) + return -1; + + /* use the name with "/" first, as obtained by iterator function */ + obj1_name=info1[i].name; + obj2_name=info2[j].name; + + /* objects are not the same type */ + if ( info1[i].type != info2[j].type ) + { + printf("Comparison not supported\n"); + printf("<%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; + } + + nfound=diff( file1_id, obj1_name, file2_id, obj2_name, options, info1[i].type ); + + return nfound; +} + + +/*------------------------------------------------------------------------- + * Function: diff + * + * Purpose: switch between types and choose the diff function + * + * Return: Number of differences found + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: May 9, 2003 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +int diff( hid_t file1_id, + const char *obj1_name, + hid_t file2_id, + const char *obj2_name, + diff_opt_t options, + int type ) +{ + int nfound=0; + + switch ( type ) + { + case H5G_DATASET: + nfound=diff_dataset(file1_id,file2_id,obj1_name,obj2_name,options); + break; + + default: + 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) ); + break; + } + + if (options.verbose) + printf("\n"); + return nfound; +} + + +/*------------------------------------------------------------------------- + * Function: diff_list + * + * Purpose: print list of objects in file + * + * Return: void + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: May 9, 2003 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +#ifdef NOT_YET +void diff_list( const char *filename, int nobjects, trav_info_t *info ) +{ + int i; + + printf("File <%s>: # of entries = %d\n", filename, nobjects ); + for ( i = 0; i < nobjects; i++) + { + switch ( info[i].type ) + { + case H5G_GROUP: + printf("%s %20s\n", info[i].name, "group" ); + break; + case H5G_DATASET: + printf("%s %20s\n", info[i].name, "dataset" ); + break; + case H5G_TYPE: + printf("%s %20s\n", info[i].name, "datatype" ); + break; + case H5G_LINK: + printf("%s %20s\n", info[i].name, "link" ); + break; + default: + printf("%s %20s\n", info[i].name, "User defined object" ); + break; + } + } + +} +#endif + + + + + diff --git a/tools/lib/h5diff.h b/tools/lib/h5diff.h new file mode 100644 index 0000000..3313765 --- /dev/null +++ b/tools/lib/h5diff.h @@ -0,0 +1,162 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef H5DIFF_H__ +#define H5DIFF_H__ + +#include "hdf5.h" +#include "h5trav.h" + + +#if 0 +#define H5DIFF_DEBUG +#endif + + +/*------------------------------------------------------------------------- + * printf formatting + *------------------------------------------------------------------------- + */ + +#define FFORMAT "%-15.10g %-15.10g %-15.10g\n" +#define IFORMAT "%-15d %-15d %-15d\n" +#define UIFORMAT "%-15u %-15u %-15u\n" +#define LIFORMAT "%-15ld %-15ld %-15ld\n" +#define ULIFORMAT "%-15lu %-15lu %-15lu\n" +/* with -p option */ +#define FPFORMAT "%-15.10g %-15.10g %-15.10g %-14.10g\n" +#define IPFORMAT "%-15d %-15d %-15d %-14d\n" +#define UIPFORMAT "%-15u %-15u %-15u %-14u\n" +#define LPIFORMAT "%-15ld %-15ld %-15ld %-14ld\n" +#define ULPIFORMAT "%-15lu %-15lu %-15lu %-14lu\n" +#define SPACES " " + + +/*------------------------------------------------------------------------- + * command line options + *------------------------------------------------------------------------- + */ + +typedef struct { + int r; /* report only what objects differ */ + int d; /* delta */ + double delta; /* delta value */ + int p; /* relative error */ + double percent; /* relative error value */ + int n; /* count */ + int count; /* count value */ + int verbose; /* print information */ +} diff_opt_t; + + + +/*------------------------------------------------------------------------- + * public functions + *------------------------------------------------------------------------- + */ + +#ifdef __cplusplus +extern "C" { +#endif + +int h5diff(const char *fname1, + const char *fname2, + const char *objname1, + const char *objname2, + diff_opt_t options); + + +#ifdef __cplusplus +} +#endif + + + +/*------------------------------------------------------------------------- + * private functions + *------------------------------------------------------------------------- + */ + + +int diff_dataset( hid_t file1_id, + hid_t file2_id, + const char *obj1_name, + 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, + diff_opt_t options, + int type ); + +int diff_compare( hid_t file1_id, + const char *file1_name, + const char *obj1_name, + int nobjects1, + trav_info_t *info1, + hid_t file2_id, + const char *file2_name, + const char *obj2_name, + int nobjects2, + trav_info_t *info2, + diff_opt_t options ); + +int diff_match( hid_t file1_id, + int nobjects1, + trav_info_t *info1, + hid_t file2_id, + int nobjects2, + trav_info_t *info2, + diff_opt_t options ); + +int diff_array( void *buf1, + void *buf2, + hsize_t tot_cnt, + int rank, + hsize_t *dims, + diff_opt_t options, + const char *obj1, + const char *obj2, + hid_t m_type ); + +/*------------------------------------------------------------------------- + * utility functions + *------------------------------------------------------------------------- + */ + +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 ); + +#if defined (H5DIFF_DEBUG) +void print_sizes( const char *obj1, const char *obj2, + hid_t f_type1, hid_t f_type2, + hid_t m_type1, hid_t m_type2 ); +#endif + +#ifdef NOT_YET +void diff_list( const char *filename, int nobjects, trav_info_t *info ); +#endif /* NOT_YET */ + + + +#endif /* H5DIFF_H__ */ diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c new file mode 100644 index 0000000..f9518de --- /dev/null +++ b/tools/lib/h5diff_array.c @@ -0,0 +1,1107 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + +#include "h5diff.h" +#include "H5private.h" +#include +#include + + + +/*------------------------------------------------------------------------- + * Function: diff_array + * + * Purpose: compare array; + * currenttly only the NATIVE types below are supported + * + * Return: number of differences found + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: May 30, 2003 + * + *------------------------------------------------------------------------- + */ +int diff_array( void *buf1, + void *buf2, + hsize_t tot_cnt, + int rank, + hsize_t *dims, + diff_opt_t options, + const char *obj1, + const char *obj2, + hid_t m_type ) +{ + char fmt_llong[255], fmt_ullong[255]; + char fmt_llongp[255], fmt_ullongp[255]; + size_t type_size;/* just check */ + int nfound=0; /* number of differences found */ + int ph=1; /* print header */ + int acc[32]; /* accumulator and matrix position */ + int pos[32]; + unsigned i; + int j; + char *_buf1 = (char*)buf1; + char *_buf2 = (char*)buf2; + + + /* Build default formats for long long types */ + sprintf(fmt_llong, "%%%sd %%%sd %%%sd\n", + H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH); + sprintf(fmt_ullong, "%%%su %%%su %%%su\n", + H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH); + sprintf(fmt_llongp, "%%%sd %%%sd %%%sd %%%sd\n", + H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH); + sprintf(fmt_ullongp, "%%%su %%%su %%%su %%%su\n", + H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH, H5_PRINTF_LL_WIDTH); + + + acc[rank-1]=1; + for(j=(rank-2); j>=0; j--) + { + acc[j]=acc[j+1]*(int)dims[j+1]; + } + + /* Get the size. */ + type_size = H5Tget_size( m_type ); + +/*------------------------------------------------------------------------- + * H5T_NATIVE_SCHAR + *------------------------------------------------------------------------- + */ + if (H5Tequal(m_type, H5T_NATIVE_SCHAR)) + { + char temp1_char; + char temp2_char; + assert(type_size==sizeof(char)); + for ( i = 0; i < tot_cnt; i++) + { + memcpy(&temp1_char, _buf1, sizeof(char)); + memcpy(&temp2_char, _buf2, sizeof(char)); + /* -d and !-p */ + if (options.d && !options.p) + { + if (abs(temp1_char-temp2_char) > options.delta) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(IFORMAT,temp1_char,temp2_char,abs(temp1_char-temp2_char)); + } + nfound++; + } + } + /* !-d and -p */ + else if (!options.d && options.p) + { + if ( temp1_char!=0 && abs(1-temp2_char/temp1_char) > options.percent ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + /* -d and -p */ + else if ( options.d && options.p) + { + if ( temp1_char!=0 && abs(1-temp2_char/temp1_char) > options.percent && + abs(temp1_char-temp2_char) > options.delta ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + else if (temp1_char != temp2_char) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(IFORMAT,temp1_char,temp2_char,abs(temp1_char-temp2_char)); + } + nfound++; + } + + _buf1+=sizeof(char); + _buf2+=sizeof(char); + }/* i */ + + } /*H5T_NATIVE_SCHAR*/ + + +/*------------------------------------------------------------------------- + * H5T_NATIVE_UCHAR + *------------------------------------------------------------------------- + */ + else if (H5Tequal(m_type, H5T_NATIVE_UCHAR)) + { + unsigned char temp1_uchar; + unsigned char temp2_uchar; + assert(type_size==sizeof(unsigned char)); + for ( i = 0; i < tot_cnt; i++) + { + memcpy(&temp1_uchar, _buf1, sizeof(unsigned char)); + memcpy(&temp2_uchar, _buf2, sizeof(unsigned char)); + /* -d and !-p */ + if (options.d && !options.p) + { + if (abs(temp1_uchar-temp2_uchar) > options.delta) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(IFORMAT,temp1_uchar,temp2_uchar,abs(temp1_uchar-temp2_uchar)); + } + nfound++; + } + } + /* !-d and -p */ + else if (!options.d && options.p) + { + if ( temp1_uchar!=0 && abs(1-temp2_uchar/temp1_uchar) > options.percent ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + /* -d and -p */ + else if ( options.d && options.p) + { + if ( temp1_uchar!=0 && abs(1-temp2_uchar/temp1_uchar) > options.percent && + abs(temp1_uchar-temp2_uchar) > options.delta ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + else if (temp1_uchar != temp2_uchar) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(IFORMAT,temp1_uchar,temp2_uchar,abs(temp1_uchar-temp2_uchar)); + } + nfound++; + } + + _buf1+=sizeof(unsigned char); + _buf2+=sizeof(unsigned char); + }/* i */ + + } /*H5T_NATIVE_UCHAR*/ + + +/*------------------------------------------------------------------------- + * H5T_NATIVE_SHORT + *------------------------------------------------------------------------- + */ + + else if (H5Tequal(m_type, H5T_NATIVE_SHORT)) + { + short temp1_short; + short temp2_short; + assert(type_size==sizeof(short)); + for ( i = 0; i < tot_cnt; i++) + { + memcpy(&temp1_short, _buf1, sizeof(short)); + memcpy(&temp2_short, _buf2, sizeof(short)); + /* -d and !-p */ + if (options.d && !options.p) + { + if (abs(temp1_short-temp2_short) > options.delta) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(IFORMAT,temp1_short,temp2_short,abs(temp1_short-temp2_short)); + } + nfound++; + } + } + /* !-d and -p */ + else if (!options.d && options.p) + { + if ( temp1_short!=0 && abs(1-temp2_short/temp1_short) > options.percent ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + /* -d and -p */ + else if ( options.d && options.p) + { + if ( temp1_short!=0 && abs(1-temp2_short/temp1_short) > options.percent && + abs(temp1_short-temp2_short) > options.delta ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + else if (temp1_short != temp2_short) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(IFORMAT,temp1_short,temp2_short,abs(temp1_short-temp2_short)); + } + nfound++; + } + + _buf1+=sizeof(short); + _buf2+=sizeof(short); + }/* i */ + + } /*H5T_NATIVE_SHORT*/ + +/*------------------------------------------------------------------------- + * H5T_NATIVE_USHORT + *------------------------------------------------------------------------- + */ + + else if (H5Tequal(m_type, H5T_NATIVE_USHORT)) + { + unsigned short temp1_ushort; + unsigned short temp2_ushort; + assert(type_size==sizeof(short)); + for ( i = 0; i < tot_cnt; i++) + { + memcpy(&temp1_ushort, _buf1, sizeof(unsigned short)); + memcpy(&temp2_ushort, _buf2, sizeof(unsigned short)); + /* -d and !-p */ + if (options.d && !options.p) + { + if (abs(temp1_ushort-temp2_ushort) > options.delta) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(IFORMAT,temp1_ushort,temp2_ushort,abs(temp1_ushort-temp2_ushort)); + } + nfound++; + } + } + /* !-d and -p */ + else if (!options.d && options.p) + { + if ( temp1_ushort!=0 && abs(1-temp2_ushort/temp1_ushort) > options.percent ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + /* -d and -p */ + else if ( options.d && options.p) + { + if ( temp1_ushort!=0 && abs(1-temp2_ushort/temp1_ushort) > options.percent && + abs(temp1_ushort-temp2_ushort) > options.delta ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + else if (temp1_ushort != temp2_ushort) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(IFORMAT,temp1_ushort,temp2_ushort,abs(temp1_ushort-temp2_ushort)); + } + nfound++; + } + + _buf1+=sizeof(unsigned short); + _buf2+=sizeof(unsigned short); + }/* i */ + + } /*H5T_NATIVE_USHORT*/ + + +/*------------------------------------------------------------------------- + * H5T_NATIVE_INT + *------------------------------------------------------------------------- + */ + + else if (H5Tequal(m_type, H5T_NATIVE_INT)) + { + int temp1_int; + int temp2_int; + assert(type_size==sizeof(int)); + for ( i = 0; i < tot_cnt; i++) + { + memcpy(&temp1_int, _buf1, sizeof(int)); + memcpy(&temp2_int, _buf2, sizeof(int)); + /* -d and !-p */ + if (options.d && !options.p) + { + if (abs(temp1_int-temp2_int) > options.delta) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(IFORMAT,temp1_int,temp2_int,abs(temp1_int-temp2_int)); + } + nfound++; + } + } + /* !-d and -p */ + else if (!options.d && options.p) + { + if ( temp1_int!=0 && abs(1-temp2_int/temp1_int) > options.percent ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + /* -d and -p */ + else if ( options.d && options.p) + { + if ( temp1_int!=0 && abs(1-temp2_int/temp1_int) > options.percent && + abs(temp1_int-temp2_int) > options.delta ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + else if (temp1_int != temp2_int) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(IFORMAT,temp1_int,temp2_int,abs(temp1_int-temp2_int)); + } + nfound++; + } + + _buf1+=sizeof(int); + _buf2+=sizeof(int); + }/* i */ + + } /*H5T_NATIVE_INT*/ + + +/*------------------------------------------------------------------------- + * H5T_NATIVE_UINT + *------------------------------------------------------------------------- + */ + + else if (H5Tequal(m_type, H5T_NATIVE_UINT)) + { + unsigned int temp1_uint; + unsigned int temp2_uint; + assert(type_size==sizeof(int)); + for ( i = 0; i < tot_cnt; i++) + { + memcpy(&temp1_uint, _buf1, sizeof(unsigned int)); + memcpy(&temp2_uint, _buf2, sizeof(unsigned int)); + /* -d and !-p */ + if (options.d && !options.p) + { + if (abs((int)(temp1_uint-temp2_uint)) > options.delta) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(UIFORMAT,temp1_uint,temp2_uint,abs((int)(temp1_uint-temp2_uint))); + } + nfound++; + } + } + /* !-d and -p */ + else if (!options.d && options.p) + { + if ( temp1_uint!=0 && abs((int)(1-temp2_uint/temp1_uint)) > options.percent ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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))); + } + nfound++; + } + } + /* -d and -p */ + else if ( options.d && options.p) + { + if ( temp1_uint!=0 && abs((int)(1-temp2_uint/temp1_uint)) > options.percent && + abs((int)(temp1_uint-temp2_uint)) > options.delta ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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))); + } + nfound++; + } + } + else if (temp1_uint != temp2_uint) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(UIFORMAT,temp1_uint,temp2_uint,abs((int)(temp1_uint-temp2_uint))); + } + nfound++; + } + + _buf1+=sizeof(unsigned int); + _buf2+=sizeof(unsigned int); + }/* i */ + + } /*H5T_NATIVE_UINT*/ + + +/*------------------------------------------------------------------------- + * H5T_NATIVE_LONG + *------------------------------------------------------------------------- + */ + + else if (H5Tequal(m_type, H5T_NATIVE_LONG)) + { + long temp1_long; + long temp2_long; + assert(type_size==sizeof(long)); + for ( i = 0; i < tot_cnt; i++) + { + memcpy(&temp1_long, _buf1, sizeof(long)); + memcpy(&temp2_long, _buf2, sizeof(long)); + /* -d and !-p */ + if (options.d && !options.p) + { + if (labs(temp1_long-temp2_long) > (long)options.delta) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(LIFORMAT,temp1_long,temp2_long,labs(temp1_long-temp2_long)); + } + nfound++; + } + } + /* !-d and -p */ + else if (!options.d && options.p) + { + if ( temp1_long!=0 && labs(1-temp2_long/temp1_long) > (long)options.percent ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + /* -d and -p */ + else if ( options.d && options.p) + { + if ( temp1_long!=0 && labs(1-temp2_long/temp1_long) > (long)options.percent && + labs(temp1_long-temp2_long) > (long)options.delta ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + else if (temp1_long != temp2_long) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(LIFORMAT,temp1_long,temp2_long,labs(temp1_long-temp2_long)); + } + nfound++; + } + + _buf1+=sizeof(long); + _buf2+=sizeof(long); + }/* i */ + + } /*H5T_NATIVE_LONG*/ + +/*------------------------------------------------------------------------- + * H5T_NATIVE_ULONG + *------------------------------------------------------------------------- + */ + + else if (H5Tequal(m_type, H5T_NATIVE_ULONG)) + { + unsigned long temp1_ulong; + unsigned long temp2_ulong; + assert(type_size==sizeof(unsigned long)); + for ( i = 0; i < tot_cnt; i++) + { + memcpy(&temp1_ulong, _buf1, sizeof(unsigned long)); + memcpy(&temp2_ulong, _buf2, sizeof(unsigned long)); + /* -d and !-p */ + if (options.d && !options.p) + { + if (labs((long)(temp1_ulong-temp2_ulong)) > (long)options.delta) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(ULIFORMAT,temp1_ulong,temp2_ulong,labs((long)(temp1_ulong-temp2_ulong))); + } + nfound++; + } + } + /* !-d and -p */ + else if (!options.d && options.p) + { + if ( temp1_ulong!=0 && labs((long)(1-temp2_ulong/temp1_ulong)) > (long)options.percent ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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))); + } + nfound++; + } + } + /* -d and -p */ + else if ( options.d && options.p) + { + if ( temp1_ulong!=0 && labs((long)(1-temp2_ulong/temp1_ulong)) > (long)options.percent && + labs((long)(temp1_ulong-temp2_ulong)) > (long)options.delta ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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))); + } + nfound++; + } + } + else if (temp1_ulong != temp2_ulong) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(ULIFORMAT,temp1_ulong,temp2_ulong,labs((long)(temp1_ulong-temp2_ulong))); + } + nfound++; + } + + _buf1+=sizeof(unsigned long); + _buf2+=sizeof(unsigned long); + }/* i */ + + } /*H5T_NATIVE_ULONG*/ + +/*------------------------------------------------------------------------- + * H5T_NATIVE_LLONG + *------------------------------------------------------------------------- + */ + + else if (H5Tequal(m_type, H5T_NATIVE_LLONG)) + { + long_long temp1_llong; + long_long temp2_llong; + assert(type_size==sizeof(long_long)); + for ( i = 0; i < tot_cnt; i++) + { + memcpy(&temp1_llong, _buf1, sizeof(long_long)); + memcpy(&temp2_llong, _buf2, sizeof(long_long)); + /* -d and !-p */ + if (options.d && !options.p) + { + if (labs((long)(temp1_llong-temp2_llong)) > (long)options.delta) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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))); + } + nfound++; + } + } + /* !-d and -p */ + else if (!options.d && options.p) + { + if ( temp1_llong!=0 && labs((long)(1-temp2_llong/temp1_llong)) > (long)options.percent ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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))); + } + nfound++; + } + } + /* -d and -p */ + else if ( options.d && options.p) + { + if ( temp1_llong!=0 && labs((long)(1-temp2_llong/temp1_llong)) > (long)options.percent && + labs((long)(temp1_llong-temp2_llong)) > (long)options.delta ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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))); + } + nfound++; + } + } + else if (temp1_llong != temp2_llong) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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))); + } + nfound++; + } + + _buf1+=sizeof(long_long); + _buf2+=sizeof(long_long); + }/* i */ + + } /*H5T_NATIVE_LLONG*/ + +/*------------------------------------------------------------------------- + * H5T_NATIVE_ULLONG + *------------------------------------------------------------------------- + */ + + else if (H5Tequal(m_type, H5T_NATIVE_ULLONG)) + { + unsigned long_long temp1_ullong; + unsigned long_long temp2_ullong; + assert(type_size==sizeof(unsigned long_long)); + for ( i = 0; i < tot_cnt; i++) + { + memcpy(&temp1_ullong, _buf1, sizeof(unsigned long_long)); + memcpy(&temp2_ullong, _buf2, sizeof(unsigned long_long)); + /* -d and !-p */ + if (options.d && !options.p) + { + if (labs((long)(temp1_ullong-temp2_ullong)) > (long)options.delta) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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))); + } + nfound++; + } + } + /* !-d and -p */ + else if (!options.d && options.p) + { + if ( temp1_ullong!=0 && labs((long)(1-temp2_ullong/temp1_ullong)) > (long)options.percent ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)), + (unsigned long_long)labs((long)(1-temp2_ullong/temp1_ullong))); + } + nfound++; + } + } + /* -d and -p */ + else if ( options.d && options.p) + { + if ( temp1_ullong!=0 && labs((long)(1-temp2_ullong/temp1_ullong)) > (long)options.percent && + labs((long)(temp1_ullong-temp2_ullong)) > (long)options.delta ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)), + (unsigned long_long)labs((long)(1-temp2_ullong/temp1_ullong))); + } + nfound++; + } + } + else if (temp1_ullong != temp2_ullong) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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))); + } + nfound++; + } + + _buf1+=sizeof(unsigned long_long); + _buf2+=sizeof(unsigned long_long); + }/* i */ + + } /*H5T_NATIVE_ULLONG*/ + +/*------------------------------------------------------------------------- + * H5T_NATIVE_FLOAT + *------------------------------------------------------------------------- + */ + + else if (H5Tequal(m_type, H5T_NATIVE_FLOAT)) + { + float temp1_float; + float temp2_float; + assert(type_size==sizeof(float)); + for ( i = 0; i < tot_cnt; i++) + { + memcpy(&temp1_float, _buf1, sizeof(float)); + memcpy(&temp2_float, _buf2, sizeof(float)); + /* -d and !-p */ + if (options.d && !options.p) + { + if (fabs(temp1_float-temp2_float) > options.delta) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(FFORMAT,temp1_float,temp2_float,fabs(temp1_float-temp2_float)); + } + nfound++; + } + } + /* !-d and -p */ + else if (!options.d && options.p) + { + if ( temp1_float!=0 && fabs(1-temp2_float/temp1_float) > options.percent ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + /* -d and -p */ + else if ( options.d && options.p) + { + if ( temp1_float!=0 && fabs(1-temp2_float/temp1_float) > options.percent && + fabs(temp1_float-temp2_float) > options.delta ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + else if (temp1_float != temp2_float) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(FFORMAT,temp1_float,temp2_float,fabs(temp1_float-temp2_float)); + } + nfound++; + } + + _buf1+=sizeof(float); + _buf2+=sizeof(float); + }/* i */ + + } /*H5T_NATIVE_FLOAT*/ + +/*------------------------------------------------------------------------- + * H5T_NATIVE_DOUBLE + *------------------------------------------------------------------------- + */ + + else if (H5Tequal(m_type, H5T_NATIVE_DOUBLE)) + { + double temp1_double; + double temp2_double; + assert(type_size==sizeof(double)); + for ( i = 0; i < tot_cnt; i++) + { + memcpy(&temp1_double, _buf1, sizeof(double)); + memcpy(&temp2_double, _buf2, sizeof(double)); + /* -d and !-p */ + if (options.d && !options.p) + { + if (fabs(temp1_double-temp2_double) > options.delta) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(FFORMAT,temp1_double,temp2_double,fabs(temp1_double-temp2_double)); + } + nfound++; + } + } + /* !-d and -p */ + else if (!options.d && options.p) + { + if ( temp1_double!=0 && fabs(1-temp2_double/temp1_double) > options.percent ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + /* -d and -p */ + else if ( options.d && options.p) + { + if ( temp1_double!=0 && fabs(1-temp2_double/temp1_double) > options.percent && + fabs(temp1_double-temp2_double) > options.delta ) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + 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)); + } + nfound++; + } + } + else if (temp1_double != temp2_double) + { + if (options.n && nfound>=options.count) + return nfound; + if ( options.r==0 ) + { + print_pos(&ph,0,i,acc,pos,rank,obj1,obj2); + printf(SPACES); + printf(FFORMAT,temp1_double,temp2_double,fabs(temp1_double-temp2_double)); + } + nfound++; + } + + _buf1+=sizeof(double); + _buf2+=sizeof(double); + }/* i */ + + } /*H5T_NATIVE_DOUBLE*/ + +/*------------------------------------------------------------------------- + * no more + *------------------------------------------------------------------------- + */ + else + { + assert(0); + } + + return nfound; +} + + diff --git a/tools/lib/h5diff_dset.c b/tools/lib/h5diff_dset.c new file mode 100644 index 0000000..15a8769 --- /dev/null +++ b/tools/lib/h5diff_dset.c @@ -0,0 +1,408 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "h5diff.h" +#include "H5private.h" +#include + + + +/*------------------------------------------------------------------------- + * Function: diff_dataset + * + * 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 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +int diff_dataset( hid_t file1_id, + hid_t file2_id, + const char *obj1_name, + const char *obj2_name, + diff_opt_t options ) +{ + 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[32], dims2[32]; + hsize_t maxdim1[32], maxdim2[32]; + H5T_class_t tclass1; + H5T_class_t tclass2; + 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 */ + int i; + + + /* disable error reporting */ + H5E_BEGIN_TRY { + +/*------------------------------------------------------------------------- + * open the handles + *------------------------------------------------------------------------- + */ + + /* Open the datasets */ + if ( (dset1_id = H5Dopen(file1_id,obj1_name)) < 0 ) + { + printf("Cannot open dataset <%s>\n", obj1_name ); + goto out; + } + if ( (dset2_id = H5Dopen(file2_id,obj2_name)) < 0 ) + { + printf("Cannot open dataset <%s>\n", obj2_name ); + goto out; + } + /* enable error reporting */ + } H5E_END_TRY; + + /* Get the dataspace handle */ + if ( (space1_id = H5Dget_space(dset1_id)) < 0 ) + goto out; + + /* Get rank */ + if ( (rank1 = H5Sget_simple_extent_ndims(space1_id)) < 0 ) + goto out; + + /* Get the dataspace handle */ + if ( (space2_id = H5Dget_space(dset2_id)) < 0 ) + goto out; + + /* Get rank */ + if ( (rank2 = H5Sget_simple_extent_ndims(space2_id)) < 0 ) + goto out; + + /* Get dimensions */ + if ( H5Sget_simple_extent_dims(space1_id,dims1,maxdim1) < 0 ) + goto out; + + /* Get dimensions */ + if ( H5Sget_simple_extent_dims(space2_id,dims2,maxdim2) < 0 ) + goto out; + +/*------------------------------------------------------------------------- + * Get the file data type + *------------------------------------------------------------------------- + */ + + /* Get the data type */ + if ( (f_type1 = H5Dget_type(dset1_id)) < 0 ) + goto out; + + /* Get the data type */ + if ( (f_type2 = H5Dget_type(dset2_id)) < 0 ) + goto out; + + +/*------------------------------------------------------------------------- + * check for the same class + *------------------------------------------------------------------------- + */ + + if ((tclass1=H5Tget_class(f_type1))<0) + goto out; + + if ((tclass2=H5Tget_class(f_type2))<0) + goto out; + + if ( tclass1 != tclass2 ) + { + 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) ); + goto out; + } + +/*------------------------------------------------------------------------- + * check for non supported classes + *------------------------------------------------------------------------- + */ + + assert(tclass1==tclass2); + switch (tclass1) + { + case H5T_TIME: + case H5T_STRING: + case H5T_BITFIELD: + case H5T_OPAQUE: + case H5T_COMPOUND: + case H5T_REFERENCE: + case H5T_ENUM: + case H5T_VLEN: + case H5T_ARRAY: + 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) ); + goto out; + default: + break; + } + +/*------------------------------------------------------------------------- + * check for the same rank + *------------------------------------------------------------------------- + */ + + if ( rank1 != rank2 ) + { + printf("Comparison not supported\n"); + printf("<%s> has rank %d, dimensions ", obj1_name, rank1); + print_dims(rank1,dims1); + printf(", max dimensions "); + print_dims(rank1,maxdim1); + printf("\n" ); + printf("<%s> has rank %d, dimensions ", obj2_name, rank2); + print_dims(rank2,dims2); + printf(", max dimensions "); + print_dims(rank2,maxdim2); + goto out; + } + +/*------------------------------------------------------------------------- + * check for different dimensions + *------------------------------------------------------------------------- + */ + + assert(rank1==rank2); + for ( i=0; i has rank %d, dimensions ", obj1_name, rank1); + print_dims(rank1,dims1); + printf(", max dimensions "); + print_dims(rank1,maxdim1); + printf("\n" ); + printf("<%s> has rank %d, dimensions ", obj2_name, rank2); + print_dims(rank2,dims2); + printf(", max dimensions "); + print_dims(rank2,maxdim2); + goto out; + } + +/*------------------------------------------------------------------------- + * maximum dimensions; just give a warning + *------------------------------------------------------------------------- + */ + if (maxdim_diff==1) + { + printf( "Warning: Different maximum dimensions\n"); + printf("<%s> has max dimensions ", obj1_name); + print_dims(rank1,maxdim1); + printf("\n"); + printf("<%s> has max dimensions ", obj2_name); + print_dims(rank2,maxdim2); + printf("\n"); + } + +/*------------------------------------------------------------------------- + * get number of elements + *------------------------------------------------------------------------- + */ + + 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]; + } + + assert(tot_cnt1==tot_cnt2); + +/*------------------------------------------------------------------------- + * check for equal file datatype; warning only + *------------------------------------------------------------------------- + */ + + if ( (H5Tequal(f_type1, f_type2)==0) ) + { + printf("Warning: Different storage datatype\n"); + printf("<%s> has file datatype ", obj1_name); + print_type(f_type1); + printf("\n"); + printf("<%s> has file datatype ", obj2_name); + print_type(f_type2); + printf("\n"); + } + +/*------------------------------------------------------------------------- + * memory type and sizes + *------------------------------------------------------------------------- + */ + + m_type1 = H5Tget_native_type( f_type1 , H5T_DIR_DEFAULT); + m_type2 = H5Tget_native_type( f_type2 , H5T_DIR_DEFAULT); + + m_size1 = H5Tget_size( m_type1 ); + m_size2 = H5Tget_size( m_type2 ); + +#if defined (H5DIFF_DEBUG) + 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 ) + { + 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 + *------------------------------------------------------------------------- + */ + + sign1=H5Tget_sign(m_type1); + sign2=H5Tget_sign(m_type2); + if ( sign1 != sign2 ) + { + 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)); + goto out; + } + + +/*------------------------------------------------------------------------- + * "upgrade" the smaller memory size + *------------------------------------------------------------------------- + */ + + if ( m_size1 != m_size2 ) + { + if ( m_size1 < m_size2 ) + { + assert( (H5Tclose(m_type1)) >=0); + m_type1 = H5Tget_native_type( f_type2 , H5T_DIR_DEFAULT); + m_size1 = H5Tget_size( m_type1 ); + } + else + { + assert( (H5Tclose(m_type2)) >=0); + m_type2 = H5Tget_native_type( f_type1 , H5T_DIR_DEFAULT); + m_size2 = H5Tget_size( m_type2 ); + } +#if defined (H5DIFF_DEBUG) + printf("WARNING: Size was upgraded\n"); + 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)); + + if ( buf1 == NULL || buf2 == NULL ) + { + printf( "cannot read into memory\n" ); + goto out; + } + +/*------------------------------------------------------------------------- + * read + *------------------------------------------------------------------------- + */ + + if ( H5Dread(dset1_id,m_type1,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf1) < 0 ) + goto out; + + if ( H5Dread(dset2_id,m_type2,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf2) < 0 ) + goto out; + +/*------------------------------------------------------------------------- + * 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) + printf("%d differences found\n", nfound ); + +/*------------------------------------------------------------------------- + * close + *------------------------------------------------------------------------- + */ + +out: + + if ( buf1) HDfree(buf1); + if ( buf2) HDfree(buf2); + + /* Close */ + if ( dset1_id!=-1 ) assert( (H5Dclose(dset1_id)) >=0); + if ( dset2_id!=-1 ) assert( (H5Dclose(dset2_id)) >=0); + if ( space1_id!=-1 ) assert( (H5Sclose(space1_id)) >=0); + if ( space2_id!=-1 ) assert( (H5Sclose(space2_id)) >=0); + if ( f_type1!=-1 ) assert( (H5Tclose(f_type1)) >=0); + if ( f_type2!=-1 ) assert( (H5Tclose(f_type2)) >=0); + if ( m_type1!=-1 ) assert( (H5Tclose(m_type1)) >=0); + if ( m_type2!=-1 ) assert( (H5Tclose(m_type2)) >=0); + + return nfound; + +} + diff --git a/tools/lib/h5diff_util.c b/tools/lib/h5diff_util.c new file mode 100644 index 0000000..0bf4a8e --- /dev/null +++ b/tools/lib/h5diff_util.c @@ -0,0 +1,409 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "h5diff.h" +#include + + + +/*------------------------------------------------------------------------- + * Function: diff_can + * + * Purpose: Check if TYPE_ID is supported; only the listed types are + * supported in the current version + * + *------------------------------------------------------------------------- + */ +int diff_can(hid_t type_id) +{ + int ret=0; + if ( (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 + * + * Purpose: convert an array index position to matrix notation + * + * Return: pos matrix array + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: May 9, 2003 + * + *------------------------------------------------------------------------- + */ +void print_pos( int *ph, int p, unsigned int curr_pos, int *acc, + int *pos, int rank, const char *obj1, const char *obj2 ) +{ + int i; + + /* print header */ + if ( *ph==1 ) + { + *ph=0; + if (p) + { + printf("%-15s %-15s %-15s %-15s %-15s\n", "position", obj1, obj2, "difference", + "relative"); + printf("------------------------------------------------------------------------\n"); + } + else + { + printf("%-15s %-15s %-15s %-20s\n", "position", obj1, 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]; + } + assert( curr_pos == 0 ); + + printf("[ " ); + for ( i = 0; i < rank; i++) + { + printf("%d ", pos[i] ); + } + printf("]" ); +} + +/*------------------------------------------------------------------------- + * Function: print_dims + * + * Purpose: print dimensions + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: May 9, 2003 + * + *------------------------------------------------------------------------- + */ +void print_dims( int r, hsize_t *d ) +{ + int i; + printf("[ " ); + for ( i=0; i0 && '/'==name[i-1]) + --i; + + /* Skip backward over base name */ + while (i>0 && '/'!=name[i-1]) + --i; + + return(name+i); +} + +/*------------------------------------------------------------------------- + * Function: get_type + * + * Purpose: Returns the type as a string + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: May 9, 2003 + * + *------------------------------------------------------------------------- + */ +const char* +get_type(int type) +{ + switch (type) + { + case H5G_DATASET: + return("H5G_DATASET"); + case H5G_GROUP: + return("H5G_GROUP"); + case H5G_TYPE: + return("H5G_TYPE"); + case H5G_LINK: + return("H5G_LINK"); + default: + return("user defined type"); + } +} + +/*------------------------------------------------------------------------- + * Function: get_sign + * + * Purpose: Returns the sign as a string + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: May 9, 2003 + * + * Comments: + * + *------------------------------------------------------------------------- + */ +const char* +get_sign(H5T_sign_t sign) +{ + switch (sign) + { + default: + return("H5T_SGN_ERROR"); + case H5T_SGN_NONE: + return("H5T_SGN_NONE"); + case H5T_SGN_2: + return("H5T_SGN_2"); + } +} + + +/*------------------------------------------------------------------------- + * Function: get_class + * + * Purpose: Returns the class as a string + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: May 9, 2003 + * + *------------------------------------------------------------------------- + */ +const char* +get_class(H5T_class_t tclass) +{ + switch (tclass) + { + default: + return("Invalid class"); + case H5T_TIME: + return("H5T_TIME"); + case H5T_INTEGER: + return("H5T_INTEGER"); + case H5T_FLOAT: + return("H5T_FLOAT"); + case H5T_STRING: + return("H5T_STRING"); + case H5T_BITFIELD: + return("H5T_BITFIELD"); + case H5T_OPAQUE: + return("H5T_OPAQUE"); + case H5T_COMPOUND: + return("H5T_COMPOUND"); + case H5T_REFERENCE: + return("H5T_REFERENCE"); + case H5T_ENUM: + return("H5T_ENUM"); + case H5T_VLEN: + return("H5T_VLEN"); + case H5T_ARRAY: + return("H5T_ARRAY"); + } +} + + +/*------------------------------------------------------------------------- + * Function: print_sizes + * + * Purpose: Print datatype sizes + * + *------------------------------------------------------------------------- + */ +#if defined (H5DIFF_DEBUG) +void print_sizes( const char *obj1, const char *obj2, + hid_t f_type1, hid_t f_type2, + hid_t m_type1, hid_t m_type2 ) +{ + size_t f_size1, f_size2; /* size of type in file */ + size_t m_size1, m_size2; /* size of type in memory */ + + f_size1 = H5Tget_size( f_type1 ); + f_size2 = H5Tget_size( f_type2 ); + m_size1 = H5Tget_size( m_type1 ); + m_size2 = H5Tget_size( m_type2 ); + + printf("\n"); + printf("------------------\n"); + printf("sizeof(char) %u\n", sizeof(char) ); + printf("sizeof(short) %u\n", sizeof(short) ); + printf("sizeof(int) %u\n", sizeof(int) ); + printf("sizeof(long) %u\n", sizeof(long) ); + printf("<%s> ------------------\n", obj1); + printf("type on file "); + print_type(f_type1); + printf("\n"); + printf("size on file %u\n", f_size1 ); + + printf("type on memory "); + print_type(m_type1); + printf("\n"); + printf("size on memory %u\n", m_size1 ); + + printf("<%s> ------------------\n", obj2); + printf("type on file "); + print_type(f_type2); + printf("\n"); + printf("size on file %u\n", f_size2 ); + + printf("type on memory "); + print_type(m_type2); + printf("\n"); + printf("size on memory %u\n", m_size2 ); + printf("\n"); +} +#endif /* H5DIFF_DEBUG */ + + diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c new file mode 100644 index 0000000..09c2033 --- /dev/null +++ b/tools/lib/h5trav.c @@ -0,0 +1,461 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + +#include "h5trav.h" +#include "H5private.h" + + + +/* functions for traversal */ +int traverse( hid_t loc_id, + const char *group_name, + trav_table_t *table, + trav_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 ); + +/*------------------------------------------------------------------------- + * Function: h5trav_getinfo + * + * Purpose: get an array of "trav_info_t" , containing the name and type of + * objects in the file + * + * Return: number of objects in file + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 6, 2002 + * + *------------------------------------------------------------------------- + */ + +int h5trav_getinfo( hid_t file_id, trav_info_t *info ) +{ + + trav_table_t *table=NULL; + int nobjects=0; + + /* init table */ + trav_table_init( &table ); + + /* iterate starting on the root group */ + if (( nobjects = traverse( file_id, "/", table, info, &nobjects )) < 0 ) + return -1; + + /* free table */ + trav_table_free( table ); + + return nobjects; + +} + + +/*------------------------------------------------------------------------- + * Function: h5trav_getindex + * + * Purpose: get index of OBJ in list + * + * Return: index, -1 if not found + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: May 9, 2003 + * + *------------------------------------------------------------------------- + */ + +int h5trav_getindex( const char *obj, int nobjs, trav_info_t *info ) +{ + char *pdest; + int result; + int i; + + for ( i = 0; i < nobjs; i++) + { + if ( strcmp(obj,info[i].name)==0 ) + return i; + + pdest = strstr( info[i].name, obj ); + result = (int)(pdest - info[i].name); + + /* found at position 1, meaning without '/' */ + if( pdest != NULL && result==1 ) + return i; + } + return -1; +} + + + +/*------------------------------------------------------------------------- + * Function: h5trav_freeinfo + * + * Purpose: free info memory + * + *------------------------------------------------------------------------- + */ + +void h5trav_freeinfo( trav_info_t *info, int nobjs ) +{ + int i; + if ( info ) + { + for ( i = 0; i < nobjs; i++) + { + if (info[i].name) + HDfree( info[i].name ); + } + HDfree(info); + } +} + + +/*------------------------------------------------------------------------- + * 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, 0, &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, 0, &statbuf) < 0 ) + return -1; + + ((trav_info_t *)op_data)->type = statbuf.type; + ((trav_info_t *)op_data)->name = (char *)HDstrdup(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 ) +{ + + trav_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: recursive function that searches HDF5 objects in LOC_ID + * + * Return: number of objects found in LOC_ID + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 4, 2002 + * + *------------------------------------------------------------------------- + */ + +int traverse( hid_t loc_id, + const char *group_name, + trav_table_t *table, + trav_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; + + 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*) HDmalloc(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 */ + H5E_BEGIN_TRY { + + /* get info */ + H5Gget_objinfo( loc_id, path, 1, &statbuf); + } H5E_END_TRY; + + /* add to array */ + if ( info ) + { + info[*idx].name = (char *)HDstrdup(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 && trav_table_search(statbuf.objno, table ) == -1) + { + /* add object to table */ + trav_table_add(statbuf.objno, path, H5G_GROUP, 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 = trav_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 && trav_table_search(statbuf.objno, table ) == -1) + { + /* add object to table */ + trav_table_add(statbuf.objno, path, H5G_DATASET, table ); + } + + /* search table + dataset with more than one link to it */ + if (statbuf.nlink > 1) + { + if ((j = trav_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 && trav_table_search(statbuf.objno, table ) == -1) + { + /* add object to table */ + trav_table_add(statbuf.objno, path, H5G_TYPE, table ); + } + + break; + + + /*------------------------------------------------------------------------- + * H5G_LINK + *------------------------------------------------------------------------- + */ + + case H5G_LINK: + + /* increment */ + inserted_objs++; + + break; + + + default: + break; + + } + + /*------------------------------------------------------------------------- + * end switch + *------------------------------------------------------------------------- + */ + + if ( name ) + HDfree( name ); + + if ( path ) + HDfree( path ); + + } /* i */ + + return inserted_objs; +} + diff --git a/tools/lib/h5trav.h b/tools/lib/h5trav.h new file mode 100644 index 0000000..cb61cd1 --- /dev/null +++ b/tools/lib/h5trav.h @@ -0,0 +1,94 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef H5TRAV_H__ +#define H5TRAV_H__ + +#include "hdf5.h" + + +/*------------------------------------------------------------------------- + * public struct to store name and type of an object + * the TYPE can be: + * H5G_UNKNOWN = -1, + * 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 + *------------------------------------------------------------------------- + */ + +typedef struct trav_info_t { + char *name; + H5G_obj_t type; +} trav_info_t; + + +/*------------------------------------------------------------------------- + * struct to store basic info needed for the h5trav table traversal algorythm + *------------------------------------------------------------------------- + */ + +typedef struct trav_obj_t { + haddr_t objno; + unsigned flags[2]; + char *objname; + int displayed; + H5G_obj_t type; +} trav_obj_t; + + +/*------------------------------------------------------------------------- + * private struct that stores all objects + *------------------------------------------------------------------------- + */ + +typedef struct trav_table_t { + int size; + int nobjs; + trav_obj_t *objs; +} trav_table_t; + + +/*------------------------------------------------------------------------- + * "h5trav info" public functions + *------------------------------------------------------------------------- + */ + +#ifdef __cplusplus +extern "C" { +#endif + +int h5trav_getinfo( hid_t file_id, trav_info_t *info ); +int h5trav_getindex( const char *obj, int nobjs, trav_info_t *info ); +void h5trav_freeinfo( trav_info_t *info, int nobjs ); + +#ifdef __cplusplus +} +#endif + +/*------------------------------------------------------------------------- + * table private functions + *------------------------------------------------------------------------- + */ + +void trav_table_init(trav_table_t **table); +void trav_table_free(trav_table_t *table); +int trav_table_search(haddr_t objno, trav_table_t *table ); +void trav_table_add(haddr_t objno, char *objname, int type, trav_table_t *table); +void trav_table_addflags(unsigned *flags, char *objname, int type, trav_table_t *table); + + + +#endif /* H5TRAV_H__ */ diff --git a/tools/lib/h5trav_table.c b/tools/lib/h5trav_table.c new file mode 100644 index 0000000..8d29c7c --- /dev/null +++ b/tools/lib/h5trav_table.c @@ -0,0 +1,193 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + +#include "h5trav.h" +#include "H5private.h" + +/*------------------------------------------------------------------------- + * Function: trav_table_search + * + * Purpose: Search in the table for OBJNO + * + * Return: index of object in table + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 4, 2002 + * + *------------------------------------------------------------------------- + */ + +int trav_table_search(haddr_t objno, trav_table_t *table ) +{ + int i; + + for (i = 0; i < table->nobjs; i++) + if (table->objs[i].objno == objno) + return i; + + return -1; +} + + +/*------------------------------------------------------------------------- + * Function: trav_table_add + * + * Purpose: Add OBJNO, NAME and TYPE of object to table + * + * Return: void + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 4, 2002 + * + *------------------------------------------------------------------------- + */ + +void +trav_table_add(haddr_t objno, char *objname, int type, trav_table_t *table) +{ + int i; + + if (table->nobjs == table->size) { + table->size *= 2; + table->objs = + (trav_obj_t*)HDrealloc(table->objs, table->size * sizeof(trav_obj_t)); + + for (i = table->nobjs; i < table->size; i++) { + table->objs[i].objno = 0; + table->objs[i].flags[0] = table->objs[i].flags[1] = 0; + table->objs[i].displayed = 0; + table->objs[i].type = H5G_UNKNOWN; + table->objs[i].objname = NULL; + } + } + + i = table->nobjs++; + table->objs[i].objno = objno; + table->objs[i].flags[0] = table->objs[i].flags[1] = 0; + HDfree(table->objs[i].objname); + table->objs[i].objname = (char *)HDstrdup(objname); + table->objs[i].type = type; +} + + +/*------------------------------------------------------------------------- + * Function: trav_table_addflags + * + * Purpose: Add FLAGS, NAME and TYPE of object to table + * + * Return: void + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 4, 2002 + * + *------------------------------------------------------------------------- + */ + +void +trav_table_addflags(unsigned *flags, char *objname, int type, trav_table_t *table) +{ + int i; + + if (table->nobjs == table->size) { + table->size *= 2; + table->objs = + (trav_obj_t*)HDrealloc(table->objs, table->size * sizeof(trav_obj_t)); + + for (i = table->nobjs; i < table->size; i++) { + table->objs[i].objno = 0; + table->objs[i].flags[0] = table->objs[i].flags[1] = 0; + table->objs[i].displayed = 0; + table->objs[i].type = H5G_UNKNOWN; + table->objs[i].objname = NULL; + } + } + + i = table->nobjs++; + table->objs[i].objno = 0; + table->objs[i].flags[0] = flags[0]; + table->objs[i].flags[1] = flags[1]; + HDfree(table->objs[i].objname); + table->objs[i].objname = (char *)HDstrdup(objname); + table->objs[i].type = type; +} + + +/*------------------------------------------------------------------------- + * Function: trav_table_init + * + * Purpose: Initialize the table + * + * Return: void + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 4, 2002 + * + *------------------------------------------------------------------------- + */ + +void trav_table_init( trav_table_t **tbl ) +{ + int i; + trav_table_t* table = (trav_table_t*) HDmalloc(sizeof(trav_table_t)); + + table->size = 20; + table->nobjs = 0; + table->objs = + (trav_obj_t*)HDmalloc(table->size * sizeof(trav_obj_t)); + + for (i = 0; i < table->size; i++) { + table->objs[i].objno = 0; + table->objs[i].flags[0] = table->objs[i].flags[1] = 0; + table->objs[i].displayed = 0; + table->objs[i].type = H5G_UNKNOWN; + table->objs[i].objname = NULL; + } + + *tbl = table; +} + + + +/*------------------------------------------------------------------------- + * Function: trav_table_free + * + * Purpose: free table memory + * + * Return: void + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 4, 2002 + * + *------------------------------------------------------------------------- + */ + +void trav_table_free( trav_table_t *table ) +{ + int i; + + for ( i = 0; i < table->nobjs; i++) + HDfree( table->objs[i].objname ); + + HDfree(table->objs); + HDfree(table); + +} + + -- cgit v0.12