2003-11-04 06:10:57 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
* Copyright by The HDF Group. *
|
2003-11-04 06:10:57 +08:00
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:36 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2017-04-18 03:32:16 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2003-11-04 06:10:57 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2011-02-09 05:35:54 +08:00
|
|
|
#include "H5private.h"
|
2004-10-07 00:11:18 +08:00
|
|
|
#include "h5tools.h"
|
2011-02-09 05:35:54 +08:00
|
|
|
#include "h5tools_utils.h"
|
2003-11-04 06:10:57 +08:00
|
|
|
#include "h5diff.h"
|
2011-02-09 05:35:54 +08:00
|
|
|
|
2011-03-22 23:47:07 +08:00
|
|
|
#define ATTR_NAME_MAX 255
|
|
|
|
|
|
|
|
typedef struct table_attr_t {
|
2022-07-27 05:45:46 +08:00
|
|
|
char *name;
|
2020-09-30 22:27:10 +08:00
|
|
|
unsigned exist[2];
|
2011-03-22 23:47:07 +08:00
|
|
|
} match_attr_t;
|
|
|
|
|
|
|
|
typedef struct table_attrs_t {
|
2020-09-30 22:27:10 +08:00
|
|
|
size_t size;
|
|
|
|
size_t nattrs;
|
|
|
|
size_t nattrs_only1;
|
|
|
|
size_t nattrs_only2;
|
2011-03-22 23:47:07 +08:00
|
|
|
match_attr_t *attrs;
|
|
|
|
} table_attrs_t;
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: table_attrs_init
|
|
|
|
*
|
|
|
|
* Purpose: Initialize the table
|
|
|
|
*
|
|
|
|
* Parameter:
|
|
|
|
* - tbl [OUT]
|
|
|
|
*
|
|
|
|
*------------------------------------------------------------------------*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
table_attrs_init(table_attrs_t **tbl)
|
2011-03-22 23:47:07 +08:00
|
|
|
{
|
2023-06-29 06:48:12 +08:00
|
|
|
table_attrs_t *table_attrs = (table_attrs_t *)malloc(sizeof(table_attrs_t));
|
2011-03-22 23:47:07 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
table_attrs->size = 0;
|
|
|
|
table_attrs->nattrs = 0;
|
2011-03-22 23:47:07 +08:00
|
|
|
table_attrs->nattrs_only1 = 0;
|
|
|
|
table_attrs->nattrs_only2 = 0;
|
2020-09-30 22:27:10 +08:00
|
|
|
table_attrs->attrs = NULL;
|
2011-03-22 23:47:07 +08:00
|
|
|
|
|
|
|
*tbl = table_attrs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: table_attrs_free
|
|
|
|
*
|
|
|
|
* Purpose: free given table
|
|
|
|
*
|
|
|
|
* Parameter:
|
|
|
|
* - table [IN]
|
|
|
|
*
|
|
|
|
*------------------------------------------------------------------------*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
table_attrs_free(table_attrs_t *table)
|
2011-03-22 23:47:07 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2016-08-02 01:26:41 +08:00
|
|
|
if (table) {
|
|
|
|
if (table->attrs) {
|
|
|
|
for (i = 0; i < table->nattrs; i++) {
|
|
|
|
if (table->attrs[i].name) {
|
2023-06-29 06:48:12 +08:00
|
|
|
free(table->attrs[i].name);
|
2016-08-02 01:26:41 +08:00
|
|
|
}
|
2011-03-22 23:47:07 +08:00
|
|
|
} /* end for */
|
2023-06-29 06:48:12 +08:00
|
|
|
free(table->attrs);
|
2011-03-22 23:47:07 +08:00
|
|
|
table->attrs = NULL;
|
|
|
|
} /* end if */
|
2023-06-29 06:48:12 +08:00
|
|
|
free(table);
|
2011-03-22 23:47:07 +08:00
|
|
|
table = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: table_attr_mark_exist
|
|
|
|
*
|
2017-05-20 00:35:07 +08:00
|
|
|
* Purpose: mark given attribute name to table as sign of exist
|
2011-03-22 23:47:07 +08:00
|
|
|
*
|
|
|
|
* Parameter:
|
|
|
|
* - exist [IN]
|
|
|
|
* - name [IN] : attribute name
|
|
|
|
* - table [OUT]
|
|
|
|
*
|
|
|
|
*------------------------------------------------------------------------*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
2021-03-10 00:59:44 +08:00
|
|
|
table_attr_mark_exist(const unsigned *exist, char *name, table_attrs_t *table)
|
2011-03-22 23:47:07 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
if (table->nattrs == table->size) {
|
2016-11-07 04:08:19 +08:00
|
|
|
match_attr_t *new_attrs;
|
|
|
|
|
2011-03-22 23:47:07 +08:00
|
|
|
table->size = MAX(1, table->size * 2);
|
2023-06-29 06:48:12 +08:00
|
|
|
new_attrs = (match_attr_t *)realloc(table->attrs, table->size * sizeof(match_attr_t));
|
2020-09-30 22:27:10 +08:00
|
|
|
if (new_attrs)
|
2016-05-05 00:39:28 +08:00
|
|
|
table->attrs = new_attrs;
|
2011-03-22 23:47:07 +08:00
|
|
|
} /* end if */
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (table->nattrs < table->size) {
|
2016-11-07 04:08:19 +08:00
|
|
|
size_t curr_val;
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
curr_val = table->nattrs;
|
2016-05-05 00:39:28 +08:00
|
|
|
table->attrs[curr_val].exist[0] = exist[0];
|
|
|
|
table->attrs[curr_val].exist[1] = exist[1];
|
2020-09-30 22:27:10 +08:00
|
|
|
if (name)
|
2023-09-16 06:13:18 +08:00
|
|
|
table->attrs[curr_val].name = (char *)strdup(name);
|
2016-05-05 00:39:28 +08:00
|
|
|
table->nattrs++;
|
|
|
|
}
|
2011-03-22 23:47:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: build_match_list_attrs
|
|
|
|
*
|
|
|
|
* Purpose: get list of matching attribute name from obj1 and obj2
|
|
|
|
*
|
|
|
|
* Note:
|
2016-05-05 00:39:28 +08:00
|
|
|
* Find common attribute; the algorithm for search is referred from
|
2011-03-22 23:47:07 +08:00
|
|
|
* build_match_list() in h5diff.c .
|
|
|
|
*
|
|
|
|
* Parameter:
|
|
|
|
* table_out [OUT] : return the list
|
|
|
|
*------------------------------------------------------------------------*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static herr_t
|
|
|
|
build_match_list_attrs(hid_t loc1_id, hid_t loc2_id, table_attrs_t **table_out, diff_opt_t *opts)
|
2011-03-22 23:47:07 +08:00
|
|
|
{
|
|
|
|
table_attrs_t *table_lp = NULL;
|
2020-09-30 22:27:10 +08:00
|
|
|
H5O_info2_t oinfo1, oinfo2; /* Object info */
|
|
|
|
hid_t attr1_id = H5I_INVALID_HID; /* attr ID */
|
|
|
|
hid_t attr2_id = H5I_INVALID_HID; /* attr ID */
|
|
|
|
size_t curr1 = 0;
|
|
|
|
size_t curr2 = 0;
|
2019-12-28 16:16:44 +08:00
|
|
|
unsigned infile[2];
|
|
|
|
char name1[ATTR_NAME_MAX];
|
|
|
|
char name2[ATTR_NAME_MAX];
|
|
|
|
int cmp;
|
|
|
|
unsigned i;
|
|
|
|
herr_t ret_value = SUCCEED;
|
|
|
|
|
2020-01-24 00:20:34 +08:00
|
|
|
H5TOOLS_START_DEBUG(" - errstat:%d", opts->err_stat);
|
2017-10-14 05:34:01 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Oget_info3(loc1_id, &oinfo1, H5O_INFO_NUM_ATTRS) < 0) {
|
2019-12-28 13:02:26 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(FAIL, "H5Oget_info first object failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
}
|
2020-01-17 05:29:34 +08:00
|
|
|
H5TOOLS_DEBUG("H5Oget_info3 loc1id=%d", oinfo1.num_attrs);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Oget_info3(loc2_id, &oinfo2, H5O_INFO_NUM_ATTRS) < 0) {
|
2019-12-28 13:02:26 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(FAIL, "H5Oget_info second object failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
}
|
2020-01-17 05:29:34 +08:00
|
|
|
H5TOOLS_DEBUG("H5Oget_info3 loc2id=%d", oinfo2.num_attrs);
|
2011-03-22 23:47:07 +08:00
|
|
|
|
2017-10-14 05:34:01 +08:00
|
|
|
table_attrs_init(&table_lp);
|
|
|
|
if (table_lp == NULL)
|
2019-12-28 13:02:26 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(FAIL, "Table allocation failed");
|
2011-03-22 23:47:07 +08:00
|
|
|
|
2016-05-05 00:39:28 +08:00
|
|
|
/*--------------------------------------------------
|
|
|
|
* build the list
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
while (curr1 < oinfo1.num_attrs && curr2 < oinfo2.num_attrs) {
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("list_attrs 1: %ld - %ld", curr1, oinfo1.num_attrs);
|
|
|
|
H5TOOLS_DEBUG("list_attrs 2: %ld - %ld", curr2, oinfo2.num_attrs);
|
2017-10-18 05:13:12 +08:00
|
|
|
|
2016-05-05 00:39:28 +08:00
|
|
|
/*------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* open attribute1 */
|
|
|
|
if ((attr1_id = H5Aopen_by_idx(loc1_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr1, H5P_DEFAULT,
|
|
|
|
H5P_DEFAULT)) < 0)
|
2019-12-28 13:02:26 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(FAIL, "H5Aopen_by_idx first attribute failed");
|
2011-03-22 23:47:07 +08:00
|
|
|
/* get name */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Aget_name(attr1_id, (size_t)ATTR_NAME_MAX, name1) < 0)
|
2019-12-28 13:02:26 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(FAIL, "H5Aget_name first attribute failed");
|
2011-03-22 23:47:07 +08:00
|
|
|
|
2016-05-05 00:39:28 +08:00
|
|
|
/*------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* open attribute2 */
|
|
|
|
if ((attr2_id = H5Aopen_by_idx(loc2_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr2, H5P_DEFAULT,
|
|
|
|
H5P_DEFAULT)) < 0)
|
2019-12-28 13:02:26 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(FAIL, "H5Aopen_by_idx second attribute failed");
|
2011-03-22 23:47:07 +08:00
|
|
|
/* get name */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Aget_name(attr2_id, (size_t)ATTR_NAME_MAX, name2) < 0)
|
2019-12-28 13:02:26 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(FAIL, "H5Aget_name second attribute failed");
|
2011-03-22 23:47:07 +08:00
|
|
|
|
|
|
|
/* criteria is string compare */
|
2023-09-16 06:13:18 +08:00
|
|
|
cmp = strcmp(name1, name2);
|
2011-03-22 23:47:07 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (cmp == 0) {
|
2011-03-22 23:47:07 +08:00
|
|
|
infile[0] = 1;
|
|
|
|
infile[1] = 1;
|
|
|
|
table_attr_mark_exist(infile, name1, table_lp);
|
|
|
|
curr1++;
|
|
|
|
curr2++;
|
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
else if (cmp < 0) {
|
2011-03-22 23:47:07 +08:00
|
|
|
infile[0] = 1;
|
|
|
|
infile[1] = 0;
|
|
|
|
table_attr_mark_exist(infile, name1, table_lp);
|
|
|
|
table_lp->nattrs_only1++;
|
|
|
|
curr1++;
|
|
|
|
}
|
2016-05-05 00:39:28 +08:00
|
|
|
else {
|
2011-03-22 23:47:07 +08:00
|
|
|
infile[0] = 0;
|
|
|
|
infile[1] = 1;
|
|
|
|
table_attr_mark_exist(infile, name2, table_lp);
|
|
|
|
table_lp->nattrs_only2++;
|
|
|
|
curr2++;
|
|
|
|
}
|
2012-10-20 05:28:14 +08:00
|
|
|
|
|
|
|
/* close for next turn */
|
|
|
|
H5Aclose(attr1_id);
|
2020-01-14 07:09:48 +08:00
|
|
|
attr1_id = H5I_INVALID_HID;
|
2012-10-20 05:28:14 +08:00
|
|
|
H5Aclose(attr2_id);
|
2020-01-14 07:09:48 +08:00
|
|
|
attr2_id = H5I_INVALID_HID;
|
2011-03-22 23:47:07 +08:00
|
|
|
} /* end while */
|
|
|
|
|
|
|
|
/* list1 did not end */
|
|
|
|
infile[0] = 1;
|
|
|
|
infile[1] = 0;
|
2020-09-30 22:27:10 +08:00
|
|
|
while (curr1 < oinfo1.num_attrs) {
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("list_attrs 1: %ld - %ld", curr1, oinfo1.num_attrs);
|
2017-10-18 05:13:12 +08:00
|
|
|
|
2016-05-05 00:39:28 +08:00
|
|
|
/*------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* open attribute1 */
|
|
|
|
if ((attr1_id = H5Aopen_by_idx(loc1_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr1, H5P_DEFAULT,
|
|
|
|
H5P_DEFAULT)) < 0)
|
2019-12-28 13:02:26 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(FAIL, "H5Aopen_by_idx first attribute failed");
|
2011-03-22 23:47:07 +08:00
|
|
|
/* get name */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Aget_name(attr1_id, (size_t)ATTR_NAME_MAX, name1) < 0)
|
2019-12-28 13:02:26 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(FAIL, "H5Aget_name first attribute failed");
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("list_attrs 1 name - %s", name1);
|
2011-03-22 23:47:07 +08:00
|
|
|
|
|
|
|
table_attr_mark_exist(infile, name1, table_lp);
|
|
|
|
table_lp->nattrs_only1++;
|
|
|
|
curr1++;
|
2012-10-20 05:28:14 +08:00
|
|
|
|
|
|
|
/* close for next turn */
|
|
|
|
H5Aclose(attr1_id);
|
2020-01-14 07:09:48 +08:00
|
|
|
attr1_id = H5I_INVALID_HID;
|
2011-03-22 23:47:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* list2 did not end */
|
|
|
|
infile[0] = 0;
|
|
|
|
infile[1] = 1;
|
2020-09-30 22:27:10 +08:00
|
|
|
while (curr2 < oinfo2.num_attrs) {
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("list_attrs 2: %ld - %ld", curr2, oinfo2.num_attrs);
|
2016-05-05 00:39:28 +08:00
|
|
|
/*------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* open attribute2 */
|
|
|
|
if ((attr2_id = H5Aopen_by_idx(loc2_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr2, H5P_DEFAULT,
|
|
|
|
H5P_DEFAULT)) < 0)
|
2019-12-28 13:02:26 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(FAIL, "H5Aopen_by_idx second attribute failed");
|
2011-03-22 23:47:07 +08:00
|
|
|
/* get name */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Aget_name(attr2_id, (size_t)ATTR_NAME_MAX, name2) < 0)
|
2019-12-28 13:02:26 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(FAIL, "H5Aget_name second attribute failed");
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("list_attrs 2 name - %s", name2);
|
2011-03-22 23:47:07 +08:00
|
|
|
|
|
|
|
table_attr_mark_exist(infile, name2, table_lp);
|
|
|
|
table_lp->nattrs_only2++;
|
|
|
|
curr2++;
|
2012-10-20 05:28:14 +08:00
|
|
|
|
|
|
|
/* close for next turn */
|
|
|
|
H5Aclose(attr2_id);
|
2020-01-14 07:09:48 +08:00
|
|
|
attr2_id = H5I_INVALID_HID;
|
2011-03-22 23:47:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------
|
2016-05-05 00:39:28 +08:00
|
|
|
* print the list
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
if (opts->mode_verbose_level == 2) {
|
2011-03-22 23:47:07 +08:00
|
|
|
/* if '-v2' is detected */
|
|
|
|
parallel_print(" obj1 obj2\n");
|
|
|
|
parallel_print(" --------------------------------------\n");
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < (unsigned int)table_lp->nattrs; i++) {
|
2019-12-12 00:44:56 +08:00
|
|
|
int c1, c2;
|
2011-03-22 23:47:07 +08:00
|
|
|
c1 = (table_lp->attrs[i].exist[0]) ? 'x' : ' ';
|
|
|
|
c2 = (table_lp->attrs[i].exist[1]) ? 'x' : ' ';
|
2016-11-07 04:08:19 +08:00
|
|
|
parallel_print("%5c %6c %-15s\n", c1, c2, table_lp->attrs[i].name);
|
2011-03-22 23:47:07 +08:00
|
|
|
} /* end for */
|
|
|
|
}
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (opts->mode_verbose_level >= 1)
|
2022-02-05 00:53:55 +08:00
|
|
|
parallel_print("Attributes status: %zu common, %zu only in obj1, %zu only in obj2\n",
|
2020-09-30 22:27:10 +08:00
|
|
|
table_lp->nattrs - table_lp->nattrs_only1 - table_lp->nattrs_only2,
|
|
|
|
table_lp->nattrs_only1, table_lp->nattrs_only2);
|
2011-03-22 23:47:07 +08:00
|
|
|
|
2017-10-14 05:34:01 +08:00
|
|
|
done:
|
2011-03-22 23:47:07 +08:00
|
|
|
*table_out = table_lp;
|
|
|
|
|
2017-10-14 05:34:01 +08:00
|
|
|
/* disable error reporting */
|
2020-09-30 22:27:10 +08:00
|
|
|
H5E_BEGIN_TRY
|
|
|
|
{
|
2012-10-20 05:28:14 +08:00
|
|
|
H5Aclose(attr1_id);
|
|
|
|
H5Aclose(attr2_id);
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
2023-06-16 12:49:02 +08:00
|
|
|
H5E_END_TRY
|
2017-10-14 05:34:01 +08:00
|
|
|
|
2020-01-24 00:20:34 +08:00
|
|
|
H5TOOLS_ENDDEBUG(" - errstat:%d", opts->err_stat);
|
2012-10-20 05:28:14 +08:00
|
|
|
|
2017-10-14 05:34:01 +08:00
|
|
|
return ret_value;
|
2011-03-22 23:47:07 +08:00
|
|
|
}
|
2003-11-04 06:10:57 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2019-12-20 06:29:35 +08:00
|
|
|
* Function: diff_attr_data
|
2003-11-04 06:10:57 +08:00
|
|
|
*
|
2019-12-20 06:29:35 +08:00
|
|
|
* Purpose: compare attribute data located in attr1_id and attr2_id, which are
|
|
|
|
* obtained from open attributes
|
2007-03-06 00:26:50 +08:00
|
|
|
*
|
2017-10-14 05:34:01 +08:00
|
|
|
* Return: number of differences found
|
2003-11-04 06:10:57 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t
|
|
|
|
diff_attr_data(hid_t attr1_id, hid_t attr2_id, const char *name1, const char *name2, const char *path1,
|
|
|
|
const char *path2, diff_opt_t *opts)
|
2003-11-04 06:10:57 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t space1_id = H5I_INVALID_HID; /* space ID */
|
|
|
|
hid_t space2_id = H5I_INVALID_HID; /* space ID */
|
|
|
|
hid_t ftype1_id = H5I_INVALID_HID; /* file data type ID */
|
|
|
|
hid_t ftype2_id = H5I_INVALID_HID; /* file data type ID */
|
|
|
|
hid_t mtype1_id = H5I_INVALID_HID; /* memory data type ID */
|
|
|
|
hid_t mtype2_id = H5I_INVALID_HID; /* memory data type ID */
|
|
|
|
size_t msize1; /* memory size of memory type */
|
|
|
|
size_t msize2; /* memory size of memory type */
|
2022-07-27 05:45:46 +08:00
|
|
|
void *buf1 = NULL; /* data buffer */
|
|
|
|
void *buf2 = NULL; /* data buffer */
|
2023-09-06 02:50:06 +08:00
|
|
|
bool buf1hasdata = false; /* buffer has data */
|
|
|
|
bool buf2hasdata = false; /* buffer has data */
|
2020-09-30 22:27:10 +08:00
|
|
|
int rank1; /* rank of dataset */
|
|
|
|
int rank2; /* rank of dataset */
|
|
|
|
hsize_t dims1[H5S_MAX_RANK]; /* dimensions of dataset */
|
|
|
|
hsize_t dims2[H5S_MAX_RANK]; /* dimensions of dataset */
|
2008-08-22 03:15:05 +08:00
|
|
|
hsize_t nfound = 0;
|
2020-08-06 08:15:57 +08:00
|
|
|
size_t sz;
|
2019-12-28 16:16:44 +08:00
|
|
|
diff_err_t ret_value = opts->err_stat;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-01-24 00:20:34 +08:00
|
|
|
H5TOOLS_START_DEBUG(" - errstat:%d", opts->err_stat);
|
2019-12-20 06:29:35 +08:00
|
|
|
/* get the datatypes */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((ftype1_id = H5Aget_type(attr1_id)) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aget_type first attribute failed");
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((ftype2_id = H5Aget_type(attr2_id)) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aget_type second attribute failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
|
|
|
|
if (H5Tget_class(ftype1_id) == H5T_REFERENCE) {
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((mtype1_id = H5Tcopy(H5T_STD_REF)) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tcopy(H5T_STD_REF) first attribute ftype failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
}
|
|
|
|
else {
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((mtype1_id = H5Tget_native_type(ftype1_id, H5T_DIR_DEFAULT)) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tget_native_type first attribute ftype failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
}
|
|
|
|
if (H5Tget_class(ftype2_id) == H5T_REFERENCE) {
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((mtype2_id = H5Tcopy(H5T_STD_REF)) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tcopy(H5T_STD_REF) second attribute ftype failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
}
|
|
|
|
else {
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((mtype2_id = H5Tget_native_type(ftype2_id, H5T_DIR_DEFAULT)) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tget_native_type second attribute ftype failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((msize1 = H5Tget_size(mtype1_id)) == 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tget_size first attribute mtype failed");
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((msize2 = H5Tget_size(mtype2_id)) == 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tget_size second attribute mtype failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
|
|
|
|
/* get the dataspace */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((space1_id = H5Aget_space(attr1_id)) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aget_space first attribute failed");
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((space2_id = H5Aget_space(attr2_id)) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aget_space second attribute failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
|
|
|
|
/* get dimensions */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((rank1 = H5Sget_simple_extent_dims(space1_id, dims1, NULL)) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Sget_simple_extent_dims first attribute failed");
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((rank2 = H5Sget_simple_extent_dims(space2_id, dims2, NULL)) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Sget_simple_extent_dims second attribute failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* check for comparable TYPE and SPACE
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*/
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("Check for comparable TYPE and SPACE");
|
|
|
|
|
|
|
|
H5TOOLS_DEBUG("attr_names: %s - %s", name1, name2);
|
|
|
|
if (name1) {
|
2023-09-16 06:13:18 +08:00
|
|
|
sz = strlen(name1);
|
2020-08-06 08:15:57 +08:00
|
|
|
H5TOOLS_DEBUG("attr1_name: %s - %d", name1, sz);
|
|
|
|
if (sz > 0) {
|
2023-06-29 06:48:12 +08:00
|
|
|
opts->obj_name[0] = (char *)malloc(sz + 1);
|
2023-09-16 06:13:18 +08:00
|
|
|
strncpy(opts->obj_name[0], name1, sz + 1);
|
2020-07-16 00:20:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (name2) {
|
2023-09-16 06:13:18 +08:00
|
|
|
sz = strlen(name2);
|
2020-08-06 08:15:57 +08:00
|
|
|
H5TOOLS_DEBUG("attr2_name: %s - %d", name2, sz);
|
|
|
|
if (sz > 0) {
|
2023-06-29 06:48:12 +08:00
|
|
|
opts->obj_name[1] = (char *)malloc(sz + 1);
|
2023-09-16 06:13:18 +08:00
|
|
|
strncpy(opts->obj_name[1], name2, sz + 1);
|
2020-07-16 00:20:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
H5TOOLS_DEBUG("attr_names: %s - %s", opts->obj_name[0], opts->obj_name[1]);
|
2019-12-20 06:29:35 +08:00
|
|
|
|
|
|
|
/* pass dims1 and dims2 for maxdims as well since attribute's maxdims
|
2020-09-30 22:27:10 +08:00
|
|
|
* are always same */
|
|
|
|
if (diff_can_type(ftype1_id, ftype2_id, rank1, rank2, dims1, dims2, dims1, dims2, opts, 0) == 1) {
|
2020-08-06 08:15:57 +08:00
|
|
|
|
|
|
|
int j;
|
|
|
|
|
2019-12-20 06:29:35 +08:00
|
|
|
/*-----------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* "upgrade" the smaller memory size
|
|
|
|
*------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
if (FAIL == match_up_memsize(ftype1_id, ftype2_id, &mtype1_id, &mtype2_id, &msize1, &msize2))
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "match_up_memsize failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("initialize read");
|
2019-12-20 06:29:35 +08:00
|
|
|
/*---------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* initialize diff_opt_t structure for dimensions
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*/
|
2020-07-16 00:20:16 +08:00
|
|
|
opts->nelmts = 1;
|
2020-09-30 22:27:10 +08:00
|
|
|
for (j = 0; j < rank1; j++) {
|
2020-07-16 00:20:16 +08:00
|
|
|
opts->dims[j] = dims1[j];
|
|
|
|
opts->nelmts *= dims1[j];
|
|
|
|
}
|
|
|
|
opts->rank = rank1;
|
2020-07-31 00:25:24 +08:00
|
|
|
init_acc_pos((unsigned)opts->rank, opts->dims, opts->acc, opts->pos, opts->p_min_idx);
|
2019-12-20 06:29:35 +08:00
|
|
|
|
2020-07-16 00:20:16 +08:00
|
|
|
/*---------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* read
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*/
|
2023-06-29 06:48:12 +08:00
|
|
|
buf1 = (void *)calloc((size_t)(opts->nelmts), msize1);
|
|
|
|
buf2 = (void *)calloc((size_t)(opts->nelmts), msize2);
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("attr buffer size %ld * %ld", opts->nelmts, msize1);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (buf1 == NULL || buf2 == NULL) {
|
2019-12-20 06:29:35 +08:00
|
|
|
parallel_print("cannot read into memory\n");
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "buffer allocation failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Aread(attr1_id, mtype1_id, buf1) < 0) {
|
2019-12-20 06:29:35 +08:00
|
|
|
parallel_print("Failed reading attribute1 %s\n", name1);
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aget_type first attribute failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
}
|
|
|
|
else
|
2023-09-06 02:50:06 +08:00
|
|
|
buf1hasdata = true;
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("attr H5Aread 1");
|
2019-12-20 06:29:35 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Aread(attr2_id, mtype2_id, buf2) < 0) {
|
2019-12-20 06:29:35 +08:00
|
|
|
parallel_print("Failed reading attribute2 %s\n", name2);
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aget_type second attribute failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
}
|
|
|
|
else
|
2023-09-06 02:50:06 +08:00
|
|
|
buf2hasdata = true;
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("attr H5Aread 2");
|
2019-12-20 06:29:35 +08:00
|
|
|
|
|
|
|
/* format output string */
|
2020-07-16 00:20:16 +08:00
|
|
|
if (opts->obj_name[0] != NULL)
|
2023-06-29 06:48:12 +08:00
|
|
|
free(opts->obj_name[0]);
|
2020-07-16 00:20:16 +08:00
|
|
|
opts->obj_name[0] = NULL;
|
|
|
|
if (opts->obj_name[1] != NULL)
|
2023-06-29 06:48:12 +08:00
|
|
|
free(opts->obj_name[1]);
|
2020-07-16 00:20:16 +08:00
|
|
|
opts->obj_name[1] = NULL;
|
|
|
|
|
|
|
|
H5TOOLS_DEBUG("attr_names: %s - %s : %s - %s", name1, name2, path1, path2);
|
|
|
|
if (name1) {
|
2023-09-16 06:13:18 +08:00
|
|
|
sz = strlen(name1) + strlen(path1) + 7;
|
2020-08-06 08:15:57 +08:00
|
|
|
H5TOOLS_DEBUG("attr1_name: %s - %d", name1, sz);
|
2023-06-29 06:48:12 +08:00
|
|
|
opts->obj_name[0] = (char *)calloc(sz + 1, sizeof(char));
|
2023-09-16 06:13:18 +08:00
|
|
|
snprintf(opts->obj_name[0], sz, "%s of <%s>", name1, path1);
|
2020-08-06 08:15:57 +08:00
|
|
|
opts->obj_name[0][sz] = '\0';
|
2020-07-16 00:20:16 +08:00
|
|
|
}
|
|
|
|
if (name2) {
|
2023-09-16 06:13:18 +08:00
|
|
|
sz = strlen(name2) + strlen(path2) + 7;
|
2020-08-06 08:15:57 +08:00
|
|
|
H5TOOLS_DEBUG("attr2_name: %s - %d", name2, sz);
|
2023-06-29 06:48:12 +08:00
|
|
|
opts->obj_name[1] = (char *)calloc(sz + 1, sizeof(char));
|
2023-09-16 06:13:18 +08:00
|
|
|
snprintf(opts->obj_name[1], sz, "%s of <%s>", name2, path2);
|
2020-08-06 08:15:57 +08:00
|
|
|
opts->obj_name[1][sz] = '\0';
|
2020-07-16 00:20:16 +08:00
|
|
|
}
|
2019-12-20 06:29:35 +08:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* array compare
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*/
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("array compare %s - %s", opts->obj_name[0], opts->obj_name[1]);
|
|
|
|
|
|
|
|
opts->hs_nelmts = opts->nelmts;
|
2020-09-30 22:27:10 +08:00
|
|
|
opts->m_tid = mtype1_id;
|
2020-07-16 00:20:16 +08:00
|
|
|
|
|
|
|
/* initialize the current stripmine position; this is necessary to print the array indices */
|
|
|
|
for (j = 0; j < opts->rank; j++)
|
|
|
|
opts->sm_pos[j] = (hsize_t)0;
|
2019-12-20 06:29:35 +08:00
|
|
|
|
|
|
|
/* always print name */
|
|
|
|
/* verbose (-v) and report (-r) mode */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (opts->mode_verbose || opts->mode_report) {
|
2020-07-16 00:20:16 +08:00
|
|
|
do_print_attrname("attribute", opts->obj_name[0], opts->obj_name[1]);
|
2019-12-20 06:29:35 +08:00
|
|
|
|
2020-07-16 00:20:16 +08:00
|
|
|
nfound = diff_array(buf1, buf2, opts, attr1_id, attr2_id);
|
2019-12-20 06:29:35 +08:00
|
|
|
print_found(nfound);
|
|
|
|
}
|
|
|
|
/* quiet mode (-q), just count differences */
|
2020-09-30 22:27:10 +08:00
|
|
|
else if (opts->mode_quiet) {
|
2020-07-16 00:20:16 +08:00
|
|
|
nfound = diff_array(buf1, buf2, opts, attr1_id, attr2_id);
|
2019-12-20 06:29:35 +08:00
|
|
|
}
|
|
|
|
/* the rest (-c, none, ...) */
|
|
|
|
else {
|
2020-07-16 00:20:16 +08:00
|
|
|
nfound = diff_array(buf1, buf2, opts, attr1_id, attr2_id);
|
2019-12-20 06:29:35 +08:00
|
|
|
|
|
|
|
/* print info if compatible and difference found */
|
|
|
|
if (nfound) {
|
2020-07-16 00:20:16 +08:00
|
|
|
do_print_attrname("attribute", opts->obj_name[0], opts->obj_name[1]);
|
2019-12-20 06:29:35 +08:00
|
|
|
print_found(nfound);
|
|
|
|
} /* end if */
|
2020-09-30 22:27:10 +08:00
|
|
|
} /* end else */
|
2019-12-20 06:29:35 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
H5TOOLS_DEBUG("check for comparable TYPE and SPACE complete nfound:%d - errstat:%d", nfound,
|
|
|
|
opts->err_stat);
|
2019-12-20 06:29:35 +08:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* close
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
if (opts->obj_name[0] != NULL)
|
2023-06-29 06:48:12 +08:00
|
|
|
free(opts->obj_name[0]);
|
2020-09-30 22:27:10 +08:00
|
|
|
opts->obj_name[0] = NULL;
|
|
|
|
if (opts->obj_name[1] != NULL)
|
2023-06-29 06:48:12 +08:00
|
|
|
free(opts->obj_name[1]);
|
2020-09-30 22:27:10 +08:00
|
|
|
opts->obj_name[1] = NULL;
|
2019-12-20 06:29:35 +08:00
|
|
|
|
|
|
|
/* Free buf1 and buf2, check both VLEN-data VLEN-string to reclaim any
|
2020-09-30 22:27:10 +08:00
|
|
|
* VLEN memory first */
|
2023-09-06 02:50:06 +08:00
|
|
|
if (true == h5tools_detect_vlen(mtype1_id))
|
2019-12-20 06:29:35 +08:00
|
|
|
H5Treclaim(mtype1_id, space1_id, H5P_DEFAULT, buf1);
|
2023-06-29 06:48:12 +08:00
|
|
|
free(buf1);
|
2019-12-20 06:29:35 +08:00
|
|
|
buf1 = NULL;
|
|
|
|
|
2023-09-06 02:50:06 +08:00
|
|
|
if (true == h5tools_detect_vlen(mtype2_id))
|
2019-12-20 06:29:35 +08:00
|
|
|
H5Treclaim(mtype2_id, space2_id, H5P_DEFAULT, buf2);
|
2023-06-29 06:48:12 +08:00
|
|
|
free(buf2);
|
2019-12-20 06:29:35 +08:00
|
|
|
buf2 = NULL;
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Tclose(ftype1_id) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aget_type first attribute failed");
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Tclose(ftype2_id) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aget_type second attribute failed");
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sclose(space1_id) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aget_type first attribute failed");
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sclose(space2_id) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aget_type second attribute failed");
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Tclose(mtype1_id) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tclose first attribute mtype failed");
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Tclose(mtype2_id) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Tclose second attribute mtype failed");
|
2019-12-20 06:29:35 +08:00
|
|
|
|
|
|
|
done:
|
|
|
|
opts->err_stat = opts->err_stat | ret_value;
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
H5E_BEGIN_TRY
|
|
|
|
{
|
|
|
|
if (buf1) {
|
2023-09-06 02:50:06 +08:00
|
|
|
if (buf1hasdata && true == h5tools_detect_vlen(mtype1_id))
|
2019-12-20 06:29:35 +08:00
|
|
|
H5Treclaim(mtype1_id, space1_id, H5P_DEFAULT, buf1);
|
2023-06-29 06:48:12 +08:00
|
|
|
free(buf1);
|
2019-12-20 06:29:35 +08:00
|
|
|
} /* end if */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (buf2) {
|
2023-09-06 02:50:06 +08:00
|
|
|
if (buf2hasdata && true == h5tools_detect_vlen(mtype2_id))
|
2019-12-20 06:29:35 +08:00
|
|
|
H5Treclaim(mtype2_id, space2_id, H5P_DEFAULT, buf2);
|
2023-06-29 06:48:12 +08:00
|
|
|
free(buf2);
|
2019-12-20 06:29:35 +08:00
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
H5Tclose(ftype1_id);
|
|
|
|
H5Tclose(ftype2_id);
|
|
|
|
H5Tclose(mtype1_id);
|
|
|
|
H5Tclose(mtype2_id);
|
|
|
|
H5Sclose(space1_id);
|
|
|
|
H5Sclose(space2_id);
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
2023-06-16 12:49:02 +08:00
|
|
|
H5E_END_TRY
|
2019-12-20 06:29:35 +08:00
|
|
|
|
2020-01-24 00:20:34 +08:00
|
|
|
H5TOOLS_ENDDEBUG(" - errstat:%d", opts->err_stat);
|
2019-12-20 06:29:35 +08:00
|
|
|
|
|
|
|
return nfound;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: diff_attr
|
|
|
|
*
|
|
|
|
* Purpose: compare attributes located in LOC1_ID and LOC2_ID, which are
|
|
|
|
* obtained either from
|
|
|
|
* loc_id = H5Gopen2(fid, name, H5P_DEFAULT);
|
|
|
|
* loc_id = H5Dopen2(fid, name);
|
|
|
|
* loc_id = H5Topen2(fid, name, H5P_DEFAULT);
|
|
|
|
*
|
|
|
|
* Return: number of differences found
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t
|
|
|
|
diff_attr(hid_t loc1_id, hid_t loc2_id, const char *path1, const char *path2, diff_opt_t *opts)
|
2019-12-20 06:29:35 +08:00
|
|
|
{
|
2019-12-21 04:18:01 +08:00
|
|
|
table_attrs_t *match_list_attrs = NULL;
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t attr1_id = H5I_INVALID_HID; /* attr ID */
|
|
|
|
hid_t attr2_id = H5I_INVALID_HID; /* attr ID */
|
2022-07-27 05:45:46 +08:00
|
|
|
char *name1 = NULL;
|
|
|
|
char *name2 = NULL;
|
2020-09-30 22:27:10 +08:00
|
|
|
unsigned u; /* Local index variable */
|
|
|
|
hsize_t nfound = 0;
|
2019-12-28 16:16:44 +08:00
|
|
|
hsize_t nfound_total = 0;
|
2020-09-30 22:27:10 +08:00
|
|
|
diff_opt_t attr_opts;
|
2019-12-28 16:16:44 +08:00
|
|
|
diff_err_t ret_value = opts->err_stat;
|
2019-12-20 06:29:35 +08:00
|
|
|
|
2020-01-24 00:20:34 +08:00
|
|
|
H5TOOLS_START_DEBUG(" - errstat:%d", opts->err_stat);
|
2020-09-30 22:27:10 +08:00
|
|
|
attr_opts = *opts;
|
2020-07-16 00:20:16 +08:00
|
|
|
attr_opts.obj_name[0] = NULL;
|
|
|
|
attr_opts.obj_name[1] = NULL;
|
2017-05-20 00:35:07 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (build_match_list_attrs(loc1_id, loc2_id, &match_list_attrs, &attr_opts) < 0) {
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "build_match_list_attrs failed");
|
2017-10-18 05:13:12 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
H5TOOLS_DEBUG("check match_list_attrs - opts->contents:%d - errstat:%d", attr_opts.contents,
|
|
|
|
attr_opts.err_stat);
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2013-02-19 03:46:03 +08:00
|
|
|
/* if detect any unique extra attr */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (match_list_attrs->nattrs_only1 || match_list_attrs->nattrs_only2) {
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("attributes only in one file");
|
2013-02-19 03:46:03 +08:00
|
|
|
/* exit will be 1 */
|
2020-07-16 00:20:16 +08:00
|
|
|
attr_opts.contents = 0;
|
2013-02-19 03:46:03 +08:00
|
|
|
}
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("match_list_attrs info - opts->contents:%d", attr_opts.contents);
|
2013-02-19 03:46:03 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
for (u = 0; u < (unsigned)match_list_attrs->nattrs; u++) {
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("match_list_attrs loop[%d] - errstat:%d", u, attr_opts.err_stat);
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((match_list_attrs->attrs[u].exist[0]) && (match_list_attrs->attrs[u].exist[1])) {
|
2016-05-05 00:39:28 +08:00
|
|
|
name1 = name2 = match_list_attrs->attrs[u].name;
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("name - %s", name1);
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2016-05-05 00:39:28 +08:00
|
|
|
/*--------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* attribute 1 */
|
|
|
|
if ((attr1_id = H5Aopen(loc1_id, name1, H5P_DEFAULT)) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aopen first attribute failed");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2016-05-05 00:39:28 +08:00
|
|
|
/*--------------
|
2020-09-30 22:27:10 +08:00
|
|
|
* attribute 2 */
|
|
|
|
if ((attr2_id = H5Aopen(loc2_id, name2, H5P_DEFAULT)) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aopen second attribute failed");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2020-07-16 00:20:16 +08:00
|
|
|
H5TOOLS_DEBUG("got attributes");
|
|
|
|
nfound = diff_attr_data(attr1_id, attr2_id, name1, name2, path1, path2, &attr_opts);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Aclose(attr1_id) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aget_type first attribute failed");
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Aclose(attr2_id) < 0)
|
2019-12-28 16:16:44 +08:00
|
|
|
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "H5Aget_type second attribute failed");
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2016-05-05 00:39:28 +08:00
|
|
|
nfound_total += nfound;
|
2011-03-22 23:47:07 +08:00
|
|
|
}
|
2011-02-08 08:53:45 +08:00
|
|
|
} /* u */
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2017-10-14 05:34:01 +08:00
|
|
|
done:
|
2020-07-16 00:20:16 +08:00
|
|
|
opts->print_header = attr_opts.print_header;
|
2020-09-30 22:27:10 +08:00
|
|
|
opts->contents = attr_opts.contents;
|
|
|
|
opts->not_cmp = attr_opts.not_cmp;
|
|
|
|
opts->err_stat = attr_opts.err_stat | ret_value;
|
2017-10-18 05:13:12 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
H5E_BEGIN_TRY
|
|
|
|
{
|
2011-03-22 23:47:07 +08:00
|
|
|
table_attrs_free(match_list_attrs);
|
|
|
|
|
2011-02-08 08:53:45 +08:00
|
|
|
H5Aclose(attr1_id);
|
|
|
|
H5Aclose(attr2_id);
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
2023-06-16 12:49:02 +08:00
|
|
|
H5E_END_TRY
|
2011-02-08 08:53:45 +08:00
|
|
|
|
2020-01-24 00:20:34 +08:00
|
|
|
H5TOOLS_ENDDEBUG(" - errstat:%d", opts->err_stat);
|
2011-02-08 08:53:45 +08:00
|
|
|
return nfound_total;
|
2003-11-04 06:10:57 +08:00
|
|
|
}
|