Home > marsbar > examples > batch > configure_er_model.m

configure_er_model

PURPOSE ^

batch script wrapper to configure model for MarsBaR ER data

SYNOPSIS ^

function model_file = configure_er_model(sess_dir, sesses, sdirname)

DESCRIPTION ^

 batch script wrapper to configure model for MarsBaR ER data
 
 sess_dir        - directory containing session directories
 sesses          - string or cell array of session directory names
 sdirname        - subdirectory name to put model in

 Returns
 model_file      - full path to SPM model file

 This wrapper does single or multisesson analyses.

 If only one session directory is passed, and sdirname is not an absolute
 path, then the function assumes sdirname is a subdirectory of the session
 directory
 
 $Id: configure_er_model.m,v 1.1.1.1 2004/08/14 00:07:52 matthewbrett Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function model_file = configure_er_model(sess_dir, sesses, sdirname)
0002 % batch script wrapper to configure model for MarsBaR ER data
0003 %
0004 % sess_dir        - directory containing session directories
0005 % sesses          - string or cell array of session directory names
0006 % sdirname        - subdirectory name to put model in
0007 %
0008 % Returns
0009 % model_file      - full path to SPM model file
0010 %
0011 % This wrapper does single or multisesson analyses.
0012 %
0013 % If only one session directory is passed, and sdirname is not an absolute
0014 % path, then the function assumes sdirname is a subdirectory of the session
0015 % directory
0016 %
0017 % $Id: configure_er_model.m,v 1.1.1.1 2004/08/14 00:07:52 matthewbrett Exp $
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 % store path
0031 pwd_orig = pwd;
0032 
0033 % make absolute path
0034 sess_dir = spm_get('CPath', sess_dir);
0035 
0036 % If only one session directory is passed, and sdirname is not an
0037 % absolute path, then assume sdirname is a subdirectory of the session
0038 % directory
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 % results directory
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   % Batch directory should be current directory, but maybe not
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   % Fill batch thing and send
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, ...          % model
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 %-Returns true if path is absolute, false if relative (or empty)
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

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019