Skip to content

Commit f0a4e03

Browse files
committed
add h5read(), h5write() procedures
1 parent 60247db commit f0a4e03

12 files changed

+362
-62
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ utils.f90
99
${CMAKE_CURRENT_BINARY_DIR}/hdf5_config.f90
1010
read.f90 read_scalar.f90 read_scalar_ascii.f90 reader.f90
1111
write.f90 write_scalar.f90 writer.f90
12+
reader_lt.f90 writer_lt.f90
1213
interface.f90
1314
attr.f90 attr_read.f90 attr_write.f90
1415
mpi.F90

src/interface.f90

Lines changed: 102 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,15 @@ module h5fortran
8686
public :: hdf5_file, is_hdf5
8787
public :: hdf_rank_check, hdf_shape_check, hdf5version, h5exist, hdf5_close
8888
public :: mpi_collective, mpi_hyperslab
89-
public :: h5write_attr, h5read_attr
89+
public :: h5write, h5read, h5write_attr, h5read_attr
90+
91+
interface h5write
92+
procedure lt0write, lt1write, lt2write, lt3write, lt4write, lt5write, lt6write, lt7write
93+
end interface
94+
95+
interface h5read
96+
procedure lt0read, lt1read, lt2read, lt3read, lt4read, lt5read, lt6read, lt7read
97+
end interface
9098

9199
interface h5write_attr
92100
procedure lt0writeattr, lt1writeattr
@@ -156,6 +164,99 @@ module subroutine get_hdf5_config(parallel_compression)
156164
end subroutine
157165
end interface
158166

167+
interface !< writer_lt.f90
168+
169+
module subroutine lt0write(filename, dname, A)
170+
character(*), intent(in) :: filename, dname
171+
class(*), intent(in) :: A
172+
end subroutine
173+
174+
module subroutine lt1write(filename, dname, A)
175+
character(*), intent(in) :: filename, dname
176+
class(*), intent(in) :: A(:)
177+
end subroutine
178+
179+
module subroutine lt2write(filename, dname, A)
180+
character(*), intent(in) :: filename, dname
181+
class(*), intent(in) :: A(:,:)
182+
end subroutine
183+
184+
module subroutine lt3write(filename, dname, A)
185+
character(*), intent(in) :: filename, dname
186+
class(*), intent(in) :: A(:,:,:)
187+
end subroutine
188+
189+
module subroutine lt4write(filename, dname, A)
190+
character(*), intent(in) :: filename, dname
191+
class(*), intent(in) :: A(:,:,:,:)
192+
end subroutine
193+
194+
module subroutine lt5write(filename, dname, A)
195+
character(*), intent(in) :: filename, dname
196+
class(*), intent(in) :: A(:,:,:,:,:)
197+
end subroutine
198+
199+
module subroutine lt6write(filename, dname, A)
200+
character(*), intent(in) :: filename, dname
201+
class(*), intent(in) :: A(:,:,:,:,:,:)
202+
end subroutine
203+
204+
module subroutine lt7write(filename, dname, A)
205+
character(*), intent(in) :: filename, dname
206+
class(*), intent(in) :: A(:,:,:,:,:,:,:)
207+
end subroutine
208+
209+
end interface
210+
211+
212+
interface !< reader_lt.f90
213+
214+
module logical function h5exist(filename, dname, mpi)
215+
character(*), intent(in) :: filename, dname
216+
logical, intent(in), optional :: mpi
217+
end function
218+
219+
module subroutine lt0read(filename, dname, A)
220+
character(*), intent(in) :: filename, dname
221+
class(*), intent(out) :: A
222+
end subroutine
223+
224+
module subroutine lt1read(filename, dname, A)
225+
character(*), intent(in) :: filename, dname
226+
class(*), intent(inout) :: A(:)
227+
end subroutine
228+
229+
module subroutine lt2read(filename, dname, A)
230+
character(*), intent(in) :: filename, dname
231+
class(*), intent(inout) :: A(:,:)
232+
end subroutine
233+
234+
module subroutine lt3read(filename, dname, A)
235+
character(*), intent(in) :: filename, dname
236+
class(*), intent(inout) :: A(:,:,:)
237+
end subroutine
238+
239+
module subroutine lt4read(filename, dname, A)
240+
character(*), intent(in) :: filename, dname
241+
class(*), intent(inout) :: A(:,:,:,:)
242+
end subroutine
243+
244+
module subroutine lt5read(filename, dname, A)
245+
character(*), intent(in) :: filename, dname
246+
class(*), intent(inout) :: A(:,:,:,:,:)
247+
end subroutine
248+
249+
module subroutine lt6read(filename, dname, A)
250+
character(*), intent(in) :: filename, dname
251+
class(*), intent(inout) :: A(:,:,:,:,:,:)
252+
end subroutine
253+
254+
module subroutine lt7read(filename, dname, A)
255+
character(*), intent(in) :: filename, dname
256+
class(*), intent(inout) :: A(:,:,:,:,:,:,:)
257+
end subroutine
258+
end interface
259+
159260

160261
interface !< writer.f90
161262

@@ -284,11 +385,6 @@ module logical function hdf_check_exist(self, dname)
284385
!! * arrays: to work correctly when actual argument is allocatable
285386
!! * scalar: to work correctly with character type
286387

287-
module logical function h5exist(filename, dname, mpi)
288-
character(*), intent(in) :: filename, dname
289-
logical, intent(in) :: mpi
290-
end function
291-
292388
module subroutine h5read_scalar(self, dname, A)
293389
class(hdf5_file), intent(in) :: self
294390
character(*), intent(in) :: dname

src/reader.f90

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@
77
contains
88

99

