-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoctave
executable file
·86 lines (70 loc) · 2.04 KB
/
octave
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
#! /bin/sh
#
# Execute an Octave script. This is a thin wrapper around Octave that
# is used in KONECT Analysis, but is not necessarily specific to it. It
# is also exported to other projects.
#
# ARGUMENTS
# $1 filename of script to execute, usually a .m script
#
# OUTPUT FILES
# error.log Errors from all runs of this script are appended
# to this file
#
SCRIPT=$1
[ "$PREFIX" ] && PREFIX=."$PREFIX"
LOGNAME=$(basename "$SCRIPT" .m)
# Error log
exec 6>>error.log
# Words to use in the logfile are the lowercase environment variables.
# This may break in some cases.
for NAME in $(set | sed -e 's,=.*$,,;tnext;d;:next;/^[a-z][a-z_-]*$/!d') ; do
eval VALUE=\"\$"$NAME"\"
length=$(echo $(echo "$VALUE" | wc -c))
if [ "$length" -lt 30 ] ; then # Don't insert value if too long
LOGNAME=$LOGNAME.$VALUE
fi
done
export LOG="${TMPDIR-/tmp}/o.$LOGNAME$PREFIX.log"
printf >&2 '\t%s\n' "$LOG"
## #
## # Reset locale because Octave outputs some localized number formats with the
## # wrong locale.
## #
## unset $(set | sed -E 's,^(LC_.*)=.*$,\1,;t;d')
## set | grep -E '^LC' >&2
#
# Invocation of Octave:
#
# -q Quiet
#
# Note: --no-window-system is not supported by Octave 3.0
#
DIR_SCRIPT=$(dirname "$SCRIPT")
if echo "$DIR_SCRIPT" | grep -vq '^/' ; then
DIR_SCRIPT="$PWD/$DIR_SCRIPT"
fi
OCTAVE_PATH="$OCTAVE_PATH:$MATLABPATH"
OCTAVE_PATH="$DIR_SCRIPT:$OCTAVE_PATH"
export OCTAVE_PATH
exec 3>$LOG
GNUTERM=dumb DISPLAY= octave -q -W --no-gui --no-window-system "$SCRIPT" "$LOG" >&3 2>&1 ||
{
# The error messages of Octave don't conform to a well-defined
# standard, and usually don't even show the location first.
# Therefore, we first extract all "location" lines, and then
# output the full log.
<"$LOG" sed >&2 -E -e '
s|^error:\s*(.*) at line ([0-9]+), column ([0-9]+)\s*$|\1:\2:\3:|;t
s,^parse error near line ([0-9]+) of file (.+)$,\2:\1:,;t
d
'
<"$LOG" sed >&2 -n -E -e '
/^(error:|parse error)/,$p
'
echo >&2 "*** error in $LOG"
echo >&6 "*** error in $LOG"
exit 1
}
echo >&3 '=== FINISHED SUCCESSFULLY ==='
exit 0