source: palm/trunk/SOURCE/progress_bar.f90 @ 1682

Last change on this file since 1682 was 1682, checked in by knoop, 9 years ago

Code annotations made doxygen readable

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