我试图在不知道数据集类型的情况下在 c 中打开 hdf5 数据集。我可以使用“H5Dget_type(dataset_id)”获取数据集类型,但是,当我想为数据数组分配内存时,即“datatype(int, float, etc.) dset[n]”,我无法在不知道的情况下做到这一点数据类型(int、float 等)。
所以,我的问题是如何获取数据类型以便使用它为我要使用的数组分配内存?
谢谢!
最佳答案
如果您未绑定(bind)特定工具,请查看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"
关于c - 如何在c中读取未知数据类型的hdf5数据集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55325503/