Print a progress bar on the terminal
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=I4), | intent(in) | :: | val |
actual position |
||
integer(kind=I4), | intent(in) | :: | max_val |
maximum value reached |
||
logical(kind=I4), | intent(in) | :: | init |
progress bar initialization |
subroutine progress_bar_terminal(val, max_val, init) !! Print a progress bar on the terminal implicit none integer(kind=I4), intent(in) :: val !! *actual position* integer(kind=I4), intent(in) :: max_val !! *maximum value reached* logical(kind=I4), intent(in) :: init !! *progress bar initialization* character(len=102) :: bar integer(kind=I4) :: ival if ( init ) then write(*, *) write(bar, '(a)') '[' // repeat('.', 100) // ']' write(*, '(a)', advance = 'no') bar return endif ival = nint( 99.99 * ( real(val, kind = R8) / max_val ) ) write(bar, '(a)') '[' // repeat('*', ival) // repeat('.', 100 - ival) // ']' write(*, '(a)', advance = 'no') repeat(achar(8), 102) // bar if ( val == max_val ) then write(*, *) ' ... done' write(*, *) endif return endsubroutine progress_bar_terminal