Skip to content

Commit

Permalink
improve progress_bar
Browse files Browse the repository at this point in the history
  • Loading branch information
fangjian authored and fangjian committed Jan 31, 2024
1 parent fc1c7d1 commit f2e0586
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ message(STATUS "UDF path: ${UDF_SRC}")

add_executable(astr
astr.F90
${UDF_SOURCE_FILES}
bc.F90
CMakeLists.txt
cmdefne.F90
commarray.F90
comsolver.F90
Expand Down Expand Up @@ -42,7 +42,6 @@ add_executable(astr
tecio.F90
test.F90
thermchem.F90
${UDF_SOURCE_FILES}
utility.F90
vtkio.F90)

Expand Down
59 changes: 59 additions & 0 deletions src/utility.F90
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,65 @@ module utility
contains
!
!+-------------------------------------------------------------------+
!| Progress indicators library. |
!+-------------------------------------------------------------------+
!| CHANGE RECORD |
!| ------------- |
!| 31-01-2024 | copied by J. Fang via: |
!| https://github.com/macie/fortran-libs |
!| Maciej Żok, 2010 MIT License |
!+-------------------------------------------------------------------+
subroutine progress_bar(iteration,maximum,info2show,barlength)
!
! Prints progress bar.
!
! Args:
! iteration - iteration number
! maximum - total iterations
! barlength - length of the bar
!
! use iso_fortran_env
integer,intent(in) :: iteration,maximum
character(len=*),intent(in),optional :: info2show
integer,intent(in),optional :: barlength
integer :: counter,nlength
integer :: done
real(4) :: perc
!
if(present(barlength)) then
nlength=barlength
else
nlength=10
endif
!
perc = 100.0*real(iteration)/real(maximum)
done = floor(perc/(100.0/real(nlength))) ! mark length
!
write(6,'(1A1,A,A)',advance='no')char(13),info2show,'['
if (done .LE. 0) then
do counter = 1, nlength
write(6,'(1A1,A)',advance='no')'='
end do
else if ((done .GT. 0) .and. (done .LT. nlength)) then
do counter = 1, done
write(6,'(1A1,A)',advance='no')'>'
end do
do counter = done+1, nlength
write(6,'(1A1,A)',advance='no')'='
end do
else
do counter = 1, nlength
write(6,'(1A1,A)',advance='no')'>'
end do
end if
write(6,'(A,F5.1,A)',advance='no')'] ',perc,'%'
!
end subroutine progress_bar
!+-------------------------------------------------------------------+
!| The end of the subroutine progress_bar. |
!+-------------------------------------------------------------------+
!
!+-------------------------------------------------------------------+
!| This subroutine is used to report time cost by each subroutine. |
!+-------------------------------------------------------------------+
!| note: should only be called from one rank, usually the root |
Expand Down

0 comments on commit f2e0586

Please sign in to comment.