#! /bin/sh
set -e
set -x
filename="$1"
# set work file names
tmp="$0.tmp"
log="$0.log"
optimise_with_reduce ()
{
cat <<EOF | reduce > $log
off echo$
load scope$
on double$
on noconvert$
on rounded$
off int$
off nat$
out "${tmp}"$
optimize mtt_tmp0 :=: `cat ${filename} | gawk '{ print $2 }'` iname mtt_tmp$
write "`cat ${filename} | gawk '{ print $1 }'` := mtt_tmp0"$
shut "${tmp}"$
;end;
EOF
}
optimise_with_maxima ()
{
cat ${filename} |\
tr "\t\n" " " |\
sed -e 's/\ //g' |\
sed -e 's/\(MTTdX([0-9.]*,[0-9.]*)\)/\1 /' |\
sed -e 's/\(MTTy([0-9.]*,[0-9.]*)\)/\1 /' |\
sed -e 's/\(MTTYz([0-9.]*,[0-9.]*)\)/\1 /' |\
sed -e 's/[A-Za-z0-9_.:()]*(D2)\(.*\)/\1/' |\
sed -e 's/\([A-Za-z0-9_.:()]*\)(C3)/\1/g' |\
optimise_max2r.awk |\
tr "A-Z" "a-z" > ${tmp}
}
optimise_with_maxima
#cat $filename
mv ${tmp} ${filename}
exit 0