如果我将Offset设置为非零,则在使用hyperslab从HDF5文件读取数据时获取异常

时间:2014-08-01 11:09:00

标签: 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));

1 个答案:

答案 0 :(得分:0)

在努力尝试之后,我知道为什么会这样。在这里,我创建的内存空间等于count,它应该大于给予hyperslab的计数。

//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);