summaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorJonathan Kim <jkm@hdfgroup.org>2011-03-22 15:47:07 (GMT)
committerJonathan Kim <jkm@hdfgroup.org>2011-03-22 15:47:07 (GMT)
commit4147de8d02fdfb651e860df999f87263d72be573 (patch)
tree0c12e5c4d19e03085adffaf51ac0fd7f1d67154e /tools/lib
parentf92d2371ffce9ec664833187cadb0223fa1dc1c2 (diff)
downloadhdf5-4147de8d02fdfb651e860df999f87263d72be573.zip
hdf5-4147de8d02fdfb651e860df999f87263d72be573.tar.gz
hdf5-4147de8d02fdfb651e860df999f87263d72be573.tar.bz2
[svn-r20294] Purpose:
Fixed CHICAGO: Bug 2121 - h5diff - incorrect and lack of output for the different set of attributes (different number and names) Description: Previously h5diff compared attributes correctly only when two objects have the same number of attributes and attribute names are identical. This fix covers all other cases. Also didn't display useful information about attribute difference. This fixes both issues. Tested: jam (linux32-LE), amani (linux64-LE), heiwa (linuxppc64-BE), tejeda (mac32-LE), linew (solaris-BE)
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/h5diff.c43
-rw-r--r--tools/lib/h5diff.h4
-rw-r--r--tools/lib/h5diff_attr.c308
-rw-r--r--tools/lib/h5tools_utils.c7
4 files changed, 317 insertions, 45 deletions
diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c
index a616dba..a4d8469 100644
--- a/tools/lib/h5diff.c
+++ b/tools/lib/h5diff.c
@@ -47,8 +47,7 @@
* 2) when diff was found (normal mode)
*-------------------------------------------------------------------------
*/
-int
-print_objname (diff_opt_t * options, hsize_t nfound)
+int print_objname (diff_opt_t * options, hsize_t nfound)
{
return ((options->m_verbose || nfound) && !options->m_quiet) ? 1 : 0;
}
@@ -60,13 +59,31 @@ print_objname (diff_opt_t * options, hsize_t nfound)
*
*-------------------------------------------------------------------------
*/
-void
-do_print_objname (const char *OBJ, const char *path1, const char *path2)
+void do_print_objname (const char *OBJ, const char *path1, const char *path2, diff_opt_t * opts)
{
+ /* if verbose level is higher than 0, put space line before
+ * displaying any object or symbolic links. This improves
+ * readability of the output.
+ */
+ if (opts->m_verbose_level >= 1)
+ parallel_print("\n");
parallel_print("%-7s: <%s> and <%s>\n", OBJ, path1, path2);
}
/*-------------------------------------------------------------------------
+ * Function: do_print_attrname
+ *
+ * Purpose: print attribute name
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+do_print_attrname (const char *attr, const char *path1, const char *path2)
+{
+ parallel_print("%-7s: <%s> and <%s>\n", attr, path1, path2);
+}
+
+/*-------------------------------------------------------------------------
* Function: print_warn
*
* Purpose: check print warning condition.
@@ -1689,7 +1706,7 @@ out:
{
if(print_objname(options, nfound))
{
- do_print_objname("dangling link", obj1name, obj2name);
+ do_print_objname("dangling link", obj1name, obj2name, options);
print_found(nfound);
}
}
@@ -1828,7 +1845,7 @@ hsize_t diff(hid_t file1_id,
/* verbose (-v) and report (-r) mode */
if(options->m_verbose || options->m_report)
{
- do_print_objname("dataset", path1, path2);
+ do_print_objname("dataset", path1, path2, options);
nfound = diff_dataset(file1_id, file2_id, path1, path2, options);
print_found(nfound);
}
@@ -1844,7 +1861,7 @@ hsize_t diff(hid_t file1_id,
/* print info if compatible and difference found */
if (!options->not_cmp && nfound)
{
- do_print_objname("dataset", path1, path2);
+ do_print_objname("dataset", path1, path2, options);
print_found(nfound);
}
}
@@ -1867,7 +1884,7 @@ hsize_t diff(hid_t file1_id,
nfound = (ret > 0) ? 0 : 1;
if(print_objname(options,nfound))
- do_print_objname("datatype", path1, path2);
+ do_print_objname("datatype", path1, path2, options);
/* always print the number of differences found in verbose mode */
if(options->m_verbose)
@@ -1894,7 +1911,7 @@ hsize_t diff(hid_t file1_id,
*/
case H5TRAV_TYPE_GROUP:
if(print_objname(options, nfound))
- do_print_objname("group", path1, path2);
+ do_print_objname("group", path1, path2, options);
/* always print the number of differences found in verbose mode */
if(options->m_verbose)
@@ -1933,7 +1950,7 @@ hsize_t diff(hid_t file1_id,
nfound = (ret != 0) ? 1 : 0;
if(print_objname(options, nfound))
- do_print_objname("link", path1, path2);
+ do_print_objname("link", path1, path2, options);
if (options->follow_links)
{
@@ -1985,7 +2002,7 @@ hsize_t diff(hid_t file1_id,
nfound = (ret != 0) ? 1 : 0;
if(print_objname(options, nfound))
- do_print_objname("external link", path1, path2);
+ do_print_objname("external link", path1, path2, options);
if (options->follow_links)
{
@@ -2021,7 +2038,7 @@ hsize_t diff(hid_t file1_id,
nfound = 0;
if (print_objname (options, nfound))
- do_print_objname ("user defined link", path1, path2);
+ do_print_objname ("user defined link", path1, path2, options);
} /* end else */
/* always print the number of differences found in verbose mode */
@@ -2058,7 +2075,7 @@ out2:
{
if(print_objname(options, nfound))
{
- do_print_objname("dangling link", path1, path2);
+ do_print_objname("dangling link", path1, path2, options);
print_found(nfound);
}
}
diff --git a/tools/lib/h5diff.h b/tools/lib/h5diff.h
index 7e4e016..19d5ed5 100644
--- a/tools/lib/h5diff.h
+++ b/tools/lib/h5diff.h
@@ -36,6 +36,7 @@ typedef struct {
int m_quiet; /* quiet mide: no output at all */
int m_report; /* report mode: print the data */
int m_verbose; /* verbose mode: print the data, list of objcets, warnings */
+ int m_verbose_level; /* control verbose details */
int d; /* delta, absolute value to compare */
double delta; /* delta value */
int p; /* relative error to compare*/
@@ -169,7 +170,8 @@ const char* get_class(H5T_class_t tclass);
const char* get_sign(H5T_sign_t sign);
void print_dimensions (int rank, hsize_t *dims);
int print_objname(diff_opt_t *options, hsize_t nfound);
-void do_print_objname (const char *OBJ, const char *path1, const char *path2);
+void do_print_objname (const char *OBJ, const char *path1, const char *path2, diff_opt_t * opts);
+void do_print_attrname (const char *attr, const char *path1, const char *path2);
/*-------------------------------------------------------------------------
diff --git a/tools/lib/h5diff_attr.c b/tools/lib/h5diff_attr.c
index 097c809..e5c5965 100644
--- a/tools/lib/h5diff_attr.c
+++ b/tools/lib/h5diff_attr.c
@@ -18,6 +18,262 @@
#include "h5tools_utils.h"
#include "h5diff.h"
+#define ATTR_NAME_MAX 255
+
+typedef struct table_attr_t {
+ char *name;
+ unsigned exist[2];
+} match_attr_t;
+
+typedef struct table_attrs_t {
+ size_t size;
+ size_t nattrs;
+ size_t nattrs_only1;
+ size_t nattrs_only2;
+ match_attr_t *attrs;
+} table_attrs_t;
+
+
+/*-------------------------------------------------------------------------
+ * Function: table_attrs_init
+ *
+ * Purpose: Initialize the table
+ *
+ * Parameter:
+ * - tbl [OUT]
+ *
+ * Programmer: Jonathan Kim
+ *
+ * Date: March 15, 2011
+ *------------------------------------------------------------------------*/
+static void table_attrs_init(table_attrs_t **tbl)
+{
+ table_attrs_t* table_attrs = (table_attrs_t*) HDmalloc(sizeof(table_attrs_t));
+
+ table_attrs->size = 0;
+ table_attrs->nattrs = 0;
+ table_attrs->nattrs_only1 = 0;
+ table_attrs->nattrs_only2 = 0;
+ table_attrs->attrs = NULL;
+
+ *tbl = table_attrs;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: table_attrs_free
+ *
+ * Purpose: free given table
+ *
+ * Parameter:
+ * - table [IN]
+ *
+ * Programmer: Jonathan Kim
+ *
+ * Date: March 15, 2011
+ *------------------------------------------------------------------------*/
+static void table_attrs_free( table_attrs_t *table )
+{
+ unsigned int i;
+
+ if (table)
+ {
+ if(table->attrs)
+ {
+ for(i = 0; i < table->nattrs; i++)
+ {
+ if(table->attrs[i].name)
+ HDfree(table->attrs[i].name );
+ } /* end for */
+ HDfree(table->attrs);
+ table->attrs = NULL;
+ } /* end if */
+ HDfree(table);
+ table = NULL;
+ }
+}
+
+/*-------------------------------------------------------------------------
+ * Function: table_attr_mark_exist
+ *
+ * Purpose: mark given attribute name to table as sign of exsit
+ *
+ * Parameter:
+ * - exist [IN]
+ * - name [IN] : attribute name
+ * - table [OUT]
+ *
+ * Programmer: Jonathan Kim
+ *
+ * Date: March 15, 2011
+ *------------------------------------------------------------------------*/
+static void table_attr_mark_exist(unsigned *exist, char *name, table_attrs_t *table)
+{
+ unsigned int new;
+
+ if(table->nattrs == table->size) {
+ table->size = MAX(1, table->size * 2);
+ table->attrs = (match_attr_t *)HDrealloc(table->attrs, table->size * sizeof(match_attr_t));
+ } /* end if */
+
+ new = table->nattrs++;
+ table->attrs[new].exist[0] = exist[0];
+ table->attrs[new].exist[1] = exist[1];
+ table->attrs[new].name = (char *)HDstrdup(name);
+}
+
+/*-------------------------------------------------------------------------
+ * Function: build_match_list_attrs
+ *
+ * Purpose: get list of matching attribute name from obj1 and obj2
+ *
+ * Note:
+ * Find common attribute; the algorithm for search is referred from
+ * build_match_list() in h5diff.c .
+ *
+ * Parameter:
+ * table_out [OUT] : return the list
+ *
+ * Programmer: Jonathan Kim
+ *
+ * Date: March 15, 2011
+ *------------------------------------------------------------------------*/
+static herr_t build_match_list_attrs(hid_t loc1_id, hid_t loc2_id, table_attrs_t ** table_out, diff_opt_t *options)
+{
+ H5O_info_t oinfo1, oinfo2; /* Object info */
+ hid_t attr1_id=-1; /* attr ID */
+ hid_t attr2_id=-1; /* attr ID */
+ size_t curr1 = 0;
+ size_t curr2 = 0;
+ unsigned infile[2];
+ char name1[ATTR_NAME_MAX];
+ char name2[ATTR_NAME_MAX];
+ int cmp;
+ unsigned i;
+ table_attrs_t *table_lp = NULL;
+
+ if(H5Oget_info(loc1_id, &oinfo1) < 0)
+ goto error;
+ if(H5Oget_info(loc2_id, &oinfo2) < 0)
+ goto error;
+
+ table_attrs_init( &table_lp );
+
+
+ /*--------------------------------------------------
+ * build the list
+ */
+ while(curr1 < oinfo1.num_attrs && curr2 < oinfo2.num_attrs)
+ {
+ /*------------------
+ * open attribute1 */
+ if((attr1_id = H5Aopen_by_idx(loc1_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr1, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
+ /* get name */
+ if(H5Aget_name(attr1_id, ATTR_NAME_MAX, name1) < 0)
+ goto error;
+
+ /*------------------
+ * open attribute2 */
+ if((attr2_id = H5Aopen_by_idx(loc2_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr2, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
+ /* get name */
+ if(H5Aget_name(attr2_id, ATTR_NAME_MAX, name2) < 0)
+ goto error;
+
+ /* criteria is string compare */
+ cmp = HDstrcmp(name1, name2);
+
+ if(cmp == 0)
+ {
+ infile[0] = 1;
+ infile[1] = 1;
+ table_attr_mark_exist(infile, name1, table_lp);
+ curr1++;
+ curr2++;
+ }
+ else if(cmp < 0)
+ {
+ infile[0] = 1;
+ infile[1] = 0;
+ table_attr_mark_exist(infile, name1, table_lp);
+ table_lp->nattrs_only1++;
+ curr1++;
+ }
+ else
+ {
+ infile[0] = 0;
+ infile[1] = 1;
+ table_attr_mark_exist(infile, name2, table_lp);
+ table_lp->nattrs_only2++;
+ curr2++;
+ }
+ } /* end while */
+
+ /* list1 did not end */
+ infile[0] = 1;
+ infile[1] = 0;
+ while(curr1 < oinfo1.num_attrs)
+ {
+ /*------------------
+ * open attribute1 */
+ if((attr1_id = H5Aopen_by_idx(loc1_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr1, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
+ /* get name */
+ if(H5Aget_name(attr1_id, ATTR_NAME_MAX, name1) < 0)
+ goto error;
+
+ table_attr_mark_exist(infile, name1, table_lp);
+ table_lp->nattrs_only1++;
+ curr1++;
+ }
+
+ /* list2 did not end */
+ infile[0] = 0;
+ infile[1] = 1;
+ while(curr2 < oinfo2.num_attrs)
+ {
+ /*------------------
+ * open attribute2 */
+ if((attr2_id = H5Aopen_by_idx(loc2_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr2, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
+ /* get name */
+ if(H5Aget_name(attr2_id, ATTR_NAME_MAX, name2) < 0)
+ goto error;
+
+ table_attr_mark_exist(infile, name2, table_lp);
+ table_lp->nattrs_only2++;
+ curr2++;
+ }
+
+ /*------------------------------------------------------
+ * print the list
+ */
+ if(options->m_verbose_level == 2)
+ {
+ /* if '-v2' is detected */
+ parallel_print(" obj1 obj2\n");
+ parallel_print(" --------------------------------------\n");
+ for(i = 0; i < (unsigned int) table_lp->nattrs; i++)
+ {
+ char c1, c2;
+ c1 = (table_lp->attrs[i].exist[0]) ? 'x' : ' ';
+ c2 = (table_lp->attrs[i].exist[1]) ? 'x' : ' ';
+ parallel_print("%5c %6c %-15s\n", c1, c2, table_lp->attrs[i].name);
+ } /* end for */
+ }
+
+ if(options->m_verbose_level >= 1)
+ {
+ parallel_print("Attributes status: %d common, %d only in obj1, %d only in obj2\n", table_lp->nattrs - table_lp->nattrs_only1 - table_lp->nattrs_only2, table_lp->nattrs_only1, table_lp->nattrs_only2 );
+ }
+
+ *table_out = table_lp;
+
+ return 0;
+
+error:
+ return -1;
+}
/*-------------------------------------------------------------------------
* Function: diff_attr
@@ -63,45 +319,33 @@ hsize_t diff_attr(hid_t loc1_id,
int rank2; /* rank of dataset */
hsize_t dims1[H5S_MAX_RANK];/* dimensions of dataset */
hsize_t dims2[H5S_MAX_RANK];/* dimensions of dataset */
- char name1[512];
- char name2[512];
+ char *name1;
+ char *name2;
char np1[512];
char np2[512];
- H5O_info_t oinfo1, oinfo2; /* Object info */
unsigned u; /* Local index variable */
hsize_t nfound = 0;
hsize_t nfound_total = 0;
int j;
- if(H5Oget_info(loc1_id, &oinfo1) < 0)
- goto error;
- if(H5Oget_info(loc2_id, &oinfo2) < 0)
+ table_attrs_t * match_list_attrs = NULL;
+ if( build_match_list_attrs(loc1_id, loc2_id, &match_list_attrs, options) < 0)
goto error;
- if(oinfo1.num_attrs != oinfo2.num_attrs)
- return 1;
-
- for(u = 0; u < (unsigned)oinfo1.num_attrs; u++) {
- /* reset buffers for every attribute, we might goto out and call free */
- buf1 = NULL;
- buf2 = NULL;
+ for(u = 0; u < (unsigned)match_list_attrs->nattrs; u++)
+ {
+ if( (match_list_attrs->attrs[u].exist[0]) && (match_list_attrs->attrs[u].exist[1]) )
+ {
+ name1 = name2 = match_list_attrs->attrs[u].name;
- /* open attribute */
- if((attr1_id = H5Aopen_by_idx(loc1_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto error;
- /* get name */
- if(H5Aget_name(attr1_id, 255, name1) < 0)
+ /*--------------
+ * attribute 1 */
+ if((attr1_id = H5Aopen(loc1_id, name1, H5P_DEFAULT)) < 0)
goto error;
- /* use the name on the first file to open the second file */
- H5E_BEGIN_TRY
- {
- if((attr2_id = H5Aopen(loc2_id, name1, H5P_DEFAULT)) < 0)
- goto error;
- } H5E_END_TRY;
-
- /* get name */
- if(H5Aget_name(attr2_id, 255, name2) < 0)
+ /*--------------
+ * attribute 2 */
+ if((attr2_id = H5Aopen(loc2_id, name2, H5P_DEFAULT)) < 0)
goto error;
/* get the datatypes */
@@ -192,7 +436,7 @@ hsize_t diff_attr(hid_t loc1_id,
/* always print name */
/* verbose (-v) and report (-r) mode */
if(options->m_verbose || options->m_report) {
- do_print_objname("attribute", np1, np2);
+ do_print_attrname("attribute", np1, np2);
nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1,
options, np1, np2, mtype1_id, attr1_id, attr2_id);
@@ -210,7 +454,7 @@ hsize_t diff_attr(hid_t loc1_id,
/* not comparable, no display the different number */
if(!options->not_cmp && nfound) {
- do_print_objname("attribute", np1, np2);
+ do_print_attrname("attribute", np1, np2);
print_found(nfound);
} /* end if */
} /* end else */
@@ -251,8 +495,11 @@ hsize_t diff_attr(hid_t loc1_id,
goto error;
nfound_total += nfound;
+ }
} /* u */
+ table_attrs_free(match_list_attrs);
+
return nfound_total;
error:
@@ -267,6 +514,9 @@ error:
H5Dvlen_reclaim(mtype2_id, space2_id, H5P_DEFAULT, buf2);
HDfree(buf2);
} /* end if */
+
+ table_attrs_free(match_list_attrs);
+
H5Tclose(ftype1_id);
H5Tclose(ftype2_id);
H5Tclose(mtype1_id);
diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c
index 7586fd0..5048b87 100644
--- a/tools/lib/h5tools_utils.c
+++ b/tools/lib/h5tools_utils.c
@@ -231,8 +231,11 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti
if (l_opts[i].has_arg != no_arg) {
if (arg[len] == '=') {
opt_arg = &arg[len + 1];
- } else if (opt_ind < (argc - 1) && argv[opt_ind + 1][0] != '-') {
- opt_arg = argv[++opt_ind];
+ }
+ else if (l_opts[i].has_arg != optional_arg) {
+ if (opt_ind < (argc - 1))
+ if (argv[opt_ind + 1][0] != '-')
+ opt_arg = argv[++opt_ind];
} else if (l_opts[i].has_arg == require_arg) {
if (opt_err)
HDfprintf(stderr,