c - 如何在c中读取未知数据类型的hdf5数据集?

标签 c hdf5

我试图在不知道数据集类型的情况下在 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/

相关文章:

C - 如何解析具有特定格式的文件(或字符串)

c++ - 在方法定义中使用 inline 关键字是否可能会导致问题?

c - GCC优化和调试

python - 将大量数据附加到表 (HDF5) 数据库,其中 database.numcols != newdata.numcols?

python - 使用 vaex 绘制大数据图

c - 在调用 mmap 后我是否需要保持文件打开?

c - C中使用char*和char[]表示常量char数组的区别

python - 从之前保存的 hdf5 文件中加载部分模型权重

python - 如何解决ImportError : libhdf5_serial. so.103: cannot open shared object file: No such file or directory while Importing h5py

python - H5Py 和存储