我正在使用HDFql创建一个 HDF5 文件。我正在创建一个组并将一些数据放入其中,效果很好。然后我向文件添加一个属性(这似乎也有效,因为当我使用 HDF 编辑器检查 HDF5 文件时它会显示出来),但我不知道如何读取属性的值。这是一个最小的例子:
#include <iostream.h>
#include <HDFql.hpp>
int main (int argc, const char * argv[]) {
char script[1024];
//Create the HDF5 file and the group "test"
HDFql::execute("CREATE TRUNCATE FILE /tmp/test.h5");
HDFql::execute("USE FILE /tmp/test.h5");
HDFql::execute("CREATE GROUP test");
//Generate some arbitrary data and place it in test/data
int data_length = 1000;
int data[data_length];
for(int i=0; i<data_length; i++) {data[i] = i;}
sprintf(script, "CREATE DATASET test/data AS INT(%d) VALUES FROM MEMORY %d",
data_length, HDFql::variableTransientRegister(data));
HDFql::execute(script);
//Create an attribute called "channels" and give it an arbitrary value of 11
HDFql::execute("CREATE ATTRIBUTE test/data/channels AS INT VALUES(11)");
//Show the attribute
HDFql::execute("SHOW ATTRIBUTE test/data/channels");
//Try to move the cursor to the attribute
HDFql::cursorLast();
//If that worked, print the attribute contents
if(HDFql::cursorGetInt())
{
std::cout << "channels = " << *HDFql::cursorGetInt() << std::endl;
} else
{
std::cout << "Couldn't find attribute" << std::endl;
}
HDFql::execute("CLOSE FILE");
}
我希望控制台的输出是channels = 11,而不是我得到channels = 1953719668。奇怪的是,如果我cursorGetChar改为调用,返回值是“t”,如果我说
std::cout << "channels = " << HDFql::cursorGetChar() << std::endl;
输出变为channels = test/data/channels.
所以我想我误解了 HDFql 游标的工作原理。所以我的问题是:我的代码有什么问题?为什么我的代码错了?
非常感谢!