1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
function setKernel(KernelName)
% SETKERNAL Configures solver to use the function set associated with
% the kernal (potential) specified in KernelName.
%
% setKernel(KernelName) Sets the Matlab path to include
% ../MatlabPath/kernals/<KernelName>
% Find the path to MatFMM...
% (NOTE: Here it is assumed that the user has already placed MatFMM
% in the Matlab path -- otherwise they couldn't have invoked the
% solver).
P = path;
i2 = findstr('MatFMM', P); % Starting position of 'MatFMM' string in P
i1 = findstr(':', P(1:i2)); % Preceding path separator locations
if size(i1,2)==0; i1 = 0; end;
i1 = i1 + 1;
i2 = i2 + 5;
MatFMM = P(i1:i2); % This should be the MatFMM path
% Check if user did something tricky, or if I did something stupid...
if size(MatFMM,2) == 0
error('Could not find MatFMM in current Matlab path');
end
%fprintf(['MatFMM path = ', MatFMM, '\n']);
% Now construct path to the main kernal library...
Klib = [MatFMM, '/kernels'];
%fprintf(['MatFMM kernel lib path = ', Klib, '\n']);
% Create a list of all kernal function libraries to be cleared
% from path...
Kflibs = {[Klib, '/Cauchy'],...
[Klib, '/Helmholtz']};
% Clear old kernels from path if any...
purgeKernelsFromPath(P,Kflibs);
% Now build path to target function set (could be optimized?)...
fdir = [Klib, '/', KernelName];
%fprintf(['\n *** SETTING KERNEL PATH: ', fdir, '\n'])
% Now set append function set directory to Matlab's search path...
addpath(fdir);
function purgeKernelsFromPath(P, Kflibs)
% Clears Matlab path of any references to MatFMM kernels that may
% have been appended during a previous session.
for flib = Kflibs
s = flib{:};
if size(findstr(s,P),2) > 0
rmpath(s);
end
end
end %------------------------------------------------------------------
end %---------------------------------------------------------------------- |
Partager