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