Overview
Comment:Put under RCS
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: f928abb12e6103ead494e496b16ed4220e9a2de08419db46330f1d796e79ad4f
User & Date: gawthrop@users.sourceforge.net on 2000-12-28 12:48:53.000
Other Links: branch diff | manifest | tags
Context
2000-12-28
12:53:10
*** empty log message *** check-in: 7c534b51f6 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
12:48:53
Put under RCS check-in: f928abb12e user: gawthrop@users.sourceforge.net tags: origin/master, trunk
12:31:15
*** empty log message *** check-in: 72f66b24e2 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes
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
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







+
+
+















-
-
+
+






# Copyright (c) P.J.Gawthrop, 1996.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
# Revision 1.3  1996/11/03  21:11:44  peterg
# Removed END; statement
#
## Revision 1.2  1996/11/02 10:20:53  peterg
## Created from lbl2sympar
##
###############################################################


# Inform user
echo "Creating $1_cr.r"

rm -f mtt_error

#Write some file headers
echo "%% constitutive relationship  file ($1_cr.r)" > $1_cr.r
echo "%% Generated by MTT at `date`" >> $1_cr.r

# This is the main transformation using gawk
gawk -f $MTTPATH/trans/awk/lbl2cr.awk <$1_lbl.txt  2>mtt_error.txt | \
# This is the main transformation using awk
awk -f $MTTPATH/trans/awk/lbl2cr.awk <$1_lbl.txt  2>mtt_error.txt | \
	sh >> $1_cr.r

# Now invoke the standard error handling.
#mtt_error mtt_error.txt


11
12
13
14
15
16
17



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







+
+
+







# Copyright (c) P.J.Gawthrop, 1996.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
# Revision 1.6  1996/12/07  19:39:51  peterg
# Minor debugging.
#
## Revision 1.5  1996/09/12 17:18:44  peter
## Don't add an RCS header ..
##
## Revision 1.4  1996/08/30 19:01:21  peter
## Added headers to sympar file.
##
## Revision 1.3  1996/08/30 10:18:33  peter
38
39
40
41
42
43
44
45

46
47

48
49
50
51
52
41
42
43
44
45
46
47

48
49

50
51
52
53
54
55







-
+

-
+






rm -f mtt_error

#Write some file headers
echo "%% Symbolic parameter file ($1_sympar.r)" > $1_sympar.r
echo "%% Generated by MTT at `date`" >> $1_sympar.r

# This is the main transformation using gawk
# This is the main transformation using awk
tr ';' ',' <  $1_lbl.txt | \
gawk -f $MTTPATH/trans/awk/lbl2sympar.awk >> $1_sympar.r 2>mtt_error.txt
awk -f $MTTPATH/trans/awk/lbl2sympar.awk | sort >> $1_sympar.r 2>mtt_error.txt

# Now invoke the standard error handling.
mtt_error mtt_error.txt


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 1998

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.9  2000/11/16 13:11:06  peterg
## Included PAR and UNITS declarations
##
## Revision 1.8  1999/02/17 21:42:19  peterg
## Replaced print by printf to avoid extra nl in paragraph command.
##
## Revision 1.7  1998/07/27 12:56:26  peterg
## Splits up | separated expressions.
##
## Revision 1.6  1998/07/27 10:56:31  peterg
121
122
123
124
125
126
127
128









129
130
131
132
133
134
135
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146







-
+
+
+
+
+
+
+
+
+







      }
    END{if (NR==0) print "\\item This component has no UNITs declarations"
}' >> $1_lbl.tex
cat <<EOF >> $1_lbl.tex
\end{description}
EOF


# Write the actual lbl file
cat >> $1_lbl.tex <<EOF
\subsubsection*{The label file: $1\_lbl.txt}
\begin{verbatim}
EOF
cat $1_lbl.txt >> $1_lbl.tex
cat >> $1_lbl.tex <<EOF
\end{verbatim}
EOF







1
2
3
4
5
6
7
8
9

10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19









+

-
+







#! /bin/sh

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

# Bourne shell script: matlab_header
# Generic octave function header


#Write some file headers
echo "function [A,B,C,D,E] = $1_$2" 
echo "function [$3] = $1_$2" 
echo "% $2 function for system $1 ($1_$2.m)"   
echo "% Generated by MTT at `date`"  
echo  

#Globals
sympar2global_txt2m $1 
echo  ';'
8
9
10
11
12
13
14



15
16
17
18
19
20
21

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

24
25
26
27
28
29
30
31







+
+
+






-
+









% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % $Id$
% % $Log$
% % Revision 1.1  1998/03/22 10:26:47  peterg
% % Initial revision
% %
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Load the general translator package
LOAD GENTRAN;
GENTRANLANG!* := 'FORTRAN;
ON GENTRANSEG;
MAXEXPPRINTLEN!* := 80;
MAXEXPPRINTLEN!* := 400;

PROCEDURE matlab_Matrix;
BEGIN
  ON NERO;
  write "mtt_matrix = zeros(", mtt_matrix_n, ",", mtt_matrix_m, ");";
  IF MTT_Matrix_n>0 THEN
    IF MTT_Matrix_m>0 THEN
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, 1996

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.7  1998/03/06 17:14:09  peterg
## Cospetic change to message
##
## Revision 1.6  1998/03/05 10:17:41  peterg
## Cosmetic change
##
## Revision 1.5  1998/03/05 10:14:37  peterg
## Toned down the error warning message
##
## Revision 1.4  1998/02/26 10:21:51  peterg
38
39
40
41
42
43
44
45

46
47
48
49
50
41
42
43
44
45
46
47

