Search code examples
fortranhdf5

How to write string array to a HDF5 dataset with Fortran API?


A string array is defined using fortran language:

character(len = 20), dimension(5) :: strings = (/"hello", "world", "Hello", "HDF5", "fortran"/)

Now I want to save this array into a dataset using h5ltmake_dataset_string_f() interface illustrated by HDF5 API reference documentation

Fortran90 Interface: h5ltmake_dataset_string_f

subroutine h5ltmake_dataset_string_f(loc_id,dset_name,buf,errcode )

    implicit none

integer(HID_T), intent(IN) :: loc_id ! file or group identifier

character(LEN=*), intent(IN) :: dset_name ! name of the dataset

character(LEN=*), intent(IN), dimension(:) :: buf ! data buffer

integer :: errcode ! error code

end subroutine h5ltmake_dataset_string_f

My calling code below

h5ltmake_dataset_string_f(group_id, dset_name, strings, error)

and group_id, dset_name and error have been defined before subroutine call.

But when I compile and build this code, compile error occurs says

h5ltmake_dataset_string_f(): the actual arguments and dummy arguments have been violated!

So how to write the strings into one dataset?


Solution

  • Use API h5dwrite_f(...), not h5ltmake_dataset_f() to write string array.