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