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

Commit

Permalink
Got rid of spinner, as it was too much of a hassle
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Nov 20, 2022
1 parent e51926d commit af4d5c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
29 changes: 4 additions & 25 deletions src/io/io_progress_bar.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module io_progress_bar
implicit none
public

character(len=1), dimension(4), parameter, private :: spinstr = ["\","-","|","/"] !! The progress spinner sequency
character(len=1),parameter, private :: barchar = "#" !! The progress bar character

type :: progress_bar
Expand All @@ -16,29 +15,25 @@ module io_progress_bar
!! Implements a class for a simple progress bar that can print on the screen.
integer(I4B) :: PBARSIZE = 80 !! Number of characters acros for a whole progress bar
integer(I8B) :: loop_length !! The total number of loops that the progrees bar is executing
integer(I8B) :: spinner_cycle_length !! The number of loop iterations it takes to execute a full spinner cycle
integer(I8B) :: spinner_skip !! The number of loop iterations to execute before updating the spinner
character(len=:), allocatable :: barstr !! The string that prints out as the progress bar
integer(I4B) :: bar_pos !! The current position of the progress bar
integer(I4B) :: spin_pos !! Position of the "spinner" that indicates that progress is being made
character(len=32) :: fmt !! The format string that is used to define the progress bar itself
character(len=64) :: message !! The current message displayed at the end of the progress bar
contains
procedure :: reset => io_pbar_reset !! Resets the progress bar to the beginning
procedure :: update => io_pbar_update !! Updates the progress bar with new values and causes the "spinner" to flip.
procedure :: update => io_pbar_update !! Updates the progress bar with new values
end type progress_bar

contains

subroutine io_pbar_reset(self, loop_length, spinner_cycle_length)
subroutine io_pbar_reset(self, loop_length)
!! author: David A. Minton
!!
!! Resets the progress bar to the beginning
implicit none
! Arguments
class(progress_bar),intent(inout) :: self !! The progress bar object
integer(I8B), intent(in) :: loop_length !! The length of the loop that the progress bar is attached to
integer(I8B), intent(in), optional :: spinner_cycle_length !! The number of iterations between a complete spinner cycle. If not passd, the default is to update the spinner each call
! Internals
character(len=2) :: numchar
integer(I4B) :: k
Expand All @@ -54,14 +49,6 @@ subroutine io_pbar_reset(self, loop_length, spinner_cycle_length)
self%loop_length = loop_length
self%bar_pos = 0
self%message = ""
if (present(spinner_cycle_length)) then
self%spinner_cycle_length = spinner_cycle_length
self%spinner_skip = self%spinner_cycle_length / size(spinstr)
else
self%spinner_cycle_length = size(spinstr)
self%spinner_skip = 1
end if
self%spin_pos = 1

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

Expand All @@ -72,15 +59,15 @@ end subroutine io_pbar_reset
subroutine io_pbar_update(self,i,message)
!! author: David A. Minton
!!
!! Updates the progress bar with new values and causes the "spinner" to flip.
!! Updates the progress bar with new values
implicit none
! Arguments
class(progress_bar), intent(inout) :: self !! Progres bar object
integer(I8B), intent(in) :: i !! The current loop index of the progress loop
character(len=*), intent(in), optional :: message !! An optional message to display to the right of the progress bar
! Internals
real(DP) :: frac
integer(I4B) :: bar_pos, spin_pos !! The current integer position of the progress bar and spinner
integer(I4B) :: bar_pos !! The current integer position of the progress bar
logical :: update = .false.

! Compute the current position
Expand All @@ -94,14 +81,6 @@ subroutine io_pbar_update(self,i,message)
self%bar_pos = bar_pos
end if

! Compute the current value of the spinner and set the spinner character
spin_pos = mod(i / self%spinner_skip, size(spinstr)) + 1
if (spin_pos /= self%spin_pos) then
self%barstr(bar_pos+1:bar_pos+1) = spinstr(spin_pos)
self%spin_pos = spin_pos
update = .true.
end if

if (present(message)) then
if (message /= self%message) then
update = .true.
Expand Down
2 changes: 1 addition & 1 deletion src/main/swiftest_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ program swiftest_driver
!$ write(*,'(a,i3,/)') ' Number of threads = ', nthreads
!write(*, *) " *************** Main Loop *************** "
if (param%lrestart .and. param%lenergy) call nbody_system%conservation_report(param, lterminal=.true.)
call pbar%reset(nloops, spinner_cycle_length=istep_out)
call pbar%reset(nloops)
write(pbarmessage,fmt=pbarfmt) t0, tstop
call pbar%update(1,message=pbarmessage)
do iloop = 1, nloops
Expand Down

0 comments on commit af4d5c0

Please sign in to comment.