Skip to content

Commit 62881f3

Browse files
committed
read character unify with h5fortrn
1 parent 159d67d commit 62881f3

File tree

10 files changed

+534
-145
lines changed

10 files changed

+534
-145
lines changed

src/interface.f90

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,17 @@ module h5fortran
106106
procedure lt0readattr, lt1readattr
107107
end interface
108108

109+
interface read_char
110+
procedure read_char0, read_char1, read_char2, read_char3, read_char4, read_char5, read_char6, read_char7
111+
end interface
109112

110113
!! for submodules only
111114
public :: HSIZE_T, H5T_NATIVE_REAL, H5T_NATIVE_DOUBLE, H5T_NATIVE_INTEGER, H5T_NATIVE_CHARACTER, H5T_STD_I64LE
112115
public :: H5T_INTEGER_F, H5T_FLOAT_F, H5T_STRING_F
116+
!! HDF5 types for end users
117+
118+
119+
!> Submodules
113120

114121
interface !< write.f90
115122

@@ -272,55 +279,55 @@ module subroutine h5write_scalar(self, dname, A, compact)
272279
module subroutine h5write_1d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
273280
class(hdf5_file), intent(in) :: self
274281
character(*), intent(in) :: dname
275-
class(*), intent(in) :: A(:)
282+
class(*), intent(in), dimension(:) :: A
276283
integer, intent(in), dimension(1), optional :: chunk_size, istart, iend, stride, dset_dims
277284
logical, intent(in), optional :: compact
278285
end subroutine
279286

280287
module subroutine h5write_2d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
281288
class(hdf5_file), intent(in) :: self
282289
character(*), intent(in) :: dname
283-
class(*), intent(in) :: A(:,:)
290+
class(*), intent(in), dimension(:,:):: A
284291
integer, intent(in), dimension(2), optional :: chunk_size, istart, iend, stride, dset_dims
285292
logical, intent(in), optional :: compact
286293
end subroutine
287294

288295
module subroutine h5write_3d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
289296
class(hdf5_file), intent(in) :: self
290297
character(*), intent(in) :: dname
291-
class(*), intent(in) :: A(:,:,:)
298+
class(*), intent(in), dimension(:,:,:) :: A
292299
integer, intent(in), dimension(3), optional :: chunk_size, istart, iend, stride, dset_dims
293300
logical, intent(in), optional :: compact
294301
end subroutine
295302

296303
module subroutine h5write_4d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
297304
class(hdf5_file), intent(in) :: self
298305
character(*), intent(in) :: dname
299-
class(*), intent(in) :: A(:,:,:,:)
306+
class(*), intent(in), dimension(:,:,:,:) :: A
300307
integer, intent(in), dimension(4), optional :: chunk_size, istart, iend, stride, dset_dims
301308
logical, intent(in), optional :: compact
302309
end subroutine
303310

304311
module subroutine h5write_5d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
305312
class(hdf5_file), intent(in) :: self
306313
character(*), intent(in) :: dname
307-
class(*), intent(in) :: A(:,:,:,:,:)
314+
class(*), intent(in), dimension(:,:,:,:,:) :: A
308315
integer, intent(in), dimension(5), optional :: chunk_size, istart, iend, stride, dset_dims
309316
logical, intent(in), optional :: compact
310317
end subroutine
311318

312319
module subroutine h5write_6d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
313320
class(hdf5_file), intent(in) :: self
314321
character(*), intent(in) :: dname
315-
class(*), intent(in) :: A(:,:,:,:,:,:)
322+
class(*), intent(in), dimension(:,:,:,:,:,:) :: A
316323
integer, intent(in), dimension(6), optional :: chunk_size, istart, iend, stride, dset_dims
317324
logical, intent(in), optional :: compact
318325
end subroutine
319326

320327
module subroutine h5write_7d(self, dname, A, dset_dims, istart, iend, stride, chunk_size, compact)
321328
class(hdf5_file), intent(in) :: self
322329
character(*), intent(in) :: dname
323-
class(*), intent(in) :: A(:,:,:,:,:,:,:)
330+
class(*), intent(in), dimension(:,:,:,:,:,:,:) :: A
324331
integer, intent(in), dimension(7), optional :: chunk_size, istart, iend, stride, dset_dims
325332
logical, intent(in), optional :: compact
326333
end subroutine
@@ -399,58 +406,113 @@ module logical function hdf_check_exist(self, dname)
399406
!! * arrays: to work correctly when actual argument is allocatable
400407
!! * scalar: to work correctly with character type
401408

