c# - 如果我将 Offset 设置为非零,则使用 hyperslab 从 HDF5 文件读取数据时出现异常

标签 c# .net hdf5

我在这里尝试从 hdf5 文件中读取部分数据。我能够在数据集中写入和读取整个数据,但现在我想读取部分数据,因为我正在使用“Hyperslab”,它会抛出异常

'H5D.read: 
Failed to read data to data set 5000002 with status -1'

现在它在相同条件下给我 5000000 错误

在线

H5D.read(dataSetIdTO, typeId, memspaceid, filespaceid,
         new H5PropertyListId(new H5P.Template()), new H5Array<int>(readDataBack));

编辑: 只有当 offset 不为 0(零)时才会抛出此异常,如果我设置 offset[0]=0 那么它工作正常

我的代码

//Open hdf5 file
H5FileId fileId = H5F.open("myCSharp.h5", H5F.OpenMode.ACC_RDONLY);

long[] offset = new long[1];
offset[0] = 1;

long[] count = new long[1];
count[0] = 500;

//Open group
H5GroupId groupId = H5G.open(fileId, "GroupName");

// Open the data set.
H5DataSetId dataSetIdTO = H5D.open(groupId, "DataSetName");

// Get space id from our data set
H5DataSpaceId filespaceid = H5D.getSpace(dataSetIdTO);

//Create new space to read hyperslab in memory
H5DataSpaceId memspaceid = H5S.create_simple(1, count);

//select hyperslabs in dataspace
H5S.selectHyperslab(memspaceid, H5S.SelectOperator.SET, offset, count);
H5S.selectHyperslab(filespaceid, H5S.SelectOperator.SET, offset, count);

//array to read data
int[] readDataBack = new int[500];

H5DataTypeId typeId = new H5DataTypeId(H5T.H5Type.NATIVE_INT);

//Read data from dataset 
// * I got Exception here*
H5D.read(dataSetIdTO, typeId, memspaceid, filespaceid,
          new H5PropertyListId(new H5P.Template()), new H5Array<int>(readDataBack));

最佳答案

经过如此多的努力,我才知道为什么会这样。在这里,我正在创建等于 count 的内存空间,它应该大于给 hyperslab 的 count。

//Create new space to read hyperslab in memory
H5DataSpaceId memspaceid = H5S.create_simple(1, count);

取而代之的是我需要制作新的长数组

//delclar long array for memory space dims
long[] memSpaceDims = new long[1];
memSpaceDims[0] = 5001; //it should be greater than count[0]

//Create new space to read hyperslab in memory
H5DataSpaceId memspaceid = H5S.create_simple(1, memSpaceDims);

关于c# - 如果我将 Offset 设置为非零,则使用 hyperslab 从 HDF5 文件读取数据时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25078939/

相关文章:

c# - 将基类中最复杂的方法声明为虚方法

c# - Monotouch EKEvent 注释未保存

.net - 如何在 .NET Standard 库中使用 Sqlite?

python - 如何使用 h5py 区分 HDF5 数据集和组?

python - 如何比较和检查两个二进制(h5)文件在数值上是否具有相同的内容

c# - 使用 AutoMapper 进行映射时如何忽略 Destination 集合类型属性?

c# - 允许用户在应用程序中嵌入原始 sql 查询是一种好习惯吗?

.net - 找不到 "Microsoft.NET.CoreRuntime"

c# - 抽象类和只读属性

python - 用pytables压缩数组