Differences From Artifact [4aa34d622e]:

To Artifact [a02e2cb627]:


10
11
12
13
14
15
16



17
18
19
20
21
22
23
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26







+
+
+







# Copyright (c) P.J.Gawthrop 1991, 1994, 1995, 1996

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.11  1998/05/21 08:05:23  peterg
## Back under RCS
##
## Revision 1.10  1998/04/14 07:25:02  peterg
## _input now has arguments (x,t)
##
## Revision 1.9  1998/03/30 14:18:07  peterg
## Removed NERO command
##
## Revision 1.8  1998/02/25 18:03:49  peterg
44
45
46
47
48
49
50

51
52
53
54
55








56
57
58
59
60
61
62
63
64




65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

















94
95
96
97
98
99
100







+





+
+
+
+
+
+
+
+









+
+
+
+













-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







## Revision 1.1  1996/08/18 12:03:49  peter
## Initial revision
##
###############################################################

#Inform user
echo Creating $1_ode.m
echo Creating $1_odea.m
echo Creating $1_odeo.m


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

#Remove the temporary files
rm -f $1_ode.mc
rm -f $1_ode.m1
rm -f $1_ode.m2
rm -f $1_ode.m3
rm -f $1_ode.m4
rm -f $1_odea.m1;

# Use reduce to accomplish the transformation
reduce >ode_r2m.log << EOF

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

%Read the reduce  ODE   file
in "$1_ode.r";

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


%Set up the number of argument variables to zero in case the user has forgotten
MTTNVar := 0;

%Read the parameter file
in "$1_sympar.r";

%ON NERO;        % Suppress zero elements

%Define the common part of the functions.

PROCEDURE common;
BEGIN
  IF MTTNvar>0 THEN
  BEGIN
    write "% Read in the parameters";
    write "global ...;;";
    FOR i := 1:MTTNvar DO
    IF numberp(MTTVar(i,1)) 
      THEN 
      BEGIN
      % Do nowt
      END
      ELSE  
      BEGIN
         IF i<MTTNvar THEN write MTTVar(i,1), " ..."
                      ELSE write MTTVar(i,1), ";"
      END;
  END;
  
  write "% Read in the input";
  write "u = $1_input(x,t)";

  write "% Read in the definitions";
  write "[nx,ny,nu,nz,nyz] = $1_def";

%  write "% Read in the arguments";
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
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







+

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







  
  write "% Set up the Input variables";
  IF MTTNu>0 THEN
  FOR i := 1:MTTNu DO
  BEGIN
    write "mttu", i, " = u(", i, ");";
  END;

END;
  
% Firstly do the dx = f(x,t) function.
OUT "$1_ode.m";
  
write "function mttdx = $1_ode(x,t);";
write "% mttdx = $1_ode(x,t);";
write "%ODE in Simulab form for system $1;;";
write "%File $1_ode.m;;";
write "%Generated by MTT;;";

common();


% The common part
OUT "$1_ode.mc";
common();
SHUT "$1_ode.mc";

% Set up internal inputs (if any)
OUT "$1_ode.m3";
  write "% Set up the Internal Input variables";
  IF MTTNyz>0 THEN
  FOR i := 1:MTTNyz DO
  BEGIN
    write "mttui", i, " = mttui(", i, ");";
  END;
SHUT "$1_ode.m3";

OUT "$1_ode.m4";
  write "% Set up the Internal Input variables (saved in the state vector)";
  IF MTTNyz>0 THEN
  FOR i := 1:MTTNyz DO
  BEGIN
    write "mttui(", i, ") = x(", i+MTTNx, ");";
  END;
SHUT "$1_ode.m4";

% The body of the ode function
  GENTRANOUT "$1_ode.m1";
  mtt_matrix := MTTdX$
  mtt_matrix_n := MTTNx$
  mtt_matrix_m := 1$
  mtt_matrix_name := MTTdX$
  matlab_matrix(); 
  GENTRAN MTTdx := mtt_matrix;
  GENTRANSHUT "$1_ode.m1";
  
% The algebraic equations (if any)
  GENTRANOUT "$1_odea.m1";
  mtt_matrix := MTTYz$
  mtt_matrix_n := MTTNYz$
  mtt_matrix_m := 1$
  mtt_matrix_name := MTTYz$
  matlab_matrix(); 
  GENTRAN MTTYz := mtt_matrix;
  GENTRANSHUT "$1_odea.m1";

 
%Fortran switches - one line expressions
OFF echo;
ON fort$
cardno!* := 1$
fortwidth!* := 10000$
OFF period$

168
169
170
171
172
173
174

175








176


177


178


179








180


















































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







+

+
+
+
+
+
+
+
+

+
+

+
+

+
+

+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
fortwidth!* := 500$
OFF period$

MTTy := MTTy;

SHUT "$1_odeo.m";

EOF

# Create the ode.m function
cat <<EOF > $1_ode.m
function mttdx = $1_ode(x,t);
% mttdx = $1_ode(x,t);
%ODE in Octave form for system $1;
%File $1_ode.m;
%Generated by MTT on `date`;
EOF

# Create the globals
sympar2global_txt2m $1 >> $1_ode.m

#Common bit
cat $1_ode.mc >> $1_ode.m

#Extract internal input from state vector
cat $1_ode.m4 >> $1_ode.m

cat <<EOF >> $1_ode.m
% Solve the algebraic equations (if any)
if nyz>0
  global xx;
  xx = x;
  mttui = fsolve('$1_odea',mttui);
end;
EOF

cat $1_ode.m3 >> $1_ode.m

cat <<EOF >> $1_ode.m

% The differential equations
EOF
cat $1_ode.m1 >> $1_ode.m

cat <<EOF >> $1_ode.m

% Append the internal inputs to the state derivative
mttdx = [mttdx; mttui];
EOF


# Create the odea.m function
cat <<EOF > $1_odea.m
function mttyz = $1_odea(mttui);
% mttyz = $1_odea(mttui);
%Algebraic equations in Octave form for system $1;
%File $1_odea.m;
%Generated by MTT on `date`;
EOF

# Create the globals
sympar2global_txt2m $1 >> $1_odea.m

cat <<EOF >> $1_odea.m

global xx t;
x = xx;
EOF

#Common bit
cat $1_ode.mc >> $1_odea.m

# Internal inputs
cat $1_ode.m3 >> $1_odea.m

cat <<EOF >> $1_odea.m

% The algebraic equations
EOF
cat $1_odea.m1 >> $1_odea.m







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