subroutine WriteCharacter_HDF5_serial(fileid,name,hfField)
! adapted from https://forum.hdfgroup.org/t/writing-a-string-array-as-attribute-in-fortran/8503/6
implicit none
integer(HID_T),intent(in) :: fileId
character(len=*),intent(in) :: name
character(len=*),intent(in) :: hfField
! Local
integer(HID_T) :: h5_strtype,h5_dspace,h5_dset
integer(HSIZE_T),dimension(2) :: size
character(len=len(hfField)+1),dimension(1) :: str_data
integer(SIZE_T),dimension(1) :: str_len
integer :: error
! string output requires to open a file local = non-parallel
str_len(1) = len_trim(hfField)
size(1) = str_len(1)
size(2) = 1
str_data(1) = hfField//char(0)
! create data space
call H5Tcopy_f(H5T_STRING,h5_strtype,error)
call H5Tset_strpad_f(h5_strtype,H5T_STR_NULLPAD_F,error)
call h5screate_simple_f(1,size(2),h5_dspace,error)
call h5dcreate_f(fileid,trim(name),h5_strtype,h5_dspace,h5_dset,error)
call h5dwrite_vl_f(h5_dset,h5_strtype,str_data,size,str_len,error,h5_dspace)
call h5dclose_f(h5_dset,error)
call h5sclose_f(h5_dspace,error)
endsubroutine WriteCharacter_HDF5_serial