Home > bioelectromagnetism > progress_bar.m

progress_bar

PURPOSE ^

progress_bar - Display a 'Progress Bar'

SYNOPSIS ^

function progress_bar(action,progress,title)

DESCRIPTION ^

 progress_bar - Display a 'Progress Bar'
 
 Usage: progress_bar('init',progress,title)
         Initialises the progress bar.  Input 'progress' is
         optional, assumed zero, otherwise a decimal
         value between 0:1.  Input 'title' is optional,
         but can be used to indicate the process of the
         progress bar.

 Usage: progress_bar('Set',progress)
         Updates the progress bar.  Input 'progress' is
         a decimal value between 0:1.

 Usage: progress_bar('Clear')
         Clears the progress bar.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function progress_bar(action,progress,title)
0002 
0003 % progress_bar - Display a 'Progress Bar'
0004 %
0005 % Usage: progress_bar('init',progress,title)
0006 %         Initialises the progress bar.  Input 'progress' is
0007 %         optional, assumed zero, otherwise a decimal
0008 %         value between 0:1.  Input 'title' is optional,
0009 %         but can be used to indicate the process of the
0010 %         progress bar.
0011 %
0012 % Usage: progress_bar('Set',progress)
0013 %         Updates the progress bar.  Input 'progress' is
0014 %         a decimal value between 0:1.
0015 %
0016 % Usage: progress_bar('Clear')
0017 %         Clears the progress bar.
0018 %
0019 
0020 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:35 $
0021 
0022 % @(#)spm_progress_bar.m    2.1 John Ashburner 99/05/17
0023 % Modified 03/2002, Darren.Weber_at_radiology.ucsf.edu
0024 %                   - removed spm specific references
0025 %                   - modified inputs/input handling to my liking
0026 %                   - progress bar is now a patch object and the
0027 %                     erasemode is xor with no figure backingstore
0028 %
0029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0030 
0031 
0032 if isequal(nargin,0),
0033     action = 'init';
0034 end
0035 
0036 action = lower(action);
0037 
0038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0039 % initialize
0040 if strcmp(action,'init'),
0041     
0042     tim = clock;
0043     timestr = sprintf('  Began %02.0f:%02.0f:%02.0f',tim(4),tim(5),tim(6));
0044     
0045     if exist('title','var'),
0046         if ~isempty(title),
0047             name = strcat(sprintf('%s  -',title),timestr);
0048         else
0049             name = strcat('Progress  -',timestr);
0050         end
0051     else
0052         name = strcat('Progress  -',timestr);
0053     end
0054     
0055     fg = figure('MenuBar','none',...
0056                 'NumberTitle','off',...
0057                 'Name',name,...
0058                 'Tag','ProgressBar',...
0059                 'BackingStore','off',...
0060                 'Pointer','watch',...
0061                 'Position',[1 1 300 75]);
0062     movegui(fg,'center');
0063     ax = axes('Position',[0.1 0.25 0.8 0.4],...
0064               'YTick',[],...
0065               'Xlim', [0 1],'Ylim',[0 1],...
0066               'Box','on',...
0067               'FontSize',8,...
0068               'Tag','ProgressBarAxis',...
0069               'Parent',fg);
0070     
0071     xlab = get(ax,'xticklabel');
0072     xlab = str2num(xlab) * 100;
0073     xlab = num2str(xlab);
0074     set(ax,'xticklabel',xlab)
0075     
0076     if exist('progress','var'),
0077         if ~isempty(progress), setpb(fg,progress);
0078         else
0079             progress = 0;
0080             setpb(fg,progress);
0081         end
0082     else
0083         progress = 0;
0084         setpb(fg,progress);
0085     end
0086     
0087     drawnow;
0088     
0089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0090 % set
0091 elseif strcmp(action,'set'),
0092     
0093     fg = findobj('Tag','ProgressBar');
0094     
0095     if ~isempty(fg), setpb(fg,progress); end;
0096 
0097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0098 % clear
0099 elseif strcmp(action,'clear'),
0100     fg = findobj('Tag','ProgressBar');
0101     if ~isempty(fg), close(fg);    end;
0102 end;
0103 
0104 return
0105 
0106 
0107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0108 function setpb(fig,progress)
0109     
0110     pbaxis = findobj(fig,'Tag','ProgressBarAxis');
0111     
0112     if ~isempty(pbaxis),
0113         
0114         vert = [0 0; progress 0; progress 1; 0 1];
0115         face = [1 2 3 4];
0116         
0117         pbpatch = findobj(fig,'Tag','ProgressBarPatch');
0118         
0119         if ~isempty(pbpatch),
0120             set(pbpatch,'Vertices',vert);
0121         else
0122             pbpatch = patch('Faces',face,'Vertices',vert,'FaceColor','r',...
0123                 'Tag','ProgressBarPatch',...
0124                 'EraseMode','none',...
0125                 'Parent',pbaxis);
0126         end
0127         
0128         title = get(pbaxis,'Title');
0129         set(title,'string',sprintf('%5.1f%% Complete',100*progress),'EraseMode','xor');
0130         
0131         drawnow;
0132         
0133         figure(fig);
0134     end;
0135 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003