Skip to content

Commit

Permalink
automatically synchronized identical files to 9109b70
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoostenveld committed Jan 13, 2022
1 parent 9109b70 commit f7adf3a
Show file tree
Hide file tree
Showing 4 changed files with 524 additions and 680 deletions.
301 changes: 131 additions & 170 deletions fileio/private/ft_hastoolbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
% silent = 0 means that it will give some feedback about adding the toolbox
% silent = 1 means that it will not give feedback

% Copyright (C) 2005-2022, Robert Oostenveld
% Copyright (C) 2005-2019, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
Expand Down Expand Up @@ -187,115 +187,9 @@
silent = 0;
end

if ~iscell(toolbox)
toolbox = {toolbox};
end

% determine whether the toolbox is installed
toolbox = upper(toolbox);

for k = 1:numel(toolbox)
[dependency{k}, fallback_toolbox] = getdependency(toolbox{k}, silent);
status(k) = is_present(dependency{k});
if ~status(k) && ~isempty(fallback_toolbox)
toolbox{k} = fallback_toolbox;
end
end

% try to determine the path of the requested toolbox and add it
if any(~status) && autoadd>0

% for core FieldTrip modules
prefix = fileparts(which('ft_defaults'));
if any(~status)
status = myaddpath(fullfile(prefix, lower(toolbox)), silent);
end

% for external FieldTrip modules
prefix = fullfile(fileparts(which('ft_defaults')), 'external');
if any(~status)
status(~status) = myaddpath(fullfile(prefix, lower(toolbox(~status))), silent);
licensefile = strcat(lower(toolbox), '_license');
if status && cellfun(@exist, licensefile, repmat({'file'}, size(licensefile)))
% this will execute openmeeg_license, mne_license and duneuro_license
% which display the license on screen for three seconds
cellfun(@feval, licensefile);
end
end

% for contributed FieldTrip extensions
prefix = fullfile(fileparts(which('ft_defaults')), 'contrib');
if any(~status)
status(~status) = myaddpath(fullfile(prefix, lower(toolbox(~status))), silent);
licensefile = [lower(toolbox) '_license'];
if status && cellfun(@exist, licensefile, repmat({'file'}, size(licensefile)))
% this will execute openmeeg_license, mne_license and artinis_license
% which display the license on screen for a few seconds
cellfun(@feval, licensefile);
end
end

% for linux computers in the Donders Centre for Cognitive Neuroimaging
prefix = '/home/common/matlab';
if any(~status) && is_folder({prefix})
status(~status) = myaddpath(fullfile(prefix, lower(toolbox(~status))), silent);
end

% for windows computers in the Donders Centre for Cognitive Neuroimaging
prefix = 'h:\common\matlab';
if any(~status) && is_folder({prefix})
status(~status) = myaddpath(fullfile(prefix, lower(toolbox(~status))), silent);
end

% use the MATLAB subdirectory in your homedirectory, this works on linux and mac
prefix = fullfile(getenv('HOME'), 'matlab');
if any(~status) && is_folder({prefix})
status(~status) = myaddpath(fullfile(prefix, lower(toolbox(~status))), silent);
end

if any(~status)
% the toolbox is not on the path and cannot be added
sel = find(strcmp(url(:,1), toolbox));
if ~isempty(sel)
msg = sprintf('the %s toolbox is not installed, %s', toolbox{~status}, url{sel, 2});
else
msg = sprintf('the %s toolbox is not installed', toolbox{~status});
end
if autoadd==1
error(msg);
elseif autoadd==2
warning(msg);
else
% fail silently
end
end

elseif any(~status) && autoadd<0
% the toolbox is not on the path and should not be added
sel = find(strcmp(url(:,1), toolbox));
if ~isempty(sel)
msg = sprintf('the %s toolbox is not installed, %s', toolbox{~status}, url{sel, 2});
else
msg = sprintf('the %s toolbox is not installed', toolbox{~status});
end
error(msg);
end

% this function is called many times in FieldTrip and associated toolboxes
% use efficient handling if the same toolbox has been investigated before
% if status
% previous.(fixname(toolbox)) = status;
% end

% remember the previous path, allows us to determine on the next call
% whether the path has been modified outise of this function
% previouspath = path;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% helper function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [dependency, fallback_toolbox] = getdependency(toolbox, silent)

% In case SPMxUP not available, allow to use fallback toolbox
fallback_toolbox='';

