function vbm5(varargin)
% vbm5.m: 
% Creation of custom template, followed by 
% VBM preprocessing with custom template T1 or T2 images with SPM2.
% This uses method 5 from my paper, 
% "Comparison of different methodological implementations of VBM in neurodegenerative disease"
% Please note, with some setup work,
% this can be configured to run over Sun Grid Engine.  (SGE)
% By default SGE mode is disabled, but you can
% un-comment line 12 in vbm.m and line 19 in make_template.m 
% to allow SGE mode to be used. you will need to make some other changes in
% the code also.  Email me with any questions about SGE mode.
%
% SEE ALSO: vbm_ui.m
% Jan. 10, 2006
% Matthew L. Senjem
% Mayo Clinic 
% Senjem.Matthew1@mayo.edu
%
% When using this code, please reference the following paper:
%
% Senjem ML, Gunter JL, Shiung MM, Petersen RC, Jack CR Jr., "Comparison of different methodological implementations of voxel-based
% morphometry in neurodegenerative disease." Neuroimage. 2005 Jun;26(2):600-8. 

if nargin
    for i=1:nargin
        v=varargin{i};
        if isstr(v)         
            if (strcmpi(v,'t1') | strcmpi(v,'t2') | strcmpi(v,'spect') | strcmpi(v,'pet')| strcmpi(v,'epi')| strcmpi(v,'pd')| strcmpi(v,'transm')) 
                modality=v;
            else 
                ImgList = v;
            end
        end
    end
end
if ~exist('modality','var')
    moda = spm_input('Modality?',1,'m','T1|T2',[1 2], 1);
    switch moda
        case 1
            modality='t1';
        case 2
            modality='t2';
    end
end
if exist('ImgList','var')
    imgVols=spm_vol(ImgList);
    rotate = spm_input('Adjust pitch on oblique images (0.5 radians)?','+1','m','Yes|No',[1 0], 1);
    if rotate
        imgVols=adjust_pitch(imgVols,0.5);
    end
else
    imgVols = spm_vol(spm_get(Inf,'*.IMAGE','Select Input Images'));%imgVols='';
end
optimal = spm_input('Normalize to Whole Head/GM/WM ?',1,'m','Normalize to Whole Head|Normalize to GM prior|Normalize to WM prior',[0 1 2], 1);
[template,priors,imgVols]=make_template('',modality,imgVols,optimal);
[pth,nam,ext] = fileparts(template);
templatedir=pth;
template_cell{1} = [templatedir,'/s8template.img'];
template_cell{2} = [templatedir,'/s8gray.img'];
template_cell{3} = [templatedir,'/s8white.img'];
template_cell{4} = [templatedir,'/s8csf.img'];
numsubjects=length(imgVols);

% if ~exist('template_cell','var')
%     template_cell{1} = spm_get(1,'s8template*.IMAGE','Select template for normalization');
%     template_cell{2} = spm_get(1,'s8gray*.IMAGE','Select gray matter prior'); 
%     template_cell{3} = spm_get(1,'s8white*.IMAGE','Select white matter prior');
%     template_cell{4} = spm_get(1,'s8csf*.IMAGE','Select CSF prior');
% end
%if ~exist('numsubjects','var')
%    numsubjects = input('how many subjects?');
%end
mls_fluid_prep('pet','vbmonly','numsubjects',numsubjects,'norm2custom',template_cell,'smooth',12,'imgVols',imgVols,'optimal',optimal);