%% prelim

fid_prefix = 'buster359';
%load(['C:\Users\USER\Documents\mingfaifong\' fid_prefix '\' fid_prefix '_nowaveform.mat']);
load(['C:\Users\USER\Documents\mingfaifong\' fid_prefix '\' fid_prefix '_FullRecNoWaveformNoClean.mat']);
%time = spktimes(cleanspk==1); channel = channels(cleanspk==1);
%clear channels cleanspk spktimes
[e1 e2] = get_events(fid_prefix);
time = time - e1(1);

%% asdr stuff

dt = 3600;
bins = [floor(min(time)/3600):1:ceil(max(time))/3600]*3600;
asdr = histc(time,bins)/dt;
plot(bins,asdr,'.','MarkerSize',15);
if iseven(round(min(time)/3600))
    set(gca,'XTick',[round(min(time)/3600):2:ceil(max(time)/3600)]*3600,...
        'XTickLabel',[round(min(time)/3600):2:ceil(max(time)/3600)]);
    xlim([min(bins) max(bins)]);
else
    set(gca,'XTick',[round(min(time)/3600)-1:2:ceil(max(time)/3600)]*3600,...
        'XTickLabel',[round(min(time)/3600)-1:2:ceil(max(time)/3600)]);
    xlim([min(bins) max(bins)]);
end
ymax = ceil(max(asdr)/10)*10;
ylim([0 ymax]);
grid on;
xlabel('Time (hours)','FontSize',18);
ylabel('Array-Wide Spike Rate (Hz)','FontSize',18);
title([fid_prefix ' (ASDR for 1-hour bins)'],'FontSize',14);


for i = 1:length(e1)
    text(bins(2),ymax-i*.05*ymax,[char(num2str(round((e1(i)/3600+min(time)/3600)*100)/100)) 'hr: ' char(e2(i))]);
end
    

%% save stuff
    print('-depsc',[fid_prefix '_ASDR_bin1hr.eps']);
    screen2png(gcf,[fid_prefix '_ASDR_bin1hr.png'],'C:\Users\USER\Documents\mingfaifong\');
    saveas(gcf,[fid_prefix '_ASDR_bin1hr.fig'],'fig');