%% load data

dirID = 'C:\Users\Jon\Desktop\mingledorf\2012-09-25_goon21367_MEA_6well\';
fid = 'goon21367_17DIV_wash4-5_01';
loadspk([dirID fid '.spk'],[0 24*3600],[]);

w(1,:) = [3 4 5 12 13 20 21 28 29];
w(2,:) = [7 14 15 16 22 23 24 30 31];
w(3,:) = [38 39 40 46 47 48 55 56 63];
w(4,:) = [36 37 44 45 52 53 60 61 62];
w(5,:) = [34 35 41 42 43 49 50 51 58];
w(6,:) = [2 9 10 17 18 19 25 26 27];

time = ans.time;
channel = ans.channel;
unit = ans.unit;
meta = ans.meta;
%waveform = ans.waveform;
threshold = ans.threshold;

save([dirID fid '.mat'],'time','channel','unit','meta','threshold');

%% generate asdr
clear t asdr
dt = 3600;
bins = ceil(min(time)/dt)*dt:dt:floor(max(time)/dt)*dt;
asdr = zeros(6,length(bins));

for i = 1:6
    %t{i} = time(clean==1 & ismember(channel,w(i,:))==1);
    t{i} = time(ismember(channel,w(i,:))==1);
    %c{i} = channel(clean==1 & ismember(channel,w(i,:))==1);
    asdr(i,:) = hist(t{i},bins)/dt;
end

%% plot stuff
for i = 1:6
    subplot(6,1,i)
    hold off;
    %stairs(bins/3600-max(bins/3600),asdr(i,:),'-k');
    %stairs(bins/3600,asdr(i,:),'-k');
    stairs(bins/3600,asdr(i,:),'-k','LineWidth',2);
    %stairs(bins/60,asdr(i,:),'-k');
    %plot(bins(1:end-1)/3600+.5,asdr(i,1:end-1),'-ok','LineWidth',2,'MarkerSize',5);
    %xlim([48 24*5]);
    %ylim([0 1000]);
    %set(gca,'YScale','log')
    %set(gca,'XTick',-224:4:max(time)/3600);
    ylabel('ASDR (Hz)');
end

%xlabel('Time (minutes)');
xlabel('Time (hours)');

%subplot(6,1,1);
%title(['fatty21369 (24-hour pre-recording)']);

for i = 1:6
subplot(6,1,i)
set(gca,'TickLength',[0.0025 0.025],'TickDir','out','XTick',[-24:4:72]);
axis([-18 72 0 21]);
end