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

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