Differences From Artifact [7ef04b9230]:

To Artifact [10c4312f8d]:


9
10
11
12
13
14
15




16
17
18
19
20
21
22
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$




## 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.
##
## Revision 1.7.2.1  2001/05/04 04:07:24  geraint







>
>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## 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.
##
## Revision 1.7.2.1  2001/05/04 04:07:24  geraint
118
119
120
121
122
123
124
































































125
126
127
128
129

130

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
        ms="$Nx $Nu $Nx $Nu"
	;;
    *)
        echo def2write_r: representation $rep not recognised
        exit
esac

































































# Write out the code
echo 'off echo$'                    >$1_$2_write.r

if [ ${opt:-""} = "-optimise" ]; then
    echo 'load scope$'

else

    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`; 
    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$'
	    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







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|


|
>

>











<

|
<









|
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

212
213

214
215
216
217
218
219
220
221
222
223
        ms="$Nx $Nu $Nx $Nu"
	;;
    *)
        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 <<EOF
off echo$
load scope$
on double$
on noconvert$
on rounded$
off int$
off nat$

out "$tmp2"$
EOF
    } > $tmp
    
    echo "optimize" >> $tmp
    grep -i -e "^$lhs" $dae |\
	sed -e 's/;/\ INAME\ mtt_tmp/g' |\
	sed -e 's/:=/:=/g' >> $tmp
    {
	cat <<EOF

shut "$tmp2"$
EOF
    } >> $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 "" > $1_$2_write.r

if [ ${opt:-""} = "-optimise" ]; then
    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"` 
    m=`first "$ms"`; ms=`rest "$ms"`
    is=`n2m 1 $n`; 
    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"

	    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

MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]