[hdf-forum] How to write hyperslabs?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[hdf-forum] How to write hyperslabs?

Natalie Happenhofer

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/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.hdfgroup.org/pipermail/hdf-forum_hdfgroup.org/attachments/20081016/e94aa871/attachment.html>

Reply | Threaded
Open this post in threaded view
|

[hdf-forum] How to write hyperslabs?

Ger van Diepen
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.




Reply | Threaded
Open this post in threaded view
|

[hdf-forum] Static Lib with VS2005

Ray Burkholder
In reply to this post by Natalie Happenhofer
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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.hdfgroup.org/pipermail/hdf-forum_hdfgroup.org/attachments/20081018/bb55dbd2/attachment.html>

Reply | Threaded
Open this post in threaded view
|

[hdf-forum] How to write hyperslabs?

Natalie Happenhofer
In reply to this post by Ger van Diepen

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 at astron.nl
> To: hdf-forum at hdfgroup.org; nataliehapp at 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 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.
>

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.hdfgroup.org/pipermail/hdf-forum_hdfgroup.org/attachments/20081020/c5e91507/attachment.html>

Reply | Threaded
Open this post in threaded view
|

[hdf-forum] Static Lib with VS2005

Robert Seip
In reply to this post by Ray Burkholder
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 at oneunified.net]
Sent: Saturday, October 18, 2008 10:18 PM
To: hdf-forum at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.hdfgroup.org/pipermail/hdf-forum_hdfgroup.org/attachments/20081020/0c4db161/attachment.html>