-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtime.f90
55 lines (44 loc) · 1.4 KB
/
time.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
! MODULE: time
! AUTHOR: Jouni Makitalo
! DESCRIPTION:
! Routines for measuring time and time intervals.
MODULE time
IMPLICIT NONE
INTEGER, PARAMETER :: r8=SELECTED_REAL_KIND(12,100)
REAL (KIND=r8), PRIVATE, SAVE :: time_start, time_start_cpu
CONTAINS
FUNCTION get_time() RESULT(sec)
IMPLICIT NONE
INTEGER, DIMENSION(8) :: t
REAL (KIND=r8) :: sec
CALL DATE_AND_TIME(values=t)
sec = t(3)*86400.0_r8+t(5)*3600.0_r8+t(6)*60.0_r8+t(7)+t(8)/1000.0_r8
END FUNCTION get_time
SUBROUTINE timer_start()
time_start = get_time()
END SUBROUTINE timer_start
FUNCTION timer_end() RESULT(sec)
IMPLICIT NONE
REAL (KIND=r8) :: sec
sec = get_time() - time_start
END FUNCTION timer_end
FUNCTION sec_to_str(sec) RESULT(str)
REAL (KIND=r8), INTENT(IN) :: sec
CHARACTER (LEN=128) :: str
INTEGER :: hours, minutes, seconds
hours = FLOOR(sec/3600.0_r8)
minutes = FLOOR((sec-hours*3600.0_r8)/60.0_r8)
seconds = FLOOR((sec-hours*3600.0_r8-minutes*60.0_r8))
write(str, '(I0,A,I0,A,I0,A)') hours, ' hours ', minutes, ' minutes ',&
seconds, ' seconds '
END FUNCTION sec_to_str
SUBROUTINE cpu_timer_start()
CALL cpu_time(time_start_cpu)
END SUBROUTINE cpu_timer_start
FUNCTION cpu_timer_end() RESULT(sec)
IMPLICIT NONE
REAL (KIND=r8) :: sec
CALL cpu_time(sec)
sec = sec - time_start_cpu
END FUNCTION cpu_timer_end
END MODULE time