matRad_checkMexFileExists

Purpose ^

Checks if a matching mex file exists, and can create a link

Synopsis ^

function fileExists = matRad_checkMexFileExists(filename,linkOctave)

Description ^

 Checks if a matching mex file exists, and can create a link 
 if a matching custom, system specific precompiled octave mex file is found

 call
   matRad_checkMexFileExists(filename)
   matRad_checkMexFileExists(filename,linkOctave)
 
 input:
   filename:   name of the mex file (without extension)
   linkOctave: (optional: default true) If set to true, the function will check 
               for a custom build mex file for octave with our custom extension
               mexoct<system>. If such a file exists, it will create a link to 
               the file as filename.mex since octave not uses system-specific 
               extensions by default. If false, the function will only check 
               for an existing .mex file for octave.
 output:
   fileExists: true if the mex file exists (or can be linked), and false
               otherwise

 References
   -

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 Copyright 2020 the matRad development team. 
 
 This file is part of the matRad project. It is subject to the license 
 terms in the LICENSE file found in the top-level directory of this 
 distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part 
 of the matRad project, including this file, may be copied, modified, 
 propagated, or distributed except according to the terms contained in the 
 LICENSE file.

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Cross-reference information ^

This function calls: This function is called by:

Source code ^

0001 function fileExists = matRad_checkMexFileExists(filename,linkOctave) 
0002 % Checks if a matching mex file exists, and can create a link
0003 % if a matching custom, system specific precompiled octave mex file is found
0004 %
0005 % call
0006 %   matRad_checkMexFileExists(filename)
0007 %   matRad_checkMexFileExists(filename,linkOctave)
0008 %
0009 % input:
0010 %   filename:   name of the mex file (without extension)
0011 %   linkOctave: (optional: default true) If set to true, the function will check
0012 %               for a custom build mex file for octave with our custom extension
0013 %               mexoct<system>. If such a file exists, it will create a link to
0014 %               the file as filename.mex since octave not uses system-specific
0015 %               extensions by default. If false, the function will only check
0016 %               for an existing .mex file for octave.
0017 % output:
0018 %   fileExists: true if the mex file exists (or can be linked), and false
0019 %               otherwise
0020 %
0021 % References
0022 %   -
0023 %
0024 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0025 %
0026 % Copyright 2020 the matRad development team.
0027 %
0028 % This file is part of the matRad project. It is subject to the license
0029 % terms in the LICENSE file found in the top-level directory of this
0030 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part
0031 % of the matRad project, including this file, may be copied, modified,
0032 % propagated, or distributed except according to the terms contained in the
0033 % LICENSE file.
0034 %
0035 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0036 
0037 matRad_cfg = MatRad_Config.instance();
0038 
0039 if nargin < 2
0040     linkOctave = true;
0041 end
0042   
0043 %Explicitly check for matching mex file (id 3)
0044 fileExists = (exist(filename,'file') == 3);
0045 
0046 %For octave we have experimental precompiled files for Octave 5 64 bit
0047 [env,ver] = matRad_getEnvironment();
0048 
0049 if ~fileExists && strcmp(env,'OCTAVE') && linkOctave        
0050      
0051     %Check Octave 5
0052     versplit = strsplit(ver,'.');
0053     isOctave5 = str2double(versplit{1}) == 5;     
0054   
0055     if ~isOctave5
0056         fileExists = false;
0057         return;
0058     end
0059     
0060     %Check Architecture
0061     [~,maxArraySize] = computer();
0062     
0063     if maxArraySize > 2^31
0064         bitExt = '64';
0065     else
0066         bitExt = '32';
0067     end
0068        
0069     if ispc
0070         systemext = 'mexoctw';
0071     elseif ismac 
0072         systemext = 'mexoctmac';
0073     elseif isunix
0074         systemext = 'mexocta';
0075     else
0076         %No file for unknown operating system
0077         fileExists = false;
0078         return;
0079     end
0080     
0081     %Build our octfilename
0082     octfilename = [filename '.' systemext bitExt];
0083 
0084     %Check if matching precompiled octave file exists
0085     fileExists = (exist(octfilename,'file') == 2);
0086     
0087     %If it exists, we create a link with the ending "mex" which is used by octave
0088     if fileExists
0089         mexFileName = [filename '.' mexext];
0090       
0091         %Make the link in the right directory
0092         cFilePath = which(octfilename);
0093         [MexFolder,~,~] = fileparts(cFilePath);
0094         
0095         oldpath = fullfile(MexFolder,octfilename);
0096         linkpath = fullfile(MexFolder,mexFileName);
0097         
0098         %Create link
0099         
0100         [status,msg] = link(oldpath,linkpath);        
0101         
0102         if status == 0
0103             matRad_cfg.dispWarning('Trying to use a precompiled mex for Octave 5. This is experimental!');
0104             fileExists = true;
0105         else
0106             matRad_cfg.dispWarning('Could not link existing precompiled mex file %s to %s\n',octfilename,mexFileName);
0107             fileExists = false;
0108         end
0109     end
0110 end
0111

| Generated by m2html © 2005