function irbldemo(Action)
% IRBLDEMO:    Interactive command window for irbleigs routine. The irbleigs routine
%              can be called separately. This command window is used to help illustrate
%              the features and options of the irbleigs routine.
%
% See also IRBLEIGS.

%  AUTHORS:
%  James Baglama     University of Rhode Island, E-mail: jbaglama@math.uri.edu
%  Daniela Calvetti  Case Western Reserve University,  E-mail: dxc57@po.cwru.edu
%  Lothar Reichel    Kent State University, E-mail: reichel@mcs.kent.edu

% Global variables.
global A M OPTS matrixprod waithan dnbls;


% Demo is being initialized
if nargin==0, Action='initialize'; end


switch Action
   
  case 'initialize' % Initialize values.
   
       OPTS.sigma='SE'; OPTS.k=1; OPTS.blsz=1; OPTS.nbls=3; OPTS.shift='ML';
       OPTS.endpt='MON'; OPTS.maxdpol=200; OPTS.sizint=1; OPTS.maxit=100; 
       OPTS.tol = 1d-3; matrixprod=[]; err=[]; M=[]; OPTS.V0 = randn(100,1);
       dnbls = OPTS.nbls;

       % Set default matrix.
       A = delsq(numgrid('C',10));
   
       % Call function to set up user interface. 
       graphwin
       
   case 'Standard' % Set values to be used in the standard eigenvalue problem.
       set(findobj(gcf,'Tag','Standard'),'Value',1);
       set(findobj(gcf,'Tag','Generalized'),'Value',0);
       set(findobj(gcf,'Tag','SelectA'),'String','Select Matrix A');
       set(findobj(gcf,'Tag','Mmatrix'),'Visible','off');
       set(findobj(gcf,'Tag','matrix1'),'String','51 x 51 Five Point Discrete Laplacian ''C''');
       set(findobj(gcf,'Tag','matrix2'),'String','125 x 125 Anderson Matrix');
       set(findobj(gcf,'Tag','matrix3'),'String','900 x 900 Five Point Discrete Laplacian ''S''');
       set(findobj(gcf,'Tag','matrix1'),'Value',1);
       set(findobj(gcf,'Tag','matrix2'),'Value',0);
       set(findobj(gcf,'Tag','matrix3'),'Value',0);
       set(findobj(gcf,'Tag','matrix4'),'Value',0);
       set(findobj(gcf,'Tag','matrixUser'),'String',' ');
       data = get(findobj(gcf,'Tag','Standard'),'Value');
       A = delsq(numgrid('C',10));
       M = [];
              
   case 'Generalized' % Set values to be used in the generalized eigenvalue problem.
       set(findobj(gcf,'Tag','Standard'),'Value',0);
       set(findobj(gcf,'Tag','Generalized'),'Value',1);
       set(findobj(gcf,'Tag','SelectA'),'String','Select Matrices A and M (Matrices are 100 x 100)');
       set(findobj(gcf,'Tag','Mmatrix'),'Visible','on');
       set(findobj(gcf,'Tag','matrix1'),'String','A: Five Point Discrete Laplacian ''S''');
       set(findobj(gcf,'Tag','matrix2'),'String','A: Idenity Matrix');
       set(findobj(gcf,'Tag','matrix3'),'String','A: PROLATE Matrix (From Gallery)');
       Str1 = ' M: Five Point Discrete Laplacian ''S'' | ';
       Str2 = ' M: Diagonal Matrix 1:100 | ';
       Str3 = ' M: Idenity Matrix        | ';
       Str4 = ' M: LEHMER (From Gallery) | ';
       Str5 = ' M: MINIJ  (From Gallery) | ';
       Str6 = ' M: MOLER  (From Gallery) | ';
       Str7 = ' M: TOEPPD (From Gallery)  ';
       T = strcat(Str1,Str2,Str3,Str4,Str5,Str6,Str7);
       set(findobj(gcf,'Tag','Mmatrix'),'String',T);
       data = get(findobj(gcf,'Tag','Mmatrix'),'UserData');
       umat = data(get(findobj(gcf,'Tag','Mmatrix'),'Value'),:);
       if ~isempty(umat),eval(umat); end
       set(findobj(gcf,'Tag','matrix1'),'Value',1);
       set(findobj(gcf,'Tag','matrix2'),'Value',0);
       set(findobj(gcf,'Tag','matrix3'),'Value',0);
       set(findobj(gcf,'Tag','matrix4'),'Value',0);
       set(findobj(gcf,'Tag','matrixUser'),'String',' ');
       A = delsq(numgrid('S',12));
       
   case 'Mmatrix' % Get the M matrix in the generalized eigenvalue problem.
      data = get(findobj(gcf,'Tag','Mmatrix'),'UserData');
      umat = data(get(findobj(gcf,'Tag','Mmatrix'),'Value'),:);
      if ~isempty(umat),eval(umat); end
                       
   case 'matrix1' % Get matrix A.
       set(findobj(gcf,'Tag','matrix1'),'Value',1);
       set(findobj(gcf,'Tag','matrix2'),'Value',0);
       set(findobj(gcf,'Tag','matrix3'),'Value',0);
       set(findobj(gcf,'Tag','matrix4'),'Value',0);
       set(findobj(gcf,'Tag','matrixUser'),'String',' ');
       data = get(findobj(gcf,'Tag','Standard'),'Value');
       if data
          A = delsq(numgrid('C',10));
       else
          A = delsq(numgrid('S',12));
       end   
       
  case 'matrix2' % Get matrix A.
       set(findobj(gcf,'Tag','matrix1'),'Value',0);
       set(findobj(gcf,'Tag','matrix2'),'Value',1);
       set(findobj(gcf,'Tag','matrix3'),'Value',0);
       set(findobj(gcf,'Tag','matrix4'),'Value',0);
       set(findobj(gcf,'Tag','matrixUser'),'String',' ');
       data = get(findobj(gcf,'Tag','Standard'),'Value');
       if data
          A = getAndmatr;
       else
          A = eye(100);
       end   
       
  case 'matrix3' % Get matrix A.    
       set(findobj(gcf,'Tag','matrix1'),'Value',0);
       set(findobj(gcf,'Tag','matrix2'),'Value',0);
       set(findobj(gcf,'Tag','matrix3'),'Value',1);
       set(findobj(gcf,'Tag','matrix4'),'Value',0);
       set(findobj(gcf,'Tag','matrixUser'),'String',' ');
       data = get(findobj(gcf,'Tag','Standard'),'Value');
       if data
          A = delsq(numgrid('S',32));
       else
          A = gallery('prolate',100);
       end   

   case 'matrix4' % Output the string 'A=sparse(diag(1:100));' in the user input box.    
       set(findobj(gcf,'Tag','matrix1'),'Value',0);
       set(findobj(gcf,'Tag','matrix2'),'Value',0);
       set(findobj(gcf,'Tag','matrix3'),'Value',0);
       set(findobj(gcf,'Tag','matrix4'),'Value',1);
       set(findobj(gcf,'Tag','matrixUser'),'String','A=sparse(diag(1:100));');
       A = sparse(diag(1:100));
       
  case 'matrixUser' % Get user input matrix A. No testing of input.
       umat = get(findobj(gcf,'Tag','matrixUser'),'String');
       if ~isempty(umat),eval(umat); end
       
  case 'SIGMA' % Set option SIGMA to be 'SE' or 'LE'.   
       set(findobj(gcf,'Tag','Userval'),'String',' ');
       data = get(findobj(gcf,'Tag','SIGMA'),'UserData');
       OPTS.sigma = data(get(findobj(gcf,'Tag','SIGMA'),'Value'),:);
       set(findobj(0,'Tag','SIGMA'),'Userdata',str2mat('SE', 'LE'));
       set(findobj(0,'Tag','SIGMA'),'String',strcat('SE | LE'));
       set(findobj(0,'Tag','ZERTYP'),'String',' ML | WL ');  
            
  case 'K' % Set option K to be a value between 1 and 10.
       data = get(findobj(gcf,'Tag','K'),'UserData');
       OPTS.k = data(get(findobj(gcf,'Tag','K'),'Value'));
      
  case 'BLSZ' % Set option BLSZ to be a value between 1 and 6.
       data = get(findobj(gcf,'Tag','BLSZ'),'UserData');
       OPTS.blsz = data(get(findobj(gcf,'Tag','BLSZ'),'Value'));
       
  case 'NBLS' % Set option NBLS to be a value between 3 and 20.
       data = get(findobj(gcf,'Tag','NBLS'),'UserData');
       OPTS.nbls = data(get(findobj(gcf,'Tag','NBLS'),'Value'));
              
  case 'ZERTYP' % Set option ZERTYP to be 'ML' or 'WL'.
     data = get(findobj(gcf,'Tag','ZERTYP'),'UserData');
     OPTS.shift = data(get(findobj(gcf,'Tag','ZERTYP'),'Value'),:);
     
  case 'MAXDPOL' % Set option MAXDPOL to be values ranging from 200 to 6000.
     data = get(findobj(gcf,'Tag','MAXDPOL'),'UserData');
     OPTS.maxdpol = data(get(findobj(gcf,'Tag','MAXDPOL'),'Value'));
     
  case 'ENDPT' % Set option ENDPT to be 'MON' or 'FLT'.
     data = get(findobj(gcf,'Tag','ENDPT'),'UserData');
     OPTS.endpt = data(get(findobj(gcf,'Tag','ENDPT'),'Value'),:);
     
  case 'SIZINT' % Set option SIZINT to be a value between 1 and 10. 
     data = get(findobj(gcf,'Tag','SIZINT'),'UserData');
     OPTS.sizint = data(get(findobj(gcf,'Tag','SIZINT'),'Value'));
     
  case 'MAXIT' % Set option MAXIT to be values ranging from 100 to 6000.
     data = get(findobj(gcf,'Tag','MAXIT'),'UserData');
     OPTS.maxit = data(get(findobj(gcf,'Tag','MAXIT'),'Value'));
     
  case 'TOL' % Set option TOL to be values ranging from 1d-3 to 1d-16.
     data = get(findobj(gcf,'Tag','TOL'),'UserData');
     OPTS.tol = data(get(findobj(gcf,'Tag','TOL'),'Value'));
          
  case 'Userval' % Get user numeric value for option SIGMA.
     userSIGMA = get(findobj(gcf,'Tag','Userval'),'String');
     if ~isempty(userSIGMA)
         eval(strcat(userSIGMA,';')); OPTS.sigma=str2num(userSIGMA);
     end
     set(findobj(0,'Tag','ZERTYP'),'Value',2);
     set(findobj(0,'Tag','ZERTYP'),'String',' -- | WL ');
     set(findobj(0,'Tag','SIGMA'),'Value',3);
     set(findobj(0,'Tag','SIGMA'),'Userdata',str2mat('SE', 'LE',userSIGMA));
     set(findobj(0,'Tag','SIGMA'),'String',strcat('SE | LE | ',userSIGMA));
     
           
  case 'GetEigs' % Call subroutine irbleigs to compute the eigenvalues.
      % Output a wait bar. 
      waithan = waitbar(0,'Please wait...');
      % Check starting matrix and modify if need be.
      V = getfield(OPTS,'V0'); blsz = getfield(OPTS,'blsz');
      if ((size(V,1) ~= size(A,1)) | (size(V,2) ~= blsz))
         OPTS.V0 = randn(size(A,1),blsz);
      end 
      % Save the orginal number of blocks NBLS.
      dnbls = OPTS.nbls;
      % Call IRBLEIGS and compute the cputime.
      if isempty(M)
         tic; D=irbleigs(A,OPTS); tim = toc;
      else
         tic; D=irbleigs(A,M,OPTS); tim = toc;
      end 
      % Reset the number of blocks if NBLS changed.
      if OPTS.nbls ~= dnbls
         if dnbls >= 3
            OPTS.nbls = dnbls;
            set(findobj(0,'Tag','NBLS'),'Value',dnbls-2);
            if dnbls > 20
               S = ' 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |  '
               DS = num2str(dnbls);
               S = strcat(S,DS);
               set(findobj(0,'Tag','NBLS'),'String',S);
               set(findobj(0,'Tag','NBLS'),'Userdata',...
               [3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 dnbls]);
            end
         else    
            set(findobj(0,'Tag','NBLS'),'String','ERROR!');
         end
      end   
                   
      close(waithan); % Close wait bar.
      % Clear plot and set axis.
      plot(0.5,0.5,'Color',[0.8 0.8 0.8]);
      set(gca,'XTick',[],'YTick',[],'Visible','off');
      axis normal;
      if ~isempty(D)
        % Set numeric values to strings for output.
        D=num2str(D);mprod = num2str(matrixprod);tim = num2str(tim);
        D=str2mat('Eigenvalues ', ' ',D,' ',...
           ['# Matrix-Vectors Products: ',mprod],['CPU time: ',tim]);
        % Print the eigenvalues.
        text(0,0.5,D,'FontSize',11,'Color','b','FontWeight','bold');
     else
        axis([0 1 0 1]);
        Str1 = '               NO CONVERGENCE!';
        Str2 = ' Try the following suggestions.';
        Str3 = ' 1.) Increase block size BLSZ. For finding interior';
        Str4 = '     eigenvalues a larger block size may be needed.';
        Str5 = ' 2.) Increase the number of Lanczos vectors NBLS.';
        Str6 = '     A larger Krylov subspace may help.';
        Str7 = ' 3.) Decrease the tolerance, TOL.';
        Str8 = ' 4.) More iterations may be required. Increase MAXIT.';
        Str9 = ' 5.) Try different values for MAXDPOL, SIZINT and ENDPT.';
        Str10= ' NOTE:';
        Str11= ' Krylov methods have a difficult time finding clustered';
        Str12= ' eigenvalues. Increasing the block size helps find small';
        Str13= ' clusters, however if the cluster is very large, the ';
        Str14= ' IRBLEIGS method may not converge.';
        D=str2mat(Str1,Str2,Str3,Str4,Str5,Str6,Str7,Str8,Str9,Str10,...
                  Str11,Str12,Str13,Str14);
        text(0,0.5,D,'Fontsize',8,'Color','r');
     end
      
   case 'Setup' % Print the initial message at start up.
      % Clear plot.
      plot(0.5,0.5,'Color',[0.8 0.8 0.8]);
      set(gca,'XTick',[],'YTick',[],'Visible','off');
      axis([0 1 0 1]);
      Str1 = '        WELCOME TO THE IRBLDEMO!!';
      Str2 = 'This is a demo to illustrate the different options';
      Str3 = 'that are available in the IRBLEIGS subroutine.';
      Str4 = 'Select a matrix or input a matrix, then set the ';
      Str5 = 'options by using the pull down menus on the left.';
      Str6 = 'To get eigenvalues, select the ''Get Eigs.'' button.';
      Str7 = ' ';
      Str8 = 'For more information on the options move the';
      Str9 = 'mouse over the option and press the right mouse'; 
      Str10= 'button or press the Help button.';
      Str11=' ';
      Str12='Authors: J. Baglama, D. Calvetti, and L. Reichel';
      Str13='Date: 10 - 10 - 2002';
      D=str2mat(Str1,Str2,Str3,Str4,Str5,Str6,Str7,Str8,Str9,Str10,Str11,Str12,Str13);
      text(0,0.5,D,'Fontsize',10,'Color','r');

      
   case 'HelpIRBL' % Output help window.
      Helpdemo;
      
   case 'SIGMAinfo' % Output information about SIGMA. 
      % Clear plot.
      plot(0.5,0.5,'Color',[0.8 0.8 0.8]);
      set(gca,'XTick',[],'YTick',[],'Visible','off');
      axis([0 1 0 1]);
      Str1=' SIGMA - Which eigenvalues.';
      Str2=' ';
      Str3=     '    SE - Smallest eigenvalues.';
      Str4=     '    LE - Largest eigenvalues. ';
      Str5=     '    Numeric Value - Find K eigenvalues';
      Str6=     '    near the numeric input value.';
      D=str2mat(Str1,Str2,Str3,Str4,Str5,Str6);
      text(0,0.5,D,'Fontsize',10,'Color','r');
      
      case 'Kinfo' % Output information about K.
    % Clear plot.
      plot(0.5,0.5,'Color',[0.8 0.8 0.8]);
      set(gca,'XTick',[],'YTick',[],'Visible','off');
      axis([0 1 0 1]);
      Str1=' K - Number of desired eigenvalues.';
      D=str2mat(Str1);
      text(0,0.5,D,'Fontsize',10,'Color','r');
      
      case 'BLSZinfo' % Output information about BLSZ.
    % Clear plot.
      plot(0.5,0.5,'Color',[0.8 0.8 0.8]);
      set(gca,'XTick',[],'YTick',[],'Visible','off');
      axis([0 1 0 1]);
      Str1=' BLSZ - Block size of Lanczos Trid. matrix.';
      D=str2mat(Str1);
      text(0,0.5,D,'Fontsize',10,'Color','r');
      
      case 'NBLSinfo' % Output information about NBLS.
    % Clear plot.
      plot(0.5,0.5,'Color',[0.8 0.8 0.8]);
      set(gca,'XTick',[],'YTick',[],'Visible','off');
      axis([0 1 0 1]);
      Str1=' NBLS - # of blocks of Lanczos Trid. matrix.';
      D=str2mat(Str1);
      text(0,0.5,D,'Fontsize',10,'Color','r');
      
      case 'ZERTYPinfo' % Output information about ZERTYP.
    % Clear plot.
      plot(0.5,0.5,'Color',[0.8 0.8 0.8]);
      set(gca,'XTick',[],'YTick',[],'Visible','off');
      axis([0 1 0 1]);
      Str1=' ZERTYP - Which type of shift is to be used. ';
      Str2= ' ';
      Str3=     '   WL - Weighted fast Leja points.'; 
      Str4=     '   ML - ''Mapped'' fast Leja points. ';
      D=str2mat(Str1,Str2,Str3,Str4);
      text(0,0.5,D,'Fontsize',10,'Color','r');
      
      case 'MAXDPOLinfo' % Output information about MAXDPOL. 
    % Clear plot.
      plot(0.5,0.5,'Color',[0.8 0.8 0.8]);
      set(gca,'XTick',[],'YTick',[],'Visible','off');
      axis([0 1 0 1]);
      Str1 = 'MAXDPOL - Max. degree of damping poly.';
      D=str2mat(Str1);
      text(0,0.5,D,'Fontsize',10,'Color','r');
      
      case 'ENDPTinfo' % Output information about ENDPT.
    % Clear plot.
      plot(0.5,0.5,'Color',[0.8 0.8 0.8]);
      set(gca,'XTick',[],'YTick',[],'Visible','off');
      axis([0 1 0 1]);
      Str1=' ENDPT  - Specifies the location of the interior';
      Str2='          end point for the dampening interval.';
      Str3= ' ';
      Str4='      FLT - Let the interior end point float. ';                  
      Str5='      MON - Interior end points are chosen so ';
      Str6='            that the dampening intervals are';
      Str7='            nested.';
      D=str2mat(Str1,Str2,Str3,Str4,Str5,Str6,Str7);
      text(0,0.5,D,'Fontsize',10,'Color','r');
      
      case 'SIZINTinfo' % Output information about SIZINT.
    % Clear plot.
      plot(0.5,0.5,'Color',[0.8 0.8 0.8]);
      set(gca,'XTick',[],'YTick',[],'Visible','off');
      axis([0 1 0 1]);
      Str1=' SIZINT - Size of the dampening interval.';
      Str2='Value of 1 indicates consecutive Ritz';
      Str3 ='values are used to determine the endpoints';
      Str4='of the dampening interval. Value of 2';
      Str5='indicates endpoints are chosen from Ritz';
      Str6='values that are seprated by one Ritz value. Etc.';
      D=str2mat(Str1,Str2,Str3,Str4,Str5,Str6);
      text(0,0.5,D,'Fontsize',10,'Color','r');
      
      case 'MAXITinfo' % Output information about MAXIT.
    % Clear plot.
      plot(0.5,0.5,'Color',[0.8 0.8 0.8]);
      set(gca,'XTick',[],'YTick',[],'Visible','off');
      axis([0 1 0 1]);
      Str1=' MAXIT  - Maximum number of iterations.';
      D=str2mat(Str1);
      text(0,0.5,D,'Fontsize',10,'Color','r');
      
      case 'TOLinfo' % Output information about TOL.
    % Clear plot.
      plot(0.5,0.5,'Color',[0.8 0.8 0.8]);
      set(gca,'XTick',[],'YTick',[],'Visible','off');
      axis([0 1 0 1]);
      Str1 =' TOL - Tolerance used for convergence.';
      Str2 ='       Convergence is determined when ';            
      Str3 ='       || Ax - lambda*x ||_2 \leq TOL*||A||_2';
      Str4 ='       ||A||_2 is approximated by largest';
      Str5 ='       absolute Ritz value.  ';
      D=str2mat(Str1,Str2,Str3,Str4,Str5);
      text(0,0.5,D,'Fontsize',10,'Color','r');

     case 'FENinfo' % Output information about finding eigenvalues near a value.
     % Clear plot.
      plot(0.5,0.5,'Color',[0.8 0.8 0.8]);
      set(gca,'XTick',[],'YTick',[],'Visible','off');
      axis([0 1 0 1]);
      Str1 ='This option will find eigenvalues near any';
      Str2 ='numeric value. If the value is outside the';
      Str3 ='spectrum using the option SIGMA = SE or LE';
      Str4 ='will produce faster convergence.';
      D=str2mat(Str1,Str2,Str3,Str4);
      text(0,0.5,D,'Fontsize',10,'Color','r');
      
