Home > rest_20090422 > rest_spm5_files > nic_spm_progress_bar.m

nic_spm_progress_bar

PURPOSE ^

Display a 'Progress Bar' in the 'Interactive' window

SYNOPSIS ^

function nic_spm_progress_bar(action,varargin)

DESCRIPTION ^

 Display a 'Progress Bar' in the 'Interactive' window
 FORMAT spm_progress_bar('Init',height,xlabel,ylabel,flgs)
 Initialises the bar in the 'Interactive' window.
 If flgs contains a 't', then use tex interpreter for labels.

 FORMAT spm_progress_bar('Set',value)
 Sets the height of the bar itself.

 FORMAT spm_progress_bar('Clear')
 Clears the 'Interactive' window.
_______________________________________________________________________
 Copyright (C) 2005 Wellcome Department of Imaging Neuroscienic_e

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

nic_spm_progress_bar.m

SOURCE CODE ^

0001 function nic_spm_progress_bar(action,varargin)
0002 % Display a 'Progress Bar' in the 'Interactive' window
0003 % FORMAT spm_progress_bar('Init',height,xlabel,ylabel,flgs)
0004 % Initialises the bar in the 'Interactive' window.
0005 % If flgs contains a 't', then use tex interpreter for labels.
0006 %
0007 % FORMAT spm_progress_bar('Set',value)
0008 % Sets the height of the bar itself.
0009 %
0010 % FORMAT spm_progress_bar('Clear')
0011 % Clears the 'Interactive' window.
0012 %_______________________________________________________________________
0013 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscienic_e
0014 
0015 % John Ashburner
0016 % $Id: spm_progress_bar.m 272 2005-10-25 20:05:27Z guillaume $
0017 
0018 if ~nargin, action = 'Init'; end
0019 
0020 % Find the interactive window and exit if not
0021 %-----------------------------------------------------------------------
0022 Finter = nic_spm_figure('FindWin','Interactive');
0023 if isempty(Finter), return; end
0024 
0025 switch lower(action)
0026     % Initialise
0027     %-------------------------------------------------------------------
0028     case 'init'
0029         error(nargchk(0,5,nargin));
0030         if nargin > 1, arg1 = varargin{1}; else arg1 = 1;           end
0031         if nargin > 2, arg2 = varargin{2}; else arg2 = 'Computing'; end
0032         if nargin > 3, arg3 = varargin{3}; else arg3 = '';          end
0033         if nargin > 4, arg4 = varargin{4}; else arg4 = ' ';         end
0034         if any(arg4 == 't'), interp = 'tex'; else interp = 'none';  end
0035         pb = struct('pointer',get(Finter,'Pointer'),...
0036                     'name'   ,get(Finter,'Name'),...
0037                     'buffer', get(Finter,'DoubleBuffer'));
0038         nic_spm_progress_bar('Clear');
0039         set(Finter,'Pointer','watch');
0040         set(Finter,'Name',pb.name);
0041         set(Finter,'DoubleBuffer','on');
0042         pb.ax = axes('Position', [0.45 0.2 0.05 0.6],...
0043                      'XTick',    [],...
0044                      'Xlim',     [0 1],...
0045                      'Ylim',     [0 max([arg1 eps])],...
0046                      'Box',      'on',...
0047                      'Parent',   Finter);
0048         lab = get(pb.ax,'Xlabel');
0049         set(lab,'string',arg2,'FontSize',10,'Interpreter',interp);
0050         lab = get(pb.ax,'Ylabel');
0051         set(lab,'string',arg3,'FontSize',10,'Interpreter',interp);
0052         lab = get(pb.ax,'Title');
0053         set(lab,'string','0% Complete','Interpreter',interp);
0054         t = clock;
0055         str = sprintf('Began %2.0f:%02.0f:%02.0f',t(4),t(5),t(6));
0056         text(2,arg1/2,0,str,'FontSize',10,'Parent',pb.ax);
0057         l = line('Xdata',     [0.5 0.5],...
0058                  'Ydata',     [0 0],...
0059                  'LineWidth', 8,...
0060                  'Color',     [1 0 0],...
0061                  'Tag',       'ProgressBar',...
0062                  'Parent',    pb.ax);
0063         set(l,'UserData',pb);
0064         drawnow;
0065         
0066     % Set
0067     %-------------------------------------------------------------------
0068     case 'set'
0069         error(nargchk(1,2,nargin));
0070         if nargin == 1, value = 0; else  value = varargin{1}; end
0071         br = findobj(Finter,'Tag','ProgressBar');
0072         if ~isempty(br)
0073             pb = get(br,'UserData');
0074             set(br,'Ydata',[0 value]);
0075             lim = get(get(br,'Parent'),'Ylim');lim=lim(2);
0076             lab = get(pb.ax,'Title'); 
0077             set(lab,'string',sprintf('%.0f%% Complete',100*value/lim)); 
0078             drawnow;
0079         end    
0080     
0081     % Clear
0082     %-------------------------------------------------------------------
0083     case 'clear'
0084         error(nargchk(1,1,nargin));
0085         pb = get(findobj(Finter,'Tag','ProgressBar'),'UserData');
0086         nic_spm_figure('Clear',Finter);
0087         if isstruct(pb)
0088             set(Finter,'Pointer',     pb.pointer);
0089             set(Finter,'Name',        pb.name);
0090             set(Finter,'DoubleBuffer',pb.buffer);
0091         end
0092         drawnow;
0093     
0094     % Error
0095     %-------------------------------------------------------------------
0096     otherwise
0097         error('Unknown action string');
0098 end

Generated on Wed 29-Apr-2009 01:06:38 by m2html © 2005