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

Last change on this file since 3226 was 3225, checked in by kanani, 6 years ago

Correct revision messages of last commit

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