[hdf-forum] How to write hyperslabs?

Ger van Diepen diepen at astron.nl
Thu Oct 16 08:29:15 EDT 2008


Hi Natalie,

Below is an extract from a class HDF5DataSet I've written some time ago for the casacore package. It writes a hyperslab.
I hope you more or less understand the code. Block is similar to the std::vector.
I can point you to the code if you would like to see more or use it.

Why don't you use something like Blitz++ or boost::multi_array (or casacore::Array) instead of struggling with C pointers? All do full array arithmetic, etc.

Cheers,
Ger

  void HDF5DataSet::put (const Slicer& section, const void* buf)
  {
    // Define the data set selection.
    Block<hsize_t> offset = fromShape(section.start());
    Block<hsize_t> count  = fromShape(section.length());
    Block<hsize_t> stride = fromShape(section.stride());
    if (H5Sselect_hyperslab (itsDSid, H5S_SELECT_SET, offset.storage(),
			     stride.storage(), count.storage(), NULL) < 0) {
      throw HDF5Error("invalid data set array selection");
    }
    // Define a data space for the memory buffer.
    HDF5HidDataSpace memspace (H5Screate_simple (count.size(),
						 count.storage(), NULL));
    // Define memory selection.
    offset = 0;
    if (H5Sselect_hyperslab (memspace, H5S_SELECT_SET, offset.storage(),
			     NULL, count.storage(), NULL) < 0) {
      throw HDF5Error("setting slab of memory buffer");
    }
    // Read the data.
    if (H5Dwrite (getHid(), itsDataType.getHidMem(), memspace, itsDSid,
		  H5P_DEFAULT, buf) < 0) {
      throw HDF5Error("writing slab into data set array");
    }
  }
 
 
>>> Natalie Happenhofer <nataliehapp at hotmail.com> 10/16/08 1:50 PM >>> 

Hi!
I need to write a 2-dimensional .h5 file, the data in it should look like the following array (concerning shape)

1 2 3 2 4 
1 2 5 2 4 
1 1 4 2 4 

My problem is that I need to allocate the space for my data array dynamically, i.e. it looks like this in C++:

float** Data = new float* [xdims]
for(int i=1; i<xdims; i++) Data[i] = new float [ydims];

as my data array is not necessarily contiguous in memory, I need a way to write it to my .h5 file with hyperslabs, as someone hinted earlier - I would write xdims rows with ydims values, but how do I write a hyperslab, which functions do I have to use? In the HDF5 Users Guide I have just found how to read hyperslabs from already existing data.

thx,
NH

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe at hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.





More information about the Hdf-forum mailing list