Skip to content

Commit b8ed67a

Browse files
committed
remove redundant write methods
1 parent 92e5132 commit b8ed67a

File tree

6 files changed

+34
-171
lines changed

6 files changed

+34
-171
lines changed

API.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,6 @@ logical, intent(in), optional :: compact !< faster I/O for sub-64 kB datasets
138138
integer, intent(out), optional :: ierr !< 0 if OK
139139
```
140140

141-
While the generic `%write()` method above works for all supported types and ranks, it's also possible to specify the desired type to write.
142-
The user may desire this to be more explicit about the data type intended for disk writes.
143-
The optional arguments are the same as above; we give basic examples here:
144-
145-
```fortran
146-
call h%write_r32(dname, 1._real32)
147-
148-
call h%write_r64(dname, 1._real64)
149-
150-
call h%write_i32(dname, 1_int32)
151-
152-
call h%write_i64(dname, 1_int64)
153-
154-
call h%write_char(dname, "hello")
155-
```
156-
157141
Write dataset attribute (e.g. units or instrument)
158142

159143
```fortran

src/interface.f90

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ module h5fortran
5454
!> below are procedure that need generic mapping (type or rank agnostic)
5555

5656
!> write group or dataset integer/real
57-
generic, public :: write => &
58-
hdf_write_scalar_r32,hdf_write_scalar_r64,hdf_write_scalar_i32,hdf_write_scalar_i64, hdf_write_scalar_char, &
57+
generic, public :: write => hdf_write_scalar, &
5958
hdf_write_1d_r32, hdf_write_1d_r64, hdf_write_1d_i32, hdf_write_1d_i64, &
6059
hdf_write_2d_r32, hdf_write_2d_r64, hdf_write_2d_i32, hdf_write_2d_i64, &
6160
hdf_write_3d_r32, hdf_write_3d_r64, hdf_write_3d_i32, hdf_write_3d_i64, &
@@ -64,20 +63,6 @@ module h5fortran
6463
hdf_write_6d_r32, hdf_write_6d_r64, hdf_write_6d_i32, hdf_write_6d_i64, &
6564
hdf_write_7d_r32, hdf_write_7d_r64, hdf_write_7d_i32, hdf_write_7d_i64
6665

67-
generic, public :: write_r32 => hdf_write_scalar_r32,hdf_write_1d_r32,hdf_write_2d_r32,hdf_write_3d_r32, &
68-
hdf_write_4d_r32,hdf_write_5d_r32,hdf_write_6d_r32,hdf_write_7d_r32
69-
70-
generic, public :: write_r64 => hdf_write_scalar_r64,hdf_write_1d_r64,hdf_write_2d_r64,hdf_write_3d_r64, &
71-
hdf_write_4d_r64,hdf_write_5d_r64,hdf_write_6d_r64,hdf_write_7d_r64
72-
73-
generic, public :: write_i32 => hdf_write_scalar_i32,hdf_write_1d_i32,hdf_write_2d_i32,hdf_write_3d_i32, &
74-
hdf_write_4d_i32,hdf_write_5d_i32,hdf_write_6d_i32,hdf_write_7d_i32
75-
76-
generic, public :: write_i64 => hdf_write_scalar_i64,hdf_write_1d_i64,hdf_write_2d_i64,hdf_write_3d_i64, &
77-
hdf_write_4d_i64,hdf_write_5d_i64,hdf_write_6d_i64,hdf_write_7d_i64
78-
79-
generic, public :: write_char => hdf_write_scalar_char
80-
8166
!> write attributes
8267
generic, public :: writeattr => writeattr_char, writeattr_num
8368

@@ -90,8 +75,7 @@ module h5fortran
9075

9176
!> private methods
9277
!! each method must be declared here, and above as a generic, public
93-
procedure,private :: &
94-
hdf_write_scalar_r32, hdf_write_scalar_r64, hdf_write_scalar_i32, hdf_write_scalar_i64, hdf_write_scalar_char, &
78+
procedure,private :: hdf_write_scalar, &
9579
hdf_write_1d_r32, hdf_write_1d_r64, hdf_write_1d_i32, hdf_write_1d_i64, &
9680
hdf_write_2d_r32, hdf_write_2d_r64, hdf_write_2d_i32, hdf_write_2d_i64, &
9781
hdf_write_3d_r32, hdf_write_3d_r64, hdf_write_3d_i32, hdf_write_3d_i64, &
@@ -459,46 +443,13 @@ end subroutine lt7read
459443
end interface
460444

