-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtest_destructor.f90
52 lines (29 loc) · 973 Bytes
/
test_destructor.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
program test_destruct
!! test hdf5_file destructor, that should auto-flush and close file
!! if user forgets to %close() file
use, intrinsic :: iso_fortran_env, only : stderr=>error_unit
use h5fortran, only: hdf5_file
implicit none
character(*), parameter :: fn = "test_destruct.h5"
call test_destructor_write(fn)
print *, 'OK: destructor write'
call test_destructor_read(fn)
print *, 'OK: destructor read'
contains
subroutine test_destructor_write(fn)
character(*), intent(in) :: fn
type(hdf5_file) :: h
call h%open(fn, action="w")
call h%write('/x', 42)
!! deliberately omitted %close() to test destructor
end subroutine test_destructor_write
subroutine test_destructor_read(fn)
character(*), intent(in) :: fn
integer :: i
type(hdf5_file) :: h
call h%open(fn, action="r")
call h%read("/x", i)
if(i/=42) error stop "destructor did not flush " // fn
!! deliberately omitted %close() to test destructor
end subroutine test_destructor_read
end program