How to write hyperslabs?

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/

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@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@hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.

I have a VS2005 MFC program in which I'd like to use HDF5. For version
1.9.19, the dll version works, but the static libraries do not. When
linking in I'm getting a variety of LNK2005 errors, ie, some function has
already been defined elsewhere:

56>MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _strcspn already defined in
LIBCMTD.lib(strcspn.obj)

Is it possible to link statically with an MFC based program?

Ray.

···

--
Scanned for viruses and dangerous content at
http://www.oneunified.net and is believed to be clean.

Might want to check your compiler switches. I've not built HDF5 with
VS2005, but the default C runtime lib in VS2005 is the dynamic link version,
which is what you're showing below. For statically linked HDF5 in VS2003,
the setting I have is /MLd (debug) or /ML (release). The link below
addresses changing from the VS2005 default to /MT or /MTd. The difference
between /ML and /MT is multi-thread support in /MT, but just be aware that
in VS2003 the flag (at least the one in my build) is /ML flavor. To the
best of my knowledge, MFC does not complicate things here.

Hope this is a help.

http://www.tc.cornell.edu/SoftwarePages/Migrating+to+Visual+Studio+2005+from
+Visual+Studio+.NET+2003.htm

Robert

···

-----Original Message-----
From: Ray Burkholder [mailto:ray@oneunified.net]
Sent: Saturday, October 18, 2008 10:18 PM
To: hdf-forum@hdfgroup.org
Subject: [hdf-forum] Static Lib with VS2005

I have a VS2005 MFC program in which I'd like to use HDF5. For version
1.9.19, the dll version works, but the static libraries do not. When
linking in I'm getting a variety of LNK2005 errors, ie, some function has
already been defined elsewhere:

56>MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _strcspn already defined in
LIBCMTD.lib(strcspn.obj)

Is it possible to link statically with an MFC based program?

Ray.

--
Scanned for viruses & dangerous content at One Unified
<http://www.oneunified.net> and is believed to be clean.

Hi!
I´ve tried to work with boost::multiarray, but it does not work either,that´s what I´m trying to do:

typedef boost::multi_array<double, 2> array;
array AData (boost::extents[xdims][ydims]);

status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, AData);

AData is the array I want to write to my .h5-file, and this is the error I get:
c:\dokumente und einstellungen\natalie happenhofer\eigene dateien\atox_main.cpp(428) : error C2664: 'H5Dwrite': conversion of parameter 6 'array' in 'const void *' not possible.

the problem is that I need a structure working with the HDF5-Api!

greetings,
NH

···

Date: Thu, 16 Oct 2008 14:29:15 +0200
From: diepen@astron.nl
To: hdf-forum@hdfgroup.org; nataliehapp@hotmail.com
Subject: Re: [hdf-forum] How to write hyperslabs?

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@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@hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe@hdfgroup.org.

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