function plot_grid(signals,imagecolour,autonorm,varargin)

if size(varargin)==1;
correlationgrid=varargin{1};
colorbarlabel=varargin{1};
    if autonorm ==1;
        colorbartitle='Normalised Peak (%)';
    else
        colorbartitle='Peak (Z-Score)';
    end
else correlationgrid=varargin{1};
    colorbarlabel=varargin{2};
    colorbartitle='Peak (Count)';
end

correlationgrid1=correlationgrid
for i=1:length(correlationgrid);
    correlationgrid1(i,i+1:end)=0
    correlationgrid1(i:end,i)=1
end

opengl('software')
figure(6);
set(gcf,'Name','Cross Correlation Grid');clf
if imagecolour==1;
    map=jet(100);
else map=gray(100);
    map=flipud(map);
end
colormap(map);
s=subplot(1,1,1);H=image(correlationgrid);caxis([0,100]);box off;ch=colorbar
set(H,'AlphaData',correlationgrid1)
set(ch,'ytick',[1, 100],'yticklabel', {['0'],['100']});
ylabel(ch,colorbartitle)
set(gca,'XAxisLocation','bottom');
axis square;
xlabel('Target Unit',...
    'fontsize', 14 ...
    ,'fontweight', 'bold');
ylabel('Reference Unit',...
    'fontsize', 14 ...
    ,'fontweight', 'bold');
set(gca, 'YTick',1:length(correlationgrid),...
    'yticklabel',{signals.name});
set(gca, 'XTick', 1:length(correlationgrid),...
    'xticklabel',{signals.name});
     xticklabel_rotate([],90,[]);
set(s,'outerposition',[0 0.1 1 0.9])
%set(gca,'YDir','normal')
%set(gca,'XDir','normal')
set(gcf,'color','w')


