This routine counts elapsed time between two calls.
The two elements in targ
will be populated by time_message
and correspond to the cumulative time and the time at the last
call to time_message for this entry or zero depending on if
the second element is zero or non-zero. Essentially the second
element acts both as a store for the time at a call and a flag
which flip-flops, to work out if we're currently timing or not.
RN targ(2) must be non-zero at initialization.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | lprint | |||
real, | intent(inout) | :: | targ(2) | |||
character(len=*), | intent(in) | :: | chmessage |
subroutine time_message(lprint,targ,chmessage)
use warning_helpers, only: is_zero
implicit none
character (len=*), intent(in) :: chmessage
logical, intent(in) :: lprint
real, intent(in out) :: targ(2) ! tsum and told
real :: tnew
real, parameter :: small_number=1.e-10
tnew=timer_local()
if (is_zero(targ(2))) then
!>RN targ(2) must be non-zero at initialization.
if (is_zero(tnew)) tnew = small_number
targ(2) = tnew
else
targ(1)=targ(1)+tnew-targ(2)
if (lprint) print *, chmessage,': ',tnew-targ(2),' seconds'
targ(2)=0.
end if
end subroutine time_message