Creates a directory structure for jlmt_proc_series calculations new_stimlist = check_stim_dirs(stimlist); Given a list of paths to stimuli, checks to make sure that there are corresponding directories in the destination tree. At the level of the specific stimulus file, a directory is created with the stimulus name. A subdirectory is placed in that directory with the extension for the filetype. Within that directory, a symlink is optionally created to the original stimulus file. Returns a list of files with the new target path. Subsequent analysis directories will be placed at this same level. INPUTS stimlist - relative paths from srcroot to individual stimuli, passed as a cell array of strings srcroot - (optional) passed in as tag/value pair. Directory where stimuli are stored. destroot - (optional) passed in as tag/value pair. Directory where subdirectories for each stim will be created OUTPUTS new_stimlist - list of symlinks to original stimuli. Copyright (c) 2006-2012 The Regents of the University of California All Rights Reserved December 29, 2006 Petr Janata April 30,2008 - Added escaping of irregular directory name characters(space, parenthesis, etc.) 08Jul2019 - added ability to copy source file from atonal via rsync
0001 function new_stimlist = check_stim_dirs(stimlist,varargin) 0002 % Creates a directory structure for jlmt_proc_series calculations 0003 % 0004 % new_stimlist = check_stim_dirs(stimlist); 0005 % 0006 % Given a list of paths to stimuli, checks to make sure that there are 0007 % corresponding directories in the destination tree. At the level of the 0008 % specific stimulus file, a directory is created with the stimulus name. A 0009 % subdirectory is placed in that directory with the extension for the 0010 % filetype. Within that directory, a symlink is optionally created to the 0011 % original stimulus file. 0012 % 0013 % Returns a list of files with the new target path. 0014 % 0015 % Subsequent analysis directories will be placed at this same level. 0016 % 0017 % INPUTS 0018 % stimlist - relative paths from srcroot to individual stimuli, passed as a cell array of strings 0019 % srcroot - (optional) passed in as tag/value pair. Directory where stimuli are stored. 0020 % destroot - (optional) passed in as tag/value pair. Directory where subdirectories for each stim will be created 0021 % 0022 % OUTPUTS 0023 % new_stimlist - list of symlinks to original stimuli. 0024 % 0025 % Copyright (c) 2006-2012 The Regents of the University of California 0026 % All Rights Reserved 0027 % 0028 % December 29, 2006 Petr Janata 0029 % April 30,2008 - Added escaping of irregular directory name 0030 % characters(space, parenthesis, etc.) 0031 % 08Jul2019 - added ability to copy source file from atonal via rsync 0032 0033 destroot = ''; 0034 srcroot = ''; 0035 MAKE_SYMLINK = false; 0036 RSYNC = false; 0037 VERBOSE = false; 0038 new_stimlist = {}; 0039 0040 % Process the input arguments 0041 narg = length(varargin); 0042 for iarg = 1:2:narg 0043 switch varargin{iarg} 0044 case {'destroot'} 0045 destroot = varargin{iarg+1}; 0046 case {'srcroot'} 0047 srcroot = varargin{iarg+1}; 0048 0049 % Check whether the source is something we need to make an rsync copy 0050 % from. This check is a bit of a hack right now, and should be made 0051 % less machine-specific. 0052 if ~isempty(regexp(srcroot,'atonal.ucdavis.edu','once')) 0053 RSYNC = true; 0054 else 0055 MAKE_SYMLINK = true; 0056 end 0057 0058 0059 case {'verbose'} 0060 VERBOSE = varargin{iarg+1}; 0061 otherwise 0062 fprintf('check_stim_dirs: Unknown input argument: %s\n', varargin{iarg}); 0063 end 0064 end 0065 0066 if ~iscell(stimlist) 0067 stimlist = {stimlist}; 0068 end 0069 0070 0071 if(VERBOSE) 0072 fprintf('\nChecking stimulus directories...\n'); 0073 end 0074 0075 check_dir(destroot); 0076 0077 nstims = length(stimlist); 0078 for istim = 1:nstims 0079 if VERBOSE 0080 fprintf('Stim %d/%d\n', istim,nstims); 0081 end 0082 curr_dir = destroot; 0083 0084 res = stimlist{istim}; 0085 while ~isempty(res) 0086 [tok,res] = strtok(res,filesep); 0087 if ~isempty(res) 0088 curr_dir = fullfile(curr_dir,tok); 0089 check_dir(curr_dir, VERBOSE); 0090 else 0091 [dummy,fname,fext] = fileparts(tok); 0092 curr_dir = fullfile(curr_dir,fname); 0093 check_dir(curr_dir, VERBOSE); % directory named after the stimulus 0094 0095 curr_dir = fullfile(curr_dir,fext(2:end)); 0096 check_dir(curr_dir, VERBOSE); 0097 0098 if MAKE_SYMLINK || RSYNC 0099 srcfile = fullfile(srcroot,stimlist{istim}); 0100 linkname = fullfile(curr_dir,tok); 0101 if ~exist(linkname) 0102 srcfile = regexprep(srcfile,'[()'',& ]','\\$0'); 0103 linkname_escaped = regexprep(linkname,'[()'',& ]','\\$0'); 0104 if MAKE_SYMLINK 0105 unix_str = sprintf('ln -s %s %s >& /dev/null', srcfile, linkname_escaped); 0106 else 0107 unix_str = sprintf('rsync -a "%s" "%s" >& /dev/null', srcfile, linkname); 0108 end 0109 0110 if VERBOSE 0111 fprintf('%s\n', unix_str); 0112 end 0113 status = unix(unix_str); 0114 0115 end 0116 new_stimlist(end+1) = {linkname}; 0117 end 0118 end 0119 end 0120 end % for istim=