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

Last change on this file since 2716 was 2716, checked in by kanani, 6 years ago

Correction of "Former revisions" section

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