Create a progress bar through successive calls
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | m | Message to display |
||
real(kind=wp), | intent(in) | :: | p | Progress fraction \(p\in[0,1]\) |
||
integer, | intent(in), | optional | :: | ml | Message reserve length (used to align long messages) |
subroutine showProgress(m,p,ml)
!! Create a progress bar through successive calls
character(*),intent(in)::m
!! Message to display
real(wp),intent(in)::p
!! Progress fraction \(p\in[0,1]\)
!! 0 = start progress
!! 1 = complete progress
integer,intent(in),optional::ml
!! Message reserve length (used to align long messages)
real(wp)::r
real(wp),save::po
real(wp),save::tStart
real(wp)::tNow
integer::mld
integer::N,k
N = 40
mld = 40
if(present(ml)) mld = ml
if(p<=0.0_wp) then
po = p
tStart = wallTime()
else if(p-po<=0.005 .and. p<1.0_wp) then
return
else
po = p
end if
tNow = wallTime()
write(stdout,'(1A)',advance='no') achar(13)//colorize(m//repeat(' ',mld-len(m))//' [',[5,5,0])
do k=1,N
r = real(k-1,wp)/real(N-1,wp)
if(r<=p) then
write(stdout,'(1A)',advance='no') colorize('=',colorMap(r,[0.0_wp,1.0_wp]))
else
write(stdout,'(1A)',advance='no') colorize(' ',[0,0,0])
end if
end do
write(stdout,'(1A,1A,1X,1A,1A,1A,1A,1A,1A)',advance='no') colorize('] ',[5,5,0]), &
& colorize(realToChar(100.0_wp*p,'1F5.1'),colorMap(p,[0.0_wp,1.0_wp])), &
& colorize('%',[5,5,0]), colorize(' (',[5,5,0]), realToTime(tNow-tStart), &
& colorize(' / ',[5,5,0]), realToTime( (tNow-tStart)/(p+0.0001_wp) ), colorize(')',[5,5,0])
if(p>=1.0_wp) write(stdout,'(1A)') repeat(' ',10)
flush(stdout)
end subroutine showProgress