Index: mttroot/mtt/bin/trans/def2write_r ================================================================== --- mttroot/mtt/bin/trans/def2write_r +++ mttroot/mtt/bin/trans/def2write_r @@ -11,10 +11,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.14 2002/08/09 14:34:45 geraint +## Fix to prevent numbers being formed with a decimal point in the exponent, Reduce cannot handle these. +## ## Revision 1.13 2002/07/10 17:43:05 geraint ## Added feature [ 562453 ] Optimisation of algebraic equations. ## ## Revision 1.12 2002/06/28 10:13:40 geraint ## Includes fix_c.r in ese2rdae and def2write_r to eliminate occurrances of x**y. @@ -167,18 +170,23 @@ { sys="$1" lhs="$2" rhs="$3" - crr="${sys}_cr.r" dae="${sys}_dae.r" tmp="mtt_optimise.tmp" + tmp1="mtt_optimise1.tmp" tmp2="mtt_optimise2.tmp" tmp3="mtt_optimise3.tmp" - { - cat < $tmp1 + nlines=`wc -l $tmp1 | gawk '{print $1}'` + if [ $nlines -gt 0 ]; then + { + cat < $tmp - - echo "optimize" >> $tmp - grep -i -e "^$lhs" $dae |\ - sed -e 's/;/\ INAME\ mtt_tmp/g' |\ - sed -e 's/:=/:=/g' >> $tmp - { - cat < $tmp + cat $tmp1 >> $tmp + { + cat <> $tmp - echo "%%% $lhs %%%" >> def2write_r1.log - ${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 + } >> $tmp + echo "%%% $lhs %%%" >> def2write_r1.log + ${SYMBOLIC:-reduce} < $tmp >> def2write_r1.log 2>> def2write_r2.log + cat $tmp2 | gawk -v RS=';' '($2 == ":=") {print $0}' > $tmp3 + cat $tmp3 | mtt_fix_integers + fi + rm -f $tmp $tmp1 $tmp2 $tmp3 return } # Remove log files @@ -222,26 +228,29 @@ echo 'off echo$' echo 'load gentran$' fi >> $1_$2_write.r for matrix in $matrices; do - n=`first "$ns"`; ns=`rest "$ns"` - m=`first "$ms"`; ms=`rest "$ms"` - is=`n2m 1 $n`; - js=`n2m 1 $m`; - if [ $n -ge 1 ]; then - 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" - comma='' - else - echo 'write' - name=`echo MTT$matrix'('$i','$j')'` - echo ' '$comma$name ':=' $name '$' - fi >> $1_$2_write.r - done - done + matrix_exists=`grep -i MTT${matrix} ${sys}_dae.r | wc -l | gawk '{print $1}'` + if [ $matrix_exists -gt 0 ]; then + n=`first "$ns"`; ns=`rest "$ns"` + m=`first "$ms"`; ms=`rest "$ms"` + is=`n2m 1 $n`; + js=`n2m 1 $m`; + if [ $n -ge 1 ]; then + 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" + comma='' + else + echo 'write' + name=`echo MTT$matrix'('$i','$j')'` + echo ' '$comma$name ':=' $name '$' + fi >> $1_$2_write.r + done + done + fi fi done echo ';END;' >>$1_$2_write.r