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