Expand Down Expand Up @@ -341,7 +235,7 @@
case 'MEG-CALC'
dependency = {'megmodel', 'megfield', 'megtrans'};
case 'MVPA-LIGHT'
dependency = {'mv_classify','train_lda'};
dependency = {'mv_crossvalidate','train_lda'};
case 'BIOSIG'
dependency = {'sopen', 'sread'};
case 'EEG'
Expand Down Expand Up @@ -561,86 +455,154 @@
case {'REALTIME', 'STATFUN', 'TRIALFUN', 'TEMPLATE/LAYOUT', 'TEMPLATE/ANATOMY', 'TEMPLATE/ATLAS', 'TEMPLATE/DEWAR', 'TEMPLATE/HEADMODEL', 'TEMPLATE/ELECTRODE', 'TEMPLATE/NEIGHBOURS', 'TEMPLATE/SOURCEMODEL'}
dependency = is_subdir_in_fieldtrip_path(toolbox);
otherwise
if ~silent, warning('cannot determine whether the %s toolbox is present', toolbox); end
if ~silent, ft_warning('cannot determine whether the %s toolbox is present', toolbox); end
dependency = false;
end

status = is_present(dependency);
if ~status && ~isempty(fallback_toolbox)
% in case of SPMxUP
toolbox = fallback_toolbox;
end

% try to determine the path of the requested toolbox and add it
if ~status && autoadd>0

% for core FieldTrip modules
prefix = fileparts(which('ft_defaults'));
if ~status
status = myaddpath(fullfile(prefix, lower(toolbox)), silent);
end

% for external FieldTrip modules
prefix = fullfile(fileparts(which('ft_defaults')), 'external');
if ~status
status = myaddpath(fullfile(prefix, lower(toolbox)), silent);
licensefile = [lower(toolbox) '_license'];
if status && exist(licensefile, 'file')
% this will execute openmeeg_license, mne_license and duneuro_license
% which display the license on screen for three seconds
feval(licensefile);
end
end

% for contributed FieldTrip extensions
prefix = fullfile(fileparts(which('ft_defaults')), 'contrib');
if ~status
status = myaddpath(fullfile(prefix, lower(toolbox)), silent);
licensefile = [lower(toolbox) '_license'];
if status && exist(licensefile, 'file')
% this will execute openmeeg_license, mne_license and artinis_license
% which display the license on screen for a few seconds
feval(licensefile);
end
end

% for linux computers in the Donders Centre for Cognitive Neuroimaging
prefix = '/home/common/matlab';
if ~status && is_folder(prefix)
status = myaddpath(fullfile(prefix, lower(toolbox)), silent);
end

% for windows computers in the Donders Centre for Cognitive Neuroimaging
prefix = 'h:\common\matlab';
if ~status && is_folder(prefix)
status = myaddpath(fullfile(prefix, lower(toolbox)), silent);
end

% use the MATLAB subdirectory in your homedirectory, this works on linux and mac
prefix = fullfile(getenv('HOME'), 'matlab');
if ~status && is_folder(prefix)
status = myaddpath(fullfile(prefix, lower(toolbox)), silent);
end

if ~status
% the toolbox is not on the path and cannot be added
sel = find(strcmp(url(:,1), toolbox));
if ~isempty(sel)
msg = sprintf('the %s toolbox is not installed, %s', toolbox, url{sel, 2});
else
msg = sprintf('the %s toolbox is not installed', toolbox);
end
if autoadd==1
error(msg);
elseif autoadd==2
warning(msg);
else
% fail silently
end
end

elseif ~status && autoadd<0
% the toolbox is not on the path and should not be added
sel = find(strcmp(url(:,1), toolbox));
if ~isempty(sel)
msg = sprintf('the %s toolbox is not installed, %s', toolbox, url{sel, 2});
else
msg = sprintf('the %s toolbox is not installed', toolbox);
end
error(msg);
end

% this function is called many times in FieldTrip and associated toolboxes
% use efficient handling if the same toolbox has been investigated before
% if status
% previous.(fixname(toolbox)) = status;
% end

% remember the previous path, allows us to determine on the next call
% whether the path has been modified outise of this function
% previouspath = path;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% helper function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function status = myaddpath(toolbox, silent)
global ft_default

if any(~is_folder(toolbox))
if ~is_folder(toolbox)
% search for a case-insensitive match, this is needed for MVPA-Light
notfolder = find(~is_folder(toolbox));
for k = notfolder(:)'
% for loop is needed here, because support for cell-arrays in fileparts
% is matlab version dependent
[p, f] = fileparts(toolbox{notfolder(k)});
dirlist = dir(p);
sel = strcmpi({dirlist.name}, f);
if sum(sel)==1
toolbox{notfolder(k)} = fullfile(p, dirlist(sel).name);
end
[p, f] = fileparts(toolbox);
dirlist = dir(p);
sel = strcmpi({dirlist.name}, f);
if sum(sel)==1
toolbox = fullfile(p, dirlist(sel).name);
end
end

if isdeployed

warning('cannot change path settings for %s in a compiled application', sprintf('%s ', toolbox{:}));
ft_warning('cannot change path settings for %s in a compiled application', toolbox);
status = true;

elseif any(is_folder(toolbox))
status = false(1,numel(toolbox));

% the toolboxes that exist as a folder can be added to the path, but there are a few exceptions
sel = is_folder(toolbox);

