Home > chronux_1_1 > spikesort > utility > matlabtools > progressBar.m

progressBar

PURPOSE ^

PROGRESSBAR Improved progress indicator.

SYNOPSIS ^

function progressBar(progressFraction, updateEvery, infoString)

DESCRIPTION ^

PROGRESSBAR       Improved progress indicator.
   PROGRESSBAR(FRACTION, UPDATEEVERY, INFOSTRING) modifies Matlab's
   waitbar functionality to allow the indicator to decrease, automate
   creation/deletion and restrict updates so the indicator is only
   redrawn every kth iteration.

   If the indicator figure does not exist when PROGRESSBAR is called, it
   will be created (via WAITBAR) initialized with the message INFOSTRING
   and percent complete given by FRACTION * 100%.

   If the figure already exists, it is updated if FRACTION < 1.0, and if
   the number of calls since initialization is an integral multiple of
   the UPDATEEVERY parameter used to initialize the figure (this update
   rate can be changed by passing in a new value).  Otherwise, nothing
   happens.

   To force an update on an existing progressbar regardless of the the
   UPDATEEVERY count, pass in [] for the second argument.  (E.g., this
   can be used to force info string updates.)
   
   Finally, if FRACTION is >= 1.0, the indicator is deleted (or it is not
   shown if it does not already exist).

   See also WAITBAR.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function progressBar(progressFraction, updateEvery, infoString)
0002 %PROGRESSBAR       Improved progress indicator.
0003 %   PROGRESSBAR(FRACTION, UPDATEEVERY, INFOSTRING) modifies Matlab's
0004 %   waitbar functionality to allow the indicator to decrease, automate
0005 %   creation/deletion and restrict updates so the indicator is only
0006 %   redrawn every kth iteration.
0007 %
0008 %   If the indicator figure does not exist when PROGRESSBAR is called, it
0009 %   will be created (via WAITBAR) initialized with the message INFOSTRING
0010 %   and percent complete given by FRACTION * 100%.
0011 %
0012 %   If the figure already exists, it is updated if FRACTION < 1.0, and if
0013 %   the number of calls since initialization is an integral multiple of
0014 %   the UPDATEEVERY parameter used to initialize the figure (this update
0015 %   rate can be changed by passing in a new value).  Otherwise, nothing
0016 %   happens.
0017 %
0018 %   To force an update on an existing progressbar regardless of the the
0019 %   UPDATEEVERY count, pass in [] for the second argument.  (E.g., this
0020 %   can be used to force info string updates.)
0021 %
0022 %   Finally, if FRACTION is >= 1.0, the indicator is deleted (or it is not
0023 %   shown if it does not already exist).
0024 %
0025 %   See also WAITBAR.
0026 
0027 persistent progressHandle iter updateRate;
0028 
0029 if (progressFraction >= 1.0)  % delete if it exists & reset the handle
0030     if (~isempty(progressHandle) & ishandle(progressHandle))
0031         delete(progressHandle);
0032     end
0033     clear progressHandle iter;
0034 elseif (isempty(progressHandle) | ~ishandle(progressHandle))  % create if it doesn't exist
0035     if (nargin < 3),  infoString = '';  end;
0036     if (nargin < 2)
0037         error('At least two arguments are required when initializing.');
0038     end
0039     updateRate = updateEvery;
0040     iter = 1;
0041     progressHandle = waitbar(progressFraction, infoString);
0042     posDef = get(0, 'DefaultFigurePosition');  posWait = get(progressHandle, 'Position');
0043     set(progressHandle, 'Position', [posDef(1:2) posWait(3:4)]);
0044     
0045     p = findobj(progressHandle, 'Type', 'Patch');
0046     set(p, 'EraseMode', 'normal');   % allows the indicator to shrink properly
0047 else  % update it if thats the right thing to do
0048     if (nargin > 1)
0049         if (isempty(updateRate))
0050             update = 1;
0051         else
0052             updateRate = updateEvery;
0053             update = (iter == updateRate);
0054         end
0055     else
0056         update = (iter == updateRate);
0057     end
0058     if (update)
0059         iter = 1;
0060         if (nargin < 3)
0061             waitbar(progressFraction, progressHandle);
0062         else
0063             waitbar(progressFraction, progressHandle, infoString);
0064         end
0065     else
0066         iter = iter + 1;
0067     end    
0068 end
0069

Generated on Sun 13-Aug-2006 11:49:44 by m2html © 2003