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

Last change on this file since 1929 was 1851, checked in by maronga, 9 years ago

last commit documented

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