1 | !> @file src/inifor_control.f90 |
---|
2 | !------------------------------------------------------------------------------! |
---|
3 | ! This file is part of the PALM model system. |
---|
4 | ! |
---|
5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
6 | ! terms of the GNU General Public License as published by the Free Software |
---|
7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
8 | ! version. |
---|
9 | ! |
---|
10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
13 | ! |
---|
14 | ! You should have received a copy of the GNU General Public License along with |
---|
15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | ! |
---|
17 | ! Copyright 2017-2018 Leibniz Universitaet Hannover |
---|
18 | ! Copyright 2017-2018 Deutscher Wetterdienst Offenbach |
---|
19 | !------------------------------------------------------------------------------! |
---|
20 | ! |
---|
21 | ! Current revisions: |
---|
22 | ! ----------------- |
---|
23 | ! |
---|
24 | ! |
---|
25 | ! Former revisions: |
---|
26 | ! ----------------- |
---|
27 | ! $Id: inifor_control.f90 3447 2018-10-29 15:52:54Z eckhard $ |
---|
28 | ! Renamed source files for compatibilty with PALM build system |
---|
29 | ! |
---|
30 | ! |
---|
31 | ! 3395 2018-10-22 17:32:49Z eckhard |
---|
32 | ! Suppress debugging messages unless --debug option is given |
---|
33 | ! |
---|
34 | ! |
---|
35 | ! 3183 2018-07-27 14:25:55Z suehring |
---|
36 | ! Added version and copyright output |
---|
37 | ! |
---|
38 | ! |
---|
39 | ! 3182 2018-07-27 13:36:03Z suehring |
---|
40 | ! Initial revision |
---|
41 | ! |
---|
42 | ! |
---|
43 | ! |
---|
44 | ! Authors: |
---|
45 | ! -------- |
---|
46 | ! @author Eckhard Kadasch |
---|
47 | ! |
---|
48 | ! Description: |
---|
49 | ! ------------ |
---|
50 | !> The control module provides routines for timing INIFOR and writing runtime |
---|
51 | !> feedback to the terminal and a log file. |
---|
52 | !------------------------------------------------------------------------------! |
---|
53 | MODULE control |
---|
54 | |
---|
55 | USE defs, & |
---|
56 | ONLY: LNAME, dp, VERSION, COPYRIGHT |
---|
57 | |
---|
58 | USE util, & |
---|
59 | ONLY: real_to_str, real_to_str_f |
---|
60 | |
---|
61 | IMPLICIT NONE |
---|
62 | |
---|
63 | CHARACTER (LEN=5000) :: message = '' |
---|
64 | |
---|
65 | CONTAINS |
---|
66 | |
---|
67 | SUBROUTINE report(routine, message, debug) |
---|
68 | |
---|
69 | CHARACTER(LEN=*), INTENT(IN) :: routine |
---|
70 | CHARACTER(LEN=*), INTENT(IN) :: message |
---|
71 | LOGICAL, OPTIONAL, INTENT(IN) :: debug |
---|
72 | INTEGER :: u |
---|
73 | LOGICAL, SAVE :: is_first_run = .TRUE. |
---|
74 | LOGICAL :: suppress_message |
---|
75 | |
---|
76 | |
---|
77 | IF (is_first_run) THEN |
---|
78 | OPEN( NEWUNIT=u, FILE='inifor.log', STATUS='replace' ) |
---|
79 | is_first_run = .FALSE. |
---|
80 | ELSE |
---|
81 | OPEN( NEWUNIT=u, FILE='inifor.log', POSITION='append', STATUS='old' ) |
---|
82 | END IF |
---|
83 | |
---|
84 | |
---|
85 | suppress_message = .FALSE. |
---|
86 | IF (PRESENT(debug)) THEN |
---|
87 | IF (.NOT. debug) suppress_message = .TRUE. |
---|
88 | END IF |
---|
89 | |
---|
90 | IF (.NOT. suppress_message) THEN |
---|
91 | PRINT *, "inifor: " // TRIM(message) // " [ " // TRIM(routine) // " ]" |
---|
92 | WRITE(u, *) TRIM(message) // " [ " // TRIM(routine) // " ]" |
---|
93 | END IF |
---|
94 | |
---|
95 | CLOSE(u) |
---|
96 | |
---|
97 | END SUBROUTINE report |
---|
98 | |
---|
99 | |
---|
100 | SUBROUTINE warn(routine, message) |
---|
101 | |
---|
102 | CHARACTER(LEN=*), INTENT(IN) :: routine |
---|
103 | CHARACTER(LEN=*), INTENT(IN) :: message |
---|
104 | |
---|
105 | CALL report(routine, "WARNING: " // TRIM(message)) |
---|
106 | |
---|
107 | END SUBROUTINE warn |
---|
108 | |
---|
109 | |
---|
110 | SUBROUTINE abort(routine, message) |
---|
111 | |
---|
112 | CHARACTER(LEN=*), INTENT(IN) :: routine |
---|
113 | CHARACTER(LEN=*), INTENT(IN) :: message |
---|
114 | |
---|
115 | CALL report(routine, "ERROR: " // TRIM(message) // " Stopping.") |
---|
116 | STOP |
---|
117 | |
---|
118 | END SUBROUTINE abort |
---|
119 | |
---|
120 | |
---|
121 | SUBROUTINE print_version() |
---|
122 | PRINT *, "INIFOR " // VERSION |
---|
123 | PRINT *, COPYRIGHT |
---|
124 | END SUBROUTINE print_version |
---|
125 | |
---|
126 | |
---|
127 | SUBROUTINE run_control(mode, budget) |
---|
128 | |
---|
129 | CHARACTER(LEN=*), INTENT(IN) :: mode, budget |
---|
130 | REAL(dp), SAVE :: t0, t1 |
---|
131 | REAL(dp), SAVE :: t_comp=0.0_dp, & |
---|
132 | t_alloc=0.0_dp, & |
---|
133 | t_init=0.0_dp, & |
---|
134 | t_read=0.0_dp, & |
---|
135 | t_total=0.0_dp, & |
---|
136 | t_write=0.0_dp |
---|
137 | CHARACTER(LEN=*), PARAMETER :: fmt='(F6.2)' |
---|
138 | |
---|
139 | |
---|
140 | SELECT CASE(TRIM(mode)) |
---|
141 | |
---|
142 | CASE('init') |
---|
143 | CALL CPU_TIME(t0) |
---|
144 | |
---|
145 | CASE('time') |
---|
146 | |
---|
147 | CALL CPU_TIME(t1) |
---|
148 | |
---|
149 | SELECT CASE(TRIM(budget)) |
---|
150 | |
---|
151 | CASE('alloc') |
---|
152 | t_alloc = t_alloc + t1 - t0 |
---|
153 | |
---|
154 | CASE('init') |
---|
155 | t_init = t_init + t1 - t0 |
---|
156 | |
---|
157 | CASE('read') |
---|
158 | t_read = t_read + t1 - t0 |
---|
159 | |
---|
160 | CASE('write') |
---|
161 | t_write = t_write + t1 - t0 |
---|
162 | |
---|
163 | CASE('comp') |
---|
164 | t_comp = t_comp + t1 - t0 |
---|
165 | |
---|
166 | CASE DEFAULT |
---|
167 | CALL abort('run_control', "Time Budget '" // TRIM(mode) // "' is not supported.") |
---|
168 | |
---|
169 | END SELECT |
---|
170 | |
---|
171 | t0 = t1 |
---|
172 | |
---|
173 | CASE('report') |
---|
174 | t_total = t_init + t_read + t_write + t_comp |
---|
175 | |
---|
176 | CALL report('run_control', " *** CPU time ***") |
---|
177 | |
---|
178 | CALL report('run_control', "Initialization: " // real_to_str(t_init) // & |
---|
179 | " s (" // TRIM(real_to_str(100*t_init/t_total, fmt)) // " %)") |
---|
180 | |
---|
181 | CALL report('run_control', "(De-)Allocation:" // real_to_str(t_alloc) // & |
---|
182 | " s (" // TRIM(real_to_str(100*t_alloc/t_total, fmt)) // " %)") |
---|
183 | |
---|
184 | CALL report('run_control', "Reading data: " // real_to_str(t_read) // & |
---|
185 | " s (" // TRIM(real_to_str(100*t_read/t_total, fmt)) // " %)") |
---|
186 | |
---|
187 | CALL report('run_control', "Writing data: " // real_to_str(t_write) // & |
---|
188 | " s (" // TRIM(real_to_str(100*t_write/t_total, fmt)) // " %)") |
---|
189 | |
---|
190 | CALL report('run_control', "Computation: " // real_to_str(t_comp) // & |
---|
191 | " s (" // TRIM(real_to_str(100*t_comp/t_total, fmt)) // " %)") |
---|
192 | |
---|
193 | CALL report('run_control', "Total: " // real_to_str(t_total) // & |
---|
194 | " s (" // TRIM(real_to_str(100*t_total/t_total, fmt)) // " %)") |
---|
195 | |
---|
196 | CASE DEFAULT |
---|
197 | CALL abort('run_control', "Mode '" // TRIM(mode) // "' is not supported.") |
---|
198 | |
---|
199 | END SELECT |
---|
200 | |
---|
201 | END SUBROUTINE run_control |
---|
202 | |
---|
203 | END MODULE |
---|
204 | |
---|