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

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

Correct revision messages of last commit

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