function vbm_mni(varargin)
% vbm_mni.m: VBM preprocessing with MNI template T1 or T2 images with SPM2.
% 
% 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. 

spm_defaults;
global defaults
moda = spm_input('Modality?',1,'m',...
	'T1|T2',[1 2], 1);

switch moda
    case 1
        modality='t1';
    case 2
        modality='t2';
end
if nargin & strcmpi(varargin{1},'sge') 
    sge=1;
    if ~exist('results_dir','var')
        results_dir = spm_input('Directory to save results in?','+1','s',pwd);
        cd(results_dir)
    end
else
    sge=0;
end

imgVols = spm_vol(spm_get(Inf,'*.IMAGE','Select Input Images'));
rotate = spm_input('Adjust pitch on oblique images (0.5 radians)?','+1','m','Yes|No',[1 0], 1);
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);
if rotate
    imgVols=adjust_pitch(imgVols,0.5,1);
end

if ~exist('numsubjects','var')
    numsubjects = length(imgVols);
end
if sge
%     srccall =    'source /usr/local/sge/default/common/settings.sh';
%     system(srccall);
    sge_mls_fluid_prep('pet','vbmonly','numsubjects',numsubjects,'norm2mni',modality,'smooth',12,'imgVols',imgVols,'results_dir',results_dir,'optimal',optimal)
else
    mls_fluid_prep('pet','vbmonly','numsubjects',numsubjects,'norm2mni',modality,'smooth',12,'imgVols',imgVols,'optimal',optimal)
end