简体   繁体   English

c++中如何批量读取hdf5文件

[英]How to read batch hdf5 files in c++

I have 400 hdf5 files.我有 400 个 hdf5 文件。 I need read them to use some data in these files to simulation.我需要阅读它们以使用这些文件中的一些数据进行模拟。 How to write in a simple way?如何写得通俗易懂?

I just write a function to read.我随便写一个function来读。 But it didn't work well但效果不佳

You can solve your issue by doing the following using HDFql in C++ (assuming that your HDF5 files are stored in a directory named data and that each file has a dataset named dset containing 10 integers):您可以使用C++中的 HDFql 执行以下操作来解决您的问题(假设您的 HDF5 文件存储在名为data的目录中,并且每个文件都有一个名为dset的数据集,其中包含 10 个整数):

// declare variables
std::stringstream script;
int values[10];
char *file;

// register variable 'values' for subsequent usage (by HDFql), which will store values from dataset 'dset'
HDFql::variableRegister(&values);

// retrieve files stored in directory '/data' (where HDF5 files are hypothetical stored)
HDFql::execute("SHOW FILE /data/");

// read and process dataset 'dset' from each file retrieved
while(HDFql::cursorNext() == HDFql::Success)
{
    // get file name
    file = HDFql::cursorGetChar();
    std::cout << "File found: " << file << std::endl;

    // prepare script to read dataset 'dset' and populate variable 'values' with it
    script.str("");
    script << "SELECT FROM /data/" << file << " dset INTO MEMORY " << HDFql::variableGetNumber(&values);

    // execute script
    HDFql::execute(script);

    // process variable 'values'
    // (...)
}

For additional info check the reference manual and examples that illustrate HDFql functionalities.有关其他信息,请查看说明 HDFql 功能的参考手册示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM