From: Rafael L. <ra...@ic...> - 2001-10-03 13:16:23
|
I am almost sure that somebody has already written such a thing, but I just added comment to my own progress_meter.m function and thought it would be a interesting addition to OctaveSF. The file is attached below and I am reproducing the doc string here. Please, feel free to send comments/patches. If you do not object, I will add it to the CVS repository. I only need to know in which directory. Enjoy. ## usage: progress_meter (0, [label, [ncols]]) ## progress_meter (adv) ## ## This function shows a progress meter at stdout and is intended for ## giving visual feedback on the progress of long loop operations. ## A typical call would be like this: ## ## progress_meter (0, "Computing ... ", 60); ## N = 2000; ## for j = 1:N ## eig (randn (40)); # this is the core of the loop operation ## progress_meter (j/N); ## endfor ## ## and the following progress_meter will be shown: ## ## Computing ... |== | - 10% 1m15s ## ## which changes over time, looking later like this: ## ## Computing ... |============ | / 42% 43s ## ## progress_meter should always be called before the loop with the first ## argument equal to 0. The third optional argument is the number of ## text columns spanned by the display (it defaults to the value of the ## COLUMNS environment variable). The second optional argument is the ## label that will be shown at the left of the progress meter display. ## ## The other fields in the display are: a horizontal bar giving a ## pictorial indication of the advancement, a "flipping clock", a ## indication of percentage completed, and an estimated time of ## completion. ## ## When calling progress_meter inside the loop, only one argument should ## be given, which is the amount of advancement. Its is equal to 0 at ## the beginning and must reach 1 at the end of the loop. ## ## Implementation notes: ## ## 1) A number of global variables are defined in order to keep the ## internal state of the meter. All Their names start with ## "progress_meter_". The user must avoid to mess with them in her ## code. ## 2) This implementation relies on Unix specificities, like the ## getenv("COLUMNS") call and the use of "\r" in printf(). For now, ## progress_meter has only be tested in Linux. ## 3) The estimated time of completion is noisy, since it is computed ## from one iteration to another, with tic() and toc() calls. -- Rafael Laboissiere |