end       

%===================================================================
function graphwin

% This function sets up the graphical user interface.

% Global variables.
global A M OPTS irdemo;

% Set values and figures.
StdUnit = 'point';
StdColor = get(0,'DefaultUIcontrolBackgroundColor');
PointsPerPixel = 72/get(0,'ScreenPixelsPerInch');

% Open a new figure
 a = figure('Color',[0.8 0.8 0.8], ...
   'Position',[25 45 560 420], ...
   'Visible','off', ...
   'NumberTitle','off', ...
   'IntegerHandle','off', ...
   'Number','off',...  
   'Name','Implicitly Restarted Block Lanczos Method Demo, Baglama et al.');

% Add the axes to the new figure a.
b = axes('Parent',a, ...
   'Units',StdUnit, ...
   'Color',[0.8 0.8 0.8], ...
   'Position',PointsPerPixel*[18 179 289 227], ...
   'Units','Normalized',...
   'XColor',[0.8 0.8 0.8], ...
   'XGrid','off', ...
   'XTick',[],...
   'YColor',[0.8 0.8 0.8], ...
   'YGrid','off', ...
   'YTick',[]);

% Set no labels.
set(get(b,'XLabel'),'visible','off');
set(get(b,'YLabel'),'visible','off');

% Add various frames to the bottom and left-hand side of the figure.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[321 351 217 48], ...
   'Units','Normalized',...
   'Style','frame');
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[321 296 217 48], ...
   'Units','Normalized',...
   'Style','frame');
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[321 241 217 48], ...
   'Units','Normalized',...
   'Style','frame');
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[321 186 217 48], ...
   'Units','Normalized',...
   'Style','frame');
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[321 131 217 48], ...
   'Units','Normalized',...
   'Style','frame');
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[14 10 292 158], ...
   'Units','Normalized',...
   'Style','frame');
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[321 75 217 48], ...
   'Units','Normalized',...
   'Style','frame');

