Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果将偏移量设置为非零,则在使用hyperslab从HDF5文件读取数据时获取异常_C#_.net_Hdf5 - Fatal编程技术网

C# 如果将偏移量设置为非零,则在使用hyperslab从HDF5文件读取数据时获取异常

C# 如果将偏移量设置为非零,则在使用hyperslab从HDF5文件读取数据时获取异常,c#,.net,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 H5Propert

在这里,我试图从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));
H5D.read(dataSetIdTO、typeId、memspaceid、filespaceid、,
新的H5PropertyListId(新的H5P.Template()),新的H5Array(readDataBack));
编辑: 只有当偏移量不是0(零)时才会引发此异常,如果我将偏移量[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));
//打开hdf5文件
H5FileId fileId=H5F.open(“myCSharp.h5”,H5F.OpenMode.accrdonly);
长[]偏移=新长[1];
偏移量[0]=1;
long[]计数=新的long[1];
计数[0]=500;
//开放组
H5GroupId-groupId=H5G.open(fileId,“GroupName”);
//打开数据集。
H5DataSetId datasetdto=H5D.open(groupId,“DataSetName”);
//从数据集中获取空间id
H5DataSpaceId filespaceid=H5D.getSpace(dataSetIdTO);
//创建新空间以读取内存中的hyperslab
H5DataSpaceId memspaceid=H5S.create_simple(1,count);
//在数据空间中选择Hyperslab
H5S.selectHyperslab(memspaceid,H5S.SelectOperator.SET,offset,count);
H5S.selectHyperslab(filespaceid,H5S.SelectOperator.SET,offset,count);
//读取数据的数组
int[]readDataBack=新int[500];
H5DataTypeId-typeId=新的H5DataTypeId(H5T.H5Type.NATIVE_INT);
//从数据集读取数据
//*我这里有个例外*
H5D.read(dataSetIdTO、typeId、memspaceid、filespaceid、,
新的H5PropertyListId(新的H5P.Template()),新的H5Array(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);

您可以留下评论来改进我的问题。您的H5文件的维度是什么?排名是1,维度[0]是100000