[hdf-forum] How to write hyperslabs?
Natalie Happenhofer
nataliehapp at hotmail.com
Mon Oct 20 05:33:47 EDT 2008
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>
More information about the Hdf-forum
mailing list