Skip to content

Commit 0393352

Browse files
committed
char read: handle null pad case again
1 parent 402504d commit 0393352

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/read/scalar.f90

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
integer(HSIZE_T) :: dims(rank(value))
1414
integer(SIZE_T) :: dsize
1515
integer(hid_t) :: dset_id, type_id, space_id
16-
integer :: dclass, ier
16+
integer :: dclass, ier, i
1717

1818
logical :: vector_scalar, vstatus
1919

@@ -95,7 +95,10 @@
9595
call h5dread_vl_f(dset_id, type_id, buf_char, vldims, vlen, hdferr=ier, mem_space_id=space_id)
9696
if(ier/=0) error stop "h5fortran:read:h5dread_vl " // dname // " in " // self%filename
9797

98-
value = buf_char(1)
98+
i = index(buf_char(1), c_null_char) - 1
99+
if (i == -1) i = len_trim(buf_char(1))
100+
101+
value = buf_char(1)(:i)
99102

100103
! call h5dvlen_reclaim_f(type_id, H5S_ALL_F, H5P_DEFAULT_F, buf_char, ier)
101104
end block
@@ -116,7 +119,12 @@
116119
character(dsize) :: buf_char
117120

118121
call h5ltread_dataset_string_f(self%lid, dname, buf_char, ier)
119-
value = buf_char
122+
if(ier/=0) error stop "h5fortran:read:h5l5read_dataset_string " // dname // " in " // self%filename
123+
124+
i = index(buf_char, c_null_char) - 1
125+
if (i == -1) i = len_trim(buf_char)
126+
127+
value = buf_char(:i)
120128
end block
121129
endif
122130

0 commit comments

Comments
 (0)