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

Last change on this file since 1850 was 1850, checked in by maronga, 8 years ago

added _mod string to several filenames to meet the naming convection for modules

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