-
Notifications
You must be signed in to change notification settings - Fork 4
/
fexp_debug.f90
95 lines (72 loc) · 2.91 KB
/
fexp_debug.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
module fexp_debug
implicit none
logical, save :: ldebug
integer, save :: un
integer :: calldepth
contains
subroutine debug_set(debug, filename, unitnumber)
logical :: debug
character(len=*), optional :: filename
integer, optional :: unitnumber
integer :: ioern
if (debug) then
if (present(filename).and.present(unitnumber)) then
open (unit=unitnumber, iostat=ioern, file=filename, &
& action='readwrite', position='append', &
& status='unknown')
else
stop 'API error in debug_set: filename and unitnumber needed'
endif
if (ioern.ne.0) stop 'Error opening debug file for append'
un = unitnumber
ldebug = .true.
calldepth = 0
write(un, '(a)') "Debug session starts..."
else
ldebug = .false.
endif
end subroutine debug_set
subroutine debug_stop
if (ldebug) then
write(un, '(a)') "Debug session ends..."
ldebug = .false.
close(unit=un)
endif
end subroutine debug_stop
subroutine proc_start(procname, procarg1, procarg2, &
& procarg3, procarg4, procarg5)
character(len=*), intent(in) :: procname
character(len=*), optional, intent(in) :: procarg1, procarg2, &
& procarg3, procarg4, procarg5
if (ldebug) then
calldepth = calldepth + 1
write(un, '(a)'), repeat('-',calldepth) // "> Start of " // procname
if (present(procarg1)) then
write(un, '(a)'), repeat('-',calldepth) // "> arg1 " // procarg1
endif
if (present(procarg2)) then
write(un, '(a)'), repeat('-',calldepth) // "> arg2 " // procarg2
endif
if (present(procarg3)) then
write(un, '(a)'), repeat('-',calldepth) // "> arg3 " // procarg3
endif
if (present(procarg4)) then
write(un, '(a)'), repeat('-',calldepth) // "> arg4 " // procarg4
endif
if (present(procarg5)) then
write(un, '(a)'), repeat('-',calldepth) // "> arg5 " // procarg5
endif
endif
end subroutine proc_start
subroutine proc_end (procname, returnval)
character(len=*), intent(in) :: procname
character(len=*), optional, intent(in) :: returnval
if (ldebug) then
if (present(returnval)) then
write(un, '(a)'), repeat('-',calldepth) // "> rv " // returnval
endif
write(un, '(a)'), repeat('-',calldepth) // "> End of " // procname
calldepth = calldepth - 1
endif
end subroutine proc_end
end module fexp_debug