% Add radio buttons and text for specifying a type of matrix.
b = uicontrol('Parent',a, ...
   'Style','checkbox', ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[38 146 90 17], ...
   'Units','Normalized',...
   'String','Standard', ...
   'Value',1,...
   'Tag','Standard',...
   'CallBack','irbldemo(''Standard'')');
b = uicontrol('Parent',a, ...
   'Style','checkbox', ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[145 146 100 17], ...
   'Units','Normalized',...
   'String','Generalized', ...
   'Value',0,...
   'Tag','Generalized',...
   'CallBack','irbldemo(''Generalized'')');
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[32 126 249 13], ...
   'Units','Normalized',...
   'Style','text',...
   'Tag','SelectA',...
   'String','Select Matrix A');
b = uicontrol('Parent',a, ...
   'Style','radiobutton', ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[32 103 220 17], ...
   'Units','Normalized',...
   'String','51 x 51 Five Point Discrete Laplacian ''C'' ', ...
   'Value',1,...
   'Tag','matrix1',...
   'CallBack','irbldemo(''matrix1'')');
b = uicontrol('Parent',a, ...
   'Style','radiobutton', ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[32 86 210 17], ...
   'Units','Normalized',...
   'String','125 x 125 Anderson Matrix', ...
   'Value',0,...
   'Tag','matrix2',...
   'CallBack','irbldemo(''matrix2'')');
