spkdat = load('chronicExcBlock_cnqx-20uM_apv-10uM');
dt = 18000;  %chunk each file into 5hr (18000sec) blocks
n = ceil(max(spkdat.time)/dt);
fidlist = {};

for i = 1:n
    
    clearvars -except spkdat fidlist dt n i
    x1 = find(spkdat.time < dt*(i-1));
    x2 = find(spkdat.time < dt*i);
    ind = x2(length(x1)+1:length(x2));
    
    channel = spkdat.channel(ind);
    time = spkdat.time(ind);
    threshold = spkdat.threshold(ind);
    waveform = spkdat.waveform(:,ind);
    fid = ['frodo364_20uM-CNQX_10uM-APV_',num2str((i-1)*dt/3600),'to',num2str(i*dt/3600),'hr'];
    save(fid,'channel','time','threshold','waveform');
    fidlist = {fidlist; fid};

end