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