b = uicontrol('Parent',a, ...
   'Style','radiobutton', ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[32 69 220 17], ...
   'Units','Normalized',...
   'String','900 x 900 Five Point Discrete Laplacian ''S'' ', ...
   'Value',0,...
   'Tag','matrix3',...
   'CallBack','irbldemo(''matrix3'')');
b = uicontrol('Parent',a, ...
   'Style','radiobutton', ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[32 50 22 20], ...
   'Units','Normalized',...
   'Value',0,...
   'Tag','matrix4',...
   'CallBack','irbldemo(''matrix4'')');
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',[1 1 1], ...
   'Position',PointsPerPixel*[52 50 200 20], ...
   'Units','Normalized',...
   'Style','edit', ...
   'Horiz','left',...
   'Tag','matrixUser',...
   'CallBack','irbldemo(''matrixUser'')');
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Style','popup', ...
   'Visible','off',...
   'Position',PointsPerPixel*[32 25 245 18], ...
   'Units','Normalized',...
   'Tag','Mmatrix',...
   'UserData',str2mat(...
        'M = delsq(numgrid(''S'',12));',...
        'M = sparse(diag(1:100));',...
        'M = eye(100);',...
        'M = gallery(''lehmer'',100);',...
        'M = gallery(''minij'',100);',...
        'M = gallery(''moler'',100);',...
        'M = gallery(''toeppd'',100);'),...
   'CallBack','irbldemo(''Mmatrix'')');
   
     
