Differences From Artifact [bdaa78ff6b]:

To Artifact [f2349eb5aa]:


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.15  2002/08/29 15:45:20  geraint
## Tests for existence of matrix before entering shell loop.
## Tests for existence of expression before attempting to write or optimise.
##
## 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.
##







>
>
>
>
>
>







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

###############################################################
## 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.
## Tests for existence of expression before attempting to write or optimise.
##
## 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.
##
72
73
74
75
76
77
78
79



80
81
82
83
84
85
86
87
88
## Initial revision
##
###############################################################

optimise=''
while [ -n "`echo $1 | grep '^-'`" ]; do
    case $1 in
	-optimise)



	    opt='-optimise'
	    optimise_msg=' with optimisation' ;;
	-fixcc )
	    include=`echo 'in "'$MTT_LIB'/reduce/fix_c.r";'` ;;
	*)
	    echo "$1 is an invalid argument - ignoring" ;;
    esac
    shift
done







|
>
>
>
|
|







78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
## Initial revision
##
###############################################################

optimise=''
while [ -n "`echo $1 | grep '^-'`" ]; do
    case $1 in
	-optimise_global )
	    opt=''
	    optimise_msg='' ;;
	-optimise_local )
	    opt='-optimise_local'
	    optimise_msg=' with local optimisation' ;;
	-fixcc )
	    include=`echo 'in "'$MTT_LIB'/reduce/fix_c.r";'` ;;
	*)
	    echo "$1 is an invalid argument - ignoring" ;;
    esac
    shift
done
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
        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 );
	rhs3 = gensub ( /([^A-Za-z_0-9\.\+])([0-9]+)e([0-9]+).0([^\.0-9])/ , "\\1\\2\\3\\4" , "g" , rhs)
	printf "%s:=%s$\n", lhs, rhs3 ;
    }'
}

mtt_optimise ()
{
    sys="$1"
    lhs="$2"
    rhs="$3"
    
    dae="${sys}_dae.r"
    tmp="mtt_optimise.tmp"







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







158
159
160
161
162
163
164

















165
166
167
168
169
170
171
172
        ms="$Nx $Nu $Nx $Nu"
	;;
    *)
        echo def2write_r: representation $rep not recognised
        exit
esac


















mtt_optimise_local ()
{
    sys="$1"
    lhs="$2"
    rhs="$3"
    
    dae="${sys}_dae.r"
    tmp="mtt_optimise.tmp"
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257

258
259
260

# 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
    matrix_exists=`grep -i MTT${matrix} ${sys}_dae.r | wc -l | gawk '{print $1}'`
    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`; 

	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







|














>



|

|









>



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

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

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

if [ ${opt:-""} = "-optimise_local" ]; then
    echo 'off nat$'
#    echo 'on echo$'
else
    echo 'off echo$'
    echo 'load gentran$'
fi >> $1_$2_write.r

for matrix in $matrices; do
    matrix_exists=`grep -i MTT${matrix} ${sys}_dae.r | wc -l | gawk '{print $1}'`
    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')'`
			mtt_optimise_local $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
	echo "write \"% End Matrix MTT${matrix}\"$" >> $1_$2_write.r
    fi
done
echo ';END;'                           >>$1_$2_write.r

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