Home > wafo > misc > fwaitbar.m

fwaitbar

PURPOSE ^

Fast display of wait bar.

SYNOPSIS ^

fout = fwaitbar(x,name,msg)

DESCRIPTION ^

 FWAITBAR Fast display of wait bar. 
  
   CALL: H = fwaitbar(X,title,msg)  
             fwaitbar(X,H,msg) 
  
   H     = Handle to waitbar figure. 
   X     = Fractional length of wait bar. X should be between 0 and 1. 
   title = Title string (default 'Please wait...').  
   msg   = Message string  (default ''). 
  
  FWAITBAR creates and displays a wait bar of 
  fractional length X. Each subsequent call to waitbar, WAITBAR(X,H), 
  extends the length of the bar to the new position X. 
  
  FWAITBAR is a much speeded up version of WAITBAR (see help on WAITBAR). 
  
  Example: 
   h = fwaitbar(0,[],'this may take a while'); 
   for i=1:10, 
         % computation here % 
      if i==7, 
         fwaitbar(i/10,h,' soon finished') 
      else 
         fwaitbar(i/10,h) 
      end 
      pause(1) 
   end 
   close(h) 
   
  See also  waitbar

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function fout = fwaitbar(x,name,msg) 
002 %FWAITBAR Fast display of wait bar. 
003 % 
004 %  CALL: H = fwaitbar(X,title,msg)  
005 %            fwaitbar(X,H,msg) 
006 % 
007 %  H     = Handle to waitbar figure. 
008 %  X     = Fractional length of wait bar. X should be between 0 and 1. 
009 %  title = Title string (default 'Please wait...').  
010 %  msg   = Message string  (default ''). 
011 % 
012 % FWAITBAR creates and displays a wait bar of 
013 % fractional length X. Each subsequent call to waitbar, WAITBAR(X,H), 
014 % extends the length of the bar to the new position X. 
015 % 
016 % FWAITBAR is a much speeded up version of WAITBAR (see help on WAITBAR). 
017 % 
018 % Example: 
019 %  h = fwaitbar(0,[],'this may take a while'); 
020 %  for i=1:10, 
021 %        % computation here % 
022 %     if i==7, 
023 %        fwaitbar(i/10,h,' soon finished') 
024 %     else 
025 %        fwaitbar(i/10,h) 
026 %     end 
027 %     pause(1) 
028 %  end 
029 %  close(h) 
030 %  
031 % See also  waitbar 
032  
033 % Tested on: matlab 5.2 
034 % History 
035 % revised pab 03.03.2003 
036 %  - fixed some bugs   
037 % revised pab 25.07.2001 
038 % -changed help header to wafo style 
039 % -changed old name to msg. name is now the window name.  
040 % - added default string to name 
041 % - added example 
042 % by Olof Liungman. 
043 %   Dept. of Oceanography, Earth Sciences Centre 
044 %   Göteborg University, Sweden 
045 %   E-mail: olof.liungman@oce.gu.se 
046  
047 x = max(0,min(100*x,100)); % Make sure 0<=x<=100 
048 if nargin<3|isempty(msg), msg = '';end 
049 if nargin<2|isempty(name), name = 'Please wait...';end 
050  
051 if ischar(name) 
052   oldRootUnits = get(0,'Units'); 
053   set(0,'Units','pixels'); 
054   screenSz = get(0,'ScreenSize'); 
055   width  = 360; 
056   height = 75; 
057   x0 = (screenSz(3)-width)/2; 
058   y0 = (screenSz(4)-height)/2; 
059   pos = [x0, y0, width, height]; 
060   f = figure('MenuBar','none',... 
061      'Units','Pixels',... 
062      'NumberTitle','off',... 
063      'Pointer','watch',... 
064      'Color','w',... 
065      'Resize','on',... 
066      'CreateFcn','', ... 
067      'IntegerHandle','off',... 
068      'Tag','TMWWaitbar',... 
069      'Visible','off',... 
070      'Position',pos, ... 
071      'Name',name); 
072            
073           %set(f,'Resize','on','Position',pos); 
074           %set(f,'Resize','off') 
075   if ~strcmp(computer,'PCWIN') 
076     set(f,'DefaultTextFontSize',12) 
077     set(f,'DefaultAxesFontSize',12) 
078   end 
079   colormap([]) 
080  
081   ax = axes('XLim',[0 100],'YLim',[0 1],'Box','on','Position',... 
082        [.05 .30 .9 .30],'YTick',[],'XColor','k','YColor','k'); 
083    
084   xpatch = [0 x x 0]; 
085   ypatch = [0 0 1 1]; 
086   p = patch(xpatch,ypatch,'r','Edgecolor','r','EraseMode','none'); 
087   titleHandle = get(ax,'Title'); 
088   ud = {p, titleHandle}; 
089   set(f,'UserData',ud,...    
090      'HandleVisibility','callback',... 
091      'Visible','on',... 
092      'Resize','off'); 
093    
094   set(0, 'Units', oldRootUnits); 
095 else 
096    ud = get(name,'UserData'); 
097    p           = ud{1}; 
098    titleHandle = ud{2}; 
099  
100    xpatch = get(p,'xdata'); 
101    xpatch = [xpatch(2) x x xpatch(2)]; 
102    set(p,'Xdata',xpatch) 
103  
104 end 
105 if ~isempty(msg),set(titleHandle,'string',msg,'Color','k'),end 
106  
107 drawnow 
108  
109 if nargout>0, 
110   fout = f; 
111 end 
112  
113  
114  
115  
116

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003