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

Last change on this file since 4021 was 3655, checked in by knoop, 6 years ago

Bugfix: made "unit" and "found" intend INOUT in module interface subroutines + automatic copyright update

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