1 (edited by designer 2022-04-11 18:35:14)

Topic: Giving Back - a progress bar of sorts for Mac

Below is the code for a simplified progress bar I set up for a routine that was running for more than a minute.
I wanted to be sure things were still humming along without periodically printing out increment numbers.

It's nice in that it only takes up two lines of the "screen" and can be easily modified for the situation at hand.

! MyTotalLoops is the number of the maximum loops in my Do/EndDO structure
! nStep is my progress bar increment. I wanted 10 steps so it's MyTotalLoops/10
! ss is a counter that triggers printing a progress step when ss equals nStep. Then ss is reset

Integer(16) MyTotalLoops, nStep, ss
nStep = MyTotalLoops/10

! Before the loop, I print out numbers 1 to 10 - my progress steps - then write some spaces on a second line so the
! progress steps will line up under the numbers 1 thru 10
! The font is different in this message area so you don't see that the second line of spaces
! starts at the P and stops just before the "1"

    Write (*,*)
    Write (*,'(a)')                    'Progress Steps: 1,2,3,4,5,6,7,8,9,10'
    Write (*,'(a)',advance='no') '                '
! The ..., advance = 'no') keeps the 'print point' from moving down a line

! I initialize ss at the beginning of the big Do Loop
  ss = 1
Do
! Your task goes here
.
.
.
! At the bottom of the loop, above the EndDo, I increment my step counter, compare it to the progress bar increment,
! If it is equal, I write out a progress bar step and reset the counter

! Count steps and write out progress
    ss = ss + 1
    IF (ss == nStep) Then
        ss = 1
        Write(*,'(a2)', advance = 'no') '==-'
! The ... , advance = 'no') '--" keeps the progress dashes moving along on the same line below progress step numbers
    Endif

EndDo

! I do another write to drop below the progress bar and print out my work results
Write (*,*)


Of course, this adds a little overhead to the computing task, but there is something comforting about having an indication that the program is faithfully chugging away while not pushing everything off-screen as would happen when printing increment numbers.

I hope this helps a Mac user who is jonesing for a progress indicator.
It will run on Windows too, but Windows has AppGraphics with its more sophisticated progress bar.
This one is good enough for my tasks.

if some unicode/font options are available, you might find a thicker bar character than the equal sign.