forked from jgte/orb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatlab.aliases
More file actions
96 lines (87 loc) · 3.8 KB
/
matlab.aliases
File metadata and controls
96 lines (87 loc) · 3.8 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# short name for matlab
function mlab
{
#define default arguments
local DEFAULT_ARGS=(-nouserjavapath -nosplash)
[[ "${@/desktop/}" == "$@" ]] && DEFAULT_ARGS+=(-nodesktop)
[[ ! "${@/timing/}" == "$@" ]] && DEFAULT_ARGS+=(-timing)
#get matlab executable
local MATLAB_EXE="$(which matlab 2> /dev/null)"
[ ! -e "$MATLAB_EXE" ] && MATLAB_EXE="$(find /Applications -maxdepth 1 -type d -name MATLAB_R20[0-9][0-9]\* 2> /dev/null | sort -fd | tail -n1)/bin/matlab"
#add any other possible locations for matlab here
#...
#i'm out of options, here goes nothing
[ ! -e "$MATLAB_EXE" ] && MATLAB_EXE="matlab"
#debug
[[ "${@/nodebug/}" == "$@" ]] && echo "matlab executable : $MATLAB_EXE"
#add matlab lic file to arguments (noticeable speedup when available)
if [[ ! "${MATLAB_EXE/\/Applications\/MATLAB}" == "$MATLAB_EXE" ]]
then
local LIC=$(find /Applications/MATLAB*.app/licenses -name license\*.lic 2> /dev/null | sort -fd | tail -n1)
[ ! -z "$LIC" ] && DEFAULT_ARGS+=("-c $LIC")
fi
#define matlab code to run first (recording call time)
local MATLAB_SUP="disp('$(date +'%F %T') - matlab launched');disp([datestr(datetime('now'),'yyyy-mm-dd HH:MM:SS'),' - matlab prompt ready']);"
#look for startup scripts (does not support dirs with blanks!)
local MATLAB_STARTUP_LIST=()
if [ -d ~/.matlab ]
then
local DOT_MATLAB_DIR="$(find ~/.matlab -maxdepth 1 -type d -name R20[0-9][0-9]\* 2> /dev/null | sort -fd | tail -n1)"
#if : can figure out matlab version from path
#and : the dot matlab dir corresponds to the one in the MATLAB_EXE
#then : add for matlab dir to
[ -d "$DOT_MATLAB_DIR" ] && \
[[ ! "${MATLAB_EXE/R20}" == "$MATLAB_EXE" ]] && \
[[ ! "${MATLAB_EXE/$(basename $DOT_MATLAB_DIR)}" == "$MATLAB_EXE" ]] && \
[ -e "$DOT_MATLAB_DIR/startup.m" ] && \
MATLAB_STARTUP_LIST+=("$DOT_MATLAB_DIR/startup.m") && \
[[ "${@/nodebug/}" == "$@" ]] && echo "startup script (from dot matlab dir) : ${MATLAB_STARTUP_LIST[$(( ${#MATLAB_STARTUP_LIST[@]}-1 ))]}" || ([[ "${@/nodebug/}" == "$@" ]] && echo "UNUSED dot matlab dir : $DOT_MATLAB_DIR")
fi
#check for directories that may have startup scripts, which are exclusive (i.e. only one of these is run)
#define these in the CONFLICTING_STARTUP_DIRS file
CONFLICTING_STARTUP_DIRS=~/.matlab/matlab.startup.dirs
if [ ! -e "$PWD/startup.m" ] && [ -e "$CONFLICTING_STARTUP_DIRS" ]
then
while IFS= read -r -d '' file; do
MATLAB_STARTUP_LIST+=("$file")
#debug
[[ "${@/nodebug/}" == "$@" ]] && echo "startup script (from conflicting matlab dirs) : $file"
done < <(find $(cat $CONFLICTING_STARTUP_DIRS | sed 's:~:'$HOME':g') -maxdepth 1 -name startup.m -print0 2> /dev/null)
fi
#run startup script(s)
for i in "${MATLAB_STARTUP_LIST[@]}"
do
MATLAB_SUP+=" run('$i');"
done
#clean up the trash
rm -fv ~/java.log.* ~/matlab_crash_dump.*
#check for debug mode
[[ ! "${@/echo/}" == "$@" ]] && ECHO=echo || ECHO=
#check if we're on a login node
case $HOSTNAME in
login*)
if [[ ! "${@/term/}" == "$@" ]]
then
echo "WARNING: running matlab in terminal mode, no graphics supported"
$ECHO $MATLAB_EXE ${DEFAULT_ARGS[@]} -nodisplay -r "$MATLAB_SUP"
elif [[ ! "${@/noidev/}" == "$@" ]]
then
echo "WARNING: running matlab in TACC, this can be slow"
$ECHO $MATLAB_EXE ${DEFAULT_ARGS[@]} -r "$MATLAB_SUP"
else
#statements
echo "WARNING: this is a login node, idev'ing it (you need to run 'mlab' after idev job starts)"
$ECHO idev -m 120 -N 1 -n 4 -q development
fi
;;
*)
#run it
if [[ "${@/desktop/}" == "$@" ]]
then
$ECHO $MATLAB_EXE ${DEFAULT_ARGS[@]} -r "$MATLAB_SUP"
else
$ECHO $MATLAB_EXE ${DEFAULT_ARGS[@]} -r "$MATLAB_SUP" &
fi
;;
esac
}