Skip to content

Commit 159d67d

Browse files
committed
read:dataset: character 0d..7d
1 parent ee187eb commit 159d67d

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

src/read_char.inc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
integer(HID_T) :: type_id
2+
integer :: ier, charlen, obj_type
3+
logical :: is_vlen
4+
5+
!> variable length string
6+
integer(HSIZE_T) :: dims(rank(A)), Npts, dsize
7+
8+
charlen = len(A)
9+
10+
call open_char(self, obj_name, obj_id, file_space_id, charlen, obj_type, type_id, dims, Npts, dsize, is_vlen)
11+
12+
if(is_vlen) then
13+
call read_vlen(self, obj_name, obj_type, obj_id, type_id, dsize, A, mem_space_id, file_space_id)
14+
else
15+
call read_fixed(self, obj_name, obj_type, obj_id, type_id, dsize, A, mem_space_id, file_space_id)
16+
endif
17+
18+
call H5Tclose_f(type_id, ier)
19+
if(ier/=0) error stop "ERROR:h5fortran:read:H5Tclose " // obj_name

src/read_fixed.inc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class(hdf5_file), intent(in) :: self
2+
character(*), intent(in) :: obj_name
3+
integer, intent(in) :: obj_type
4+
integer(HID_T), intent(in) :: obj_id, type_id, mem_space_id, file_space_id
5+
6+
TYPE(C_PTR) :: f_ptr
7+
8+
integer :: ier
9+
10+
allocate(buf, mold=A)
11+
f_ptr = C_LOC(buf)
12+
13+
if(obj_type == H5I_DATASET_F) then
14+
call H5Dread_f(obj_id, type_id, f_ptr, ier, mem_space_id, file_space_id)
15+
elseif(obj_type == H5I_ATTR_F) then
16+
call H5Aread_f(obj_id, type_id, f_ptr, ier)
17+
endif
18+
if(ier/=0) error stop "ERROR:h5fortran:read_ascii: read " // obj_name // " " // self%filename
19+
20+
A = pad_trim(buf)

src/read_vlen.inc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class(hdf5_file), intent(in) :: self
2+
character(*), intent(in) :: obj_name
3+
integer, intent(in) :: obj_type
4+
integer(HID_T), intent(in) :: obj_id, type_id, mem_space_id, file_space_id
5+
integer(HSIZE_T), intent(in) :: dsize
6+
7+
TYPE(C_PTR), DIMENSION(:), ALLOCATABLE, TARGET :: cbuf
8+
character(dsize), dimension(:), allocatable :: buf
9+
CHARACTER(dsize, kind=C_CHAR), POINTER :: cstr
10+
TYPE(C_PTR) :: f_ptr
11+
12+
integer :: ier, dims(rank(A))
13+
integer(HSIZE_T) :: i
14+
15+
dims = shape(A)
16+
17+
allocate(cbuf(product(dims)), buf(product(dims)))
18+
f_ptr = C_LOC(cbuf)
19+
20+
if(obj_type == H5I_DATASET_F) then
21+
call H5Dread_f(obj_id, type_id, f_ptr, ier, mem_space_id, file_space_id)
22+
elseif(obj_type == H5I_ATTR_F) then
23+
call H5Aread_f(obj_id, type_id, f_ptr, ier)
24+
endif
25+
if(ier/=0) error stop "h5fortran:read:read_ascii: read " // obj_name // " " // self%filename
26+
27+
do i = 1, size(cbuf)
28+
call C_F_POINTER(cbuf(i), cstr)
29+
buf(i) = pad_trim(cstr)
30+
enddo
31+
32+
A = reshape(buf, dims)

0 commit comments

Comments
 (0)