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