H5Tget_member_type()返回复合HDF5数据类型的奇怪值

问题描述 投票:1回答:1

我试图通过使用函数H5Tget_nmembers()H5Tget_member_name()H5Tget_member_offset()H5Tget_member_class()H5Tget_member_type()来确定两种复合HDF5数据类型是否等效。

[前四个函数按预期工作,但是H5Tget_member_type()返回奇怪的值。

此代码片段

struct Agent0 {
    int      m_iInt1;
    int      m_iInt2;
} ta0;

hid_t hAgentDataType = H5Tcreate (H5T_COMPOUND, sizeof(ta0));
H5Tinsert(hAgentDataType, "my_int1",       qoffsetof(ta0, m_iInt1),    H5T_NATIVE_INT);
H5Tinsert(hAgentDataType, "my_int2",       qoffsetof(ta0, m_iInt2),    H5T_NATIVE_INT);

printf("type   of member %d: %ld\n",  0, H5Tget_member_type(hAgentDataType, 0));
printf("type   of member %d: %ld\n",  1, H5Tget_member_type(hAgentDataType, 1));
printf("H5T_NATIVE_INT:     %ld\n", H5T_NATIVE_INT);

提供以下输出:

type   of member 0: 216172782113784122
type   of member 1: 216172782113784123
H5T_NATIVE_INT:     216172782113783820

因此,即使成员0和1都是整数,它们也具有不同的类型值。这两个值都与H5T_NATIVE_INT的值不同。我希望所有3个值都相等...

那么H5Tget_member_type()真正返回了什么?

我如何真正比较复合数据类型的成员的数据类型?

编辑:甚至更奇怪:如果我为同一成员两次调用H5Tget_meber_type(),我将获得不同的值:

printf("call #1 for member %d: %016lx\n",  0, H5Tget_member_type(hAgentDataType, 0));
printf("call #2 for member %d: %016lx\n",  0, H5Tget_member_type(hAgentDataType, 0));

产量

call #1 for member 0: 0300000000000151
call #2 for member 0: 0300000000000152
c++ hdf5
1个回答
0
投票

如果未绑定到特定库,请查看HDFql,因为它可以减轻处理HDF5复合数据集/属性的低级详细信息。在C ++中使用HDFql,您的问题可以通过以下方式解决:

int equivalent(const std::string &compound1, const std::string &compound2)
{

    // declare variables
    HDFql::Cursor cursor;
    char script[1024];
    int i;


    // get name of members of compound1
    sprintf(script, "SHOW MEMBER %s", compound1);
    HDFql::execute(script);


    // get name of members of compound2
    HDFql::cursorUse(&cursor);
    sprintf(script, "SHOW MEMBER %s", compound2);
    HDFql::execute(script);


    if (HDFql::cursorGetCount() != HDFql::cursorGetCount(&cursor))
    {
        return -1;   // number of members of compound1 differs from number of members of compound2
    }


    // compare name of members of compound1 with name of members of compound2
    for(i = 0; i < HDFql::cursorGetCount(); i++)
    {
        HDFql::cursorNext();
        HDFql::cursorNext(&cursor);
        if (strcmp(HDFql::cursorGetChar(), HDFql::cursorGetChar(&cursor)) != 0)
        {
            return -1;   // name of member of compound1 differs from name of member of compound2
        }
    }


    // get data type of members of compound1
    HDFql::cursorUseDefault();
    sprintf(script, "SHOW DATA TYPE %s/", compound1);
    HDFql::execute(script);


    // get data type of members of compound2
    HDFql::cursorUse(&cursor);
    sprintf(script, "SHOW DATA TYPE %s/", compound2);
    HDFql::execute(script);


    // compare data type of members of compound1 with data type of members of compound2
    for(i = 0; i < HDFql::cursorGetCount(); i++)
    {
        HDFql::cursorNext();
        HDFql::cursorNext(&cursor);
        if (*HDFql::cursorGetInt() != *HDFql::cursorGetInt(&cursor))
        {
            return -1;   // data type of member of compound1 differs from data type of member of compound2
        }
    }


    // get offset of members of compound1
    HDFql::cursorUseDefault();
    sprintf(script, "SHOW OFFSET %s", compound1);
    HDFql::execute(script);


    // get offset of members of compound2
    HDFql::cursorUse(&cursor);
    sprintf(script, "SHOW OFFSET %s", compound2);
    HDFql::execute(script);


    // compare offset of members of compound1 with offset of members of compound2
    for(i = 0; i < HDFql::cursorGetCount(); i++)
    {
        HDFql::cursorNext();
        HDFql::cursorNext(&cursor);
        if (*HDFql::cursorGetInt() != *HDFql::cursorGetInt(&cursor))
        {
            return -1;   // offset of member of compound1 differs from offset of member of compound2
        }
    }


    return 0;   // compound1 is equivalent to compound2

}
© www.soinside.com 2019 - 2024. All rights reserved.