% Add text to the option block.

% Text above the options field
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'HorizontalAlignment','left', ...
   'Position',PointsPerPixel*[330 400 197 15], ...
   'Units','Normalized',...
   'FontWeight','bold',...
   'String','Use right mouse button to get info', ...
   'Style','text');

% SIGMA text.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'HorizontalAlignment','left', ...
   'Position',PointsPerPixel*[326 375 127 17], ...
   'Units','Normalized',...
   'String','SIGMA', ...
   'ButtonDownFcn','irbldemo(''SIGMAinfo'')',...
   'Style','text');
% K text.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'HorizontalAlignment','left', ...
   'Position',PointsPerPixel*[326 353 127 17], ...
   'Units','Normalized',...
   'String','K', ...
   'ButtonDownFcn','irbldemo(''Kinfo'')',...
   'Style','text');
% BLSZ text.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'HorizontalAlignment','left', ...
   'Position',PointsPerPixel*[326 319 127 17], ...
   'Units','Normalized',...
   'String','BLSZ', ...
   'ButtonDownFcn','irbldemo(''BLSZinfo'')',...
   'Style','text');
% NBLS text
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'HorizontalAlignment','left', ...
   'Position',PointsPerPixel*[326 298 127 17], ...
   'Units','Normalized',...
   'String','NBLS', ...
   'ButtonDownFcn','irbldemo(''NBLSinfo'')',...
   'Style','text');
