Index: mttroot/mtt/bin/trans/def2write_r ================================================================== --- mttroot/mtt/bin/trans/def2write_r +++ mttroot/mtt/bin/trans/def2write_r @@ -11,10 +11,19 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.11.2.1 2002/06/05 11:14:51 geraint +## ae.r now generated using def2write_r like cse?.r +## fix_c.r called at ese2rdae stage so that pow gets fixed in ae.r. +## +## These changes produce the desired result (optimised algebraic equations) but +## have highlighted a problem; when optimisation fails, Reduce does not write +## a result. For complicated systems, this can lead to missing assignments in +## the resultant code. +## ## Revision 1.11 2002/05/17 09:14:58 geraint ## Optimises each line in a separate session. Allows larger models to be built. ## ## Revision 1.10 2002/04/28 18:41:27 geraint ## Fixed [ 549658 ] awk should be gawk. @@ -152,47 +161,23 @@ mtt_optimise () { sys="$1" lhs="$2" - rhs="$3" + + lhs=`echo $lhs | sed 's/MTTEdX/MTTdX/'` - crr="${sys}_cr.r" dae="${sys}_dae.r" - tmp="mtt_optimise.tmp" - tmp2="mtt_optimise2.tmp" - tmp3="mtt_optimise3.tmp" - - { - cat < $tmp - - echo "optimize" >> $tmp - grep -i -e "^$lhs" $dae |\ - sed -e 's/;/\ INAME\ mtt_tmp/g' |\ - sed -e 's/:=/:=/g' >> $tmp - { - cat <> $tmp - - ${SYMBOLIC:-reduce} < $tmp >> def2write_r1.log 2>> def2write_r2.log - cat $tmp2 | gawk -v RS=';' '($2 == ":=") {print $0}' > $tmp3 - cat $tmp3 | mtt_fix_integers - rm -f $tmp $tmp2 $tmp3 + + exp=`grep -i -e "^$lhs" $dae` + rhs=`echo $exp | sed 's/.*:=\ \(.*\)/\1/'` + rhs=`echo $rhs | sed 's/[;$]*$//'` + + if [ ! -z "${rhs}" ]; then + mtt_optimise.sh "$lhs" "$rhs" | mtt_fix_integers + fi + return } # Remove log files @@ -216,11 +201,11 @@ js=`n2m 1 $m`; for i in $is; do for j in $js; do if [ ${opt:-""} = "-optimise" ]; then name=`echo MTT$matrix'('$i','$j')'` - mtt_optimise $1 "$comma$name" "$name" + mtt_optimise $1 "$comma$name" comma='' else echo 'write' name=`echo MTT$matrix'('$i','$j')'` echo ' '$comma$name ':=' $name '$' ADDED mttroot/mtt/bin/trans/mtt_optimise.sh Index: mttroot/mtt/bin/trans/mtt_optimise.sh ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/mtt_optimise.sh @@ -0,0 +1,45 @@ +#! /bin/sh + +set -e + +# get expression to optimise + +lhs="$1" +rhs="$2" + +create_reduce_script () +{ + lhs="$1" + rhs="$2" + + cat < ${log} + +cat ${tmp} +rm -f ${tmp} + +exit 0