409+
module subroutine read_char0(self, obj_name, A, obj_id, mem_space_id, file_space_id)
410+
class(hdf5_file), intent(in) :: self
411+
character(*), intent(in) :: obj_name
412+
character(*), intent(inout) :: A
413+
integer(HID_T), intent(in) :: obj_id, mem_space_id, file_space_id
414+
end subroutine
415+
416+
module subroutine read_char1(self, obj_name, A, obj_id, mem_space_id, file_space_id)
417+
class(hdf5_file), intent(in) :: self
418+
character(*), intent(in) :: obj_name
419+
character(*), intent(inout), dimension(:) :: A
420+
integer(HID_T), intent(in) :: obj_id, mem_space_id, file_space_id
421+
end subroutine
422+
423+
module subroutine read_char2(self, obj_name, A, obj_id, mem_space_id, file_space_id)
424+
class(hdf5_file), intent(in) :: self
425+
character(*), intent(in) :: obj_name
426+
character(*), intent(inout), dimension(:,:) :: A
427+
integer(HID_T), intent(in) :: obj_id, mem_space_id, file_space_id
428+
end subroutine
429+
430+
module subroutine read_char3(self, obj_name, A, obj_id, mem_space_id, file_space_id)
431+
class(hdf5_file), intent(in) :: self
432+
character(*), intent(in) :: obj_name
433+
character(*), intent(inout), dimension(:,:,:) :: A
434+
integer(HID_T), intent(in) :: obj_id, mem_space_id, file_space_id
435+
end subroutine
436+
437+
module subroutine read_char4(self, obj_name, A, obj_id, mem_space_id, file_space_id)
438+
class(hdf5_file), intent(in) :: self
439+
character(*), intent(in) :: obj_name
440+
character(*), intent(inout), dimension(:,:,:,:) :: A
441+
integer(HID_T), intent(in) :: obj_id, mem_space_id, file_space_id
442+
end subroutine
443+
444+
module subroutine read_char5(self, obj_name, A, obj_id, mem_space_id, file_space_id)
445+
class(hdf5_file), intent(in) :: self
446+
character(*), intent(in) :: obj_name
447+
character(*), intent(inout), dimension(:,:,:,:,:) :: A
448+
integer(HID_T), intent(in) :: obj_id, mem_space_id, file_space_id
449+
end subroutine
450+
451+
module subroutine read_char6(self, obj_name, A, obj_id, mem_space_id, file_space_id)
452+
class(hdf5_file), intent(in) :: self
453+
character(*), intent(in) :: obj_name
454+
character(*), intent(inout), dimension(:,:,:,:,:,:) :: A
455+
integer(HID_T), intent(in) :: obj_id, mem_space_id, file_space_id
456+
end subroutine
457+
458+
module subroutine read_char7(self, obj_name, A, obj_id, mem_space_id, file_space_id)
459+
class(hdf5_file), intent(in) :: self
460+
character(*), intent(in) :: obj_name
461+
character(*), intent(inout), dimension(:,:,:,:,:,:,:) :: A
462+
integer(HID_T), intent(in) :: obj_id, mem_space_id, file_space_id
463+
end subroutine
402464
module subroutine h5read_scalar(self, dname, A)
403465
class(hdf5_file), intent(in) :: self
404466
character(*), intent(in) :: dname
405-
class(*), intent(inout) :: A
467+
class(*), intent(inout) :: A
406468
end subroutine
407469

408470
module subroutine h5read_1d(self, dname, A, istart, iend, stride)
409471
class(hdf5_file), intent(in) :: self
410472
character(*), intent(in) :: dname
411-
class(*), intent(inout) :: A(:)
473+
class(*), intent(inout), dimension(:) :: A
412474
integer, intent(in), dimension(1), optional :: istart, iend, stride
413475
end subroutine
414476

