11# Determine MATLAB library path and provide facilities to load libraries with
22# this path
33
4- function get_paths ()
4+ function matlab_home_path ()
55 matlab_home = get (ENV , " MATLAB_HOME" , " " )
6-
76 if matlab_home == " "
87 if is_linux ()
98 matlab_home = dirname (dirname (realpath (chomp (readstring (` which matlab` )))))
@@ -12,38 +11,30 @@ function get_paths()
1211 if isdir (default_dir)
1312 dirs = readdir (default_dir)
1413 filter! (app -> ismatch (r" ^MATLAB_R[0-9]+[ab]\. app$" , dirs), dirs)
14+ if ~ isempty (dirs)
15+ matlab_home = joinpath (default_dir, maximum (dirs))
16+ end
1517 end
1618 elseif is_windows ()
1719 default_dir = Sys. WORD_SIZE == 32 ? " C:\\ Program Files (x86)\\ MATLAB" : " C:\\ Program Files\\ MATLAB"
1820 if isdir (default_dir)
1921 dirs = readdir (default_dir)
2022 filter! (dir -> ismatch (r" ^R[0-9]+[ab]$" , dir), dirs)
23+ if ~ isempty (dirs)
24+ matlab_home = joinpath (default_dir, maximum (dirs))
25+ end
2126 end
2227 end
2328 end
24-
25- if ~ isempty (dirs)
26- matlab_home = joinpath (default_dir, maximum (dirs))
27- end
2829 if matlab_home == " "
2930 error (" The MATLAB path could not be found. Set the MATLAB_HOME environmental variable to specify the MATLAB path." )
3031 end
32+ return matlab_home
33+ end
3134
32- if ! is_windows ()
33- default_startcmd = joinpath (matlab_home, " bin" , " matlab" )
34- if ! isfile (default_startcmd)
35- error (" The MATLAB path is invalid. Set the MATLAB_HOME evironmental variable to the MATLAB root." )
36- end
37- default_startcmd = " exec $(Base. shell_escape (default_startcmd)) "
38- elseif is_windows ()
39- default_startcmd = joinpath (matlab_home, " bin" , (Sys. WORD_SIZE == 32 ? " win32" : " win64" ), " MATLAB.exe" )
40- if ! isfile (default_startcmd)
41- error (" The MATLAB path is invalid. Set the MATLAB_HOME evironmental variable to the MATLAB root." )
42- end
43- end
44- default_startcmd *= " -nosplash"
45-
46- # Get path to MATLAB libraries
35+ function matlab_lib_path ()
36+ # get path to MATLAB libraries
37+ matlab_home = matlab_home_path ()
4738 matlab_lib_dir = if is_linux ()
4839 Sys. WORD_SIZE == 32 ? " glnx86" : " glnxa64"
4940 elseif is_apple ()
@@ -55,11 +46,25 @@ function get_paths()
5546 if ! isdir (matlab_lib_path)
5647 error (" The MATLAB library path could not be found." )
5748 end
58-
59- return default_startcmd, matlab_lib_path
49+ return matlab_lib_path
6050end
6151
62- default_startcmd, matlab_lib_path = get_paths ()
52+ function matlab_startcmd ()
53+ matlab_home = matlab_home_path ()
54+ if ! is_windows ()
55+ default_startcmd = joinpath (matlab_home, " bin" , " matlab" )
56+ if ! isfile (default_startcmd)
57+ error (" The MATLAB path is invalid. Set the MATLAB_HOME evironmental variable to the MATLAB root." )
58+ end
59+ default_startcmd = " exec $(Base. shell_escape (default_startcmd)) "
60+ elseif is_windows ()
61+ default_startcmd = joinpath (matlab_home, " bin" , (Sys. WORD_SIZE == 32 ? " win32" : " win64" ), " MATLAB.exe" )
62+ if ! isfile (default_startcmd)
63+ error (" The MATLAB path is invalid. Set the MATLAB_HOME evironmental variable to the MATLAB root." )
64+ end
65+ end
66+ return default_startcmd
67+ end
6368
6469# helper library access function
6570
0 commit comments