Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Streamlined the progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Nov 20, 2022
1 parent 217f846 commit ac4594f
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/io/io_progress_bar.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ subroutine io_pbar_reset(self, nloops)
class(progress_bar),intent(inout) :: self
integer(I8B), intent(in) :: nloops
! Internals
character(len=2) :: numchar,numchar2
character(len=32) :: startfmt
character(len=self%PBARSIZE) :: empty
character(len=2) :: numchar
integer(I4B) :: k

if (.not.allocated(self%barstr)) then
Expand All @@ -53,7 +51,7 @@ subroutine io_pbar_reset(self, nloops)
self%pos = 0
self%message = ""

write(*,fmt=self%fmt) char(13),empty
write(*,fmt=self%fmt) char(13),self%barstr

return
end subroutine io_pbar_reset
Expand All @@ -71,29 +69,25 @@ subroutine io_pbar_update(self,i,message)
! Internals
real(DP) :: frac
integer(I4B) :: pos !! The current integer position of the progress bar
character(len=1), dimension(4), parameter :: spinstr = ["/","-","\","|"]



! Compute the current position
frac = real(i,kind=DP) / real(self%nloops,kind=DP)
pos = min(int(ceiling(frac * self%PBARSIZE),kind=I4B),self%PBARSIZE)

if (pos /= self%pos) then
self%pos = pos

! Fill in the bar character up to the current position
self%barstr(pos:pos) = self%barchar
end if

! Compute the current value of the spinner and set the spinner character
self%spinner = self%spinner + 1
if (self%spinner > 4) self%spinner = 1
select case(self%spinner)
case(1)
self%barstr(pos+1:pos+1) = "/"
case(2)
self%barstr(pos+1:pos+1) = "-"
case(3)
self%barstr(pos+1:pos+1) = "\"
case(4)
self%barstr(pos+1:pos+1) = "|"
end select
if (self%spinner > size(spinstr)) self%spinner = 1

self%barstr(pos+1:pos+1) = spinstr(self%spinner)

write(*,fmt=self%fmt) char(13),self%barstr

Expand Down

0 comments on commit ac4594f

Please sign in to comment.