415477
module subroutine h5read_2d(self, dname, A, istart, iend, stride)
416478
class(hdf5_file), intent(in) :: self
417479
character(*), intent(in) :: dname
418-
class(*), intent(inout) :: A(:,:)
480+
class(*), intent(inout), dimension(:,:) :: A
419481
integer, intent(in), dimension(2), optional :: istart, iend, stride
420482
end subroutine
421483

422484
module subroutine h5read_3d(self, dname, A, istart, iend, stride)
423485
class(hdf5_file), intent(in) :: self
424486
character(*), intent(in) :: dname
425-
class(*), intent(inout) :: A(:,:,:)
487+
class(*), intent(inout), dimension(:,:,:) :: A
426488
integer, intent(in), dimension(3), optional :: istart, iend, stride
427489
end subroutine
428490

429491
module subroutine h5read_4d(self, dname, A, istart, iend, stride)
430492
class(hdf5_file), intent(in) :: self
431493
character(*), intent(in) :: dname
432-
class(*), intent(inout) :: A(:,:,:,:)
494+
class(*), intent(inout), dimension(:,:,:,:) :: A
433495
integer, intent(in), dimension(4), optional :: istart, iend, stride
434496
end subroutine
435497

436498
module subroutine h5read_5d(self, dname, A, istart, iend, stride)
437499
class(hdf5_file), intent(in) :: self
438500
character(*), intent(in) :: dname
439-
class(*), intent(inout) :: A(:,:,:,:,:)
501+
class(*), intent(inout), dimension(:,:,:,:,:) :: A
440502
integer, intent(in), dimension(5), optional :: istart, iend, stride
441503
end subroutine
442504

443505
module subroutine h5read_6d(self, dname, A, istart, iend, stride)
444506
class(hdf5_file), intent(in) :: self
445507
character(*), intent(in) :: dname
446-
class(*), intent(inout) :: A(:,:,:,:,:,:)
508+
class(*), intent(inout), dimension(:,:,:,:,:,:) :: A
447509
integer, intent(in), dimension(6), optional :: istart, iend, stride
448510
end subroutine
449511

450512
module subroutine h5read_7d(self, dname, A, istart, iend, stride)
451513
class(hdf5_file), intent(in) :: self
452514
character(*), intent(in) :: dname
453-
class(*), intent(inout) :: A(:,:,:,:,:,:,:)
515+
class(*), intent(inout), dimension(:,:,:,:,:,:,:) :: A
454516
integer, intent(in), dimension(7), optional :: istart, iend, stride
455517
end subroutine
456518

src/read.f90

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
use, intrinsic:: iso_c_binding, only : c_null_char
44

55
use hdf5, only : &
6-
H5Aget_space_f, H5Aget_type_f, H5Aopen_by_name_f, H5Aclose_f, &
6+
H5Aget_space_f, H5Aget_type_f, H5Aopen_by_name_f, H5Aclose_f, H5Aget_storage_size_f, &
77
h5pget_layout_f, h5pget_chunk_f, h5pclose_f, h5pget_nfilters_f, h5pget_filter_f, &
8-
H5Dget_create_plist_f, h5dget_type_f, h5dopen_f, h5dclose_f, H5Dget_space_f, &
8+
H5Dget_create_plist_f, h5dget_type_f, h5dopen_f, h5dclose_f, H5Dget_space_f, H5Dget_storage_size_f, &
99
H5Iget_type_f, &
1010
h5lexists_f, &
11-
H5Sget_simple_extent_ndims_f, H5Sget_simple_extent_dims_f, H5Sclose_f, &
12-
h5tclose_f, h5tget_native_type_f, h5tget_class_f, H5Tget_order_f, h5tget_size_f, h5tget_strpad_f, &
11+
H5Sget_simple_extent_ndims_f, H5Sget_simple_extent_dims_f, H5Sget_simple_extent_npoints_f, H5Sclose_f, &
12+
h5tclose_f, h5tget_native_type_f, h5tget_class_f, H5Tget_order_f, h5tget_size_f, h5tget_strpad_f, H5Tis_variable_str_f, &
1313
h5z_filter_deflate_f, &
1414
H5T_DIR_ASCEND_F, &
1515
H5I_ATTR_F, H5I_DATASET_F
@@ -119,43 +119,43 @@
119119
module procedure get_obj_class
120120

