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