
% check to make sure onsets are same across subjects
% by Dara Ghahremani (dara@psych.stanford.edu) - 10/24/03

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % get subject dirs
    dirs = spm_get(-Inf, '.img', 'Select subject directories to add');
    dirs = cellstr(dirs);
    dirs = deblank(dirs);
    for i = 1:length(dirs)
        [dummy_dir, dummy_file, dummy_ext] = fileparts(dirs{i});
        if (strcmp(dummy_ext,'.') | strcmp(dummy_ext,'')) & isempty(dummy_file)
            % we've selected a directory from within it, and
            % hence subj_name ends in /.  So let's strip it
            dirs{i} = dummy_dir;
        end
    end

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % get results dir
    dir = spm_get(-1, '.img', 'Select results directory from one subject');
    dir = deblank(dir);

    [dummy_dir, display_dir, dummy_ext] = fileparts(dir);
    if strcmp(dummy_ext, '.') & isempty(display_dir)
        % dir ends in /., so strip those
        dir = dummy_dir;     
        display_dir = dummy_dir;
        [dummy_dir, display_dir] = fileparts(display_dir);
    end
    
    % initial guess at resdir
    [dummy_dir, resdir] = fileparts(dir);
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % get template for comparison
    templateFile = spm_get(Inf, '.mat', 'Select template SPM.mat file ');
    template=load(templateFile);
    %template=load('/gablab/ggolarai/disk0/loc2003/model_templates/results_lo1a_1bk/SPM_fMRIDesMtx')

dirs
resdir
template

subjects=dirs;

for subj=1:length(subjects),

    fprintf('\n*** Subject: %s\n',subjects{subj});

   %subjdir=fullfile('/gablab/ggolarai/disk0/loc2003/',subjects{subj},'results1');
   subjdir = fullfile(subjects{subj},resdir);
   
   cd(subjdir)
   load SPM.mat
   Sess{1}.name
   for sess=1:length(Sess),
    for cond=1:length(template.Sess{sess}.ons),
   	if length(template.Sess{sess}.ons{cond})==length(Sess{sess}.ons{cond}),
	   if template.Sess{sess}.ons{cond}==Sess{sess}.ons{cond},
                fprintf('Subject %s, Session %d, Cond %d (%s) matches template\n', subjects{subj},sess,cond,Sess{1}.name{cond});
%		(Sess{sess}.ons{cond} - xX.dt) / xX.RT
           else
                fprintf('Subject %s, Session %d, Cond %d (%s) DOES NOT MATCH TEMPLATE\n', subjects{subj},sess,cond,Sess{1}.name{cond});
		(Sess{sess}.ons{cond} - xX.dt) / xX.RT	
 	   end
	else
                fprintf('Subject %s, Session %d, Cond %d (%s) DOES NOT MATCH TEMPLATE\n', subjects{subj},sess,cond,Sess{1}.name{cond});
		(Sess{sess}.ons{cond} - xX.dt) / xX.RT	
	end
    end
   end
end    

% /xX.RT) - xX.dt