elseif is_folder(toolbox)
if ~silent
ws = warning('off','backtrace'); % switch this off
warning('adding %s toolbox to your MATLAB path', toolbox{sel});
warning(ws); % revert to the previous state
ft_warning('off','backtrace');
ft_warning('adding %s toolbox to your MATLAB path', toolbox);
ft_warning('on','backtrace');
end

% deal with some exceptions
% spm, mvpa-light, ibtb
selspm = is_folder(toolbox, 'spm$'); sel(selspm) = false;
selmvpa = is_folder(toolbox, 'mvpa-light$'); sel(selmvpa) = false;
selibtb = is_folder(toolbox, 'ibtb$'); sel(selibtb) = false;

if any(selspm)
if any(~cellfun(@isempty, regexp(lower(toolbox), {'spm2$', 'spm5$', 'spm8$', 'spm12$'})))
% SPM needs to be added with all its subdirectories
addpath(genpath(toolbox{selspm}));
addpath(genpath(toolbox));
% check whether the mex files are compatible
check_spm_mex;
end
if any(selmvpa)
elseif ~isempty(regexp(lower(toolbox), 'mvpa-light$', 'once'))
% this comes with its own startup script
addpath(fullfile(toolbox{selmvpa}, 'startup'))
addpath(fullfile(toolbox, 'startup'))
startup_MVPA_Light;
end
if any(selibtb)
elseif ~isempty(regexp(lower(toolbox), 'ibtb', 'once'))
% this needs to be added with all its subdirectories
addpath(genpath(toolbox{selibtb}));
addpath(genpath(toolbox));
else
addpath(toolbox);
end

addpath(toolbox{sel});
status(sel) = true;

% remember the toolboxes that have just been added to the path, it will be cleaned up by FT_POSTAMBLE_HASTOOLBOX
% remember the toolbox that was just added to the path, it will be cleaned up by FT_POSTAMBLE_HASTOOLBOX
if ~isfield(ft_default, 'toolbox') || ~isfield(ft_default.toolbox, 'cleanup')
ft_default.toolbox.cleanup = {};
end
ft_default.toolbox.cleanup{end+(1:numel(toolbox))} = toolbox;

elseif (~cellfun('isempty', regexp(toolbox, 'spm2$', 'once')) || ...
~cellfun('isempty', regexp(toolbox, 'spm5$', 'once')) || ...
~cellfun('isempty', regexp(toolbox, 'spm8$', 'once')) || ...
~cellfun('isempty', regexp(toolbox, 'spm12$', 'once'))) && any(is_folder(strcat(toolbox,'b')))
ft_default.toolbox.cleanup{end+1} = toolbox;
status = true;
elseif (~isempty(regexp(toolbox, 'spm2$', 'once')) || ~isempty(regexp(toolbox, 'spm5$', 'once')) || ~isempty(regexp(toolbox, 'spm8$', 'once')) || ~isempty(regexp(toolbox, 'spm12$', 'once'))) && exist([toolbox 'b'], 'dir')
% the final release version of SPM is not available, add the beta version instead
status = myaddpath(strcat(toolbox, 'b'), silent);

status = myaddpath([toolbox 'b'], silent);
else
status = false;
end
Expand All @@ -649,6 +611,7 @@
% helper function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function path = unixpath(path)
%path(path=='\') = '/'; % replace backward slashes with forward slashes
path = strrep(path,'\','/');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -696,14 +659,15 @@
% helper function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function status = has_mex(name)
status = (exist([name '.' mexext], 'file')==3);
full_name=[name '.' mexext];
status = (exist(full_name, 'file')==3);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% helper function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function v = get_spm_version()
if ~is_present('spm')
v = NaN;
v=NaN;
return
end

Expand All @@ -717,7 +681,7 @@
function status = check_spm_mex()
status = true;
try
% without an input argument this should always result in an error
% this will always result in an error
spm_conv_vol
catch
me = lasterror;
Expand All @@ -726,7 +690,7 @@
end
if ~status
% SPM8 mex file issues are common on macOS with recent MATLAB versions
ft_warning('the SPM mex files are incompatible with your platform, see https://www.fieldtriptoolbox.org/faq/matlab_complains_about_a_missing_or_invalid_mex_file_what_should_i_do');
ft_warning('the SPM mex files are incompatible with your platform, see http://bit.ly/2OGF6US');
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -767,10 +731,7 @@
status = ~isempty(w) && ~isequal(w, 'variable');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% helper function
% ISFOLDER is needed for versions prior to 2017b
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function tf = is_folder(dirpath, str)
tf = cellfun(@exist, dirpath, repmat({'dir'}, size(dirpath))) == 7;
if nargin>1
tf(tf) = ~cellfun(@isempty, regexp(dirpath(tf), str, 'once'));
end
function tf = is_folder(dirpath)
tf = exist(dirpath,'dir') == 7;

0 comments on commit f7adf3a

Please sign in to comment.