461445
interface !< writer.f90
462-
module subroutine hdf_write_scalar_r32(self, dname, value, ierr, compact)
463-
class(hdf5_file), intent(inout) :: self
464-
character(*), intent(in) :: dname
465-
real(real32), intent(in) :: value
466-
logical, intent(in), optional :: compact
467-
integer, intent(out), optional :: ierr
468-
end subroutine hdf_write_scalar_r32
469-
470-
module subroutine hdf_write_scalar_r64(self, dname, value, ierr, compact)
446+
module subroutine hdf_write_scalar(self, dname, value, ierr, compact)
471447
class(hdf5_file), intent(inout) :: self
472448
character(*), intent(in) :: dname
473-
real(real64), intent(in) :: value
449+
class(*), intent(in) :: value
474450
logical, intent(in), optional :: compact
475451
integer, intent(out), optional :: ierr
476-
end subroutine hdf_write_scalar_r64
477-
478-
module subroutine hdf_write_scalar_i32(self, dname, value, ierr, compact)
479-
class(hdf5_file), intent(inout) :: self
480-
character(*), intent(in) :: dname
481-
integer(int32), intent(in) :: value
482-
logical, intent(in), optional :: compact
483-
integer, intent(out), optional :: ierr
484-
end subroutine hdf_write_scalar_i32
485-
486-
module subroutine hdf_write_scalar_i64(self, dname, value, ierr, compact)
487-
class(hdf5_file), intent(inout) :: self
488-
character(*), intent(in) :: dname
489-
integer(int64), intent(in) :: value
490-
logical, intent(in), optional :: compact
491-
integer, intent(out), optional :: ierr
492-
end subroutine hdf_write_scalar_i64
493-
494-
module subroutine hdf_write_scalar_char(self, dname, value, ierr, compact)
495-
class(hdf5_file), intent(inout) :: self
496-
character(*), intent(in) :: dname
497-
character(*), intent(in) :: value
498-
logical, intent(in), optional :: compact
499-
integer, intent(out), optional :: ierr
500-
end subroutine hdf_write_scalar_char
501-
452+
end subroutine hdf_write_scalar
502453

503454
module subroutine hdf_write_1d_r32(self,dname,value, ierr, chunk_size, istart, iend, stride, compact)
504455
class(hdf5_file), intent(inout) :: self

src/tests/test_array.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ subroutine test_write_slice(filename)
153153
print *, 'PASSED: create dataset and write slice 1D'
154154

155155
call h%write('/int32-1d', [35, 70], istart=[2], iend=[3], stride=[1])
156-
call h%write_i32('/int32-1d', [35, 70], istart=[2], iend=[3], stride=[1])
157156

158157
call h%read('/int32-1d', i1t)
159158
if (.not.all(i1t==[1,35,70,4])) then

src/tests/test_scalar.f90

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@ program scalar_test
3333
call h%open(fn, action='w')
3434
!> scalar tests
3535
call h%write('/scalar_int32', 42_int32)
36-
call h%write_i32('/scalar_i32', 42_int32)
3736

3837
call h%write('/scalar_int64', 42_int64)
39-
call h%write_i64('/scalar_i64', 42_int64)
4038

4139
call h%write('/scalar_real32', -1._real32)
42-
call h%write_r32("/scalar_r32", -1._real32)
4340

4441
call h%write('/scalar_real64', -1._real64)
45-
call h%write_r64("/scalar_r64", -1._real64)
4642

4743
!> vector
4844
call h%write('/1d_real', r1)

src/tests/test_string.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ program test_string
1515
call h%open(path, action='w')
1616

1717
call h%write('/little', '42')
18-
call h%write_char('/little_char', '42')
1918
call h%write('/MySentence', 'this is a little sentence.')
2019

2120
call h%close()

src/write/writer.in.f90

Lines changed: 29 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
contains
88

99

10-
module procedure hdf_write_scalar_r32
10+
module procedure hdf_write_scalar
1111

1212
integer(HID_T) :: sid, did
1313
integer(HSIZE_T), allocatable :: dims(:)
@@ -17,100 +17,34 @@
1717

1818
allocate(dims(0))
1919

