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

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

last commit documented

  • Property svn:keywords set to Id
File size: 6.9 KB
RevLine 
[1850]1!> @file progress_bar_mod.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!
[1818]16! Copyright 1997-2016 Leibniz Universitaet Hannover
[1402]17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! -----------------
[1469]21!
[1851]22!
[1402]23! Former revisions:
24! -----------------
25! $Id: progress_bar_mod.f90 1851 2016-04-08 13:32:50Z hellstea $
26!
[1851]27! 1850 2016-04-08 13:29:27Z maronga
28! Module renamed
29!
30!
[1809]31! 1808 2016-04-05 19:44:00Z raasch
32! routine local_flush replaced by FORTRAN statement
33!
[1683]34! 1682 2015-10-07 23:56:08Z knoop
35! Code annotations made doxygen readable
36!
[1469]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!
[1402]40! Description:
41! ------------
[1682]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.
[1402]45!------------------------------------------------------------------------------!
[1682]46 MODULE progress_bar
47 
[1402]48
49    USE control_parameters,                                                    &
[1468]50        ONLY : end_time, run_identifier, simulated_time,                       &
51               simulated_time_at_begin, time_restart
[1402]52
[1468]53    USE, INTRINSIC ::  ISO_FORTRAN_ENV,                                        &
[1402]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
[1682]63    CHARACTER(LEN=60) ::  bar      !< progress bar, initially filled with "_"
64    CHARACTER(LEN=60) ::  crosses  !< filled with "X"
[1402]65
[1682]66    INTEGER(iwp) ::  ilength !< length of progress bar filled with "X"
[1402]67
[1682]68    LOGICAL ::  batch_job = .FALSE.   !< switch to determine the run mode
[1402]69
[1682]70    REAL(wp) ::  time_to_be_simulated !< in sec
[1402]71
[1682]72    LOGICAL ::  initialized = .FALSE. !< switch to determine if bar is initialized
[1402]73
74    SAVE
75
76 CONTAINS
77
[1468]78!------------------------------------------------------------------------------!
79! Description:
80! ------------
[1682]81!> Initialize the progress bar/file
[1468]82!------------------------------------------------------------------------------!
[1682]83 
84    SUBROUTINE init_progress_bar
[1402]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
[1468]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'
[1402]107!
[1468]108!--       Line feed on stdout to seperate the progress bar from previous messages
109          WRITE ( OUTPUT_UNIT, '(1X)' )
[1402]110#if defined( __intel_compiler )
111!
[1468]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' )
[1402]118#endif
[1468]119
120       ENDIF
121
[1402]122       initialized = .TRUE.
123
124    END SUBROUTINE init_progress_bar
125
126
127!------------------------------------------------------------------------------!
128! Description:
129! ------------
[1682]130!> Print progress data to standard output (interactive) or to file (batch jobs)
[1402]131!------------------------------------------------------------------------------!
[1682]132 
133    SUBROUTINE output_progress_bar
[1402]134
135       IMPLICIT NONE
136
[1682]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
[1402]141
[1468]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
[1402]150!
[1468]151!--    In batch mode, use a file (PROGRESS), otherwise use progress bar
152       IF ( batch_job )  THEN
[1402]153
[1468]154          BACKSPACE ( 117 )
155          WRITE ( 117, FMT='(F5.2,1X,F5.2)' ) remaining_time_in_percent,       &
156                                              remaining_time_in_percent_total
[1808]157          FLUSH( 117 )
[1468]158
159       ELSE
160
[1402]161!
[1468]162!--       Calculate length of progress bar
163          ilength = remaining_time_in_percent * 60.0_wp
164          ilength = MIN( ilength, 60 )
[1402]165
[1468]166          bar(1:ilength) = crosses(1:ilength)
[1402]167
168#if defined( __intel_compiler )
[1468]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 )
[1402]173#else
[1468]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 )
[1402]178#endif
[1808]179          FLUSH( OUTPUT_UNIT )
[1402]180
[1468]181       ENDIF
182
[1402]183    END SUBROUTINE output_progress_bar
184
[1468]185!------------------------------------------------------------------------------!
186! Description:
187! ------------
[1682]188!> Finalization of the progress bar/file
[1468]189!------------------------------------------------------------------------------!
[1682]190 
191    SUBROUTINE finish_progress_bar
[1402]192
193       IMPLICIT NONE
194
[1468]195       IF ( batch_job )  THEN
[1402]196
[1468]197          CALL close_file ( 117 )
198
199       ELSE
200       
[1402]201#if defined( __intel_compiler )
202!
[1468]203!--       Reset to the default carriage control
204          OPEN ( OUTPUT_UNIT, CARRIAGECONTROL='LIST' )
[1402]205#endif
206!
[1468]207!--       Line feed when simulation has finished
208          WRITE ( OUTPUT_UNIT, '(1X)' )
[1402]209
[1468]210       ENDIF
211
[1402]212    END SUBROUTINE finish_progress_bar
213
[1468]214
[1402]215 END MODULE progress_bar
Note: See TracBrowser for help on using the repository browser.