11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% Version control history
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% $Id$
# %% $Log$
# %% Revision 1.8 2000/09/30 13:53:07 peterg
# %% Default to empty matix in numpar.m -- avoids probs for parameter-free systems
# %%
# %% Revision 1.7 2000/05/19 17:46:17 peterg
# %% Give argument to state
# %%
# %% Revision 1.6 2000/05/19 14:59:03 peterg
|
>
>
>
|
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% Version control history
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% $Id$
# %% $Log$
# %% Revision 1.9 2000/10/13 11:07:33 peterg
# %% Started conversion to new style state, input ext
# %%
# %% Revision 1.8 2000/09/30 13:53:07 peterg
# %% Default to empty matix in numpar.m -- avoids probs for parameter-free systems
# %%
# %% Revision 1.7 2000/05/19 17:46:17 peterg
# %% Give argument to state
# %%
# %% Revision 1.6 2000/05/19 14:59:03 peterg
|
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
|
# %% Revision 1.1 1998/02/25 22:10:25 peterg
# %% Initial revision
# %%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
system=$1
representation=$2
if [ "$representation" = "state" ]; then
name='mttx';
arg='';
fi
if [ "$representation" = "input" ]; then
name='mttu';
arg='(mttt,mttx,mtty)'
fi
# Inform user
echo Creating $1_$2.m
#Create the $2 file complete with headers.
case $representation in
simpar)
lang_header -noglobals $1 simpar m '' mttsimpar > $1_simpar.m
;;
numpar)
lang_header $1 numpar m '' mttpar > $1_numpar.m;
echo "## Set parameters to zero" >> $1_numpar.m;
sympar2par_txt2m $1 zero >> $1_numpar.m;
;;
state)
lang_header $1 $2 m 'mttpar' mttx > $1_$2.m;
echo " if nargin>0" >> $1_$2.m;
echo " ## Set parameters" >> $1_$2.m;
sympar2par_txt2m $1 >> $1_$2.m;
echo " endif" >> $1_$2.m;
;;
*)
echo "function $name = $1_$2$arg" > $1_$2.m
echo "%% $2 file ($1_$2.m)" >> $1_$2.m
echo "%% Generated by MTT at `date`" >> $1_$2.m
echo "% Global variable list" >> $1_$2.m
sympar2global_txt2m $1 >> $1_$2.m
;;
esac
if [ "$representation" = "simpar" ]; then
#Write out the variables in m format.
cat $1_$2.txt | grep -v METHOD |\
awk -F# 'BEGIN{
quote = "\047";
doublequote = "\042";
}
{
N=split($1,a,"=");
if (N==2) {
|
|
<
<
<
<
<
<
<
<
|
|
|
|
<
|
>
>
|
|
<
|
>
>
|
|
|
|
|
>
|
>
|
|
|
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
|
# %% Revision 1.1 1998/02/25 22:10:25 peterg
# %% Initial revision
# %%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
system=$1
representation=$2
outfile=$1_$2.m
# Inform user
echo Creating $1_$2.m
#Create the rep file complete with headers.
case $representation in
simpar)
arraycode=no
;;
numpar)
name=mttpar
arraycode=yes
;;
state)
name=mttx
arraycode=yes
;;
input)
name=mttu
arraycode=yes
;;
*)
echo Representation $representation not supported
exit
#echo "function $name = $1_$2$arg" > $outfile
#echo "%% $2 file ($1_$2.m)" >> $outfile
#echo "%% Generated by MTT at `date`" >> $outfile
#echo "% Global variable list" >> $outfile
#sympar2global_txt2m $1 >> $outfile
;;
esac
# Generate the header
mtt_header $system $representation m > $outfile
# Write out the code from the txt file
cat $1_$2.txt | strip_comments | grep -v METHOD |\
awk -F# 'BEGIN{
quote = "\047";
doublequote = "\042";
}
{
N=split($1,a,"=");
if (N==2) {
|
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
|
}
else if (match($1,"global")==1) {
statement = tolower($1); # Lower case globals as well
}
else
statement = $1;
if (NF<2) print statement
if (NF>1) print statement " # " $2
}' | sed\
-e 's/\[\([0-9]*\)\]/(\1)/g' \
-e 's/\([^a-zA-Z_]\)t\([^a-zA-Z_]\)/\1mttt\2/g' \
-e 's/x(/mttx(/g' \
-e 's/u(/mttu(/g' \
-e 's/mttmtt/mtt/g' \
-e 's/#/%/g' \
>> $1_$2.m
exit
fi
#if [ "$2" = "numpar" ]; then
# echo "## Set up the parameter vector" >> $1_numpar.m;
# echo "mttpar = []; # Default to empty matrix (Remove in mtt_m2p)" >> $1_numpar.m;
# sympar2par_txt2m $1 set >> $1_numpar.m;
#fi
case $2 in
numpar)
name=mttpar
;;
state)
name=mttx
;;
input)
name=mttu
;;
*)
esac
new_style=`strip_comments < $1_$2.txt| grep "$name(">/dev/null; echo $?`
if [ "$new_style" = "1" ]; then
echo "## Set up the $name vector" >> $1_$2.m;
echo "name = []; # Default to empty matrix (Remove in mtt_m2p)" >> $1_$2.m;
mtt_name2array $1 $2 set >> $1_$2.m
else
echo "Old-style file detected: not creating array translations"
fi
|
|
<
|
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
>
|
|
|
|
|
|
>
>
>
>
>
>
|
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
|
}
else if (match($1,"global")==1) {
statement = tolower($1); # Lower case globals as well
}
else
statement = $1;
if (NF<2) print " " statement
if (NF>1) print statement " # " $2
}' | sed\
-e 's/\[\([0-9]*\)\]/(\1)/g' \
-e 's/\([^a-zA-Z_]\)t\([^a-zA-Z_]\)/\1mttt\2/g' \
-e 's/x(/mttx(/g' \
-e 's/u(/mttu(/g' \
-e 's/mttmtt/mtt/g' \
>> $outfile
if [ "$arraycode" = "yes" ]; then
new_style=`strip_comments < $1_$2.txt| grep "$name(">/dev/null; echo $?`
if [ "$new_style" = "1" ]; then
echo >> $outfile
echo " ## Set up the $name vector" >> $outfile
echo " $name = []; # Default to empty matrix (Remove in mtt_m2p)" >> $outfile
mtt_name2array $1 $2 set >> $outfile
else
echo "Old-style file detected: not creating array translations"
fi
fi
# End of the function
echo '## END Code' >> $outfile
echo 'endfunction' >> $outfile
|