% Pull data
tb = [[2 3];
    [7 10];
    [15 18]];

ts = 0;

% fid = '2013_12_22_Smiley-24729_01';
% spk = loadspk([fid '.spk']);
% bng = loadoc2([fid '.oc2.gz']);

sp.time = [];
sp.channel = [];
sp.unit = [];

oc.meta = bng.meta;
oc.time = [];
oc.targ = [];
oc.meas = [];
oc.filt = [];
oc.erro = [];
oc.erin = [];
oc.clon = [];
oc.mode = [];
oc.out1 = [];
oc.out2 = [];
oc.vlt1 = [];
oc.off1 = [];
oc.per1 = [];
oc.wdt1 = [];
oc.slp1 = [];
oc.vlt2 = [];
oc.off2 = [];

for i = 1:size(tb,1)
    
    tbs = 3600*tb(i,:);
    
    bspk = spk.time >= tbs(1) & spk.time <= tbs(2);
    sp.time = [sp.time; spk.time(bspk) - tbs(1) + ts];
    sp.channel = [sp.channel; spk.channel(bspk)];
    sp.unit = [sp.unit; spk.unit(bspk)];
    
    boc = bng.time >= tbs(1) & bng.time <= tbs(2);
    
    oc.time = [oc.time bng.time(boc) - tbs(1) + ts];
    oc.targ = [oc.targ bng.targ(boc)];
    oc.meas = [oc.meas bng.meas(boc)];
    oc.filt = [oc.filt bng.filt(boc)];
    oc.erro = [oc.erro bng.erro(boc)];
    oc.erin = [oc.erin bng.erin(boc)];
    oc.clon = [oc.clon bng.clon(boc)];
    oc.mode = [oc.mode bng.mode(boc)];
    oc.out1 = [oc.out1 bng.out1(boc)];
    oc.out2 = [oc.out2 bng.out2(boc)];
    oc.vlt1 = [oc.vlt1 bng.vlt1(boc)];
    oc.off1 = [oc.off1 bng.off1(boc)];
    oc.per1 = [oc.per1 bng.per1(boc)];
    oc.wdt1 = [oc.wdt1 bng.wdt1(boc)];
    oc.slp1 = [oc.slp1 bng.slp1(boc)];
    oc.vlt2 = [oc.vlt2 bng.vlt2(boc)];
    oc.off2 = [oc.off2 bng.off2(boc)];
    
    ts = ts + diff(tbs);
    
end

ss = SqueakySpk([fid '_parse'],spk.meta.fs_Hz,1,sp);
ss.RemoveUnit(0);
ss.Save();
save([fid '_oc_parse'],'oc')
