Soil Water Balance (SWB2)
Toggle main menu visibility
Loading...
Searching...
No Matches
timer.F90
Go to the documentation of this file.
1
module
timer
2
3
use
fstring
,
only
:
ascharacter
4
use
iso_c_binding
5
implicit none
6
7
type
timer_t
8
9
real
(c_double) :: starttime
10
real
(c_double) :: stoptime
11
real
(c_double) :: elapsedtime = 0.0_c_double
12
real
(c_double) :: splittime = 0.0_c_double
13
14
integer (c_int)
:: seconds
15
integer (c_int)
:: minutes
16
integer (c_int)
:: hours
17
integer (c_int)
:: days
18
19
contains
20
generic :: reset =>
reset_timer_sub
21
procedure
::
reset_timer_sub
22
generic :: start =>
start_timer_sub
23
procedure
::
start_timer_sub
24
generic :: stop =>
stop_timer_sub
25
procedure
::
stop_timer_sub
26
27
generic :: calc_elapsed =>
calc_elapsed_time_sub
28
procedure
::
calc_elapsed_time_sub
29
30
generic :: calc_split =>
calc_split_time_sub
31
procedure
::
calc_split_time_sub
32
33
generic :: get_elapsed =>
get_elapsed_seconds_fn
34
procedure
::
get_elapsed_seconds_fn
35
36
generic :: get_split =>
get_split_seconds_fn
37
procedure
::
get_split_seconds_fn
38
39
generic :: calc_time_values =>
calc_time_values_sub
40
procedure
::
calc_time_values_sub
41
42
generic :: get_pretty =>
get_timer_pretty_fn
43
procedure
::
get_timer_pretty_fn
44
45
end type
timer_t
46
47
48
contains
49
50
subroutine
start_timer_sub
(this)
51
52
class(
timer_t
) :: this
53
54
call
cpu_time(this%starttime)
55
56
end subroutine
start_timer_sub
57
58
!------------------------------------------------------------------------------
59
60
subroutine
stop_timer_sub
(this)
61
62
class(
timer_t
) :: this
63
64
call
cpu_time(this%stoptime)
65
this%splittime = this%stoptime - this%starttime
66
this%elapsedtime = this%elapsedtime + (this%stoptime - this%starttime)
67
68
end subroutine
stop_timer_sub
69
70
!------------------------------------------------------------------------------
71
72
subroutine
calc_elapsed_time_sub
(this)
73
74
class(
timer_t
) :: this
75
76
this%elapsedtime = this%elapsedtime + (this%stoptime - this%starttime)
77
call
this%calc_time_values(
"elapsed"
)
78
79
end subroutine
calc_elapsed_time_sub
80
81
!------------------------------------------------------------------------------
82
83
subroutine
calc_split_time_sub
(this)
84
85
class(
timer_t
) :: this
86
87
this%splittime = this%stoptime - this%starttime
88
call
this%calc_time_values(
"split"
)
89
90
end subroutine
calc_split_time_sub
91
92
!------------------------------------------------------------------------------
93
94
subroutine
reset_timer_sub
(this)
95
96
class(
timer_t
) :: this
97
98
this%elapsedtime = 0.0_c_double
99
100
end subroutine
reset_timer_sub
101
102
!------------------------------------------------------------------------------
103
104
function
get_elapsed_seconds_fn
(this)
result
(elapsed_seconds)
105
106
class(
timer_t
) :: this
107
integer (c_int)
:: elapsed_seconds
108
109
elapsed_seconds = int(this%elapsedtime, c_int)
110
111
end function
get_elapsed_seconds_fn
112
113
!------------------------------------------------------------------------------
114
115
function
get_split_seconds_fn
(this)
result
(split_seconds)
116
117
class(
timer_t
) :: this
118
integer (c_int)
:: split_seconds
119
120
split_seconds = int(this%splittime, c_int)
121
122
end function
get_split_seconds_fn
123
124
!------------------------------------------------------------------------------
125
126
subroutine
calc_time_values_sub
(this, timer_name)
127
128
class(
timer_t
) :: this
129
character (len=*)
,
intent(in)
:: timer_name
130
131
! [ LOCALS ]
132
real
(c_double) :: remainder
133
134
select case
(timer_name)
135
case
(
"split"
)
136
remainder = this%splittime
137
case
(
"elapsed"
)
138
remainder = this%elapsedtime
139
case default
140
remainder = this%elapsedtime
141
end select
142
143
this%days = -9999
144
this%hours = -9999
145
this%minutes = -9999
146
this%seconds = -9999
147
148
if
( int(remainder) >= 86400 )
then
149
this%days = int( remainder / 86400.0_c_double )
150
remainder = modulo(remainder, 86400.0_c_double)
151
endif
152
153
if
( int(remainder) >= 3600)
then
154
this%hours = int( remainder / 3600.0_c_double )
155
remainder = modulo(remainder, 3600.0_c_double)
156
endif
157
158
if
( int(remainder) >= 60)
then
159
this%minutes = int( remainder / 60.0_c_double )
160
remainder = modulo(remainder, 60.0_c_double)
161
endif
162
163
this%seconds = int( remainder )
164
165
end subroutine
calc_time_values_sub
166
167
!------------------------------------------------------------------------------
168
169
function
get_timer_pretty_fn
(this)
result
(time_txt)
170
171
class(
timer_t
) :: this
172
character (len=:)
,
allocatable
:: time_txt
173
174
! [ LOCALS ]
175
character (len=256)
:: str
176
177
str =
""
178
179
if
( this%days >= 0 ) str =
ascharacter
(this%days)//
" days,"
180
if
( this%hours >= 0 ) str = trim(str)//
" "
//
ascharacter
(this%hours)//
" hours,"
181
if
( this%minutes >= 0 ) str = trim(str)//
" "
//
ascharacter
(this%minutes)//
" minutes,"
182
str = trim(str)//
" "
//
ascharacter
(this%seconds)//
" seconds."
183
184
time_txt = trim(adjustl(str))
185
186
end function
get_timer_pretty_fn
187
188
end module
timer
fstring
Definition
fstring.F90:1
timer
Definition
timer.F90:1
timer::calc_elapsed_time_sub
subroutine calc_elapsed_time_sub(this)
Definition
timer.F90:73
timer::get_split_seconds_fn
integer(c_int) function get_split_seconds_fn(this)
Definition
timer.F90:116
timer::get_timer_pretty_fn
character(len=:) function, allocatable get_timer_pretty_fn(this)
Definition
timer.F90:170
timer::calc_time_values_sub
subroutine calc_time_values_sub(this, timer_name)
Definition
timer.F90:127
timer::stop_timer_sub
subroutine stop_timer_sub(this)
Definition
timer.F90:61
timer::calc_split_time_sub
subroutine calc_split_time_sub(this)
Definition
timer.F90:84
timer::reset_timer_sub
subroutine reset_timer_sub(this)
Definition
timer.F90:95
timer::get_elapsed_seconds_fn
integer(c_int) function get_elapsed_seconds_fn(this)
Definition
timer.F90:105
timer::start_timer_sub
subroutine start_timer_sub(this)
Definition
timer.F90:51
fstring::ascharacter
Definition
fstring.F90:44
timer::timer_t
Definition
timer.F90:7
src
timer.F90
Generated on
for Soil Water Balance (SWB2) by
1.17.0