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