% ZERTYP text.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'HorizontalAlignment','left', ...
   'Position',PointsPerPixel*[326 265 108 17], ...
   'Units','Normalized',...
   'String','ZERTYP', ...
   'ButtonDownFcn','irbldemo(''ZERTYPinfo'')',...
   'Style','text');
% MAXDPOL text.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'HorizontalAlignment','left', ...
   'Position',PointsPerPixel*[326 242 109 17], ...
   'Units','Normalized',...
   'String','MAXDPOL', ...
   'ButtonDownFcn','irbldemo(''MAXDPOLinfo'')',...
   'Style','text');
% ENDPT text.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'HorizontalAlignment','left', ...
   'Position',PointsPerPixel*[326 211 109 17], ...
   'Units','Normalized',...
   'String','ENDPT', ...
   'ButtonDownFcn','irbldemo(''ENDPTinfo'')',...
   'Style','text');
% SIZINT text.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'HorizontalAlignment','left', ...
   'Position',PointsPerPixel*[326 188 109 17], ...
   'Units','Normalized',...
   'String','SIZINT', ...
   'ButtonDownFcn','irbldemo(''SIZINTinfo'')',...
   'Style','text');
% MAXIT text.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'HorizontalAlignment','left', ...
   'Position',PointsPerPixel*[326 157 109 17], ...
   'Units','Normalized',...
   'String','MAXIT', ...
   'ButtonDownFcn','irbldemo(''MAXITinfo'')',...
   'Style','text');
% TOL text.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'HorizontalAlignment','left', ...
   'Position',PointsPerPixel*[326 134 109 17], ...
   'Units','Normalized',...
   'String','TOL', ...
   'ButtonDownFcn','irbldemo(''TOLinfo'')',...
   'Style','text');

% Add controls for specifying various options.

% SIGMA controls.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',[1 1 1], ...
   'Style','popup', ...
   'Position',PointsPerPixel*[452 376 81 20], ...
   'Units','Normalized',...
   'Tag','SIGMA',...
   'String',' SE | LE', ...
   'UserData',str2mat('SE', 'LE'),...
   'CallBack','irbldemo(''SIGMA'')');
% K controls.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',[1 1 1], ...
   'Style','popup', ...
   'Position',PointsPerPixel*[452 356 81 17], ...
   'Units','Normalized',...
   'Tag','K',...
   'String',' 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ', ...
   'UserData',[1 2 3 4 5 6 7 8], ...
   'CallBack','irbldemo(''K'')');
% BLSZ controls.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',[1 1 1], ...
   'Style','popup', ...
   'Position',PointsPerPixel*[452 322 81 20], ...
   'Units','Normalized',...
   'Tag','BLSZ',...
   'String',' 1 | 2 | 3 | 4 | 5 | 6 ', ...
   'UserData',[1 2 3 4 5 6], ...
   'CallBack','irbldemo(''BLSZ'')');
% NBLS control.   
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'Style','popup', ...
   'BackgroundColor',[1 1 1], ...
   'Position',PointsPerPixel*[452 301 81 18], ...
   'Units','Normalized',...
   'Tag','NBLS',...
   'String',' 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 ', ...
   'UserData',[3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20], ...
   'CallBack','irbldemo(''NBLS'')');
   
% ZERTYP control.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',[1 1 1], ...
   'Style','popup', ...
   'Position',PointsPerPixel*[452 267 81 20], ...
   'Units','Normalized',...
   'Tag','ZERTYP',...
   'String',' ML | WL', ...
   'UserData',str2mat('ML', 'WL'),...
   'CallBack','irbldemo(''ZERTYP'')');
