function [] = dt_hist_code(IARwin, quietwin_index, llatlon, matched_dt, matched_B, lEnergy)

% Dt code

timeindexvec = [quietwin_index, 1/IARwin(3)*IARwin(1)+1:1/IARwin(3)*IARwin(2)];
%timeindexvec = 1:2*IARwin(1);
%timeindexvec = 2*IARwin(2)+1:47;
f1=figure;
f2=figure;
bins = linspace(0,4,40);
%bins = logspace(-2,1,40);
for i = 1:length(timeindexvec)
    figure(f1);
    ax(i)=subplot(3,4,i);
    x = abs(matched_dt{timeindexvec(i)}); %llatlon{timeindexvec(i)}(:,3); %lEnergy{timeindexvec(i)}/max(lEnergy{timeindexvec(i)});
    y = abs(matched_B{timeindexvec(i)});%/max(abs(matched_B{timeindexvec(i)}));
    if isempty(x) || isempty(y)
        continue
    end
    Fit = polyfit(x,y,1);
    scatter(x,y);
    hold on
    %plot(x,Fit(1)*x+Fit(2));
    plot(x,polyval(Fit,x));
    %all_dt = diff(3600*hour(sort(ptimes{timeindexvec(i),2}))+60*minute(sort(ptimes{timeindexvec(i),2}))+second(sort(ptimes{timeindexvec(i),2})));
    %histogram(all_dt(all_dt<4),bins);
    %set(gca,'xscale','log')
    %xlabel('delta(t) (seconds) between matched events');
    %ylabel('counts');
    xlabel('Matched dt (s)');
    ylabel('Matched B (nT)');
    title(strcat('20090824MSTK-Hour\_',num2str(timeindexvec(i)*IARwin(3)-IARwin(3)),'-',num2str(timeindexvec(i)*IARwin(3))));
    figure(f2);
    ax1(i)=subplot(3,4,i);
    histogram(x,'BinWidth',1000);
    xlabel('Matched dt (s)');
    ylabel('Count');
    title(strcat('20090824MSTK-Hour\_',num2str(timeindexvec(i)*IARwin(3)-IARwin(3)),'-',num2str(timeindexvec(i)*IARwin(3))));
end
   linkaxes(ax,'xy')
   linkaxes(ax1,'xy')
end