showprogress

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 4.7, Creation date: 2019-06-22, Last change: 2025-09-14

creates a progress text in 5% steps and deletes it finally

Description

Useful function if some procedures take unexpected time and the user needs a progress bar

See Also: VLFLreadOBJ

Example Illustration

 missing image of showprogress (i,n,dv)

Syntax

showprogress(i,n,[dv])

Input Parameter

i: current index
n: maximum index number
dv: optional step size; default is 5;

Examples


for i=1:200; showprogress(i,200); pause(.01); end; % Default step size
for i=1:200; showprogress(i,200,3); pause(.01); end; % 3 % Step size




Copyright 2019-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This function, showprogress, is designed to display a progress indicator in the console during the execution of a loop or a long-running process. It provides feedback to the user by showing the percentage of completion in increments defined by the user or by default.

Input Parameters

Algorithm Steps

  1. Check if the number of input arguments is three or more. If so, set dv to the third argument; otherwise, set dv to 5.
  2. Declare persistent variables: curc, nam, finish, and fstring.
  3. If i is 1, initialize curc to 0, finish to false, and retrieve the caller function's name using dbstack. Set nam to the caller's name and prepare the initial format string fstring.
  4. If i is greater than n, set n to i to handle cases where the loop might exceed the expected maximum.
  5. Calculate the current progress percentage as (i/n)*100 and check if it exceeds the last recorded progress by at least dv percent. If so, update curc and append the new progress percentage to fstring, then print it to the console.
  6. If i is 0 or greater than or equal to n and finish is false, delete the progress text from the console by printing backspaces and set finish to true.
Algorithm explaination created using ChatGPT on 2025-08-19 07:43. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21