Overview
Comment:More reps added
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: f86a4000fb3b2a56b150ea318b5297aae1d651acdaed81c777599c32c6533221
User & Date: gawthrop@users.sourceforge.net on 2000-10-10 21:00:43
Other Links: branch diff | manifest | tags
Context
2000-10-10
21:00:58
New code genration check-in: 93ccf23da2 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
21:00:43
More reps added check-in: f86a4000fb user: gawthrop@users.sourceforge.net tags: origin/master, trunk
21:00:27
More changes for new code gneration check-in: 6d3dc326a1 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/mtt_r2m from [07b6544b16] to [91f6e3a0f2].

1
2
3
4
5
6
7
8
9

10
11
12

13
14
15
16
17
18



19
20
21
22
23
24
25
#! /bin/sh

     ###################################### 
     ##### Model Transformation Tools #####
     ######################################

# Bourne shell script: mtt_r2m
# Reduce to octave conversion
# Based on obsolete ode_r2m  and ode_r2lang

# P.J.Gawthrop 14 June 1991, 12 Jan 1994, April 1994, Jan 95, May 1998
# July 1998
# Copyright (c) P.J.Gawthrop 1991, 1994, 1995, 1996, 1998


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



## Revision 1.21  2000/08/30 11:43:40  peterg
## -optimise switch added
##
## Revision 1.20  2000/08/30 10:43:17  peterg
## Simplified version using GENTRAN matrix :=: matrix
## lang_matrix is no longer used at all
##









>



>






>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /bin/sh

     ###################################### 
     ##### Model Transformation Tools #####
     ######################################

# Bourne shell script: mtt_r2m
# Reduce to octave conversion
# Based on obsolete ode_r2m  and ode_r2lang
# Based on obsolete mtt_r2m_old
# P.J.Gawthrop 14 June 1991, 12 Jan 1994, April 1994, Jan 95, May 1998
# July 1998
# Copyright (c) P.J.Gawthrop 1991, 1994, 1995, 1996, 1998
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.22  2000/09/15 08:27:07  peterg
## Removed debugging lines
##
## Revision 1.21  2000/08/30 11:43:40  peterg
## -optimise switch added
##
## Revision 1.20  2000/08/30 10:43:17  peterg
## Simplified version using GENTRAN matrix :=: matrix
## lang_matrix is no longer used at all
##
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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
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
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
    -noglobals)
	noglobals='-noglobals';
	;;
    -parameters)
	parameters='-parameters';
        par='mttpar'
	;;
    -optimise)
	optimise='LOAD SCOPE; ON GENTRANOPT;';
        iname='INAME mtt_o;';
	;;

    *)
	echo $1 is an unknown option
        exit;;
  esac
  shift
done

# Set up the language specific stuff
rep=$2
ext='m';
codegenerator='PASCAL'
Lc='#';
Rc='#';
Lb='(';
Rb=')';

outfile=$1"_"$rep

## Find som constants
Nx=`grep "MTTNx " <$1_def.r | awk '{print $3}' | sed 's/;//'`

#Set up gentran
cat <<EOF >mtt_setreduce.r
% Set up the code generator

% Load the general translator package
LOAD GENTRAN;
GENTRANLANG!* := '$codegenerator; %'
ON GENTRANSEG; % Segmentation 
% Optimise
$optimise 

ON GETDECS;    % Create decrarations automatically
DEFTYPE!* := 'REAL; % and default to real '
OFF GENDECS;  % No declarations
MAXEXPPRINTLEN!* := 80;
TEMPVARNUM!* := 1;
TEMPVARNAME!* := 'mtt_s; % '

$iname

% Matrix output function
%in"$MTTPATH/trans/lang_matrix.r";

%Read the reduce definitions file
in "$1_def.r";

%Read the reduce  $REP   file
in "$1_$rep.r";

%Read the substitution file
in "$1_subs.r";

%%% The following is a bug fix  from ZIB to fix 
%%% segmentation violation problem
symbolic procedure maxtype type;
% ------------------------------------------------------------------- ;
% A type may be a pair (l u) wher l is the minimum type for a variable;
% and  u is the maximum type. This procedure returns the maximum type.;
% ------------------------------------------------------------------- ;
   if atom type
   then type
   else if pairp cdr type then cadr type else car type;

% This fix handles the case that the type is a list with ONE entry.
% Should never happen ?? W.N.
%%%%%% End of bug fix


END;
EOF

#Inform user
if [ -n "$optimise" ]; then
    blurb=' using code optimisation'
