Have you looked at the examples from,

http://www.hdfgroup.org/HDF5/examples/api18-fortran.html

namely,

Read / Write String Datatype (Dataset)  h5ex_t_string_F03.f90

Scot

On Dec 24, 2014, at 9:46 AM, Mark Carter 
<[email protected]<mailto:[email protected]>> wrote:

I'm new to HDF5 and gfortran. I've able to read in an array of doubles, but I'm 
having problem reading in an array of fixed-length strings (actually bytes).

My dataset is named 'dstamp', and according to HDF5View:
No of dimensions: 1
Dimensions size: 2598
Max Dimension size: 2598
Data Type: String, length=10

In Fortran, I have overdeclared the size because I don't know in advance how 
many string there are, but I know in advance that the strings are of length 10:
character (len=10), dimension(10000)::dstamp
integer(Hsize_t), dimension(1):: dims

CALL h5fopen_f ("whatever.h5", H5F_ACC_RDWR_F, file_id, error)
call h5dopen_f(file_id, "dstamp", dset_id, error)
CALL h5dget_space_f(dset_id, dspace_id, error)
call h5sget_simple_extent_npoints_f(dspace_id, npoints, error)
print *, "dstamp npoints =", npoints
call h5sget_simple_extent_ndims_f(dspace_id, rank, error)
print *, "With rank ", rank ! rank is 1
dims = (/ npoints /)
CALL h5dread_f(dset_id, H5T_FORTRAN_S1, dstamp, dims, error)
if(error.eq.1) stop 501
CALL h5dclose_f(dset_id, error)
do i=1,15
  print *, dstamp(i)
enddo

The problem is, all it does is print a series of "2222222222"s. How do I fix 
the problem?


_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]<mailto:[email protected]>
http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Reply via email to