【问题标题】:How to read hdf5 dataset with unknown datatype in c?如何在c中读取具有未知数据类型的hdf5数据集?
【发布时间】:2019-08-14 23:14:33
【问题描述】:

我试图在不知道数据集类型的情况下用 c 打开一个 hdf5 数据集。我可以使用“H5Dget_type(dataset_id)”获取数据集类型,但是,当我想为数据数组分配内存时,即“datatype(int, float, etc.) dset[n]”,我不知道就做不到数据类型(int、float 等)。

所以,我的问题是如何获取数据类型以便使用它为我将要使用的数组分配内存?

谢谢!

【问题讨论】:

    标签: c hdf5


    【解决方案1】:

    如果您未绑定到特定工具,请查看HDFql,因为这可以让您在处理 HDF5 文件时摆脱低级细节。您的问题可以使用 C 中的 HDFql 解决如下(假设您要读取数据集my_dataset):

    // declare variables
    void *data;
    long long size;
    
    // get size (in bytes) of dataset "my_dataset" and populate HDFql default cursor with it
    hdfql_execute("SHOW SIZE my_dataset");
    
    // move HDFql default cursor to first position
    hdfql_cursor_first(NULL);
    
    // retrieve size (in bytes) from HDFql default cursor
    size = hdfql_cursor_get_bigint(NULL);
    
    // allocate memory based on the size (in bytes) of dataset "my_dataset"
    data = malloc(size);
    
    // register variable "data" for subsequent usage
    hdfql_variable_register(&data);
    
    // select (i.e. read) data from dataset "my_dataset" and populate variable "data" with it
    hdfql_execute("SELECT FROM my_dataset INTO MEMORY 0");
    
    // from this point on, variable "data" contains the data from "my_dataset"
    

    【讨论】:

      猜你喜欢
      • 2023-01-31
      • 2019-08-02
      • 2022-10-12
      • 2021-02-24
      • 2014-11-15
      • 2014-09-12
      • 1970-01-01
      • 2019-06-24
      • 2020-03-29
      相关资源
      最近更新 更多