fi
echo Creating $outfile.m $blurb



# Remove the old log file
rm -f mtt_r2m.log


if [ "$rep" = "ode" ]||[ "$rep" = "cse" ]; then
  #echo Creating $1_odea.$ext
  outfileo=$outfile"o"
  echo Creating $outfileo.m $blurb

  #rm -f $1_odea.$ext.1;

  #Header
  lang_header $noglobals $parameters $1 $rep $ext 'mttx,mttu,mttt,mttpar' mttdx > $1_$2.pas
  lang_header $noglobals $parameters $1 $2o $ext 'mttx,mttu,mttt,mttpar' mtty  > $1_$2o.pas

  rm -f mtt_ode mtt_odeo

  # Use reduce to accomplish the transformation
$SYMBOLIC  > mtt_r2m.log <<EOF
  %Set up the code generator
  in"mtt_setreduce.r";
      
    
    % The body of the odeo function
     GENTRANOUT "mtt_odeo";
     %mtt_matrix := MTTy$
     %mtt_matrix_n := MTTNy$
     %mtt_matrix_m := 1$
     %lang_matrix(); 

     GENTRAN MTT_matrix :=: MTTy$
     GENTRANSHUT "mtt_odeo";
END;;

EOF
mtt_vectorise mtt_odeo; # Its really a vector

  if [ "$rep" = "ode" ]; then
  # Use reduce to accomplish the transformation
$SYMBOLIC  >> mtt_r2m.log <<EOF
  %Set up the code generator
  in"mtt_setreduce.r";
      
  % The body of the ode function
    GENTRANOUT "mtt_ode";
    %mtt_matrix := MTTdX$
    %mtt_matrix_n := MTTNx$
    %mtt_matrix_m := 1$
    %lang_matrix();
    GENTRAN MTT_matrix :=: MTTdX$
    GENTRANSHUT "mtt_ode";
END;;

EOF
mtt_vectorise mtt_ode; # Its really a vector

  else
## cse representation

$SYMBOLIC  >> mtt_r2m.log <<EOF
  %Set up the code generator
  in"mtt_setreduce.r";
      
  % The body of the cse function
    GENTRANOUT "mtt_ode";
  %  mtt_matrix := MTTEdX$
  %  mtt_matrix_n := MTTNx$
  %  mtt_matrix_m := 1$
  %  lang_matrix();
    GENTRAN MTT_matrix :=: MTTEdX$
    GENTRANSHUT "mtt_ode";
    
%    GENTRANOUT "mtt_odee";
%    mtt_matrix := MTTE$
%    mtt_matrix_n := MTTNx$
%    mtt_matrix_m := MTTNx$
%    lang_matrix();
%    GENTRANSHUT "mtt_odee";

END;;
EOF
mtt_vectorise mtt_ode; # Its really a vector

  fi

#if [ "$rep" = "ode" ]; then
#  touch mtt_odee
#fi

sed 's/mtt_matrix/mttdx/' <mtt_ode  >> $1_$2.pas
#sed 's/mtt_matrix/mtte/'  <mtt_odee >> $1_$2.pas
sed 's/mtt_matrix/mtty/'  <mtt_odeo >> $1_$2o.pas


rm -f mtt_odeo mtt_ode #mtt_odee

# Convert from Pascal syntax to Octave syntax 
 mtt_p2m<$1_$2o.pas > $1_$2o.m 

 rm -f    $1_odeo.pas
fi
  
if [ "$rep" = "sm" ]||[ "$rep" = "ssm" ]||[ "$rep" = "dm" ]||\
   [ "$rep" = "csm" ]||[ "$rep" = "obs" ]; then

if  [ "$rep" = "sm" ]||[ "$rep" = "ssm" ]; then
   #Header
  lang_header $noglobals $parameters $1 $rep $ext "$par" [mtta,mttb,mttc,mttd] > $outfile.pas
  Symbols='a b c d'    
fi

if [ "$rep" = "dm" ]||[ "$rep" = "csm" ]; then
   #Header
  lang_header $noglobals $parameters $1 $rep $ext "$par" [mtta,mttb,mttc,mttd,mtte] > $outfile.pas
  Symbols='a b c d e'    
fi

if [ "$rep" = "obs" ]; then
  # Is the system affine (look in the _obs.r file
  affine=`grep 'affine :=' $1_obs.r | awk '{print $3}' | sed 's/;//'`
  echo 'affine = ' $affine
   #Header 
