Hi all,
After my request for help I spotted some dumb things I was doing and got
it all ironed out.
Here is my code in case anyone is either interested in seeing a fairly
minimal C# hyperslab example, or would like to give me any hints on things
I could do in better ways.
best regards,
Mark.
···
--
H5FileId datafile = H5F.open("D:\\kil_Tofdat1.h5", H5F.OpenMode.ACC_RDONLY);
// Open file on DVD
H5GroupId groupid = H5G.open(datafile, "FullSpectra");
// Open Group in file
H5DataSetId dataid = H5D.open(groupid, "TofData");
// Open Data Set in group
H5DataSpaceId filespaceid = H5D.getSpace(dataid);
// Get Data Space Id for Data Set in file.
int rank = H5S.getSimpleExtentNDims(filespaceid);
// Get rank of data from data space (4 in this case)
ulong[] dims;
dims = H5S.getSimpleExtentDims(filespaceid);
// Get the size of the space (returns numbers that match with
HDFView) so seems sensible
Console.WriteLine("rank {0}, dimensions {1} x {2} x {3} x
{4}\n", rank, dims[0], dims[1], dims[2], dims[3]);
ulong[] offset = new ulong[rank];
ulong[] count = new ulong[rank];
offset[0] = 0;
offset[1] = 0;
offset[2] = 0;
offset[3] = 0;
count[0] = 1;
count[1] = 1;
count[2] = 1;
count[3] = dims[3];
// setup counts and offsets to just read 1st "slice" of data
H5DataSpaceId memspaceid = H5S.create_simple(rank, count, null);
// create memory Data Space. Is this sane? What about that
"null"?
H5S.selectHyperslab(memspaceid, H5S.SelectOperator.SET,
offset, count);
// select hyperslab in memory data space
offset[0] = 1;
offset[1] = 199;
filespaceid = H5D.getSpace(dataid);
H5S.selectHyperslab(filespaceid, H5S.SelectOperator.SET,
offset, count);
// select hyperslab in filespaceid
double[] readDataBack = new double[dims[3]];//174499
// Set up memory to read into
H5D.read(dataid, new H5DataTypeId(H5T.H5Type.NATIVE_DOUBLE),
memspaceid, filespaceid, new H5PropertyListId(new
H5P.Template()), new H5Array<double>(readDataBack));
Console.WriteLine(" {0} {1} {2} {3} {4} {5} {6}",
readDataBack[51705], readDataBack[51706], readDataBack[51707],
readDataBack[51708], readDataBack[51709], readDataBack[51710],
readDataBack[51711]);
H5F.close(datafile);
Console.WriteLine("Closed file.");
Console.ReadLine();
--
Dr. Mark Neal,
Department of Computer Science,
University of Wales, Aberystwyth,
Aberystwyth,
SY23 3DB,
U.K.
(+44) 1970 622449
--
----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe@hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.