

%  plot_threee_time_histories_histograms.m  ver 1.1  by Tom Irvine

function[fig_num]=plot_three_time_histories_histograms(fig_num,...
    xlabel2,ylabel1,ylabel2,ylabel3,data1,data2,data3,t_string1,t_string2,t_string3,nbars)


if(nbars>100)
    nbars=100;
end

%%%

figure(fig_num)
plot(data1(:,1),data1(:,2));
[x1]=get(gca,'ylim');


%%%

figure(fig_num)
plot(data2(:,1),data2(:,2));
[x2]=get(gca,'ylim');


%%%

figure(fig_num)
plot(data3(:,1),data3(:,2));
[x3]=get(gca,'ylim');

%%%

figure(fig_num)
xx=max(abs(x1));
x=linspace(-xx,xx,nbars);
[ii1,jj1]=hist(data1(:,2),x);
hmax=max(ii1);
N=floor(log10(hmax));
M=10^N;
yabs1=max([ max(abs(ii1))  max(abs(jj1)) ]);


%%%

figure(fig_num)
xx=max(abs(x2));
x=linspace(-xx,xx,nbars);
[ii2,jj2]=hist(data2(:,2),x);
yabs2=max([ max(abs(ii2))  max(abs(jj2)) ]);


%%%

figure(fig_num)
xx=max(abs(x3));
x=linspace(-xx,xx,nbars);
[ii3,jj3]=hist(data2(:,2),x);
yabs3=max([ max(abs(ii3))  max(abs(jj3)) ]);

yabs=max([yabs1 yabs2 yabs3]);


n1=max(abs(data1(:,2)));
n2=max(abs(data2(:,2)));
n3=max(abs(data3(:,2)));

yq=max([ n1 n2 n3 ]);

[yy]=ytick_linear_altp(yq);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

hp=figure(fig_num);

subplot(3,3,3);

if(hmax>=1000)
    bar(jj1,ii1/M,1);
    yyss=sprintf('Counts x 10^{%d}',N);
    ylabel(yyss);
    
    [ymax,yTT,ytt,iflag]=ytick_linear_double_sided(yabs/M);

    yym=ymax;
    
    if(iflag==1)
        set(gca,'ytick',ytt);
        set(gca,'YTickLabel',yTT);
        ylim([min(ytt),max(ytt)]);
    end
    ylim([0,yym]);
else
    bar(jj1,ii1,1);
    ylabel('Counts');    
end

title('Histogram');
xlabel(ylabel1);
xlim([-yy,yy]);
ytickformat('%g')
grid on;
set(gca,'view',[90 -90]);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

subplot(3,3,6);

if(hmax>=1000)
    bar(jj2,ii2/M,1);
    yyss=sprintf('Counts x 10^{%d}',N);
    ylabel(yyss);
    
    if(iflag==1)
        set(gca,'ytick',ytt);
        set(gca,'YTickLabel',yTT);
        ylim([min(ytt),max(ytt)]);
    end    
    ylim([0,yym]);
else
    bar(jj2,ii2,1);
    ylabel('Counts');    
end

title('Histogram');
xlabel(ylabel2);
xlim([-yy,yy]);
ytickformat('%g')
grid on;
set(gca,'view',[90 -90])
 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

subplot(3,3,9);

if(hmax>=1000)
    bar(jj3,ii3/M,1);
    yyss=sprintf('Counts x 10^{%d}',N);
    ylabel(yyss);
    
    if(iflag==1)
        set(gca,'ytick',ytt);
        set(gca,'YTickLabel',yTT);
        ylim([min(ytt),max(ytt)]);
    end    
    ylim([0,yym]);
else
    bar(jj3,ii3,1);
    ylabel('Counts');    
end

title('Histogram');
xlabel(ylabel3);
xlim([-yy,yy]);
ytickformat('%g')
grid on;
set(gca,'view',[90 -90])



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

subplot(3,3,[1 2]);
plot(data1(:,1),data1(:,2));
ylim([-yy,yy]);
title(t_string1);
xlabel(xlabel2);
ylabel(ylabel1);
grid on;

%%%

subplot(3,3,[4 5]);
plot(data2(:,1),data2(:,2));
ylim([-yy,yy]);
title(t_string2);
xlabel(xlabel2);
ylabel(ylabel2);
grid on;

%%%

subplot(3,3,[7 8]);
plot(data3(:,1),data3(:,2));
ylim([-yy,yy]);
title(t_string3);
xlabel(xlabel2);
ylabel(ylabel3);
grid on;

%%%

set(hp, 'Position', [0 0 1000 650]);

fig_num=fig_num+1;
