Skip to content

Commit

Permalink
fixing startup, updating fmm
Browse files Browse the repository at this point in the history
  • Loading branch information
mrachh committed Jun 3, 2024
2 parents a4cc842 + 9642e81 commit bf183c2
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 69 deletions.
163 changes: 95 additions & 68 deletions startup.m
Original file line number Diff line number Diff line change
@@ -1,86 +1,113 @@
iremopts = 0;
if ~exist('opts','var')
function startup(opts)
%STARTUP chunkIE startup routine
%
% adds necessary folders to path. checks if FLAM and fmm2d directories are
% in the right locations. installs fmm2d if needed and possible
%
% Optional input:
%
% opts = options structure (defaults)
% opts.testfmm - boolean (false), test fmm intallation
% opts.fmmremex - boolean (false), force recompile of mex routine
% opts.fmmrecompile - boolean (false), force recompile of fmm2d library
%

if nargin < 1
opts = [];
iremopts = 1;
end

ifflam = true;
if(isfield(opts,'ifflam'))
ifflam = opts.ifflam;
fmmremex = false;
if isfield(opts,'fmmremex')
fmmremex = opts.fmmremex;
end

fmmrecompile = false;
if isfield(opts,'fmmrecompile')
fmmrecompile = opts.fmmrecompile;
end

iftest= false;
fmmremex = or(fmmremex,fmmrecompile);

if isfield(opts, 'iftest')
iftest = opts.iftest;
testfmm = false;
if isfield(opts, 'testfmm')
testfmm = opts.testfmm;
end

% add paths
addpath('./chunkie')
if(ifflam)
if(exist('chunkie/FLAM/startup.m'))
if(exist('./chunkie/FLAM/startup.m','file'))
run 'chunkie/FLAM/startup.m';
end
end

iffmm0 = true;


if(isfield(opts,'iffmm'))
iffmm0 = opts.iffmm;
else
msg = "CHUNKIE STARTUP: warning FLAM not found in usual location\n " + ...
"Check that the submodule was included. ";
warning('CHUNKIESTARTUP:flamnotfoundwarn',msg);
end

iffmm = true;
% install fmm2d if needed, add to path if found
if(exist('chunkie/fmm2d/matlab','dir'))
cd './chunkie/fmm2d';
addpath './matlab';
icheck = exist(['fmm2d.' mexext], 'file');
if icheck ~=3 || fmmremex || fmmrecompile
if ismac || isunix
[status,cmdout] = system('which gfortran');
if(~status)
fprintf('------- chunkIE startup: building fmm2d ----- \n');
fprintf('fortran compiler found at: %s\n',cmdout);
iffmm = true;
path1 = getenv('PATH');
cmdout2 = extractBefore(cmdout, 'gfortran');
path1 = [path1 cmdout2];
setenv('PATH', path1);
if ismac
fprintf('Here\n');
!cp -f make.inc.macos.gnu make.inc;
end
if fmmrecompile
!make clean
end
!make matlab;
testfmm = true; % test if new install

if(iffmm0)
if ismac || isunix
[status,cmdout] = system('which gfortran');
if(~status)
fprintf('fortran compiler found at: %s\n',cmdout);
iffmm = true;
path1 = getenv('PATH');
cmdout2 = extractBefore(cmdout, 'gfortran');
path1 = [path1 cmdout2];
setenv('PATH', path1);
if ismac
!cp -f chunkie/fmm2d/make.inc.macos.gnu.x86-64 chunkie/fmm2d/make.inc;
end
else
msg = "CHUNKIE STARTUP: unable to find a suitable compiler for FMM2D. " + ...
"See manual install instructions on github";
warning('CHUNKIESTARTUP:compilerwarn',msg)
end

else
fprintf('Fortran compiler not found\n');
iffmm = false;
msg = "CHUNKIE STARTUP: automatic install not supported on your operating system. " + ...
"See manual install instructions on github";
warning('CHUNKIESTARTUP:OSnosupport',msg)
end
end
cd matlab;
if testfmm
runtests;
end
cd ../../../;
else
if fmmremex || fmmrecompile
msg = "CHUNKIE STARTUP: fmm2d reinstall requested but source files not found in usual location.\n" + ...
"Check that the submodule was included. ";
warning('CHUNKIESTARTUP:fmm2dsourcenotfoundwarn',msg);
end
icheck = exist(['fmm2d.' mexext], 'file');
if icheck == 3
msg = "CHUNKIE STARTUP: fmm2d mex file found on PATH but not in usual location " + ...
"There may be unexpected behavior if this is a different fmm2d version or if other fmm2d MATLAB files are not known to MATLAB.";
warning('CHUNKIESTARTUP:fmm2ddifflocwarn',msg);

if testfmm
msg = "CHUNKIE STARTUP: testing fmm2d not supported if not installed in usual location";
warning('CHUNKIESTARTUP:fmm2dnotestwarn',msg);
end

else
fprintf('Fortran installations not supported through startup.m\n');
fprintf('Follow manual installation instructions on github\n');
iffmm = false;
end
end
msg = ['CHUNKIE STARTUP: warning fmm2d folder not found in usual location ' ...
'and no fmm2d mex file is known to MATLAB.\n If mex file exists ' ...
'in another location, add that location to path.\n '...
'Else, check that the submodule was included. '];




if(iffmm)
if(exist('chunkie/fmm2d/matlab','dir'))
cd './chunkie/fmm2d';
addpath './matlab';
icheck = exist(['fmm2d.' mexext], 'file');
if icheck ~=3
!make matlab;
end

cd matlab;
if iftest
runtests;
end
cd ../../../;
else
fprintf('Fmm installation not in standard location\n');
fprintf('Manual installation required');
end
end

clear ifflam iftest iffmm0 cmdout cmdout2 icheck iffmm path1 status
if iremopts
clear opts
warning('CHUNKIESTARTUP:fmm2dmexnotfoundwarn',msg);
end
end
clear iremopts

0 comments on commit bf183c2

Please sign in to comment.