% Jon Newman
% 2014.01.16

fs_spk = 24414;
fs_wave = 4882.81;  % I used a lower sampling frequency this time to reduced disk space requriements
fs_ds_wave = 1000;
fs_lfp = 3051.76; % Did not record LFP

%% This tank/block
tank_loc = 'Z:/2013_12_In-Vivo_Optoclamp/temp';
blocks = dir(tank_loc);

% Open the tank
TT = open_tank(tank_loc);

for i = 1:length(blocks)
    
    % Get next block
    block_loc = blocks(i).name;
    
    mf = what('./mat/');
    if ismember([block_loc '.mat'],mf.mat)
        continue;
    end

    % Get the data
    [suc, spk, wave, ~] = tank_extract_12(TT, block_loc, fs_wave, fs_ds_wave, fs_lfp);
    
    if suc
        
        % Squeaky spk
        ss = SqueakySpk(block_loc,fs_spk,1,spk);
        ss.RemoveUnit(spk.badunits);
        ss.Save;
        save(['./mat/' block_loc], 'spk','wave');
        
    else
        continue
    end
    
end