C++ 读取HDFql中属性的值
我正在使用创建HDF5文件。我正在创建一个组,并将一些数据放入其中,这很好。然后,我向文件中添加了一个属性(这似乎也起作用,因为它在我使用HDF编辑器检查HDF5文件时显示),但我不知道如何读取该属性的值。下面是一个简单的例子:C++ 读取HDFql中属性的值,c++,hdf5,hdfql,C++,Hdf5,Hdfql,我正在使用创建HDF5文件。我正在创建一个组,并将一些数据放入其中,这很好。然后,我向文件中添加了一个属性(这似乎也起作用,因为它在我使用HDF编辑器检查HDF5文件时显示),但我不知道如何读取该属性的值。下面是一个简单的例子: #include <iostream.h> #include <HDFql.hpp> int main (int argc, const char * argv[]) { char script[1024]; //Create
#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=test/data/channels
所以我想我误解了HDFql游标的工作原理。所以我的问题是:我的代码有什么问题?为什么我的代码错了
非常感谢 当您执行
显示属性test/data/channels
时,您基本上是在测试存储在test/data
中名为channels
的属性是否存在。由于此属性存在,函数HDFql::execute
返回HDFql::Success
,并且光标填充字符串test/data/channels
。另一方面,如果属性不存在,则函数HDFql::execute
将返回HDFql::ErrorNotFound
,并且光标将为空
要读取存储在属性test/data/channels
中的值,请执行以下操作:
HDFql::execute("SELECT FROM test/data/channels");
HDFql::cursorFirst();
std::cout << "channels = " << *HDFql::cursorGetInt() << std::endl;
HDFql::execute(“从测试/数据/通道中选择”);
HDFql::cursorFirst();
标准::cout
HDFql::execute("SELECT FROM test/data/channels");
HDFql::cursorFirst();
std::cout << "channels = " << *HDFql::cursorGetInt() << std::endl;