source: palm/trunk/SOURCE/progress_bar_mod.f90 @ 4180

Last change on this file since 4180 was 4180, checked in by scharf, 22 months ago

removed comments in 'Former revisions' section that are older than 01.01.2019

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