if [ "$affine" = "1" ]; then
    lang_header $noglobals $parameters $1 obs m mttx [mttobs_o,mttobs_h] >  $outfile.pas
else
    lang_header $noglobals $parameters $1 obs m mttx,mttu mttyy > $outfile.pas
fi
  Symbols='obs_o obs_h'    
fi

for Symbol in $Symbols; do
  rm -f $outfile.1
# echo Doing $Symbol

if  [ "$rep" = "sm" ]||[ "$rep" = "ssm" ]||[ "$rep" = "csm" ]||[ "$rep" = "obs" ]; then
      case $Symbol in
    a)
	N=MTTNx; M=MTTNx
	;;
    b)
	N=MTTNx; M=MTTNu
	;;
    c)
	N=MTTNy; M=MTTNx
	;;
    d)
	N=MTTNy; M=MTTNu
	;;
    e)
	N=MTTNx; M=MTTNx
	;;
    obs_o)
	N=MTTNyy; M=1
	;;
    obs_h)
	N=MTTNyy; M=MTTNuu
	;;
    *)
	
     esac
else
  NN=MTTNx+2*MTTNz+MTTNyz
  case $Symbol in
    a)
	N=$NN; M=$NN
	;;
    b)
	N=$NN; M=MTTNu
	;;
    c)
	N=MTTNy; M=$NN
	;;
    d)
	N=MTTNy; M=MTTNu
	;;
    e)
	N=$NN; M=$NN
	;;
    *)
  esac
    
fi

# Set up the matrices

    rm -f mtt_zero.m

 $SYMBOLIC  << EOF >>mtt_r2m.log
    write "Doing ", "$Symbol";
    %Set up the code generator
    in"mtt_setreduce.r";
   OUT "mtt_zero.m";
     write  "mtt$Symbol = zeros(", $N, ",", $M , ");" ;
  SHUT  "mtt_zero.m";

    GENTRANOUT "$outfile.1";
    mtt_matrix := MTT$Symbol;
    %mtt_matrix_n := $N;
    %mtt_matrix_m := $M;
    %lang_matrix();
    GENTRAN mtt_matrix :=: mtt_matrix;
    GENTRANSHUT "$outfile.1";
END;
EOF


echo "%$Symbol matrix#" >> $outfile.pas
cat mtt_zero.m >> $outfile.pas

sed "s/mtt_matrix/mtt$Symbol/" < $outfile.1 |\
grep -v '=0\.0;'  >> $outfile.pas

#echo Done $Symbol

done


fi 

# Convert from Pascal syntax to Octave syntax
 mtt_p2m <$outfile.pas > $outfile.m

rm -f $outfile.pas  
rm -f mtt_zero.m
rm -f $outfile.1  
  

# Now invoke the standard error handling.
mtt_error_r mtt_r2m.log










<
<
<
<
<







|

|
<
<
<
<
<
<
|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<
<
<
|
<
<




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

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

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


|



97
98
99
100
101
102
103





104
105
106
107
108
109
110
111
112
113






114
115






















































116



117


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
156
157
158
159
    -noglobals)
	noglobals='-noglobals';
	;;
    -parameters)
	parameters='-parameters';
        par='mttpar'
	;;





    *)
	echo $1 is an unknown option
        exit;;
  esac
  shift
done

# Set up some strings
rep=$2
ext=m






out=$1"_"$rep.$ext























































#Inform user



echo Creating $out



# Remove the old log file
rm -f mtt_r2m.log









#Header


case $rep in

    cse)




    mtt_header  $1 $rep $ext 'mttx,mttu,mttt,mttpar' 'mttedx,mtte' > $out










       ;;
    cseo)


    mtt_header  $1 $rep $ext 'mttx,mttu,mttt,mttpar' mtty > $out














       ;;
    ode)





    mtt_header  $1 $rep $ext 'mttx,mttu,mttt,mttpar' mttdx > $out



       ;;








    odeo)






    mtt_header  $1 $rep $ext 'mttx,mttu,mttt,mttpar' mtty > $out
       ;;


    sm)

    mtt_header  $1 $rep $ext mttpar 'mtta,mttb,mttc,mttd' > $out



       ;;



    *)
esac



































#Convert from the (optimised) r file

echo >> $out
echo '## Code' >> $out
grep 'mtt' < $1_$2.r |\











sed \












    -e "s/^mtt/  mtt/" \
    -e "s/:=/=/" \
    -e "s/\\$/;/" \

 >> $out





















echo endfunction >> $out










































# Now invoke the standard error handling.
#mtt_error_r mtt_r2m.log




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