10-
module procedure h5exist
11-
12-
type(hdf5_file) :: h
13-
14-
call h%open(filename, action='r', mpi=mpi)
15-
h5exist = h%exist(dname)
16-
call h%close()
17-
18-
end procedure h5exist
19-
20-
2110
module procedure h5read_1d
2211
include "reader.inc"
2312
end procedure

src/reader_lt.f90

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
submodule (h5fortran:hdf5_read) reader_lt
2+
3+
implicit none (type, external)
4+
5+
contains
6+
7+
module procedure h5exist
8+
9+
type(hdf5_file) :: h
10+
11+
call h%open(filename, action='r', mpi=mpi)
12+
h5exist = h%exist(dname)
13+
call h%close()
14+
15+
end procedure h5exist
16+
17+
18+
module procedure lt0read
19+
include "reader_lt.inc"
20+
end procedure
21+
22+
module procedure lt1read
23+
include "reader_lt.inc"
24+
end procedure
25+
26+
module procedure lt2read
27+
include "reader_lt.inc"
28+
end procedure
29+
30+
module procedure lt3read
31+
include "reader_lt.inc"
32+
end procedure
33+
34+
module procedure lt4read
35+
include "reader_lt.inc"
36+
end procedure
37+
38+
module procedure lt5read
39+
include "reader_lt.inc"
40+
end procedure
41+
42+
module procedure lt6read
43+
include "reader_lt.inc"
44+
end procedure
45+
46+
module procedure lt7read
47+
include "reader_lt.inc"
48+
end procedure
49+
50+
end submodule reader_lt

src/reader_lt.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type(hdf5_file) :: h
2+
3+
call h%open(filename, action='r')
4+
call h%read(dname, A)
5+
call h%close()

src/writer_lt.f90

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
submodule (h5fortran:write) writer_lt
2+
3+
implicit none (type, external)
4+
5+
contains
6+
7+
8+
module procedure lt0write
9+
include "writer_lt.inc"
10+
end procedure
11+
12+
module procedure lt1write
13+
include "writer_lt.inc"
14+
end procedure
15+
16+
module procedure lt2write
17+
include "writer_lt.inc"
18+
end procedure
19+
20+
module procedure lt3write
21+
include "writer_lt.inc"
22+
end procedure
23+
24+
module procedure lt4write
25+
include "writer_lt.inc"
26+
end procedure
27+
28+
module procedure lt5write
29+
include "writer_lt.inc"
30+
end procedure
31+
32+
module procedure lt6write
33+
include "writer_lt.inc"
34+
end procedure
35+
36+
module procedure lt7write
37+
include "writer_lt.inc"
38+
end procedure
39+
40+
end submodule writer_lt

src/writer_lt.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type(hdf5_file) :: h
2+
3+
call h%open(filename, action='rw')
4+
call h%write(dname, A)
5+
call h%close()

test/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ cmake_path(SET string_file ${CMAKE_CURRENT_BINARY_DIR}/test_string_py.h5)
5757
# --- non-MPI tests
5858

5959
set(nompi_tests array attributes cast deflate_props deflate_read deflate_write destructor
60-
exist
60+
exist fill
6161
)
6262

6363
nompi_test("${nompi_tests}")
@@ -92,7 +92,7 @@ endif()
9292
# --- MPI tests
9393

9494
set(mpi_tests array_mpi attributes_mpi cast_mpi destructor_mpi exist_mpi
95-
fill groups layout shape
95+
fill_mpi groups_mpi layout shape
9696
string string_read write
9797
)
9898

test/test_fill.f90

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,20 @@ program fill
44

55
use h5fortran, only : hdf5_file
66
use hdf5, only : HSIZE_T, H5T_NATIVE_REAL, H5T_NATIVE_DOUBLE, H5T_NATIVE_INTEGER, H5T_NATIVE_CHARACTER
7-
use mpi, only : mpi_init, MPI_COMM_WORLD, mpi_comm_rank
87

98
implicit none (type, external)
109

11-
external :: mpi_finalize
12-
1310
type(hdf5_file) :: h5
1411

1512
character(*), parameter :: fn = "test_fill.h5"
1613

1714
real :: NaN, r(3)
18-
integer :: i(2), ierr, mpi_id
15+
integer :: i(2)
1916
character(10) :: c, fill_value
2017

21-
call mpi_init(ierr)
22-
if (ierr /= 0) error stop "mpi_init"
23-
24-
call mpi_comm_rank(MPI_COMM_WORLD, mpi_id, ierr)
25-
if (ierr /= 0) error stop "mpi_comm_rank"
26-
2718
NaN = ieee_value(0., ieee_quiet_nan)
2819

29-
call h5%open(fn, action="w", mpi=.true.)
20+
call h5%open(fn, "w")
3021

3122
call h5%create("/r32", H5T_NATIVE_REAL, dset_dims=[3], fill_value=NaN)
3223
call h5%create("/r64", H5T_NATIVE_DOUBLE, dset_dims=[3], fill_value=NaN)
@@ -42,8 +33,7 @@ program fill
4233

4334
call h5%close()
4435

45-
46-
call h5%open(fn, action="r", mpi=.true.)
36+
call h5%open(fn, "r")
4737

4838
call h5%read("/r32", r)
4939
if(any(ieee_is_finite(r))) error stop "real32: expected all NaN"
@@ -65,9 +55,6 @@ program fill
6555

6656
call h5%close()
6757

68-
if(mpi_id == 0) print *, "OK: fill value"
69-
70-
call mpi_finalize(ierr)
71-
if (ierr /= 0) error stop "mpi_finalize"
58+
print *, "OK: fill value"
7259

7360
end program

0 commit comments

Comments
 (0)