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

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

Fix for progress bar, minor changes

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