Updates and displays the horizontal percentage-based progress bar.
subroutine update_progress_bar() !! Updates and displays the horizontal percentage-based progress bar. real :: percentage !! The percentage of the task completed. integer :: filled_length !! Length of the filled portion of the progress bar. character(len=progress_bar_width) :: bar !! The progress bar string. integer :: int_percentage !! Integer percentage value. if (total_calls == 0 .or. .not. show_progress) return ! Avoid division by zero and check the flag percentage = real(completed_calls) / real(total_calls) * 100.0 ! Ensure percentage does not exceed 100% if (percentage > 100.0) percentage = 100.0 ! Calculate integer percentage int_percentage = int(percentage) ! Update progress bar only when percentage increases by at least 1% if (int_percentage > last_percentage) then last_percentage = int_percentage ! Calculate the filled length of the progress bar filled_length = min(int(percentage / 100.0 * progress_bar_width), progress_bar_width) ! Construct the progress bar string bar = repeat('=', filled_length) if (filled_length < progress_bar_width) then bar = bar//'>'//repeat(' ', progress_bar_width - filled_length - 1) end if ! Print the progress bar and integer percentage write (*, '(A, F4.1, A)', advance='no') carriage_return//'['//bar//'] ', percentage, '%' call flush (0) ! Ensure output is displayed immediately end if end subroutine update_progress_bar