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

Last change on this file since 2000 was 2000, checked in by knoop, 5 years ago

Forced header and separation lines into 80 columns

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