function icatb_ttest_maps(c, files, outputDir, group1Name)
% Function to do one sample t-test on the selected files using SPM5
% functions.
%
% Inputs:
% 1. c - Data structure containing defaults for factorial design
% 2. files - Input files
% 3. outputDir - Output directory
% 4. group1Name - Group Name
%

spm_defaults;

global defaults;

if ~exist('outputDir', 'var')
    outputDir = pwd;
end

if ~exist('group1Name', 'var')
    group1Name = 'group';
end

cd(outputDir);

spmMATFile = fullfile(outputDir, 'SPM.mat');

try
    if exist(spmMATFile, 'file')
        delete(spmMATFile);
    end
catch
end

defaults.modality = 'FMRI';

% Input files
c.val{1}.val{1}.val{1}.val{1}.val{1}.val{1} = cellstr(files);

% Output directory
c.val{1}.val{1}.val{end}.val{1} = {outputDir};

% Get jobs for running batch analysis
[c1, jobs] = spm_jobman('harvest', c);

% Run job
spm_jobman('run', jobs);

% Load SPM.mat
spmInfo = load(spmMATFile);

% Estimate parameters
spmInfo.SPM = spm_spm(spmInfo.SPM);

% T-map contrast
spmInfo.SPM.xCon = spm_FcUtil('Set', group1Name, 'T', 'c', 1, spmInfo.SPM.xX.xKXs);

% SPM Contrasts
spm_contrasts(spmInfo.SPM);
