From f2e0586eb9e8a76b77b26558aa1f3ce91b476686 Mon Sep 17 00:00:00 2001 From: fangjian Date: Wed, 31 Jan 2024 14:52:56 +0000 Subject: [PATCH] improve progress_bar --- src/CMakeLists.txt | 3 +-- src/utility.F90 | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 598e8dd..44555af 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 @@ -42,7 +42,6 @@ add_executable(astr tecio.F90 test.F90 thermchem.F90 - ${UDF_SOURCE_FILES} utility.F90 vtkio.F90) diff --git a/src/utility.F90 b/src/utility.F90 index a414afc..4c686dd 100644 --- a/src/utility.F90 +++ b/src/utility.F90 @@ -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 |