48
49
50
51
52
53







-
+





error_file=$1;

# Test for errors and print if any
err_length=`wc -c <$error_file | awk '{print $1}'`
if [ "$err_length" != "0" ]
then
  echo "INFORMATION: An MTT transformation has generated the following messages"
  echo "             (which may not be important)"
#  echo "             (which may not be important)"
  cat $error_file
  exit 1
else
  exit 0
fi
13
14
15
16
17
18
19



20
21
22
23
24
25
26
27

28







29
30
31
32
33
34
35
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
45







+
+
+








+
-
+
+
+
+
+
+
+







    #$Id$	

while [ -n "`echo $1 | grep '^-'`" ]; do
  case $1 in
	-internal )
                internal=yes;
		;;
	-external )
                external=yes;
		;;
	*)
		echo "$1 is an invalid argument - ignoring";
                exit ;;
  esac
  shift
done

if [ -n "$internal" ]; then
    name=MTT$2"[0-9]"; # echo $name
    grep "MTT$2[^(]" $1_ese.r | wc -l
    grep -i "$name" $1_ese.r | wc -l
    exit
fi

if [ -n "$external" ]; then
    name="^MTT"$2"("; #echo $name
    grep -i "$name" $1_ese.r | wc -l
    exit
fi

## The original version for external sizes.
if [ "$2" = "xx" ]; then
  n=`mtt_getsize $1 x`
  N=`echo "$n * $n" | bc` 
118
119
120
121
122
123
124

125
126
127
128
129
130
131
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132







+







if [ "$affine" = "1" ]; then
    lang_header $1 obs m x [o_o,o_h] > $1_obs.m1
else
    lang_header $1 obs m x,u yy > $1_obs.m1
fi

# Put together the pieces
matlab_tidy $1_obs.m2
matlab_tidy $1_obs.m3
cat   $1_obs.m? >$1_obs.m

rm -f $1_obs.m?



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, May 1994, 1996.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.1  1998/04/07 08:30:20  peterg
## Initial revision
##
# Revision 1.3  1997/06/13  13:50:11  peterg
# Matrices in amstex format
#
# Revision 1.2  1997/04/18  12:54:00  peterg
# No longer does labels.
#
# Revision 1.1  1996/08/19  15:19:23  peter
39
40
41
42
43
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
42
43
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







+
+
+













-
-
-
-
-
-
-














+
+
+
+
+
+
+
+
+

+



in "$1_def.r";

%Read the obs file
in "$1_obs.r";

%Read the Obs function parameters
in "$1_obspar.r";

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

%Read the simplification parameters
in "$1_simp.r";

%Read the formatting function
in "$MTTPATH/trans/latex_matrix.r";

OFF Echo;
OFF Nat;
OFF EXP;

OUT "$1_obs.tex";

% Write the obs vector (YY)
MTT_Matrix := MTTYY$ 
MTT_Matrix_name := "MTTO"$
MTT_Matrix_n := (MTTGPCNY+1)*MTTNy$
MTT_Matrix_m := 1$
LaTeX_Matrix()$

% Write the affine form
IF affine=1 THEN 
BEGIN
  MTT_Matrix := MTTObs_o$ 
  MTT_Matrix_name := "MTTO_o"$
  MTT_Matrix_n := (MTTGPCNY+1)*MTTNy$
  MTT_Matrix_m := 1$
  LaTeX_Matrix()$

  MTT_Matrix := MTTObs_h$ 
  MTT_Matrix_name := "MTTO_h"$
  MTT_Matrix_n := (MTTGPCNy+1)*MTTNy$
  MTT_Matrix_m := (MTTGPCNu+1)*MTTNu$
  LaTeX_Matrix()$
END
ELSE
BEGIN
% Write the obs vector (YY)
  MTT_Matrix := MTTYY$ 
  MTT_Matrix_name := "MTTO"$
  MTT_Matrix_n := (MTTGPCNY+1)*MTTNy$
  MTT_Matrix_m := 1$
  LaTeX_Matrix()$
END;

SHUT "$1_obs.tex";
quit;
EOF
11
12
13
14
15
16
17



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







+
+
+







# Copyright (c) P.J.Gawthrop, 1996.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.17  1998/06/27 14:49:16  peterg
## No change
##
## Revision 1.16  1998/06/25 08:47:23  peterg
## Put correct arguments for _input -- (x,t)
##
## Revision 1.15  1998/05/21 16:20:27  peterg
## Modified to include explicit algebraic loop solution
##
## Revision 1.14  1998/05/19 19:48:02  peterg
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
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







+
-
+










-
-
+
+




+


-
+

















-
-
+
+



















