Home > installation > checkFunctionUniqueness.m

checkFunctionUniqueness

PURPOSE ^

checkFunctionUniqueness

SYNOPSIS ^

function status = checkFunctionUniqueness(altDirs)

DESCRIPTION ^

 checkFunctionUniqueness
   Checks whether RAVEN toolbox functions are unique across other
   toolboxes or user-created functions accessible in Matlab pathlist.

 Input:
   altDirs     cell array of alternative directories with functions,
               should only be specified if this function is used for other
               purposes, NOT when looking for RAVEN toolbox functions.

 Output:
   status      true if all functions are unique, otherwise false

   Usage: checkFunctionUniqueness()

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status = checkFunctionUniqueness(altDirs)
0002 % checkFunctionUniqueness
0003 %   Checks whether RAVEN toolbox functions are unique across other
0004 %   toolboxes or user-created functions accessible in Matlab pathlist.
0005 %
0006 % Input:
0007 %   altDirs     cell array of alternative directories with functions,
0008 %               should only be specified if this function is used for other
0009 %               purposes, NOT when looking for RAVEN toolbox functions.
0010 %
0011 % Output:
0012 %   status      true if all functions are unique, otherwise false
0013 %
0014 %   Usage: checkFunctionUniqueness()
0015 
0016 if nargin<1
0017     %Get the RAVEN path
0018     ravenDir=findRAVENroot();
0019     
0020     %Now getting all RAVEN functions recursively;
0021     temp_res1=dir([ravenDir '/*/*.m']);
0022     temp_res2=dir([ravenDir '/*/*/*.m']);
0023     
0024     ravenFunctions={temp_res1.name,temp_res2.name}';
0025 else
0026     if ispc
0027         splitChar = ';';
0028     else
0029         splitChar = ':';
0030     end
0031     altDirs = strsplit(altDirs,splitChar)';
0032     ravenFunctions={};
0033     for i=1:numel(altDirs)
0034         temp_res=dir(fullfile(char(altDirs(i)),'*.m'));
0035         ravenFunctions = [ravenFunctions, temp_res.name];
0036     end
0037     ravenFunctions=ravenFunctions';
0038     ravenDir=altDirs;
0039 end
0040 
0041 %startup.m is not a normal function, any startup.m in the path should run
0042 %during startup, so duplicate use of this name is fine
0043 ravenFunctions=ravenFunctions(~ismember(ravenFunctions,'startup.m'));
0044 
0045 %Getting all the paths added to Matlab
0046 if ispc
0047     matlabPaths=regexp(path, ';', 'split')';
0048 elseif isunix
0049     matlabPaths=regexp(path, ':', 'split')';
0050 end
0051 
0052 overlapPath={};
0053 overlapFunctions={};
0054 multiRaven=false;
0055 multiFunction=false;
0056 
0057 for i=1:numel(matlabPaths)
0058     if ~startsWith(matlabPaths{i},ravenDir)
0059         temp_res=dir([matlabPaths{i} '/*.m']);
0060         if ~isempty(temp_res)
0061             pathFunctions={temp_res.name}';
0062         else
0063             pathFunctions='';
0064         end
0065         if ~isempty(pathFunctions) && ~any(ismember('Contents.m',pathFunctions))
0066             if any(ismember(ravenFunctions,pathFunctions))
0067                 if sum(ismember(ravenFunctions,pathFunctions))>(numel(ravenFunctions)/4)
0068                     multiRaven=true;
0069                 else
0070                     multiFunction=true;
0071                     overlapPath = [overlapPath, matlabPaths(i)];
0072                     overlapFunctions = [overlapFunctions, {ravenFunctions(ismember(ravenFunctions,pathFunctions))}];
0073                 end
0074             end
0075         end
0076     end
0077 end
0078 
0079 if multiRaven==true || multiFunction == true
0080         if nargout > 0
0081             status = false;
0082         else
0083             fprintf('Fail\n')
0084         end
0085     if multiRaven==true && nargin < 1
0086         error(['Multiple RAVEN versions detected in MATLAB path. Remove all ',...
0087                'RAVEN directories from the MATLAB path with removeRavenFromPath(), ',...
0088                'or manually remove them. Afterwards, re-run checkInstallation']);
0089     elseif multiFunction == true
0090         for i=1:numel(overlapPath)
0091             fprintf(['   Duplicate functions in ',regexprep(overlapPath{i},'(\\)','\\$1'),'\n']);
0092             fprintf(['     ' strjoin(overlapFunctions{i},'\n     ') '\n']);
0093         end
0094     fprintf('   Resolve conflicting functions to avoid unexpected behaviour\n');
0095     end
0096 else
0097     if nargout > 0
0098         status = true;
0099     else
0100         fprintf('Pass\n')
0101     end
0102 end

Generated by m2html © 2005