Permalink
Browse files

FIX #813 - improve the detection and feedback of incorrect SPM8 mex f…

…iles on macOS, see #813
  • Loading branch information...
robertoostenveld committed Sep 21, 2018
1 parent 851de16 commit 78c06d30d4feef7e624738f651737a0993eb2f81
@@ -67,7 +67,7 @@
% replace pnt with pos
mesh = fixpos(mesh);
if ~isstruct(mesh) || ~isfield(mesh, 'pos')
if ~isstruct(mesh) || numel(mesh)>1 || ~isfield(mesh, 'pos')
ft_error('the input mesh should be a set of points or a single triangulated surface')
end
@@ -58,7 +58,7 @@
% replace pnt with pos
mesh = fixpos(mesh);
if ~isstruct(mesh) || ~isfield(mesh, 'pos')
if ~isstruct(mesh) || numel(mesh)>1 || ~isfield(mesh, 'pos')
ft_error('the input mesh should be a set of points or a single triangulated surface')
end
@@ -58,7 +58,7 @@
% replace pnt with pos
mesh = fixpos(mesh);
if ~isstruct(mesh) || ~isfield(mesh, 'pos')
if ~isstruct(mesh) || numel(mesh)>1 || ~isfield(mesh, 'pos')
ft_error('the input mesh should be a set of points or a single triangulated surface')
end
View
@@ -7,7 +7,7 @@
%
% The global configuration defaults are stored in the global "ft_default" structure.
% The ft_checkconfig function that is called by many FieldTrip functions will merge
% these global configuration defaults with the cfg ctructure that you pass to
% these global configuration defaults with the cfg ctructure that you pass to
% the FieldTrip function that you are calling.
%
% The global options and their default values are
@@ -26,7 +26,7 @@
% ft_default.toolbox.images = string, can be 'compat' or 'matlab' (default = 'compat')
%
% If you want to overrule these default settings, you can add something like this in your startup.m script
% ft_defaults
% ft_defaults
% global ft_default
% ft_default.option1 = value1
% ft_default.option2 = value2
@@ -329,6 +329,7 @@
end % function ft_default
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUBFUNCTION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
View
@@ -286,7 +286,7 @@
case 'concentricspheres'
cfg.fitind = ft_getopt(cfg, 'fitind');
cfg.order = ft_getopt(cfg, 'order');
% the low-level functions needs surface points, triangles are not needed
if input_mesh || input_pos
geometry = data;
@@ -329,7 +329,7 @@
case {'localspheres' 'singlesphere' 'singleshell'}
cfg.grad = ft_getopt(cfg, 'grad'); % used for localspheres
% these three methods all require a set of surface points
% these three methods all require a single set of surface points
if input_mesh || input_pos
geometry = data;
elseif input_seg
@@ -346,12 +346,24 @@
try
tmpcfg.tissue = 'brain';
geometry = ft_prepare_mesh(tmpcfg, data);
catch
me = lasterror;
if isequal(me.identifier, 'MATLAB:mex:ErrInvalidMEXFile')
% SPM8 mex file issues are common on macOS, these should not remain invisible
rethrow(me);
end
end
end
if isempty(geometry)
try
tmpcfg.tissue = 'scalp';
geometry = ft_prepare_mesh(tmpcfg, data);
catch
me = lasterror;
if isequal(me.identifier, 'MATLAB:mex:ErrInvalidMEXFile')
% SPM8 mex file issues are common on macOS, these should not remain invisible
rethrow(me);
end
end
end
if isempty(geometry)
View
@@ -383,7 +383,7 @@
case 'PLOTLY'
dependency = {'fig2plotly' 'savejson'};
% the following are FieldTrip modules/toolboxes
% the following are FieldTrip modules/toolboxes
case 'FILEIO'
dependency = {'ft_read_header', 'ft_read_data', 'ft_read_event', 'ft_read_sens'};
case 'FORWARD'
@@ -420,13 +420,13 @@
% try to determine the path of the requested toolbox
if autoadd>0 && ~status
% 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
@@ -438,7 +438,7 @@
feval(licensefile);
end
end
% for contributed FieldTrip extensions
prefix = fullfile(fileparts(which('ft_defaults')), 'contrib');
if ~status
@@ -450,25 +450,25 @@
feval(licensefile);
end
end
% for linux computers in the Donders Centre for Cognitive Neuroimaging
prefix = '/home/common/matlab';
if ~status && isfolder(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 && isfolder(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 && isfolder(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));
@@ -514,6 +514,8 @@
if any(~cellfun(@isempty, regexp(toolbox, {'spm2', 'spm5', 'spm8', 'spm12'})))
% SPM needs to be added with all its subdirectories
addpath(genpath(toolbox));
% check whether the mex files are compatible
check_spm_mex;
else
addpath(toolbox);
end
@@ -600,6 +602,24 @@
token = regexp(version_str,'(\d*)','tokens');
v = str2num([token{:}{:}]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUBFUNCTION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function status = check_spm_mex()
status = true;
try
% this will always result in an error
spm_conv_vol
catch
me = lasterror;
% any error is ok, except when due to an invalid MEX file
status = ~isequal(me.identifier, 'MATLAB:mex:ErrInvalidMEXFile');
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 http://bit.ly/2OGF6US');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% helper function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -628,7 +648,6 @@
assert(false,'this should not happen');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% helper function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -638,7 +657,6 @@
% must be in path and not a variable
status = ~isempty(w) && ~isequal(w, 'variable');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ISFOLDER is needed for versions prior to 2017b
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

0 comments on commit 78c06d3

Please sign in to comment.