%  Gplot graphical output related to patterns of rotations.
%
%    Gplot(Grot,Gind) plots graphically the rotations in schemes,
%    like the ones frequently used in the articles.
%    
%    Gplot(Grot,Gind,n)
%    n is optional, contains the number of rows of the matrix the rotations
%    have to act on, otherwise the largest index found is taken.
%
%    Gplot(Grot,Gind,n,tol)
%    tol sets the tolerance to for which a rotation gets zero, this is
%    optional, otherwise set to 10^(-16)
%
%
%    Software written by Raf Vandebril
%    raf.vandebril-at-cs.kuleuven.be
%    Revision Date: August 30, 2010
%


function Gplot(Grot,Gind,n,tol)
  
  % Initialization 
    xaxis=max(Gind(:,3)); % Number of vertical lines in the sequential
                          % representation
                        
    if ~exist('n')
      n=max(Gind(:,2));
    end
    
    
    if ~exist('tol')
      tol=10^(-16);
    end
    
    
    
  % plot for every rotation a vertical line so to generate the scheme
  h = figure('XVisual','0x24 (TrueColor, depth 24, RGB mask 0xff0000 0xff00 0x00ff)');

  %h=newplot;
  %hold on;
  axesh = axes('Parent',h);
  
  xlim(axesh,[0,xaxis+1]);
  ylim(axesh,[-n,-1]);
  set(axesh,'YTick',[-n:-1]);
  set(axesh,'YTickLabel',{'5','4','3','2','1'})  
  set(axesh,'YTickLabel',[n:-1:1])  
  
  hold(axesh,'all');
  for cnt=1:size(Gind,1)
    if (abs(Grot(2,cnt))>tol)
        plot([Gind(cnt,3),Gind(cnt,3)],[-Gind(cnt,1),-Gind(cnt,2)],'o-b')
        %pause
    end
  end
  hold off;
  
  
  
    
  
  
