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