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

Last change on this file since 3187 was 2726, checked in by kanani, 7 years ago

Exclude spinup time from progress bar

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