1 | !> @file progress_bar_mod.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 1997-2018 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: progress_bar_mod.f90 3232 2018-09-07 12:21:44Z suehring $ |
---|
27 | ! Increase printed length of run identifier, |
---|
28 | ! bugfix for restarts |
---|
29 | ! |
---|
30 | ! 3225 2018-08-30 16:33:14Z kanani |
---|
31 | ! Increase printed length of run identifier, |
---|
32 | ! bugfix for restarts |
---|
33 | ! |
---|
34 | ! 2726 2018-01-08 17:40:52Z kanani |
---|
35 | ! Exclude spinup time from progress bar |
---|
36 | ! |
---|
37 | ! 2718 2018-01-02 08:49:38Z maronga |
---|
38 | ! Corrected "Former revisions" section |
---|
39 | ! |
---|
40 | ! 2696 2017-12-14 17:12:51Z kanani |
---|
41 | ! Change in file header (GPL part) |
---|
42 | ! |
---|
43 | ! 2101 2017-01-05 16:42:31Z suehring |
---|
44 | ! |
---|
45 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
46 | ! Forced header and separation lines into 80 columns |
---|
47 | ! |
---|
48 | ! 1850 2016-04-08 13:29:27Z maronga |
---|
49 | ! Module renamed |
---|
50 | ! |
---|
51 | ! |
---|
52 | ! 1808 2016-04-05 19:44:00Z raasch |
---|
53 | ! routine local_flush replaced by FORTRAN statement |
---|
54 | ! |
---|
55 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
56 | ! Code annotations made doxygen readable |
---|
57 | ! |
---|
58 | ! 1468 2014-09-24 14:06:57Z maronga |
---|
59 | ! Added support for progress file PROGRESS which is used in case of batch jobs |
---|
60 | ! |
---|
61 | ! Description: |
---|
62 | ! ------------ |
---|
63 | !> This routine prints either a progress bar on the standard output in case of |
---|
64 | !> interactive runs, or it prints the progress in a separate file called |
---|
65 | !> PROGRESS. |
---|
66 | !------------------------------------------------------------------------------! |
---|
67 | MODULE progress_bar |
---|
68 | |
---|
69 | |
---|
70 | USE control_parameters, & |
---|
71 | ONLY : end_time, initializing_actions, run_identifier, simulated_time, & |
---|
72 | simulated_time_at_begin, spinup_time, time_restart |
---|
73 | |
---|
74 | USE, INTRINSIC :: ISO_FORTRAN_ENV, & |
---|
75 | ONLY : OUTPUT_UNIT |
---|
76 | |
---|
77 | USE kinds |
---|
78 | |
---|
79 | IMPLICIT NONE |
---|
80 | |
---|
81 | PRIVATE |
---|
82 | PUBLIC batch_job, finish_progress_bar, output_progress_bar |
---|
83 | |
---|
84 | CHARACTER(LEN=60) :: bar !< progress bar, initially filled with "_" |
---|
85 | CHARACTER(LEN=60) :: crosses !< filled with "X" |
---|
86 | |
---|
87 | INTEGER(iwp) :: ilength !< length of progress bar filled with "X" |
---|
88 | |
---|
89 | LOGICAL :: batch_job = .FALSE. !< switch to determine the run mode |
---|
90 | |
---|
91 | REAL(wp) :: time_to_be_simulated !< in sec |
---|
92 | |
---|
93 | LOGICAL :: initialized = .FALSE. !< switch to determine if bar is initialized |
---|
94 | |
---|
95 | SAVE |
---|
96 | |
---|
97 | CONTAINS |
---|
98 | |
---|
99 | !------------------------------------------------------------------------------! |
---|
100 | ! Description: |
---|
101 | ! ------------ |
---|
102 | !> Initialize the progress bar/file |
---|
103 | !------------------------------------------------------------------------------! |
---|
104 | |
---|
105 | SUBROUTINE init_progress_bar |
---|
106 | |
---|
107 | IMPLICIT NONE |
---|
108 | |
---|
109 | ! |
---|
110 | !-- Calculate the time to be simulated in this job |
---|
111 | !-- (in case of automatic restarts the calculated time will probably be |
---|
112 | !-- larger than the time which will actually be simulated) |
---|
113 | IF ( time_restart /= 9999999.9_wp .AND. time_restart < end_time .AND.& |
---|
114 | time_restart > simulated_time_at_begin ) THEN |
---|
115 | time_to_be_simulated = time_restart - simulated_time_at_begin |
---|
116 | ELSEIF ( initializing_actions == 'read_restart_data' ) THEN |
---|
117 | time_to_be_simulated = end_time - simulated_time_at_begin |
---|
118 | ELSE |
---|
119 | time_to_be_simulated = end_time - simulated_time_at_begin & |
---|
120 | - spinup_time |
---|
121 | ENDIF |
---|
122 | |
---|
123 | IF ( batch_job ) THEN |
---|
124 | |
---|
125 | CALL check_open ( 117 ) |
---|
126 | WRITE ( 117, FMT='(A34,/)' ) run_identifier |
---|
127 | |
---|
128 | ELSE |
---|
129 | bar = '____________________________________________________________' |
---|
130 | crosses = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' |
---|
131 | ! |
---|
132 | !-- Line feed on stdout to seperate the progress bar from previous messages |
---|
133 | WRITE ( OUTPUT_UNIT, '(1X)' ) |
---|
134 | #if defined( __intel_compiler ) |
---|
135 | ! |
---|
136 | !-- The Intel compiler does not allow to immediately flush the output buffer |
---|
137 | !-- in case that option ADVANCE='NO' is used in the write statement. |
---|
138 | !-- A workaround is to set a special carriage control feature and use "+" as |
---|
139 | !-- first output character, but this non-standard and only available with the |
---|
140 | !-- Intel compiler |
---|
141 | OPEN ( OUTPUT_UNIT, CARRIAGECONTROL='FORTRAN' ) |
---|
142 | #endif |
---|
143 | |
---|
144 | ENDIF |
---|
145 | |
---|
146 | initialized = .TRUE. |
---|
147 | |
---|
148 | END SUBROUTINE init_progress_bar |
---|
149 | |
---|
150 | |
---|
151 | !------------------------------------------------------------------------------! |
---|
152 | ! Description: |
---|
153 | ! ------------ |
---|
154 | !> Print progress data to standard output (interactive) or to file (batch jobs) |
---|
155 | !------------------------------------------------------------------------------! |
---|
156 | |
---|
157 | SUBROUTINE output_progress_bar |
---|
158 | |
---|
159 | IMPLICIT NONE |
---|
160 | |
---|
161 | REAL(wp) :: remaining_time_in_percent !< remaining time to be simulated |
---|
162 | !< in the job |
---|
163 | REAL(wp) :: remaining_time_in_percent_total !< total remaining time of |
---|
164 | !< the job chain |
---|
165 | |
---|
166 | IF ( .NOT. initialized ) CALL init_progress_bar |
---|
167 | |
---|
168 | IF ( initializing_actions == 'read_restart_data' ) THEN |
---|
169 | remaining_time_in_percent = & |
---|
170 | ( simulated_time - simulated_time_at_begin ) & |
---|
171 | / time_to_be_simulated |
---|
172 | |
---|
173 | remaining_time_in_percent_total = simulated_time / end_time |
---|
174 | ELSE |
---|
175 | remaining_time_in_percent = & |
---|
176 | ( simulated_time - simulated_time_at_begin - spinup_time ) & |
---|
177 | / time_to_be_simulated |
---|
178 | |
---|
179 | remaining_time_in_percent_total = ( ( simulated_time - spinup_time ) & |
---|
180 | / ( end_time - spinup_time ) ) |
---|
181 | ENDIF |
---|
182 | |
---|
183 | ! |
---|
184 | !-- In batch mode, use a file (PROGRESS), otherwise use progress bar |
---|
185 | IF ( batch_job ) THEN |
---|
186 | |
---|
187 | BACKSPACE ( 117 ) |
---|
188 | WRITE ( 117, FMT='(F5.2,1X,F5.2)' ) remaining_time_in_percent, & |
---|
189 | remaining_time_in_percent_total |
---|
190 | FLUSH( 117 ) |
---|
191 | |
---|
192 | ELSE |
---|
193 | |
---|
194 | ! |
---|
195 | !-- Calculate length of progress bar |
---|
196 | ilength = remaining_time_in_percent * 60.0_wp |
---|
197 | ilength = MIN( ilength, 60 ) |
---|
198 | |
---|
199 | bar(1:ilength) = crosses(1:ilength) |
---|
200 | |
---|
201 | #if defined( __intel_compiler ) |
---|
202 | WRITE ( OUTPUT_UNIT, '(A,6X,''['',A,''] '',F5.1,'' left'')' ) & |
---|
203 | '+', bar, & |
---|
204 | MAX( 0.0_wp, ( 1.0_wp - remaining_time_in_percent ) * & |
---|
205 | 100.0_wp ) |
---|
206 | #else |
---|
207 | WRITE ( OUTPUT_UNIT, '(A,6X,''['',A,''] '',F5.1,'' left'')', & |
---|
208 | ADVANCE='NO' ) CHAR( 13 ), bar, & |
---|
209 | MAX( 0.0_wp, ( 1.0_wp - remaining_time_in_percent ) * & |
---|
210 | 100.0_wp ) |
---|
211 | #endif |
---|
212 | FLUSH( OUTPUT_UNIT ) |
---|
213 | |
---|
214 | ENDIF |
---|
215 | |
---|
216 | END SUBROUTINE output_progress_bar |
---|
217 | |
---|
218 | !------------------------------------------------------------------------------! |
---|
219 | ! Description: |
---|
220 | ! ------------ |
---|
221 | !> Finalization of the progress bar/file |
---|
222 | !------------------------------------------------------------------------------! |
---|
223 | |
---|
224 | SUBROUTINE finish_progress_bar |
---|
225 | |
---|
226 | IMPLICIT NONE |
---|
227 | |
---|
228 | IF ( batch_job ) THEN |
---|
229 | |
---|
230 | CALL close_file ( 117 ) |
---|
231 | |
---|
232 | ELSE |
---|
233 | |
---|
234 | #if defined( __intel_compiler ) |
---|
235 | ! |
---|
236 | !-- Reset to the default carriage control |
---|
237 | OPEN ( OUTPUT_UNIT, CARRIAGECONTROL='LIST' ) |
---|
238 | #endif |
---|
239 | ! |
---|
240 | !-- Line feed when simulation has finished |
---|
241 | WRITE ( OUTPUT_UNIT, '(1X)' ) |
---|
242 | |
---|
243 | ENDIF |
---|
244 | |
---|
245 | END SUBROUTINE finish_progress_bar |
---|
246 | |
---|
247 | |
---|
248 | END MODULE progress_bar |
---|