function [matlabbatch] = preprocessing_job(filesList)

%%%%%%% Preprocessing

matlabbatch{1}.spm.temporal.st.scans = filesList;

matlabbatch{1}.spm.temporal.st.nslices = 33;
matlabbatch{1}.spm.temporal.st.tr = 2;
matlabbatch{1}.spm.temporal.st.ta = 1.93939393939394;
matlabbatch{1}.spm.temporal.st.so = [1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32];
matlabbatch{1}.spm.temporal.st.refslice = 33;
matlabbatch{1}.spm.temporal.st.prefix = 'a';
matlabbatch{2}.spm.spatial.realign.estwrite.data{1}(1) = cfg_dep;
matlabbatch{2}.spm.spatial.realign.estwrite.data{1}(1).tname = 'Session';
matlabbatch{2}.spm.spatial.realign.estwrite.data{1}(1).tgt_spec{1}(1).name = 'filter';
matlabbatch{2}.spm.spatial.realign.estwrite.data{1}(1).tgt_spec{1}(1).value = 'image';
matlabbatch{2}.spm.spatial.realign.estwrite.data{1}(1).tgt_spec{1}(2).name = 'strtype';
matlabbatch{2}.spm.spatial.realign.estwrite.data{1}(1).tgt_spec{1}(2).value = 'e';
matlabbatch{2}.spm.spatial.realign.estwrite.data{1}(1).sname = 'Slice Timing: Slice Timing Corr. Images (Sess 1)';
matlabbatch{2}.spm.spatial.realign.estwrite.data{1}(1).src_exbranch = substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1});
matlabbatch{2}.spm.spatial.realign.estwrite.data{1}(1).src_output = substruct('()',{1}, '.','files');
matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.quality = 0.9;
matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.sep = 4;
matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.fwhm = 5;
matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.rtm = 1;
matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.interp = 2;
matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.wrap = [0 0 0];
matlabbatch{2}.spm.spatial.realign.estwrite.eoptions.weight = {''};
matlabbatch{2}.spm.spatial.realign.estwrite.roptions.which = [0 1];
matlabbatch{2}.spm.spatial.realign.estwrite.roptions.interp = 4;
matlabbatch{2}.spm.spatial.realign.estwrite.roptions.wrap = [0 0 0];
matlabbatch{2}.spm.spatial.realign.estwrite.roptions.mask = 1;
matlabbatch{2}.spm.spatial.realign.estwrite.roptions.prefix = 'r';
matlabbatch{3}.spm.spatial.coreg.estimate.ref = {'/Users/fsh880/Documents/MATLAB/SPM/spm8/templates/EPI.nii,1'};
matlabbatch{3}.spm.spatial.coreg.estimate.source(1) = cfg_dep;
matlabbatch{3}.spm.spatial.coreg.estimate.source(1).tname = 'Source Image';
matlabbatch{3}.spm.spatial.coreg.estimate.source(1).tgt_spec{1}(1).name = 'filter';
matlabbatch{3}.spm.spatial.coreg.estimate.source(1).tgt_spec{1}(1).value = 'image';
matlabbatch{3}.spm.spatial.coreg.estimate.source(1).tgt_spec{1}(2).name = 'strtype';
matlabbatch{3}.spm.spatial.coreg.estimate.source(1).tgt_spec{1}(2).value = 'e';
matlabbatch{3}.spm.spatial.coreg.estimate.source(1).sname = 'Realign: Estimate & Reslice: Mean Image';
matlabbatch{3}.spm.spatial.coreg.estimate.source(1).src_exbranch = substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1});
matlabbatch{3}.spm.spatial.coreg.estimate.source(1).src_output = substruct('.','rmean');
matlabbatch{3}.spm.spatial.coreg.estimate.other(1) = cfg_dep;
matlabbatch{3}.spm.spatial.coreg.estimate.other(1).tname = 'Other Images';
matlabbatch{3}.spm.spatial.coreg.estimate.other(1).tgt_spec{1}(1).name = 'filter';
matlabbatch{3}.spm.spatial.coreg.estimate.other(1).tgt_spec{1}(1).value = 'image';
matlabbatch{3}.spm.spatial.coreg.estimate.other(1).tgt_spec{1}(2).name = 'strtype';
matlabbatch{3}.spm.spatial.coreg.estimate.other(1).tgt_spec{1}(2).value = 'e';
matlabbatch{3}.spm.spatial.coreg.estimate.other(1).sname = 'Realign: Estimate & Reslice: Realigned Images (Sess 1)';
matlabbatch{3}.spm.spatial.coreg.estimate.other(1).src_exbranch = substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1});
matlabbatch{3}.spm.spatial.coreg.estimate.other(1).src_output = substruct('.','sess', '()',{1}, '.','cfiles');
matlabbatch{3}.spm.spatial.coreg.estimate.eoptions.cost_fun = 'nmi';
matlabbatch{3}.spm.spatial.coreg.estimate.eoptions.sep = [4 2];
matlabbatch{3}.spm.spatial.coreg.estimate.eoptions.tol = [0.02 0.02 0.02 0.001 0.001 0.001 0.01 0.01 0.01 0.001 0.001 0.001];
matlabbatch{3}.spm.spatial.coreg.estimate.eoptions.fwhm = [7 7];
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.source(1) = cfg_dep;
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.source(1).tname = 'Source Image';
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.source(1).tgt_spec{1}(1).name = 'filter';
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.source(1).tgt_spec{1}(1).value = 'image';
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.source(1).tgt_spec{1}(2).name = 'strtype';
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.source(1).tgt_spec{1}(2).value = 'e';
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.source(1).sname = 'Realign: Estimate & Reslice: Mean Image';
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.source(1).src_exbranch = substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1});
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.source(1).src_output = substruct('.','rmean');
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.wtsrc = '';
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.resample(1) = cfg_dep;
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.resample(1).tname = 'Images to Write';
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.resample(1).tgt_spec{1}(1).name = 'filter';
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.resample(1).tgt_spec{1}(1).value = 'image';
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.resample(1).tgt_spec{1}(2).name = 'strtype';
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.resample(1).tgt_spec{1}(2).value = 'e';
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.resample(1).sname = 'Coregister: Estimate: Coregistered Images';
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.resample(1).src_exbranch = substruct('.','val', '{}',{3}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1});
matlabbatch{4}.spm.spatial.normalise.estwrite.subj.resample(1).src_output = substruct('.','cfiles');
matlabbatch{4}.spm.spatial.normalise.estwrite.eoptions.template = {'/Users/fsh880/Documents/MATLAB/SPM/spm8/templates/EPI.nii,1'};
matlabbatch{4}.spm.spatial.normalise.estwrite.eoptions.weight = '';
matlabbatch{4}.spm.spatial.normalise.estwrite.eoptions.smosrc = 8;
matlabbatch{4}.spm.spatial.normalise.estwrite.eoptions.smoref = 0;
matlabbatch{4}.spm.spatial.normalise.estwrite.eoptions.regtype = 'mni';
matlabbatch{4}.spm.spatial.normalise.estwrite.eoptions.cutoff = 25;
matlabbatch{4}.spm.spatial.normalise.estwrite.eoptions.nits = 16;
matlabbatch{4}.spm.spatial.normalise.estwrite.eoptions.reg = 1;
matlabbatch{4}.spm.spatial.normalise.estwrite.roptions.preserve = 0;
matlabbatch{4}.spm.spatial.normalise.estwrite.roptions.bb = [-78 -112 -50 78 76 85];
matlabbatch{4}.spm.spatial.normalise.estwrite.roptions.vox = [2 2 2];
matlabbatch{4}.spm.spatial.normalise.estwrite.roptions.interp = 1;
matlabbatch{4}.spm.spatial.normalise.estwrite.roptions.wrap = [0 0 0];
matlabbatch{4}.spm.spatial.normalise.estwrite.roptions.prefix = 'w';
matlabbatch{5}.spm.spatial.smooth.data(1) = cfg_dep;
matlabbatch{5}.spm.spatial.smooth.data(1).tname = 'Images to Smooth';
matlabbatch{5}.spm.spatial.smooth.data(1).tgt_spec{1}(1).name = 'filter';
matlabbatch{5}.spm.spatial.smooth.data(1).tgt_spec{1}(1).value = 'image';
matlabbatch{5}.spm.spatial.smooth.data(1).tgt_spec{1}(2).name = 'strtype';
matlabbatch{5}.spm.spatial.smooth.data(1).tgt_spec{1}(2).value = 'e';
matlabbatch{5}.spm.spatial.smooth.data(1).sname = 'Normalise: Estimate & Write: Normalised Images (Subj 1)';
matlabbatch{5}.spm.spatial.smooth.data(1).src_exbranch = substruct('.','val', '{}',{4}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1});
matlabbatch{5}.spm.spatial.smooth.data(1).src_output = substruct('()',{1}, '.','files');
matlabbatch{5}.spm.spatial.smooth.fwhm = [8 8 8];
matlabbatch{5}.spm.spatial.smooth.dtype = 0;
matlabbatch{5}.spm.spatial.smooth.im = 0;
matlabbatch{5}.spm.spatial.smooth.prefix = 's';


spm('defaults','fmri');
spm_jobman('initcfg');
spm_jobman('run',matlabbatch);

end

