【发布时间】:2021-03-22 01:00:57
【问题描述】:
我想编写一个程序来处理和保存HDF5中的数据(格式,原始数据在)。
要了解HDF5,我正在玩简单的命令。
当我尝试在下面的片段中写入数据时,总是会出错。
#include <hdf5.h>
int main ( void )
{
hid_t file_id; dataset_id;
herr_t status;
int i, j, data[4][6];
for (i = 0; i < 4; i++){
for (j = 0; j < 6; j++)
data[i][j] = i * i * j;
}
file_id = H5Fopen ( "myfile.h5", H5F_ACC_TRUNC, H5P_DEFAULT );
dataset_id = H5Dopen ( file_id, "thatdset", H5P_DEFAULT );
status = H5Dwrite ( dataset_id, H5T_NATIVE_INT,
H5S_ALL, H5S_ALL, H5P_DEFAULT,
data);
status = H5Dclose (dataset_id);
status = H5Fclose (file_id);
}
我在 freebsd 上用 clang 编译所有东西
cc myHDF5writer.c -I/usr/local/include -L/usr/local/lib -lhdf5 -g
当我运行它时,我收到以下错误:
HDF5-DIAG: Error detected in HDF5 (1.10.6) thread 0:
#000: H5F.c line 495 in H5Fopen(): invalid file open flags
major: Invalid arguments to routine
minor: Inappropriate type
...
当我尝试使用 fid = H5Fcreate ( FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); 而不是 H5Fopen 调用时,我得到了类似的错误:
...
#000: H4D.c line 298 in H5Dopen2() unable to open dataset
major: Dataset
minor: Can't open object
...
感谢您的帮助。 编辑:错字。
在 H5Fopen 中使用 H5F_ACC_RDWR 标志创建了一个文件,但出现以下错误:
HDF5-DIAG: Error detected in HDF5 (1.10.6) thread 0:
#000: H5F.c line 509 in H5Fopen(): unable to open file
major: File accessibilty
minor: Unable to open file
#001: H5Fint.c line 1498 in H5F_open(): unable to open file: time = Thu Dec 10 19:44:48 2020
, name = '/home/joengel/lecture/c/hdf5/nfile.h5', tent_flags = 1
major: File accessibilty
minor: Unable to open file
#002: H5FD.c line 734 in H5FD_open(): open failed
major: Virtual File Layer
minor: Unable to initialize object
#003: H5FDsec2.c line 346 in H5FD_sec2_open(): unable to open file: name = '/path/to/file.h5', errno = 2, error message = 'No such file or directory', flags = 1, o_flags = 2
major: File accessibilty
minor: Unable to open file
HDF5-DIAG: Error detected in HDF5 (1.10.6) thread 0:
#000: H5D.c line 288 in H5Dopen2(): not a location
major: Invalid arguments to routine
minor: Inappropriate type
#001: H5Gloc.c line 246 in H5G_loc(): invalid object ID
major: Invalid arguments to routine
minor: Bad value
HDF5-DIAG: Error detected in HDF5 (1.10.6) thread 0:
#000: H5Dio.c line 314 in H5Dwrite(): dset_id is not a dataset ID
major: Invalid arguments to routine
minor: Inappropriate type
HDF5-DIAG: Error detected in HDF5 (1.10.6) thread 0:
#000: H5D.c line 337 in H5Dclose(): not a dataset
major: Invalid arguments to routine
minor: Inappropriate type
HDF5-DIAG: Error detected in HDF5 (1.10.6) thread 0:
#000: H5F.c line 671 in H5Fclose(): not a file ID
major: File accessibilty
minor: Inappropriate type
使用h5dump 检查文件会产生h5dump errro: unable to open file
【问题讨论】:
-
您是否尝试过提供文件的完整绝对路径?
-
就像
#define FILE "/path/to/myfile.h5"一样,是的,我有。这不会改变任何事情。 -
是什么让您认为传递给
H5Fopen的标志是有效的? (这是一个非常不同的错误,它甚至不会尝试打开文件,而对H5Fcreate的调用尝试打开数据集,但失败了。) -
我很乐意为这些标记提供建议。这些flaggs是我挣扎的。我试图与 hdfgroups 在线资源成为朋友。我可能仍然需要了解他们的思路。