20-
call hdf_create(self, dname, H5T_NATIVE_REAL, dims, sid, did, compact=compact)
21-
call h5dwrite_f(did, H5T_NATIVE_REAL, value, dims, ier)
22-
23-
if (ier/=0) error stop 'h5fortran:write: could not write ' // dname // ' to ' // self%filename
24-
25-
call hdf_wrapup(did, sid)
26-
27-
if (present(ierr)) ierr = ier
28-
if (check(ier, self%filename, dname) .and. .not.present(ierr)) error stop "h5fortran:write:wrapup: " // dname
29-
30-
end procedure hdf_write_scalar_r32
31-
32-
33-
module procedure hdf_write_scalar_r64
34-
35-
integer(HID_T) :: sid, did
36-
integer(HSIZE_T), allocatable :: dims(:)
37-
integer :: ier
38-
39-
if(.not.self%is_open) error stop 'h5fortran:write: file handle is not open'
40-
41-
allocate(dims(0))
42-
43-
call hdf_create(self, dname, H5T_NATIVE_DOUBLE, dims, sid, did, compact=compact)
44-
call h5dwrite_f(did, H5T_NATIVE_DOUBLE, value, dims, ier)
45-
46-
if (ier/=0) error stop 'h5fortran:write: could not write ' // dname // ' to ' // self%filename
47-
48-
call hdf_wrapup(did, sid)
49-
50-
if (present(ierr)) ierr = ier
51-
if (check(ier, self%filename, dname) .and. .not.present(ierr)) error stop "h5fortran:write:wrapup: " // dname
52-
53-
end procedure hdf_write_scalar_r64
54-
55-
56-
module procedure hdf_write_scalar_i32
57-
58-
integer(HID_T) :: sid, did
59-
integer(HSIZE_T), allocatable :: dims(:)
60-
integer :: ier
61-
62-
if(.not.self%is_open) error stop 'h5fortran:write: file handle is not open'
63-
64-
allocate(dims(0))
65-
66-
call hdf_create(self, dname, H5T_NATIVE_INTEGER, dims, sid, did, compact=compact)
67-
call h5dwrite_f(did, H5T_NATIVE_INTEGER, value, dims, ier)
68-
69-
if (ier/=0) error stop 'h5fortran:write: could not write ' // dname // ' to ' // self%filename
70-
71-
call hdf_wrapup(did, sid)
72-
73-
if (present(ierr)) ierr = ier
74-
if (check(ier, self%filename, dname) .and. .not.present(ierr)) error stop "h5fortran:write:wrapup: " // dname
75-
76-
end procedure hdf_write_scalar_i32
77-
78-
79-
module procedure hdf_write_scalar_i64
80-
81-
integer(HID_T) :: sid, did
82-
integer(HSIZE_T), allocatable :: dims(:)
83-
integer :: ier
84-
85-
if(.not.self%is_open) error stop 'h5fortran:write: file handle is not open'
86-
87-
allocate(dims(0))
88-
89-
call hdf_create(self, dname, H5T_STD_I64LE, dims, sid, did, compact=compact)
90-
call h5dwrite_f(did, H5T_STD_I64LE, value, dims, ier)
91-
92-
if (ier/=0) error stop 'h5fortran:write: could not write ' // dname // ' to ' // self%filename
93-
94-
call hdf_wrapup(did, sid)
95-
96-
if (present(ierr)) ierr = ier
97-
if (check(ier, self%filename, dname) .and. .not.present(ierr)) error stop "h5fortran:write:wrapup: " // dname
98-
99-
end procedure hdf_write_scalar_i64
100-
101-
102-
module procedure hdf_write_scalar_char
103-
104-
integer :: ier
105-
106-
if(.not.self%is_open) error stop 'h5fortran:write: file handle is not open'
107-
108-
call h5ltmake_dataset_string_f(self%lid, dname, value, ier)
109-
110-
if (present(ierr)) ierr = ier
111-
if (check(ier, self%filename, dname) .and. .not.present(ierr)) error stop "h5fortran:write:wrapup: " // dname
112-
113-
end procedure hdf_write_scalar_char
20+
select type (value)
21+
type is (real(real32))
22+
call hdf_create(self, dname, H5T_NATIVE_REAL, dims, sid, did, compact=compact)
23+
call h5dwrite_f(did, H5T_NATIVE_REAL, value, dims, ier)
24+
type is (real(real64))
25+
call hdf_create(self, dname, H5T_NATIVE_DOUBLE, dims, sid, did, compact=compact)
26+
call h5dwrite_f(did, H5T_NATIVE_DOUBLE, value, dims, ier)
27+
type is (integer(int32))
28+
call hdf_create(self, dname, H5T_NATIVE_INTEGER, dims, sid, did, compact=compact)
29+
call h5dwrite_f(did, H5T_NATIVE_INTEGER, value, dims, ier)
30+
type is (integer(int64))
31+
call hdf_create(self, dname, H5T_STD_I64LE, dims, sid, did, compact=compact)
32+
call h5dwrite_f(did, H5T_STD_I64LE, value, dims, ier)
33+
type is (character(*))
34+
call h5ltmake_dataset_string_f(self%lid, dname, value, ier)
35+
class default
36+
error stop "h5fortran:write: unknown type"
37+
end select
38+
39+
if (ier /= 0) error stop 'h5fortran:write: could not write ' // dname // ' to ' // self%filename
40+
41+
select type (value)
42+
type is (character(*))
43+
class default
44+
call hdf_wrapup(did, sid)
45+
end select
46+
47+
end procedure hdf_write_scalar
11448

11549

11650
module procedure hdf_write_1d_r32

0 commit comments

Comments
 (0)