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.16.2.1 2002/09/03 23:44:43 geraint +## adding global optimisation (-optg). +## ## Revision 1.16 2002/09/03 19:34:15 geraint ## Write EdX regardless - csex is needed to create ode when not optimised. ## ## Revision 1.15 2002/08/29 15:45:20 geraint ## Tests for existence of matrix before entering shell loop. @@ -227,10 +230,11 @@ if [ "$matrix" = "EdX" -o $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`; + echo "write \"% Begin Matrix MTT${matrix}\"$" >> $1_$2_write.r if [ $n -ge 1 ]; then for i in $is; do for j in $js; do if [ ${opt:-""} = "-optimise_local" ]; then name=`echo MTT$matrix'('$i','$j')'` @@ -242,8 +246,9 @@ echo ' '$comma$name ':=' $name '$' fi >> $1_$2_write.r done done fi + echo "write \"% End Matrix MTT${matrix}\"$" >> $1_$2_write.r fi done echo ';END;' >>$1_$2_write.r Index: mttroot/mtt/bin/trans/mtt_optimise_global ================================================================== --- mttroot/mtt/bin/trans/mtt_optimise_global +++ mttroot/mtt/bin/trans/mtt_optimise_global @@ -35,24 +35,47 @@ 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 + +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} < $logfile 2>&1 off nat; in "${system}_def.r"; @@ -64,10 +87,13 @@ $end; EOF cp $outfile $outfile.unoptimised cp $tmpfile $outfile.tmp -cat $tmpfile | mtt_fix_integers > $outfile -#cp $tmpfile $outfile + +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