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