aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xBin/kranc52
-rw-r--r--Tools/MathematicaMisc/RunKranc.m17
2 files changed, 46 insertions, 23 deletions
diff --git a/Bin/kranc b/Bin/kranc
index 9e39af0..9f16432 100755
--- a/Bin/kranc
+++ b/Bin/kranc
@@ -1,32 +1,38 @@
#!/bin/bash
-# A shell script to run Kranc on a mathematica input file
-
-INFILE=$1
-
-if ! which math >/dev/null
+# Assume that this script is called from the Kranc/Bin directory
+export KRANCDIR=$(dirname $0)/..
+export KRANCVERBOSE=no
+
+while getopts "v" flag
+do
+ case $flag in
+ "v")
+ export KRANCVERBOSE=yes
+ ;;
+ esac
+done
+
+shift $(expr $OPTIND - 1)
+
+if [ $# -eq 0 ]
then
- echo "Cannot find math executable. Is Mathematica on your path?"
+ echo "Usage: $0 [-v] <script>"
+ exit 1
fi
-LOCALKRANCPATH="Kranc/Tools/CodeGen:Kranc/Tools/MathematicaMisc:Kranc/Tools/External"
+MMASCRIPT=$1
+shift
-if [ -z "$MATHPATH" ]
-then
- MATHPATH=$LOCALKRANCPATH
+MATH_MACOS=/Applications/Mathematica.app/Contents/MacOS/MathKernel
+
+if which math >/dev/null; then
+ MATH=math
+elif [ -x $MATH_MACOS ]; then
+ MATH=$MATH_MACOS
else
- MATHPATH=$LOCALKRANCPATH:$MATHPATH
+ echo "Cannot find math executable. Is Mathematica on your path?"
+ exit 1
fi
-export MATHPATH
-
-math <<EOF
-
-Module[{mp, newPath},
- mp = StringToStream[Environment["MATHPATH"]];
- newPath = Map[ToString, ReadList[mp, Word, WordSeparators->{":"}]];
- \$Path = Join[newPath, \$Path]];
-Needs["Errors\`"];
-exception = Catch[Get["$INFILE"], KrancError];
-PrintError[exception];
-EOF
+$MATH -run "Get[\"$KRANCDIR/Tools/MathematicaMisc/RunKranc.m\"]" $MMASCRIPT </dev/null
diff --git a/Tools/MathematicaMisc/RunKranc.m b/Tools/MathematicaMisc/RunKranc.m
new file mode 100644
index 0000000..abdb282
--- /dev/null
+++ b/Tools/MathematicaMisc/RunKranc.m
@@ -0,0 +1,17 @@
+
+script = $CommandLine[[-1]];
+krancDir = Environment["KRANCDIR"];
+
+$Path = Join[$Path,
+ {krancDir <> "/Tools/CodeGen",
+ krancDir <> "/Tools/MathematicaMisc",
+ krancDir <> "/Tools/External"}];
+Needs["Errors`"];
+Needs["KrancThorn`"];
+If[Environment["KRANCVERBOSE"] == "yes",
+ SetDebugLevel[InfoFull]];
+
+exception = Catch[Get[script], KrancError];
+PrintError[exception];
+
+Quit[];