Hi,
I want to select a hyperslab in a file, but use all of the memory space, so my call to H5Dwrite looks like this (fortran):
call h5dwrite_f(dset_id, dtreal_id, real(mygrid(grid)%u(:,1,lm)), &
array_dims, error, H5S_ALL_F,dspace_id )
Things to note here:
- I use H5S_ALL_F (otherwise the default) for the memspace selection
- I use dspace_id for the file space selection, which has been populated
using an earlier call to h5sselect_hyperslab_f.
What I see is that, while the file space selection works fine (the correct hyperslab is selected and written to, the offset of the hyperslab is also applied to the memory space. I didn't expect this, because I specifically pass H5S_ALL_F, which according to the documentation:
H5S_ALL in C (H5S_ALL_F in FORTRAN) is the default value and indicates that the whole dataspace in memory is selected for the I/O operation.
After not finding an error in my code I dove into the hdf5 source and found this in H5Dio.c:685
/* Initialize dataspace information */
if(!file_space)
file_space = dataset->shared->space;
if(!mem_space)
mem_space = file_space;
Note the last line. While if file_space is 0 (H5S_ALL), the entire space of the dataset is used, the same is not true for the memory space: if you happen to set file_space (as I do), but not mem_space (as I do), then mem_space is *not* set to the size of the memory dataspace, but to the (passed) size of the file space. Which means in that case any selection applied to the file dataspace is also applied to the memory data space.
Am I correct that this is a bug in the HDF5 implementation, or is this intended behavior? If it is intended, isn't this then a bug in the documentation?
thanks, Frank