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
|
counter=`expr $counter + 1`
done
command="$command INAME mtt_tmp"
else
command=""
fi
# Generate matrix declaration
if [ $nmatrix -gt 0 ]; then
matrix_declaration="matrix mtt$matrix($nmatrix,1)"
else
matrix_declaration="matrix mtt$matrix"
fi
logfile=${system}_${representation}_global_optimisation.log
tmpfile=${system}_${representation}_global_optimisation.tmp
outfile=${system}_${representation}.r
if [ ! -f $outfile ]; then
exit $E_FILE_NOT_EXIST
fi
# Use Reduce to perform the optimisation
${SYMBOLIC:-reduce} <<EOF > $logfile 2>&1
off nat;
in "${system}_def.r";
in "$outfile";
load scope;
out "$tmpfile";
$command;
shut "$tmpfile";
$end;
EOF
cp $outfile $outfile.unoptimised
cp $tmpfile $outfile.tmp
cat $tmpfile | mtt_fix_integers > $outfile
#cp $tmpfile $outfile
echo ";end;" >> $outfile
mtt_error_r $logfile
|
<
<
<
<
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
|
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
97
98
99
|
counter=`expr $counter + 1`
done
command="$command INAME mtt_tmp"
else
command=""
fi
logfile=${system}_${representation}_global_optimisation.log
tmpfile=${system}_${representation}_global_optimisation.tmp
outfile=${system}_${representation}.r
if [ ! -f $outfile ]; then
exit $E_FILE_NOT_EXIST
fi
find_code ()
{
file_in=${1:-${IN}}
portion=${2:-"body"}
head=`cat ${file_in} | gawk '($2 == "Begin" && $3 == "Matrix") { print NR }'`
foot=`cat ${file_in} | gawk '($2 == "End" && $3 == "Matrix") { print NR }'`
case ${portion} in
head)
start=0
end=${head}
;;
body)
start=${head}
end=${foot}
;;
foot)
start=${foot}
end=end
;;
*)
echo "Error in find_code: portion unknown"
return -1
;;
esac
cat ${file_in} |\
gawk --assign start=${start} --assign end=${end} '
(start < NR && NR < end) { print $0 }'
};
# Use Reduce to perform the optimisation
${SYMBOLIC:-reduce} <<EOF > $logfile 2>&1
off nat;
in "${system}_def.r";
in "$outfile";
load scope;
out "$tmpfile";
$command;
shut "$tmpfile";
$end;
EOF
cp $outfile $outfile.unoptimised
cp $tmpfile $outfile.tmp
find_code $outfile head > $tmpfile.head
cat $tmpfile | mtt_fix_integers > $tmpfile.body
find_code $outfile foot > $tmpfile.foot
cat $tmpfile.head $tmpfile.body $tmpfile.foot > $outfile
echo ";end;" >> $outfile
mtt_error_r $logfile
|