Differences From Artifact [10c4312f8d]:

To Artifact [ec2007c6a1]:


9
10
11
12
13
14
15






















16
17
18
19
20
21
22
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.11.2.4  2002/06/05 23:34:33  geraint
## Eliminated argument list too long warnings.
## Now get a Segmentation Fault with very long equations!
##
## Revision 1.11.2.3  2002/06/05 18:23:38  geraint
## Cosmetic change.
##
## Revision 1.11.2.2  2002/06/05 17:57:47  geraint
## Main part of optimisation routine moved to separate file.
##
## 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.
## Replaced calls to awk with call to gawk.
##
## Revision 1.9  2001/07/27 23:29:10  geraint
## Optimises only when requested (-opt).
##
77
78
79
80
81
82
83





84
85
86
87
88
89
90
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117







+
+
+
+
+







Nu=`mtt_getsize $sys u` # Inputs 
Ny=`mtt_getsize $sys y` # Outputs 
Nyz=`mtt_getsize $sys yz` # Zero outputs
#Npar=`wc -l $sys\_sympar.txt | gawk '{print $1}'`

# Set up representation-specific stuff
case $rep in
    ae)
	matrices='Yz'
	ns="$Nyz"
	ms="1"
	;;
    cse)
        matrices='EdX E'
        ns="$Nx $Nx"
        ms="1 $Nx"
	;;
    csex)
        matrices='EdX'
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
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







-
+
+

-

-
+
-
-

-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
+
+
-
-
-
-
-
+







    }'
}

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"
    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$

    # get rhs and write to tmp file to be processed by mtt_optimise.sh
out "$tmp2"$
EOF
    } > $tmp
    
    eval "grep -i -e \"^$lhs\"" $dae | eval "sed 's/\([.]*\)[;$]*$/\1/'" | eval "sed 's/\ //g'" | eval "sed 's/:=/ /'" > $tmp
    echo "optimize" >> $tmp
    grep -i -e "^$lhs" $dae |\
	sed -e 's/;/\ INAME\ mtt_tmp/g' |\
	sed -e 's/:=/:=/g' >> $tmp
    {
	cat <<EOF

    eval mtt_optimise.sh $tmp
shut "$tmp2"$
EOF
    } >> $tmp
 
    cat $tmp | mtt_fix_integers
    
    ${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
    return 0
}


# Remove log files
rm -f def2write_r1.log def2write_r2.log

# Write out the code
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
222
223
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
222
223
224







-
+










    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"
	    mtt_optimise $1 "$comma$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 ]