reading in fortran HDF5 scalar string dataset

GROUP “InputPointers” {
DATASET “ControlFileContents” {
DATATYPE H5T_STRING {
STRSIZE 30874;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_ASCII;
CTYPE H5T_C_S1;
}
DATASPACE SCALAR
}
}

ive been trying to adapt the examples in hdf5/HDF5Examples/FORTRAN/H5T/h5ex_t_vlstring_F03.F90 at develop · HDFGroup/hdf5 · GitHub

but I’m getting errors when I adjust to a scalar value

dies here
CALL H5Sget_simple_extent_dims_f(space, dims, maxdims, hdferr)

and then get this from HDF_read
F5-DIAG: Error detected in HDF5 (1.8.20) thread 0:
#000: H5Dio.c line 223 in H5Dread(): can’t read data
major: Dataset
minor: Read failed
#001: H5Dio.c line 479 in H5D__read(): unable to set up type info
major: Dataset
minor: Unable to initialize object
#002: H5Dio.c line 1015 in H5D__typeinfo_init(): unable to convert between src and dest datatype
major: Dataset
minor: Feature is unsupported
#003: H5T.c line 4516 in H5T_path_find(): no appropriate function for conversion path
major: Datatype
minor: Unable to initialize object

CALL H5Sget_simple_extent_dims_f(space, dims, maxdims, hdferr)

ALLOCATE(rdata(1:dims(1)))

!
! Read the data.
!
f_ptr = C_LOC(rdata(1))
CALL h5dread_f(dset, H5T_STRING, f_ptr, hdferr)

Hi @robert.lindsay,

If you are not bound to a particular library/solution, you may want to try HDFql as it greatly simplifies how HDF5 files are handled in Fortran (as well as in C, C++, Java, C#, Python and R). Reading the HDF5 scalar string dataset you have posted in this language could be done as follows using HDFql:

PROGRAM Example
      USE HDFql
      CHARACTER(30874) :: value
      INTEGER :: state
	  state = hdfql_variable_transient_register(value)
      state = hdfql_execute("SELECT FROM test.h5 InputPointers/ControlFileContents INTO MEMORY 0")
      WRITE(*, *) "Dataset value: ", value
END PROGRAM

Hope it helps!

You should look at the h5ex_t_string_F03 example instead. The datatype listed in the h5dump output is not of the variable-length type, which would be H5T_VLEN; it is a string.

Why are you trying to read this string using Fortran? You’ll still need to parse it using a YAML parser which can be done in Fortran, but more conveniently in other languages.