Index: mttroot/mtt/bin/trans/def2write_r ================================================================== --- mttroot/mtt/bin/trans/def2write_r +++ mttroot/mtt/bin/trans/def2write_r @@ -11,10 +11,14 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.10 2002/04/28 18:41:27 geraint +## Fixed [ 549658 ] awk should be gawk. +## Replaced calls to awk with call to gawk. +## ## Revision 1.9 2001/07/27 23:29:10 geraint ## Optimises only when requested (-opt). ## ## Revision 1.8 2001/07/13 04:54:04 geraint ## Branch merge: numerical-algebraic-solution back to main. @@ -120,16 +124,82 @@ *) echo def2write_r: representation $rep not recognised exit esac + +mtt_fix_integers () +{ + gawk -F":=" -v RS="$" -v ORS="$\n" ' +(NF == 1) { + print $0 +} +(NF > 1) { + lhs=$1 ; + rhs=$2" " ; + rhs1 = gensub ( /([^A-Za-z_0-9\.\+])([0-9]+)([^\.0-9])/ , "\\1\\2.0\\3" , "g", rhs ); + rhs2 = gensub ( /([^e]\+)([0-9]+)([^\.0-9])/ , "\\1\\2.0\\3" , "g", rhs1 ); + printf "%s:=%s$\n", lhs, rhs2 ; + }' +} + +mtt_optimise () +{ + sys="$1" + lhs="$2" + rhs="$3" + + 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 + return +} + + +# Remove log files +rm -f def2write_r1.log def2write_r2.log + # Write out the code -echo 'off echo$' >$1_$2_write.r +echo "" > $1_$2_write.r if [ ${opt:-""} = "-optimise" ]; then - echo 'load scope$' + echo 'off nat$' +# echo 'on echo$' else + echo 'off echo$' echo 'load gentran$' fi >> $1_$2_write.r for matrix in $matrices; do n=`first "$ns"`; ns=`rest "$ns"` @@ -137,19 +207,17 @@ is=`n2m 1 $n`; js=`n2m 1 $m`; for i in $is; do for j in $js; do if [ ${opt:-""} = "-optimise" ]; then - echo 'optimize' name=`echo MTT$matrix'('$i','$j')'` - echo ' '$comma$name ':=:' $name - echo 'INAME mtt_tmp$' + 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 done -echo 'END$' >>$1_$2_write.r +echo ';END;' >>$1_$2_write.r