% processedRecordings = importdata('behavior_recordings');
files = dir('2017*');
% Get a logical vector that tells which is a directory.
dirFlags = [files.isdir];
% Extract only those that are directories.
subFolders = files(dirFlags);

c=1
for i=1:length(subFolders)
   cd(subFolders(i).name)
   
%    if exist('ripples_ls.mat') && exist('ripples_hpc.mat')
%        load('ripples_hpc.mat')
%        load('ripples_ls.mat')
%        t{1} = ripples_hpc(:,2);
%        t{2} = ripples_ls(:,2);
%        [times groups]=spikes2sorted(t);
%        [ccg{i} time{i}]=CCG(times,groups,'binSize',.001,'duration',.5);
%    end
% if exist('ripple_modulation.mat')
%    load ripple_modulation
%    dat(c).ripple_mod = ripple_mod;
%    dat(c).units = units;
%    dat(c).numRipples = numRipples;
%    c=c+1; 
% end
% if exist('psd_behav.mat')
%     dat(i) = importdata('psd_behav.mat');
%     
%     
% end
%     if exist('hpc_theta_phaselocking.mat')
%       load hpc_theta_phaselocking
%       f =find(units(:,1)<5);
%       for j=1:length(f)
% %           r = (rand(length(histo{j}),1)-.5)*2*pi;
% %           polarplot([0 circ_mean(histo{j})],[0 circ_r(histo{j})],'k')
% %           polarplot([0 circ_mean(r)],[0 circ_r(r)],'r')
%           dat(i).spike_phase_histograms{j} = histo{j};
%          hold on 
%       end    
% %        
%     end
   
%    if exist('phaselocking_power_thresh.mat')
%         temp = importdata('phaselocking_power_thresh.mat');
%         dat(c).freqs = temp.freqs;
%         dat(c).spike_phase_histograms = temp.spike_phase_histograms;
%         dat(c).spike_phase_pval = temp.spike_phase_pval;
%         dat(c).spike_phase_zscore = temp.spike_phase_zscore;
%         subFolders(i).name
%          c=1+c;
%    end
   if ~isempty(dir('behav*')) && ~isempty(dir('*clu*'))
       b=dir('behav*');
       temp = importdata(b.name);
       dat(c).name = subFolders(i).name;
       dat(c).map = temp.map;
       dat(c).mapping = temp.mapping;
       dat(c).trials = temp.trials;
       dat(c).pos = temp.pos; 
%        load meta
       SetCurrentSession
       dat(c).units = GetUnits();
       for j=1:length(dat(c).units(:,1)<5)
          dat(c).spikes{j}=GetSpikeTimes(dat(c).units(j,:)); 
       end
       dat(c).lfp = bz_GetLFP([37]);
       [dat(c).rateMap dat(c).occuMap dat(c).phaseMap] = spaceRateMap(dat(c).spikes,dat(c).pos,dat(c).map,dat(c).mapping,dat(c).trials,dat(c).lfp);
       c=1+c;
       %    load behav
%    [trials,mapping,map] = updateMappingVar(trials,mapping,map);
%     save('behav.mat','x','y','trials','map*','pos')
   end
   cd ..   
end

save('DT8_current_dataset_parietal_theta.mat','-v7.3')