% MAXDPOL control.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',[1 1 1], ...
   'Style','popup', ...
   'Position',PointsPerPixel*[452 246 81 18], ...
   'Units','Normalized',...
   'Tag','MAXDPOL',...
   'String',' 200 | 400 | 600 | 800 | 1000 | 2000 | 4000 | 6000 ', ...
   'UserData',[200 400 600 800 1000 2000 4000 6000], ...
   'CallBack','irbldemo(''MAXDPOL'')');
% ENDPT control
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',[1 1 1], ...
   'Style','popup', ...
   'Position',PointsPerPixel*[452 212 81 20], ...
   'Units','Normalized',...
   'Tag','ENDPT',...
   'String',' MON| FLT ', ...
   'UserData',str2mat('MON', 'FLT'),...
   'CallBack','irbldemo(''ENDPT'')');
% SIZINT control.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',[1 1 1], ...
   'Style','popup', ...
   'Position',PointsPerPixel*[452 191 81 18], ...
   'Units','Normalized',...
   'Tag','SIZINT',...
   'String',' 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 ', ...
   'UserData',[1 2 3 4 5 6 7 8 9 10], ...
   'CallBack','irbldemo(''SIZINT'')');
% MAXIT control.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',[1 1 1], ...
   'Style','popup', ...
   'Position',PointsPerPixel*[452 157 81 20], ...
   'Units','Normalized',...
   'Tag','MAXIT',...
   'String',' 100 | 200 | 400 | 600 | 800 | 1000 | 2000 | 4000 | 6000 ', ...
   'UserData',[100  200  400  600  800  1000  2000  4000  6000], ...
   'CallBack','irbldemo(''MAXIT'')');
% TOL control.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',[1 1 1], ...
   'Style','popup', ...
   'Position',PointsPerPixel*[452 136 81 18], ...
   'Units','Normalized',...
   'Tag','TOL',...
   'String',' 1d-3 | 1d-4 | 1d-5 | 1d-6 | 1d-7 | 1d-8 | 1d-9 | 1d-10 | 1d-12 | 1d-16  ', ...
   'UserData',[1d-3  1d-4  1d-5  1d-6  1d-7  1d-8  1d-9  1d-10  1d-12 1d-16], ...
   'CallBack','irbldemo(''TOL'')');

% Add editable text field to input a numeric SIGMA value.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',StdColor, ...
   'Position',PointsPerPixel*[325 83 145 20], ...
   'Units','Normalized',...
   'Style','text',...
   'ButtonDownFcn','irbldemo(''FENinfo'')',...
   'String','FIND EIGENVALUES NEAR');
   b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'BackgroundColor',[1 1 1], ...
   'Position',PointsPerPixel*[480 85 45 20], ...
   'Units','Normalized',...
   'Style','edit', ...
   'Horiz','left',...
   'Tag','Userval',...
   'CallBack','irbldemo(''Userval'')');
            
% Add push buttons for Get Eigs., Close and Help.
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'Position',PointsPerPixel*[321 40 90 26], ...
   'Units','Normalized',...
   'Tag','GetEigs',...
   'String','Get Eigs. -->', ...
   'CallBack','irbldemo(''GetEigs'')');
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'CallBack','irbldemo(''HelpIRBL'')', ...
   'Position',PointsPerPixel*[448 40 90 26], ...
   'Units','Normalized',...
   'String','Help');
b = uicontrol('Parent',a, ...
   'Unit',StdUnit, ...
   'CallBack','close(gcf);', ...
   'Position',PointsPerPixel*[448 10 90 26], ...
   'Units','Normalized',...
   'String','Close');

% Set the figure for initial output of message.
set(a,'visible','on');

% Call irbldemo to print the initial message.
irbldemo('Setup');

% Re-set the figure for callback.
set(a,'visible','on','HandleVisibility','CallBack');

%======================================================       
function A=getAndmatr();

% This routine creates a 125 x 125 Anderson matrix.
% See the following reference for the matrix:
%
% U. Elsner, V. Mehrmann, F. Milde, R. Romer, and M. Schreiber,
% "The Anderson Model of Localization a Challenge for Modern
%  Eigenvalue Methods", SIAM J. Sci. Comput., Vol. 20, No. 6, 
%  pp. 2089-2102.
rand('state',0);
d=rand(125,1)-0.5*ones(125,1);
n = 5; omega=16.5; X=eye(125);
for i=1:125
   A(i,:)=omega*d(i)*X(i,:);
   if mod(i,n)>1, A(i,:)=A(i,:)+X(i-1,:)+X(i+1,:); end
   if mod(i,n)==0,A(i,:)=A(i,:)+X(i-1,:); end
   if mod(i,n)==1,A(i,:)=A(i,:)+X(i+1,:);end
   nsq=25;
   if mod(i,nsq)>n 
      if mod(i,nsq)<(nsq-n+1)
         A(i,:)=A(i,:)+X(i-n,:)+X(i+n,:);
      end
   end
   if (mod(i,nsq)<(n+1))&(mod(i,nsq)>0)
      A(i,:)=A(i,:)+X(i+n,:);
   end
   if (mod(i,nsq)==0), A(i,:)=A(i,:)+X(i-n,:); end
   if (mod(i,nsq)>nsq-n),A(i,:)=A(i,:)+X(i-n,:);end
   if (i>nsq)&(i<(n^3-nsq+1))
      A(i,:)=A(i,:)+X(i+nsq,:)+X(i-nsq,:);
   end
   if i<(nsq+1),A(i,:)=A(i,:)+X(i+nsq,:); end
   if i>n^3-nsq, A(i,:)=A(i,:)+X(i-nsq,:);end
