From f51532f5da856e227170bb61a2ff97cf407284e1 Mon Sep 17 00:00:00 2001 From: nhorelik Date: Fri, 26 Apr 2013 15:09:10 -0400 Subject: [PATCH] Added progress header file --- src/progress_header.F90 | 72 +++++++++++++++++++++++++++++++++++++++++ src/timer_header.F90 | 2 +- 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/progress_header.F90 diff --git a/src/progress_header.F90 b/src/progress_header.F90 new file mode 100644 index 000000000..d46b834c7 --- /dev/null +++ b/src/progress_header.F90 @@ -0,0 +1,72 @@ +module progress_header + + use, intrinsic :: ISO_FORTRAN_ENV + + implicit none + +!=============================================================================== +! PROGRESSBAR +!=============================================================================== + + type ProgressBar + private + character(len=72) :: bar="???% | " // & + " |" + contains + procedure :: set_value => bar_set_value + end type ProgressBar + +contains + +!=============================================================================== +! BAR_SET_VALUE prints the progress bar without advancing. The value is +! specified as percent completion, from 0 to 100. If the value is ever set to +! 100 or above, the +!=============================================================================== + + subroutine bar_set_value(self, val) + + class(ProgressBar), intent(inout) :: self + real(8), intent(in) :: val + + integer :: i + + ! set the percentage + if (val >= 100.) then + write(unit=self % bar(1:3),fmt="(i3)") 100 + else + write(unit=self % bar(1:3),fmt="(i3)") int(val) + end if + + ! set the bar width + if (val >= 100.) then + do i=1,65 + self % bar(i+6:i+6) = '=' + end do + else + do i=1,int(dble(65)*val/100.) + self % bar(i+6:i+6) = '=' + end do + end if + + open(UNIT=OUTPUT_UNIT, carriagecontrol='fortran') + write(UNIT=OUTPUT_UNIT, FMT='(a1,a1,a72)', ADVANCE='no') '+', char(13), & + self % bar + call flush(OUTPUT_UNIT) + + if (val >= 100.) then + + ! make new line + write(UNIT=OUTPUT_UNIT, FMT="(A)") "" + + ! reset the bar in case we want to use this instance again + self % bar = "???% | " // & + " |" + + close(UNIT=OUTPUT_UNIT) + + end if + + end subroutine bar_set_value + +end module progress_header diff --git a/src/timer_header.F90 b/src/timer_header.F90 index 7acef0fc4..0dde85d0c 100644 --- a/src/timer_header.F90 +++ b/src/timer_header.F90 @@ -45,7 +45,7 @@ contains function timer_get_value(self) result(elapsed) class(Timer), intent(in) :: self ! the timer - real(8) :: elapsed ! total elapsed time + real(8) :: elapsed ! total elapsed time integer :: end_counts ! current number of counts integer :: count_rate ! system-dependent counting rate