121121
integer :: ier, obj_type
122-
integer(HID_T) :: dtype_id, native_dtype_id
122+
integer(HID_T) :: obj_dtype, native_dtype
123123

124124
call H5Iget_type_f(obj_id, obj_type, ier)
125125
if(ier /= 0) error stop "ERROR:h5fortran:get_obj_class:H5Iget_type: " // obj_name // " " // self%filename
126126

127127
if(obj_type == H5I_DATASET_F) then
128-
call H5Dget_type_f(obj_id, dtype_id, ier)
128+
call H5Dget_type_f(obj_id, obj_dtype, ier)
129129
elseif(obj_type == H5I_ATTR_F) then
130-
call H5Aget_type_f(obj_id, dtype_id, ier)
130+
call H5Aget_type_f(obj_id, obj_dtype, ier)
131131
else
132132
error stop "ERROR:h5fortran:get_obj_class: only datasets and attributes have datatype " // obj_name // " " // self%filename
133133
endif
134-
if(ier/=0) error stop 'ERROR:h5fortran:get_class: dtype_id ' // obj_name // ' from ' // self%filename
134+
if(ier/=0) error stop 'ERROR:h5fortran:get_class: obj_dtype ' // obj_name // ' from ' // self%filename
135135

136-
call H5Tget_native_type_f(dtype_id, H5T_DIR_ASCEND_F, native_dtype_id, ier)
137-
if(ier/=0) error stop 'ERROR:h5fortran:get_class: native_dtype_id ' // obj_name // ' from ' // self%filename
136+
call H5Tget_native_type_f(obj_dtype, H5T_DIR_ASCEND_F, native_dtype, ier)
137+
if(ier/=0) error stop 'ERROR:h5fortran:get_class: native_dtype ' // obj_name // ' from ' // self%filename
138138

139139
!> compose datatype inferred
140-
call H5Tget_class_f(native_dtype_id, class, ier)
140+
call H5Tget_class_f(native_dtype, class, ier)
141141
if(ier/=0) error stop 'ERROR:h5fortran:get_class: class ' // obj_name // ' from ' // self%filename
142142

143143
if(present(size_bytes)) then
144-
call H5Tget_size_f(native_dtype_id, size_bytes, ier)
144+
call H5Tget_size_f(native_dtype, size_bytes, ier)
145145
if(ier/=0) error stop 'ERROR:h5fortran:get_class: byte size ' // obj_name // ' from ' // self%filename
146146
endif
147147

148-
call H5Tclose_f(native_dtype_id, ier)
148+
call H5Tclose_f(native_dtype, ier)
149149
if(ier/=0) error stop 'ERROR:h5fortran:get_class: closing native dtype ' // obj_name // ' from ' // self%filename
150150

151151
if(present(pad_type)) then
152152
if(class /= H5T_STRING_F) error stop "ERROR:h5fortran:get_class: pad_type only for string"
153153

154-
call H5Tget_strpad_f(dtype_id, pad_type, ier)
154+
call H5Tget_strpad_f(obj_dtype, pad_type, ier)
155155
if(ier /= 0) error stop "h5fortran:read:h5tget_strpad " // obj_name // " in " // self%filename
156156
endif
157157

158-
call H5Tclose_f(dtype_id, ier)
158+
call H5Tclose_f(obj_dtype, ier)
159159
if(ier/=0) error stop 'ERROR:h5fortran:get_class: closing dtype ' // obj_name // ' from ' // self%filename
160160

161161
end procedure get_obj_class
@@ -186,7 +186,7 @@
186186
endif
187187

188188
!> endianness and within type casting is handled by HDF5
189-
! call h5tget_order_f(native_dtype_id, order, ier)
189+
! call h5tget_order_f(native_dtype, order, ier)
190190
! if(ier/=0) error stop 'ERROR:h5fortran:reader: get endianness ' // dname // ' from ' // self%filename
191191
! !> check dataset endianness matches machine (in future, could swap endianness if needed)
192192
! call h5tget_order_f(H5T_NATIVE_INTEGER, machine_order, ier)

0 commit comments

Comments
 (0)