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

Last change on this file since 4529 was 4360, checked in by suehring, 5 years ago

Bugfix in output of time-averaged plant-canopy quanities; Output of plant-canopy data only where tall canopy is defined; land-surface model: fix wrong location strings; tests: update urban test case; all source code files: copyright update

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