% Jon Newman
% 2013.12.11

fs_wave = 24414;
fs_ds_wave = 1000;
fs_lfp = 24414;

%% This tank/block
tank_loc = 'C:\Users\jon\Documents\2013_Optoclamp-Analysis\2013_12_In-Vivo_Optoclamp\2013_12_13_A';
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_10(TT, block_loc, fs_wave, fs_ds_wave, fs_lfp);
    
    if suc
        
        % Squeaky spk
        ss = SqueakySpk(block_loc,fs_wave,1,spk);
        ss.RemoveUnit(spk.badunits);
        ss.Save;
        save(['./mat/' block_loc], 'spk','wave');
        
    else
        continue
    end
    
end