MODULE progress_bar !--------------------------------------------------------------------------------! ! This file is part of PALM. ! ! PALM is free software: you can redistribute it and/or modify it under the terms ! of the GNU General Public License as published by the Free Software Foundation, ! either version 3 of the License, or (at your option) any later version. ! ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along with ! PALM. If not, see . ! ! Copyright 1997-2014 Leibniz Universitaet Hannover !--------------------------------------------------------------------------------! ! ! Current revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! $Id: progress_bar.f90 1402 2014-05-09 14:25:13Z boeske $ ! ! Description: ! ------------ ! CPU-time measurements for any program part whatever. Results of the !------------------------------------------------------------------------------! USE control_parameters, & ONLY : end_time, simulated_time, simulated_time_at_begin, time_restart USE, INTRINSIC :: ISO_FORTRAN_ENV, & ONLY : OUTPUT_UNIT USE kinds IMPLICIT NONE PRIVATE PUBLIC batch_job, finish_progress_bar, output_progress_bar CHARACTER(LEN=60) :: bar !: progress bar, initially filled with "_" CHARACTER(LEN=60) :: crosses !: filled with "X" INTEGER(iwp) :: ilength !: length of progress bar filled with "X" LOGICAL :: batch_job = .FALSE. !: switch to determine the run mode REAL(wp) :: time_to_be_simulated !: in sec LOGICAL :: initialized = .FALSE. !: switch to determine if bar is initialized SAVE CONTAINS SUBROUTINE init_progress_bar IMPLICIT NONE ! !-- Calculate the time to be simulated in this job !-- (in case of automatic restarts the calculated time will probably be !-- larger than the time which will actually be simulated) IF ( time_restart /= 9999999.9_wp .AND. time_restart < end_time .AND.& time_restart > simulated_time_at_begin ) THEN time_to_be_simulated = time_restart - simulated_time_at_begin ELSE time_to_be_simulated = end_time - simulated_time_at_begin ENDIF bar = '____________________________________________________________' crosses = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' ! !-- Line feed on stdout to seperate the progress bar from previous messages WRITE ( OUTPUT_UNIT, '(1X)' ) #if defined( __intel_compiler ) ! !-- The Intel compiler does not allow to immediately flush the output buffer !-- in case that option ADVANCE='NO' is used in the write statement. !-- A workaround is to set a special carriage control feature and use "+" as !-- first output character, but this non-standard and only available with the !-- Intel compiler OPEN ( OUTPUT_UNIT, CARRIAGECONTROL='FORTRAN' ) #endif initialized = .TRUE. END SUBROUTINE init_progress_bar SUBROUTINE output_progress_bar !------------------------------------------------------------------------------! ! Description: ! ------------ ! !------------------------------------------------------------------------------! IMPLICIT NONE REAL(wp) :: remaining_time_in_percent !: remaining time to be simulated !: in the job ! !-- Porgress bar does not make sense in batch mode (and also ADVANCE=no does !-- not properly work in batch mode on Cray XC30) IF ( batch_job ) RETURN IF ( .NOT. initialized ) CALL init_progress_bar ! !-- Calculate length of progress bar remaining_time_in_percent = & ( simulated_time - simulated_time_at_begin ) / time_to_be_simulated ilength = remaining_time_in_percent * 60.0_wp ilength = MIN( ilength, 60 ) bar(1:ilength) = crosses(1:ilength) #if defined( __intel_compiler ) WRITE ( OUTPUT_UNIT, '(A,6X,''['',A,''] '',F5.1,'' left'')' ) & '+', bar, & MAX( 0.0_wp, ( 1.0_wp - remaining_time_in_percent ) * 100.0_wp ) #else WRITE ( OUTPUT_UNIT, '(A,6X,''['',A,''] '',F5.1,'' left'')', & ADVANCE='NO' ) CHAR( 13 ), bar, & MAX( 0.0_wp, ( 1.0_wp - remaining_time_in_percent ) * 100.0_wp ) #endif CALL local_flush( OUTPUT_UNIT ) END SUBROUTINE output_progress_bar SUBROUTINE finish_progress_bar IMPLICIT NONE IF ( batch_job ) RETURN #if defined( __intel_compiler ) ! !-- Reset to the default carriage control OPEN ( OUTPUT_UNIT, CARRIAGECONTROL='LIST' ) #endif ! !-- Line feed when simulation has finished WRITE ( OUTPUT_UNIT, '(1X)' ) END SUBROUTINE finish_progress_bar END MODULE progress_bar