end

function Helpdemo

HelpStr={'Implicitly Restarted Block Lanczos Method Demonstration';
' ';
' IRBLEIGS: Computes a few eigenvalues and eigenvectors of a Hermitian matrix.';
' ';
' IRBLEIGS will compute a few eigenvalues and eigenvectors for either the'; 
' standard eigenvalue problem A*x = lambda*x or the generalized eigenvalue'; 
' problem A*x = lambda*M*x where the matrix A is a sparse Hermitian matrix'; 
' and the matrix M is positive definite.';
' ';
' This demo is to help illustrate the different options that are available ';
' in the IRBLEIGS routine. The user must select a matrix either by choosing ';
' a radio button next to a preset matrix or entering a matrix in the text field ';
' provided. The user can then change some or all of the options on the left hand ';
' side of the figure by using the pull down menus. After selecting a matrix and ';
' setting the options use the ''Get Eigs.'' button to find the eigenvalues.';
' ';
' Pressing the right mouse button when the mouse is over the option will give';
' a short explanation of the option.';
' ';
' SIGMA - Two letter string specifying the location of the desired eigenvalues.';
'         SE - Smallest eigenvalues.';
'         LE - Largest eigenvalues. ';
'         NUMERIC VALUE - IRBLEIGS will find the K eigenvalues near the numeric value';
'                         that was inputted by the user. Note this option requires ';
'                         that two intervals must be picked which needs 4 different ';
'                         Ritz values for endpoints. IRBLEIGS may increase NBLS to';
'                         accomplish this requirement.';
'  ';
' K    -  Number of desired eigenvalues.';
' ';
' BLSZ - Block size of Lanczos Tridiagonal matrix. ';
' ';
' NBLS - Number of blocks of the Lanczos Tridiagonal matrix. ';
' ';
' ZERTYP - Two letter string to indicate which type of shift is to be used.';
'          WL - Weighted fast Leja points.'; 
'          ML - Mapped fast Leja points. Fast Leja points are computed on [-2,2] ';
'               and mapped to the dampening interval. This option is not available';
'               when sigma is a numeric value.';
' ';
' MAXDPOL - Maximum degree of the damping polynomial .';
' ';
' ENDPT  - Three letter string specifying the location of the interior end point for';
'          the dampening interval.'; 
'          FLT - Let the interior end point(s) float. ';                  
'          MON - Interior end points are chosen so that the size of the dampening interval';
'                is increasing.';
' ';
' SIZINT - Size of the dampening interval. Value of 1 indicates consecutive';
'          Ritz values are used to determine the endpoints of the dampening';
'          interval. Value of 2 indicates endpoints are chosen from Ritz';
'          values that are seprated by a single Ritz value. A value of 3';
'          indicates endpoints are chosen from Ritz values that are seprated'; 
'          by two Ritz values. Etc. ';
' ';
' MAXIT  - Maximum number of iterations.';
' ';
' TOL    - Tolerance used for convergence. Convergence is determined when ';            
'         || Ax - lambda*x ||_2 <= TOL*||A||_2. ||A||_2 is approximated by ';
'         largest absolute Ritz value.  ';
' ';
' REFERENCES: ';
'   1.) "IRBL: An Implicitly Restarted Block Lanczos Method for large-scale Hermitian'; 
'        eigenproblems", J. Baglama, D. Calvetti, and L. Reichel, SIAM J. Sci. Comput.,';
'        in press 2003.';
'   2.) "irbleigs: A MATLAB program for computing a few eigenpairs of a large sparse';
'        Hermitian matrix", J. Baglama, D. Calvetti, and L. Reichel, Technical Report';
'        submitted for publication (2001).';
'   3.) "Dealing With Linear Dependence during the Iterations of the Restarted';
'        Block Lanczos Methods", J. Baglama, Num. Algs., 25, (2000) pp. 23-36.'; 
'   4.) "Fast Leja Points", J. Baglama, D. Calvetti, and L. Reichel, ETNA, ';
'        Vol. 7 (1998), pp. 124-140.';
'   5.) "Computation of a few close eigenvalues of a large matrix with'; 
'        application to liquid crystal modeling", J. Baglama, D. Calvetti,'; 
'        L. Reichel, and A. Ruttan, J. of Comp. Phys., 146 (1998), pp. 203-226.';
'   6.) "Iterative Methods for the Computation of a Few Eigenvalues of a Large'; 
'        Symmetric Matrix", J. Baglama, D. Calvetti, and L. Reichel, BIT, 36'; 
'        (1996), pp. 400-421.';
' ';
'  AUTHORS:';
'  James Baglama     Ball State University, E-mail: jbaglama@math.bsu.edu';
'  Daniela Calvetti  Case Western Reserve University,  E-mail: dxc57@po.cwru.edu';
'  Lothar Reichel    Kent State University, E-mail: reichel@mcs.kent.edu';
' ';
'  DATE:  10/10/2002';
' ';};
      
helpwin(HelpStr,'IRBLDEMO Help');
         
