aboutsummaryrefslogtreecommitdiff
path: root/m/runmath.sh
blob: ab94b62de16b63253a938dff80217e02a875d820 (plain)
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
#! /bin/bash

# Abort on errors
set -e
# null-expand non-matching globs
set -u

MATHEMATICA="math"

script=$1

if test -z "$script"; then
    echo "Usage:"
    echo "$0 <script.m>"
    exit 2
fi

KRANCPATH="${KRANCPATH:+$KRANCPATH}"
if [ -z "$KRANCPATH" ] ; then
    KRANCPATHS=(. ../../../../arrangements/../repos ../../../arrangements/../repos $HOME)
    # look for Kranc in a number of likely locations
    # choice 2 and 3 are $CCTK_HOME if the thorn resides in arrangements or
    # git-repos
    for i in ${KRANCPATHS[@]} ; do
        if [ -d $i/kranc/Tools ] ; then
            KRANCPATH=$i/kranc
            break
        elif [ -d $i/Kranc/Tools ] ; then
            KRANCPATH=$i/Kranc
            break
        fi
    done
fi
if [ -z "$KRANCPATH" ] ; then # try some more clever things...
    KRANCBIN="$(which kranc || true)"
    if [ -h "$KRANCBIN" ] ; then
        KRANCBIN=$(readlink "$KRANCBIN")
    fi
    if [ -d "$(dirname "$KRANCBIN")/../Tools" ] ; then
        KRANCPATH="$(dirname "$KRANCBIN")/.."
    fi
fi
if [ -n "$KRANCPATH" ] ; then
    LOCALKRANCPATH="$KRANCPATH/Tools/CodeGen:$KRANCPATH/Tools/MathematicaMisc"
    
    if [ -z "${MATHPATH:+}" ]
    then
        MATHPATH=$LOCALKRANCPATH
    else
        MATHPATH=$LOCALKRANCPATH:$MATHPATH
    fi
    
    export MATHPATH
else
    echo -e "Could not find Kranc. Expect trouble unless you have made sure Mathematica\nwill find Kranc. You might also consider setting \$KRANCPATH."
fi

echo "MATHPATH = $MATHPATH"

error=$(basename $script .m).err
output=$(basename $script .m).out

rm -f $output

# Run Mathematica to regenerate the code
< $script "$MATHEMATICA" | tee $error

if grep 'KrancError' $error; then
    echo
    echo "There was an error when running Kranc on $script."
    echo "The file $error contains details."
    echo
    echo "*** The Cactus thorns have NOT been updated. ***"
    echo
    exit 1
fi

mv $error $output