+
-
+







    X=[];
    dt = (T(2)-T(1))/STEPFACTOR;
    for t=T'
      X = [X; xx'];
      ts = t;
      for i=1:STEPFACTOR
        x = xx(1:nx);
        u = $1_input(xx,ts);
        xx = $1_ode(xx,ts);
        xx = $1_ode(xx,u,ts);
        ts = ts + dt;
        dx = xx(1:nx);
        x = x + dx*dt;
        xx(1:nx) = x;
      end;
    end;
  elseif strcmp(method,'implicitl')
    %Euler integration
    X=[];
    dt = (T(2)-T(1))/STEPFACTOR;
    u = $1_input(x,t);
    A = $1_sm(x,u); 
    u = $1_input(x,u,t);
    A = $1_smx(x,u); 
    inverse = inv(eye(nx) - dt*A);
    for t=T'
      X = [X; xx'];
      ts = t;
      u = $1_input(x,t);
      for i=1:STEPFACTOR
        x = xx(1:nx);
        xx = $1_ode(xx,ts);
        xx = $1_ode(xx,u,ts);
        ts = ts + dt;
        dx = xx(1:nx);
        x = inverse*(x + dt*(dx - A*x));
        xx(1:nx) = x;
      end;
    end;
  elseif strcmp(method,'implicit')
    %Euler integration
    X=[];
    dt = (T(2)-T(1))/STEPFACTOR;
    One = eye(nx);
    for t=T'
      X = [X; xx'];
      ts = t;
      for i=1:STEPFACTOR
        x = xx(1:nx);
        u = $1_input(x,t);
    	A = $1_sm(x,u); 
        xx = $1_ode(xx,ts);
    	A = $1_smx(x,u); 
        xx = $1_ode(xx,u,ts);
        ts = ts + dt;
        dx = xx(1:nx);
        x = (One-A*dt)\(x + dt*(dx - A*x));
        xx(1:nx) = x;
      end;
    end;
  else
    error('Method %s not available here', METHOD);
    return;
  end;
  write_matrix([T,X], '$1_odes');
else
  X = zeros(size(T));
end;

if ny>0 % compute y and print it
  i = 0; Y=[];
  for t=T'
    i = i+1; X(i,:);
    u = $1_input(x,t);
    y = $1_odeo(X(i,:)',t);
    y = $1_odeo(X(i,:)',u,t);
    Y = [Y; y'];
  end;
  write_matrix([T,Y], '$1_odeso');
end;


EOF
11
12
13
14
15
16
17



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







+
+
+







# Copyright (c) P.J.Gawthrop, 1996.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.4  2000/10/17 11:07:59  peterg
## *** empty log message ***
##
## Revision 1.3  1998/05/19 19:27:04  peterg
## Zapped all the parameter stuff
##
## Revision 1.2  1996/09/13 19:40:51  peter
## Fixed problem with default paramaters.
##
## Revision 1.1  1996/09/12 19:26:57  peter
37
38
39
40
41
42
43




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
40
41
42
43
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
102
103
104







+
+
+
+




-
+

-
-
-

-
-
+
+










-
+










+
+
-
+



+

-
-
+
+
+
+





-







## Initial revision
##
###############################################################

echo Creating $1_odess.m
rm -f ode2odess_m.log

Nx=`mtt_getsize $1 x` # States
Nxx=`mtt_getsize $1 xx` # States x States
Nu=`mtt_getsize $1 u` # Inputs 
Ny=`mtt_getsize $1 y` # Inputs 

$MATRIX << EOF >  ode2odess_m.log 2>mtt_error.txt

  %Read in parameters
  $1_numpar;
  par = $1_numpar;

  [nx,ny,nu,nz,nyz] = $1_def;


   %Read in simulation parameters
  $1_simpar;
  T = [0:DT:LAST];
  simpar=$1_simpar;
  T = [0:simpar.dt:simpar.last];

  t=0;	%Just in case it appears in the parameter list.


  %Defaults
  if exist('T')==0
    T=[0:0.1:1]
  end;

  if exist('x0')==0
    x0 = zeros(nx,1);
    x0 = zeros($Nx,1);
  end;

  [n,m]=size(T);
  if m>n
    T=T';
  end;

global t;
function dx=f(x)
  global t
  par = $1_numpar;
  u = $1_input(x,zeros($Ny,1),t,par);
 dx = $1_ode(x,t);
  dx = $1_ode(x,u,t,par);;
endfunction;

i=0;
x = x0;
for t=T'
  i=i+1;
  x(i,:) = fsolve('f',x0)';
  u = $1_input(x,zeros($Ny,1),t,par);
  y(i) = $1_odeo(x,u,t,par)';
  mtt_write(t,x,y,$Nx,$Ny);   # Write it out
  x = fsolve('f',x)';
end;

i=0;
for t=T'
  i=i+1;
  y(i,:) = $1_odeo(x(i,:),t)';
end;

write_matrix([T,x], '$1_odess');
write_matrix([T,y], '$1_odesso');

EOF

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, 1998

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.11  1998/11/26 10:32:34  peterg
## Include subs.r
##
## Revision 1.10  1998/11/17 17:10:22  peterg
## Read in the constitutive relationship file as well
##
## Revision 1.9  1998/08/27 07:06:25  peterg
## Just genrate xj once.
##
## Revision 1.8  1998/08/27 07:04:44  peterg
185
186
187
188
189
190
191
192


193
194
195
196
197
198
199
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202
203







-
+
+







%END
%GENTRANSHUT "$1_smxtx.$lang";

EOF

if [ "$lang" = "m" ]; then
  mv $1_smx.$lang  mtt_junk
  lang_header $1 smx m 'mttx,mttu,mttdt' '[mtta,mttax]' > $1_smx.m
#  lang_header $1 smx m 'mttx,mttu,mttdt' '[mtta,mttax]' > $1_smx.m
  mtt_header $1 $2 m
  cat mtt_junk | mtt_p2m >> $1_smx.m
  rm -f mtt_junk

#  mv $1_smxx.$lang  mtt_junk
#  lang_header $1 smxx m 'mttx,mttu,mttxx,mttdt' '[mttax]' > $1_smxx.m
#  cat mtt_junk | mtt_p2m >> $1_smxx.m
#  rm -f mtt_junk
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
45
46
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27


28



















29







+
+
+







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

# Copyright (c) P.J.Gawthrop, 1997.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.1  1999/03/28 21:29:40  peterg
## Initial revision
##
###############################################################



# Inform user
echo "Creating $1_odeso.sdat"

rm -f mtt_error

dat2sdat $1 odeso | dat2siag > $1_odeso.sdat
# This is the main transformation using gawk
gawk '

BEGIN{
printf("Time");
}
{ if ($1=="output")
    printf(" %s(%s)", $3, $5);
}
END{
printf("\n");
}
'  SYSTEM=$1  < $1_struc.txt > $1_odeso.sdat 2>mtt_error.txt

cat $1_odeso.dat >> $1_odeso.sdat 2>>mtt_error.txt

# Now invoke the standard error handling.
mtt_error mtt_error.txt


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, 1996

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.4  2000/09/04 08:42:53  peterg
## Put in extra echo to space output
##
## Revision 1.3  2000/09/02 15:55:11  peterg
## Now doesn't include def files in da files
##
## Revision 1.2  2000/09/01 13:36:15  peterg
## Added -partition option
##
## Revision 1.1  2000/09/01 12:14:44  peterg
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
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







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






MTT_Matrix_m := 1$
Reduce_Matrix()$
SHUT "$daename";
quit;

EOF

if [ -n "$partition" ]; then
  rm -f mtt_junk
  # Now for the subsystems
  # Find subsystems
  subsystems=`mtt_get_subsystems $1`

  for subsystem in $subsystems; do
  echo Doing $subsystem
  ucname="MTT_"$subsystem"_uc"

  Nu=`mtt_getsize -internal $subsystem"_1" u`
  echo Nu $Nu

  # Use symbolic algebra to accomplish the transformation
  $SYMBOLIC >$logname  << EOF

  %Read the formatting function
  in "$MTTPATH/trans/reduce_matrix.r";

  % Definitions
  in "$defname";

  % Elementary system equations
  in "$rdaename";

  OFF Echo;
  OFF Nat;
 
  %Create the output file
  OUT "mtt_junk";
  % Connecting inputs
  MTT_Matrix := $ucname $
  MTT_Matrix_name := "$ucname" $
  MTT_Matrix_n := $Nu $
  MTT_Matrix_m := 1$
  Reduce_Matrix()$

  shut "mtt_junk";
EOF
  echo >> $1_dae.r
  echo %Connections for subsystem $subsystem  >> $1_dae.r
  echo >> $1_dae.r

  cat mtt_junk >> $1_dae.r
  rm -rf mtt_junk
  done
fi
#if [ -n "$partition" ]; then
#  rm -f mtt_junk
#  # Now for the subsystems
#  # Find subsystems
#  subsystems=`mtt_get_subsystems $1`
#
#  for subsystem in $subsystems; do
#  echo Doing $subsystem
#  ucname="MTT_"$subsystem"_uc"
#
#  Nu=`mtt_getsize -internal $subsystem u`
#  echo Nu $Nu
#
#  # Use symbolic algebra to accomplish the transformation
#  $SYMBOLIC >$logname  << EOF
#
#  %Read the formatting function
#  in "$MTTPATH/trans/reduce_matrix.r";
#
#  % Definitions
#  in "$defname";
#
#  % Elementary system equations
#  in "$rdaename";
#
#  OFF Echo;
#  OFF Nat;
# 
#  %Create the output file
#  OUT "mtt_junk";
#  % Connecting inputs
#  MTT_Matrix := $ucname $
#  MTT_Matrix_name := "$ucname" $
#  MTT_Matrix_n := $Nu $
#  MTT_Matrix_m := 1$
#  Reduce_Matrix()$
#
#  shut "mtt_junk";
#EOF
#  echo >> $1_dae.r
#  echo %Connections for subsystem $subsystem  >> $1_dae.r
#  echo >> $1_dae.r
#
#  cat mtt_junk >> $1_dae.r
#  rm -rf mtt_junk
#  done
#fi

echo "END;" >> $1_dae.r

# Now invoke the standard error handling.
mtt_error_r $logname

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
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
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
45
46
47
48
49
50



51
52
53
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68















+
+
+











+


-
+
















+
-
-
-
+
+
+
+







-
+






-
-
-
-
-
-
-
-
# Copyright (c) P.J.Gawthrop, 1998

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.4  2000/04/05 07:37:27  peterg
## *** empty log message ***
##
## Revision 1.3  1999/08/18 06:15:48  peterg
## Stripped down to just representations menu - see mtt_make_menu
##
## Revision 1.2  1999/03/09 00:03:19  peterg
## Revisions for xmtt
##
## Revision 1.1  1998/10/20 08:13:14  peterg
## Initial revision
##
###############################################################

sep='|'; # Separates the languages from the rest.

# Create reps menu
awk --field-separator='|' '{
awk --field-separator=$sep '{
  
# Find the rep and the title
  split($1,REP," ");
  rep=REP[1];
# find the languages
  N=split($2,LANG," ");

# Important representation?
 if (index(rep,"*")) {
    # Zap *
    rep=substr(rep,1,length(rep)-1);
    sub(/\*/,"",$1);
    printf("\n# Menus for representation %s\n", rep)
    printf(".rep.rep add  cascade -label \"%s\" -menu .rep.rep.%s\n", $1, rep);
    printf("menu .rep.rep.%s\n", rep);
    for (i=1;i<=N;i++) {
      lang = LANG[i];
      printf(" set mtt {mtt $args $system %s %s} \n", rep, LANG[i]); 
      printf(".rep.rep.%s add  command -label  \"%s\" ", rep, LANG[i]);
      printf(" -command  \"exec echo $mtt &; exec $mtt &\" \n"); 
      printf(" set mtt {mtt_pause $args $system %s %s} \n", rep, lang); 
      title = sprintf("Output_log_for_representation_%s_(language_%s)", rep, lang);
      printf(".rep.rep.%s add  command -label  \"%s\" ", rep, lang);
      printf(" -command  \"exec xterm -title %s -e $mtt  &\" \n", title); 
   }
 }
 else {
    printf("\n# Menus for representation %s\n", rep)
    printf(".repall.repall add  cascade  -label \"%s\" -menu .repall.repall.%s\n", $1, rep);
    printf("menu .repall.repall.%s\n", rep);
    for (i=1;i<=N;i++) {
      printf(" set mtt {mtt $args $system %s %s} \n", rep, LANG[i]); 
      printf(" set mtt {mtt $args $system %s %s; mtt_pause} \n", rep, LANG[i]); 
      printf(".repall.repall.%s add  command -label  \"%s\" ", rep, LANG[i]);
      printf(" -command  \"exec echo $mtt &; exec $mtt &\" \n"); 
   }
 }
}'









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

31
32
33

34
35
36
37
38






39
40
41
42









43









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

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
31
32
33
34
35
36
37
38
39
40
41
42
43
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
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






-
-
-
-
+
+
+
+






-
-
-
-
-
-
-


+

-
+


-
+


-
+


-
-
-
+
+
+
+
+
+




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

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

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


-
+


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

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

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

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

+
+


-
+





-
+
#! /bin/sh

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

# Bourne shell script: csm2sm_r
# Constrained-state equation to linear constrained-state matrices conversion
# P.J.Gawthrop  6th September 1991, May 1994
# Copyright (c) P.J.Gawthrop, 1991, 1994, 1996
# Bourne shell script: sm2can_r
# state matrices to various canonical forms.
# P.J.Gawthrop  12 Jan 1997
# Copyright (c) P.J.Gawthrop 1997

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.2  1996/08/25 10:11:32  peter
## Added END in output file.
## Error handling.
##
## Revision 1.1  1996/08/19 15:06:16  peter
## Initial revision
##
###############################################################


# Inform user
echo Creating $1_sm.r
echo Creating $1_can.r -- NOTE this is for SISO systems only.

# Remove the old log file
rm -f csm2sm_r.log
rm -f sm2can_r.log

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

in "$1_def.r";
in "$1_csm.r";
in "$1_cr.r";
in "$1_sympar.r";
in "$1_sm.r";
in "$1_tf.r";

%Read the formatting function
in "$MTTPATH/trans/reduce_matrix.r";


OFF Echo;
OFF Nat;

% Find the controllability and observibility matrices.
MATRIX MTTCon(MTTNx,MTTNX);
MTTAB := MTTB;
FOR j := 1:MTTNx DO
  BEGIN
   FOR i := 1:MTTNx DO 
      MTTCon(i,j) := MTTAB(i,1);
   MTTAB := MTTA*MTTAB;
  END;
% Find MTTA and MTTB : the A and B matrices

MATRIX MTTObs(MTTNx,MTTNX);
MTTCA := MTTC;
FOR i := 1:MTTNx DO
  BEGIN
   FOR j := 1:MTTNx DO 
      MTTObs(i,j) := MTTCA(1,j);
   MTTCA := MTTCA*MTTA;
  END;

%Canonical forms:
% This statement makes Gs a scalar transfer function
Gs := MTTtf(1,1);

% Numerator and denominator polynomials
bs := num(gs);
as := den(gs);

% extract coeficients and divide by coeff of s^n
% reverse operator puts list with highest oder coeffs first
ai := reverse(coeff(as,s));
a0 := first(ai);
MTTn := length(ai) - 1;


% Normalised coeficients;
ai := reverse(coeff(as/a0,s));
bi := reverse(coeff(bs/a0,s));
MTTm := length(bi)-1;

% Zap the (unity) first element of ai list;
ai := rest(ai);

% System in controller form
% MTTA_c matrix
matrix MTTA_c(MTTn,MTTn);

% First row is ai coefficients
for i := 1:MTTn do
  MTTA_c(1,i) := -part(ai,i);

% (MTTn-1)x(MTTn-1) unit matrix in lower left-land corner (if n>1)
if MTTn>1 then
  for i := 1:MTTn-1 do
    MTTA_c(i+1,i) := 1;

% B_c vector;
matrix MTTB_c(MTTn,1);
MTTB_c(1,1) := 1;

% C_c vector;
matrix MTTC_c(1,MTTn);
for i := 1:MTTm+1 do
  MTTC_c(1,i+MTTn-MTTm-1) := part(bi,i);

% D_c
MTTinvE := MTTE^(-1);
MTTA := MTTinvE*MTTA;
MTTB := MTTinvE*MTTB;
MTTD_c := MTTD;

%Observable form.
MTTA_o := tp(MTTA_c);
MTTB_o := tp(MTTC_c);
MTTC_o := tp(MTTB_c);
MTTD_o := MTTD;

%Controllability matrix of controllable form
MATRIX MTTCon_c(MTTNx,MTTNX);
MTTAB := MTTB_c;
FOR j := 1:MTTNx DO
  BEGIN
   FOR i := 1:MTTNx DO 
      MTTCon_c(i,j) := MTTAB(i,1);
   MTTAB := MTTA_c*MTTAB;
  END;

% Transformation matrix;
MTTT_c := MTTCon_c*MTTCon^(-1);

%Observability matrix of observer form
MATRIX MTTObs_o(MTTNx,MTTNX);
MTTCA := MTTC_o;
FOR i := 1:MTTNx DO
  BEGIN
   FOR j := 1:MTTNx DO 
      MTTObs_o(i,j) := MTTCA(1,j);
   MTTCA := MTTCA*MTTA_o;
  END;

% Transformation matrix;
MTTT_o := MTTObs^(-1)*MTTObs_o;

%%%%  Controller design %%%%%

% gain in controller form:
matrix MTTk_c(1,mttn);
matrix alpha_c(9,1);
alpha_c(1,1) := alpha_c1;
alpha_c(2,1) := alpha_c2;
alpha_c(3,1) := alpha_c3;
alpha_c(4,1) := alpha_c4;
alpha_c(5,1) := alpha_c5;
alpha_c(6,1) := alpha_c6;
alpha_c(7,1) := alpha_c7;
alpha_c(8,1) := alpha_c8;
alpha_c(9,1) := alpha_c9;


for i := 1:MTTNx do
 MTTk_c(1,i) := alpha_c(i,1) - part(ai,i);

% Gain in physical form
MTTk := MTTk_c*MTTT_c;

%%%%  Observer design %%%%%
% gain in Observer form:
matrix MTTl_o(MTTn,1);
matrix alpha_o(9,1);
alpha_o(1,1) := alpha_o1;
alpha_o(2,1) := alpha_o2;
alpha_o(3,1) := alpha_o3;
alpha_o(4,1) := alpha_o4;
alpha_o(5,1) := alpha_o5;
alpha_o(6,1) := alpha_o6;
alpha_o(7,1) := alpha_o7;
alpha_o(8,1) := alpha_o8;
alpha_o(9,1) := alpha_o9;

for i := 1:MTTNx DO
 MTTL_o(i,1) := alpha_o(i,1) - part(ai,i);

% Gain in physical form
MTTL := MTTT_o*MTTL_o;

% Steady-state stuff
% Create the matrix [A B; C D];
matrix ABCD(MTTn+1,MTTn+1);
for i := 1:MTTNx do
  for j := 1:MTTNx do
    ABCD(i,j) := MTTA(i,j);

for i :=1:MTTNx do
  ABCD(i,MTTNx+1) := MTTB(i,1);

for j := 1:MTTNx do
  ABCD(MTTNx+1,j) := MTTC(1,j);

ABCD(MTTNx+1,MTTNx+1) := MTTD(1,1);

matrix zero_one(MTTNx+1,1);
zero_one(MTTNx+1,1) := 1;

%Find N vector
Nxu := ABCD^(-1)*zero_one;

%Extract the parts
MATRIX MTTX_r(MTTNx,1);
FOR i := 1:MTTNx DO
  MTTX_r(i,1) := Nxu(i,1);

MTTu_r := Nxu(MTTNx+1,1);


% Compensator

matrix zero(MTTNx,1);
%State matrices
MTTA_comp := MTTA - MTTL*MTTC - MTTB*MTTK;
MTTB_comp := -MTTL;
MTTC_comp := -MTTK;

%Transfer function
%Ds := C_d*((s*MTTI - A_d)^(-1))*B_d;
%MTTTFC := Ds;

%Create the output file
OUT "$1_sm.r";
OUT "$1_can.r";

%Write out the matrices.
IF MTTNx>0 THEN
BEGIN
  write "matrix MTTA(", MTTNx, ",", MTTNx, ");";
  FOR i := 1:MTTNx DO
   FOR j := 1:MTTNx DO IF MTTA(i,j) NEQ 0 THEN
      write "MTTA(", i, ",", j, ") := ", MTTA(i,j);
END;

% Controllable form
MTT_Matrix := MTTA_c$ 
MTT_Matrix_name := "MTTA_c"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

MTT_Matrix := MTTB_c$ 
MTT_Matrix_name := "MTTB_c"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNu$
Reduce_Matrix()$

MTT_Matrix := MTTC_c$ 
MTT_Matrix_name := "MTTC_c"$
MTT_Matrix_n := MTTNy$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$


% Observable form
MTT_Matrix := MTTA_o$ 
MTT_Matrix_name := "MTTA_o"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

MTT_Matrix := MTTB_o$ 
MTT_Matrix_name := "MTTB_o"$
IF MTTNx>0 THEN
IF MTTNu>0 THEN
BEGIN
  write "matrix MTTB(", MTTNx, ",", MTTNu, ");";
  FOR i := 1:MTTNx DO
   FOR j := 1:MTTNu DO IF MTTB(i,j) NEQ 0 THEN
      write "MTTB(", i, ",", j, ") := ", MTTB(i,j);
END;
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNu$
Reduce_Matrix()$

MTT_Matrix := MTTC_o$ 
MTT_Matrix_name := "MTTC_o"$
MTT_Matrix_n := MTTNy$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

write "%  - Controllability matrix";
MTT_Matrix := MTTCon$ 
MTT_Matrix_name := "MTTCon"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

write "%  -Observability matrix";
MTT_Matrix := MTTObs$ 
MTT_Matrix_name := "MTTObs"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

write "%  -Controllability matrix - controller form";
MTT_Matrix := MTTCon_c$ 
MTT_Matrix_name := "MTTCon_c"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

write "%  - Transformation matrix - controller form";
MTT_Matrix := MTTT_c$ 
MTT_Matrix_name := "MTTT_c"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

write "%  - Gain matrix - controller form";
MTT_Matrix := MTTK_c$ 
MTT_Matrix_name := "MTTK_c"$
MTT_Matrix_n := MTTNu$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

%Write it out
IF MTTNy>0 THEN
IF MTTNx>0 THEN
BEGIN
  write "matrix MTTC(", MTTNy, ",", MTTNx, ");";
  FOR i := 1:MTTNy DO
    FOR j := 1:MTTNx DO IF MTTC(i,j) NEQ 0 THEN
      write "MTTC(", i, ",", j, ") := ", MTTC(i,j);
END;
write "%  - Gain matrix - physical form";
MTT_Matrix := MTTK$ 
MTT_Matrix_name := "MTTK"$
MTT_Matrix_n := MTTNu$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$


write "%  -Observability matrix - Observer form";
MTT_Matrix := MTTObs_o$ 
MTT_Matrix_name := "MTTObs_o"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

write "%  - Transformation matrix - Observer form";
MTT_Matrix := MTTT_o$ 
MTT_Matrix_name := "MTTT_o"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

write "%  - Observer Gain matrix - observer form";
MTT_Matrix := MTTL_o$ 
MTT_Matrix_name := "MTTL_o"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNy$
Reduce_Matrix()$

write "%  - Gain matrix - physical form";
MTT_Matrix := MTTL$ 
MTT_Matrix_name := "MTTL"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNy$
Reduce_Matrix()$
IF MTTNy>0 THEN IF MTTNu>0 THEN 
BEGIN
  write "matrix MTTD(", MTTNy, ",", MTTNu, ");";
  FOR i := 1:MTTNy DO
    FOR j := 1:MTTNu DO IF MTTD(i,j) NEQ 0 THEN
      write "MTTD(", i, ",", j, ") := ", MTTD(i,j);
END;


% Controllable form
MTT_Matrix := MTTA_comp$ 
MTT_Matrix_name := "MTTA_comp"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

MTT_Matrix := MTTB_comp$ 
MTT_Matrix_name := "MTTB_comp"$
MTT_Matrix_n := MTTNx$
MTT_Matrix_m := MTTNu$
Reduce_Matrix()$

MTT_Matrix := MTTC_comp$ 
MTT_Matrix_name := "MTTC_comp"$
MTT_Matrix_n := MTTNy$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$


KX := MTTK*MTTX_r;
MTTu_r := MTTu_r + KX(1,1);



MTTu_r := MTTu_r;
write "END;";

SHUT "$1_sm.r";
SHUT "$1_can.r";
quit;

EOF

# Now invoke the standard error handling.
mtt_error_r csm2sm_r.log
mtt_error_r sm2can_r.log
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
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







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






-
+







echo Creating $1_ir.m
echo Creating $1_iro.m
rm -f sm2ir_m.log
rm -f $1_ir.m
rm -f $1_iro.m
rm -f mtt_error

if [ "$2" = "" ]; 
then
  PARAMS='T=[0:0.1:10];u0=ones(nu,1);x0=zeros(nx,1);'
  echo Using default parameter $PARAMS
else
  PARAMS=$2;
fi
# if [ "$2" = "" ]; 
# then
#   PARAMS='T=[0:0.1:10];u0=ones(nu,1);x0=zeros(nx,1);'
#   echo Using default parameter $PARAMS
# else
#   PARAMS=$2;
# fi

# PARAMS="$PARAMS ;"

$MATRIX << EOF > sm2ir_m.log 2>mtt_error.txt

  % Read in the numeric system parameters
  $1_numpar;
  mttpar = $1_numpar;

  [nx,ny,nu,nz,nyz] = $1_def;
  t=0;	%Just in case it appears in the parameter list.

  $PARAMS

  %Defaults
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68







-
+









  [n,m]=size(T);
  if m>n
    T=T';
  end;

  [A,B,C,D] = $1_sm;
  [A,B,C,D] = $1_sm(mttpar);
  [y,x] = sm2ir(A,B,C,D,T,u0,x0);

  if nx>0
    write_matrix([T x], '$1_ir');
  end;
  if ny>0
    write_matrix([T y], '$1_iro');
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
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
45
46

47
48
49
50
51
52
53
54







+
+
+









+
+

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

-
+







# Copyright (c) P.J.Gawthrop 1998

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.3  1998/02/09 14:16:52  peterg
## Writes end statement to the o/p file
##
## Revision 1.2  1998/01/23 09:30:36  peterg
## Fixed a sign error - the coeficients of a(s) appear with - signs in
## the A_c matrix!
##
## Revision 1.1  1998/01/22 13:16:16  peterg
## Initial revision
##
###############################################################

Nu=`mtt_getsize $1 u`
Ny=`mtt_getsize $1 y`

if [ "$Nu" = "1" ]; then
  if [ "$Ny" = "1" ]; then
    blurb=' for this siso system'    
  else
    blurb=" using first output of $Ny"
  fi
else
  if [ "$Ny" = "1" ]; then
    blurb=" using first input of $Nu"
  else
    blurb=" using first input of $Nu and using first output of $Ny"
  fi
fi

# Inform user
echo Creating $1_ssk.r -- NOTE this is for SISO systems only.
echo Creating $1_ssk.r $blurb

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

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

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
91
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







-
+






-
+












OUT "$1_ssk.r";

%Write out the matrices.

write "%  - Gain matrix - controller form";
MTT_Matrix := MTTK_c$ 
MTT_Matrix_name := "MTTK_c"$
MTT_Matrix_n := MTTNu$
MTT_Matrix_n := 1$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

write "%  - Gain matrix - physical form";
MTT_Matrix := MTTK$ 
MTT_Matrix_name := "MTTK"$
MTT_Matrix_n := MTTNu$
MTT_Matrix_n := 1$
MTT_Matrix_m := MTTNx$
Reduce_Matrix()$

write "END;";

SHUT "$1_ssk.r";
quit;

EOF

# Now invoke the standard error handling.
mtt_error_r smc2ssk_r.log
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







+
+
+







# Copyright (c) P.J.Gawthrop 1998

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.2  1998/02/09 14:04:00  peterg
## Renamed matrix to cTF;
##
## Revision 1.1  1998/02/09 13:54:34  peterg
## Initial revision
##
###############################################################


# Inform user
45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62







-
+







%State matrices of the compensator
A_d := MTTA - MTTL*MTTC - MTTB*MTTK;
B_d := -MTTL;
C_d := -MTTK;
D_d := 0;

%Transfer function
MTTGc := C_d*((s*MTTI - A_d)^(-1))*B_d;
MTTcTF := C_d*((s*MTTI - A_d)^(-1))*B_d;

%Create the output file
OUT "$1_ctf.r"; 
%Write out the matrices.

write "%  - Compensator TF";
MTT_Matrix := MTTcTF$
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
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
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
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







+
+
+


















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


+
-
+

-
+







# Copyright (c) P.J.Gawthrop, 1997.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
# Revision 1.3  1997/12/06  19:10:41  peterg
# Reverted to tabular --- from supertabular
#
# Revision 1.2  1997/04/15  11:17:58  peterg
# Uses supertabular for long tables.
#
# Revision 1.1  1997/04/15  09:49:04  peterg
# Initial revision
#
###############################################################


# Inform user
echo "Creating $1_struc.tex"

rm -f mtt_error

#Write some file headers
echo "%% Structure file ($1_struc.txt)" > $1_struc.tex
echo "%% Generated by MTT at `date`" >> $1_struc.tex

# This is the main transformation using gawk
sed 's/_/\\_/g' < $1_struc.txt |  gawk '
#function header(what){
#  print "  \\centering";
# print "  \\tablefirsthead{\\hline %";
#  print "    \\multicolumn{4}{|c|}{\\bf List of " what "s for system " SYSTEM "} \\\\";
#  print "    \\hline";
#  print "     & Component & System & Repetition \\\\";
#  print "    \\hline}";
#
#  print "  \\tablehead{\\hline %";
#  print "    \\multicolumn{4}{|c|}{\\bf List of " what "s for system " SYSTEM " (continued)} \\\\";
#  print "    \\hline";
#  print "     & Component & System & Repetition \\\\";
#  print "    \\hline}";
#
#  print "  \\tabletail{\\hline}";
#  print "  \\begin{supertabular}{|l|l|l|l|}";
# This is the main transformation using awk
sed 's/_/\\_/g' < $1_struc.txt |  awk '
function header(what){
  print "  \\centering";
 print "  \\tablefirsthead{\\hline %";
  print "    \\multicolumn{4}{|c|}{\\bf List of " what "s for system " SYSTEM "} \\\\";
  print "    \\hline";
  print "     & Component & System & Repetition \\\\";
  print "    \\hline}";

  print "  \\tablehead{\\hline %";
  print "    \\multicolumn{4}{|c|}{\\bf List of " what "s for system " SYSTEM " (continued)} \\\\";
  print "    \\hline";
  print "     & Component & System & Repetition \\\\";
  print "    \\hline}";

  print "  \\tabletail{\\hline}";
  print "  \\begin{supertabular}{|l|l|l|l|}";
#}
function header(what){
  print "\\begin{table}[htbp]";
  print "  \\begin{tabular}{|l|l|l|l|}";  print "    \\hline";
  print "     & Component & System & Repetition \\\\";
  print "    \\hline";
}
#function header(what){
#  print "\\begin{table}[htbp]";
#  print "  \\centering";
#  print "  \\begin{tabular}{|l|l|l|l|}";  print "    \\hline";
#  print "     & Component & System & Repetition \\\\";
#  print "    \\hline";
}
#}
function footer(what){
  print "    \\hline";
  print "  \\end{supertabular}";
  print "  \\end{tabular}";
#  print "  \\end{tabular}";
#  print "  \\caption{" what "}";
  print "\\end{table}";
#  print "\\end{table}";
  print "   \\bigskip";
  print "   \\bigskip";
}

BEGIN{
Which=""
}
10
11
12
13
14
15
16
17



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

17
18
19
20
21
22
23
24
25
26







-
+
+
+







# P.J.Gawthrop May 1997
# Copyright (c) P.J.Gawthrop, 1997.

# echo the name of the subsystems one level down
sh $1\_sub.sh "echo  " 

# Create the corresponding subsystems --  quietly!
(sh $1\_sub.sh "mtt -q   " " sub sh") >/dev/null
#(sh $1\_sub.sh "mtt -q  " " sub sh") #>/dev/null
(sh $1\_sub.sh " cmp2sub_m2sh  " " ") >/dev/null


# Recursively execute the subsystem files
sh $1\_sub.sh "sub2subs " 




11
12
13
14
15
16
17



18
19
20
21
22
23
24
25
26
27



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


29
30
31
32







+
+
+








-
-
+
+
+

# Copyright (c) P.J.Gawthrop, 1996.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
# Revision 1.2  1996/08/30  10:19:11  peter
# New path for awk script.
#
## Revision 1.1  1996/08/18 20:00:20  peter
## Initial revision
##
###############################################################

# Inform user
echo "Creating $1_$2.doc"

# This is the main transformation using gawk
gawk -f $MTTPATH/trans/awk/tex2doc.awk $1_$2.txt  > $1_$2.doc
# This is the main transformation using awk
awk -f $MTTPATH/trans/awk/tex2doc.awk \
system_name=$1 representation=$2  > $1_$2.doc


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