0001 function model_file = configure_er_model(sess_dir, sesses, sdirname)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 if nargin < 1
0020 error('Need directory containing session subdirectories');
0021 end
0022 if nargin < 2
0023 error('Need directory names for sessions');
0024 end
0025 if ischar(sesses), sesses = cellstr(sesses); end
0026 if nargin < 3
0027 error('Need subdirectory name for results');
0028 end
0029
0030
0031 pwd_orig = pwd;
0032
0033
0034 sess_dir = spm_get('CPath', sess_dir);
0035
0036
0037
0038
0039 if ~sf_isabspath(sdirname) & length(sesses) == 1
0040 sdir_parent = fullfile(sess_dir, sesses{1});
0041 else
0042 sdir_parent = sess_dir;
0043 end
0044
0045
0046 ana_dir = fullfile(sdir_parent, sdirname);
0047 if ~exist(ana_dir, 'dir')
0048 mkdir(sdir_parent, sdirname);
0049 end
0050
0051 switch spm('ver')
0052 case 'SPM99'
0053
0054 m_file = 'er_model_spm99';
0055 ms = which(m_file);
0056 if isempty(ms)
0057 error(sprintf(['Hmm - can''t find %s on the path - maybe ' ...
0058 'you should run from the batch directory'], ...
0059 m_file))
0060 end
0061
0062
0063 global SPM_BCH_VARS
0064 SPM_BCH_VARS = struct(...
0065 'work_dir', ana_dir, ...
0066 'sess_dir', sess_dir, ...
0067 'sesses', {sesses}, ...
0068 'ana_type', 1, ...
0069 'm_file', ms);
0070 spm_bch('do_bch_wrapper');
0071 model_file = fullfile(ana_dir, 'SPMcfg.mat');
0072
0073 otherwise
0074 er_model_spm2(sess_dir, sesses, ana_dir);
0075 model_file = fullfile(ana_dir, 'SPM.mat');
0076
0077 end
0078
0079 return
0080
0081 function absf = sf_isabspath(path)
0082
0083
0084 switch (spm_platform('filesys'))
0085 case 'unx'
0086 if (~isempty(path) & path(1)=='/'), absf=1; else, absf=0; end
0087 case 'win'
0088 if (length(path)>1 & path(2)==':'), absf=1; else, absf=0; end
0089 otherwise
0090 error('isabspath not coded for this filesystem');
0091 end
0092 return