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
RevLine 
[1682]1!> @file progress_bar.f90
[1402]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! -----------------
[1682]21! Code annotations made doxygen readable
[1469]22!
[1402]23! Former revisions:
24! -----------------
25! $Id: progress_bar.f90 1682 2015-10-07 23:56:08Z knoop $
26!
[1469]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!
[1402]30! Description:
31! ------------
[1682]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.
[1402]35!------------------------------------------------------------------------------!
[1682]36 MODULE progress_bar
37 
[1402]38
39    USE control_parameters,                                                    &
[1468]40        ONLY : end_time, run_identifier, simulated_time,                       &
41               simulated_time_at_begin, time_restart
[1402]42
[1468]43    USE, INTRINSIC ::  ISO_FORTRAN_ENV,                                        &
[1402]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
[1682]53    CHARACTER(LEN=60) ::  bar      !< progress bar, initially filled with "_"
54    CHARACTER(LEN=60) ::  crosses  !< filled with "X"
[1402]55
[1682]56    INTEGER(iwp) ::  ilength !< length of progress bar filled with "X"
[1402]57
[1682]58    LOGICAL ::  batch_job = .FALSE.   !< switch to determine the run mode
[1402]59
[1682]60    REAL(wp) ::  time_to_be_simulated !< in sec
[1402]61
[1682]62    LOGICAL ::  initialized = .FALSE. !< switch to determine if bar is initialized
[1402]63
64    SAVE
65
66 CONTAINS
67
[1468]68!------------------------------------------------------------------------------!
69! Description:
70! ------------
[1682]71!> Initialize the progress bar/file
[1468]72!------------------------------------------------------------------------------!
[1682]73 
74    SUBROUTINE init_progress_bar
[1402]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
[1468]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'
[1402]97!
[1468]98!--       Line feed on stdout to seperate the progress bar from previous messages
99          WRITE ( OUTPUT_UNIT, '(1X)' )
[1402]100#if defined( __intel_compiler )
101!
[1468]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' )
[1402]108#endif
[1468]109
110       ENDIF
111
[1402]112       initialized = .TRUE.
113
114    END SUBROUTINE init_progress_bar
115
116
117!------------------------------------------------------------------------------!
118! Description:
119! ------------
[1682]120!> Print progress data to standard output (interactive) or to file (batch jobs)
[1402]121!------------------------------------------------------------------------------!
[1682]122 
123    SUBROUTINE output_progress_bar
[1402]124
125       IMPLICIT NONE
126
[1682]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
[1402]131
[1468]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
[1402]140!
[1468]141!--    In batch mode, use a file (PROGRESS), otherwise use progress bar
142       IF ( batch_job )  THEN
[1402]143
[1468]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
[1402]151!
[1468]152!--       Calculate length of progress bar
153          ilength = remaining_time_in_percent * 60.0_wp
154          ilength = MIN( ilength, 60 )
[1402]155
[1468]156          bar(1:ilength) = crosses(1:ilength)
[1402]157
158#if defined( __intel_compiler )
[1468]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 )
[1402]163#else
[1468]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 )
[1402]168#endif
[1468]169          CALL local_flush( OUTPUT_UNIT )
[1402]170
[1468]171       ENDIF
172
[1402]173    END SUBROUTINE output_progress_bar
174
[1468]175!------------------------------------------------------------------------------!
176! Description:
177! ------------
[1682]178!> Finalization of the progress bar/file
[1468]179!------------------------------------------------------------------------------!
[1682]180 
181    SUBROUTINE finish_progress_bar
[1402]182
183       IMPLICIT NONE
184
[1468]185       IF ( batch_job )  THEN
[1402]186
[1468]187          CALL close_file ( 117 )
188
189       ELSE
190       
[1402]191#if defined( __intel_compiler )
192!
[1468]193!--       Reset to the default carriage control
194          OPEN ( OUTPUT_UNIT, CARRIAGECONTROL='LIST' )
[1402]195#endif
196!
[1468]197!--       Line feed when simulation has finished
198          WRITE ( OUTPUT_UNIT, '(1X)' )
[1402]199
[1468]200       ENDIF
201
[1402]202    END SUBROUTINE finish_progress_bar
203
[1468]204
[1402]205 END MODULE progress_bar
Note: See TracBrowser for help on using the repository browser.