Home > utils > check_stim_dirs.m

check_stim_dirs

PURPOSE ^

Creates a directory structure for jlmt_proc_series calculations

SYNOPSIS ^

function new_stimlist = check_stim_dirs(stimlist,varargin)

DESCRIPTION ^

 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.)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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 
0032 destroot = '';
0033 srcroot = '';
0034 MAKE_SYMLINK = false;
0035 VERBOSE = false;
0036 new_stimlist = {};
0037 
0038 % Process the input arguments
0039 narg = length(varargin);
0040 for iarg = 1:2:narg
0041   switch varargin{iarg}
0042     case {'destroot'}
0043       destroot = varargin{iarg+1};
0044     case {'srcroot'}
0045       srcroot = varargin{iarg+1};
0046       MAKE_SYMLINK = true;
0047     case {'verbose'}
0048       VERBOSE = varargin{iarg+1};
0049     otherwise
0050       fprintf('check_stim_dirs: Unknown input argument: %s\n', varargin{iarg});
0051   end
0052 end
0053 
0054 if ~iscell(stimlist)
0055   stimlist = {stimlist};
0056 end
0057 
0058 
0059 if(VERBOSE)
0060   fprintf('\nChecking stimulus directories...\n');
0061 end
0062 
0063 check_dir(destroot);
0064 
0065 nstims = length(stimlist);
0066 for istim = 1:nstims
0067   if VERBOSE
0068     fprintf('Stim %d/%d\n', istim,nstims);
0069   end
0070   curr_dir = destroot;
0071   
0072   res = stimlist{istim};
0073   while ~isempty(res)
0074     [tok,res] = strtok(res,filesep);
0075     if ~isempty(res)
0076       curr_dir = fullfile(curr_dir,tok);
0077       check_dir(curr_dir, VERBOSE);
0078     else
0079       [dummy,fname,fext] = fileparts(tok);
0080       curr_dir = fullfile(curr_dir,fname);
0081       check_dir(curr_dir, VERBOSE);  % directory named after the stimulus
0082       
0083       curr_dir = fullfile(curr_dir,fext(2:end));
0084       check_dir(curr_dir, VERBOSE);
0085       
0086       if MAKE_SYMLINK
0087         srcfile = fullfile(srcroot,stimlist{istim});
0088         linkname = fullfile(curr_dir,tok);
0089         if ~exist(linkname)
0090           srcfile = regexprep(srcfile,'[()'',& ]','\\$0');
0091           linkname_escaped = regexprep(linkname,'[()'',& ]','\\$0');
0092           unix_str = sprintf('ln -s %s %s >& /dev/null', srcfile, linkname_escaped);
0093           if VERBOSE
0094             fprintf('%s\n', unix_str);
0095           end
0096           status = unix(unix_str);
0097           
0098         end
0099         new_stimlist(end+1) = {linkname};
0100       end
0101     end
0102   end
0103 end % for istim=

Generated on Sun 24-Mar-2019 04:00:51 by m2html © 2003