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