Overview
Comment:Fixed various obscure reduce bugs
THIS NEEDS A MAJOR REWRITE!!!!
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: a3ef8b6bcf71828f8ec3071396b83644afc5a40fcc1b7b8d34b9b8d458c1106e
User & Date: gawthrop@users.sourceforge.net on 1999-03-15 07:29:25
Other Links: branch diff | manifest | tags
Context
1999-03-15
21:55:36
Does away with the # symbol in the file - uses _de to get Nx Ny
instead
check-in: 1d58fa5dab user: gawthrop@users.sourceforge.net tags: origin/master, trunk
07:29:25
Fixed various obscure reduce bugs
THIS NEEDS A MAJOR REWRITE!!!!
check-in: a3ef8b6bcf user: gawthrop@users.sourceforge.net tags: origin/master, trunk
05:53:33
Put in user-defined representations check-in: 4f7bc6c269 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/mtt_r2m from [b59a866536] to [29ff3bb11e].

12
13
14
15
16
17
18



19
20
21
22
23
24
25
# Copyright (c) P.J.Gawthrop 1991, 1994, 1995, 1996, 1998

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



## Revision 1.4  1998/08/13 15:10:47  peterg
## Change temp var name to mtt_t1 etc
##
## Revision 1.3  1998/08/13 12:43:19  peterg
## Cahnged tmp variable to mtt_1 etc
##
## Revision 1.2  1998/07/27 20:26:44  peterg







>
>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Copyright (c) P.J.Gawthrop 1991, 1994, 1995, 1996, 1998

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.5  1998/08/13 16:25:07  peterg
## Removed some documentation form odeo.m
##
## Revision 1.4  1998/08/13 15:10:47  peterg
## Change temp var name to mtt_t1 etc
##
## Revision 1.3  1998/08/13 12:43:19  peterg
## Cahnged tmp variable to mtt_1 etc
##
## Revision 1.2  1998/07/27 20:26:44  peterg
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
ext='m';
codegenerator='PASCAL'
Lc='#';
Rc='#';
Lb='(';
Rb=')';

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

rm -f $outfile.*

#Set up gentran
cat <<EOF >mtt_setreduce.r
% Set up the code generator
% Load the general translator package
LOAD GENTRAN;
GENTRANLANG!* := '$codegenerator;
ON GENTRANSEG;







|
<
|
|







39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
ext='m';
codegenerator='PASCAL'
Lc='#';
Rc='#';
Lb='(';
Rb=')';

outfile=$1"_"$rep

echo $outfile
rm -fv $outfile.[123]
#Set up gentran
cat <<EOF >mtt_setreduce.r
% Set up the code generator
% Load the general translator package
LOAD GENTRAN;
GENTRANLANG!* := '$codegenerator;
ON GENTRANSEG;
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

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

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

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

EOF

#Inform user
echo Creating $outfile



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

#Remove the temporary files
rm -f $outfile.*

if [ "$rep" = "ode" ]; then
  #echo Creating $1_odea.$ext

  echo Creating $1_odeo.$ext
  rm -f $1_odeo.$ext.1;
  #rm -f $1_odea.$ext.1;

  #Header
  lang_header $1 $rep $ext 'mttx,mttu,t' mttdx > $outfile.1


  # Use reduce to accomplish the transformation
  $SYMBOLIC >mtt_r2lang.log << EOF
    
  %Set up the code generator
  in"mtt_setreduce.r";
      
  % The body of the ode function
    GENTRANOUT "$outfile.3";
    mtt_matrix := MTTdX$
    mtt_matrix_n := MTTNx$
    mtt_matrix_m := 1$
    mtt_matrix_name := 'MTTdX$
    lang_matrix(); 
    GENTRANSHUT "$outfile.3";
    
%%      % The algebraic equations (if any)
%%    GENTRANOUT "$1_odea.$ext.1";
%%    mtt_matrix := MTTYz$
%%    mtt_matrix_n := MTTNYz$
%%    mtt_matrix_m := 1$
%%    mtt_matrix_name := MTTYz$
%%    lang_matrix(); 
%%    GENTRANSHUT "$1_odea.$ext.1;
      
      
      % Now do the y = g(x,t) function.
      % The body of the odeo function
    GENTRANOUT "$1_odeo.$ext.1";
    mtt_matrix := MTTy$
    mtt_matrix_n := MTTNy$
    mtt_matrix_m := 1$
    mtt_matrix_name := MTTy$
    lang_matrix(); 
    GENTRANSHUT "$1_odeo.$ext.1";
      



EOF


#  cat $1_odeo.$ext.1

##  # Algebraic bits
##  $MATRIX -q  <<EOF  >> $1_ode.$ext
##    %System structure
##    [nx,ny,nu,nz,nyz] = $1_def;
##  if nyz>0







<
<
<



|




|


<



>
|
|



|
>


<
|




|



<
|
|

<
<
<
<
<
<
<
<
|
<
<

|
|
|
|
<
|
|
|
>
>
>

>
>







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

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

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




EOF

#Inform user
echo Creating $outfile.m



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

#Remove the temporary files


if [ "$rep" = "ode" ]; then
  #echo Creating $1_odea.$ext
  outfileo=$outfile"o"
  echo Creating $outfileo.m
   rm ode odeo
  #rm -f $1_odea.$ext.1;

  #Header
  lang_header $1 $rep $ext 'mttx,mttu,t' mttdx > $1_ode.p
  lang_header $1 odeo $ext 'mttx,mttu,t' mtty > $1_odeo.p

  # 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 "ode";
    mtt_matrix := MTTdX$
    mtt_matrix_n := MTTNx$
    mtt_matrix_m := 1$

    lang_matrix();
    GENTRANSHUT "ode";
    








 


      % The body of the odeo function
     GENTRANOUT "odeo";
     mtt_matrix := MTTy$
     mtt_matrix_n := MTTNy$
     mtt_matrix_m := 1$

     lang_matrix(); 
     GENTRANSHUT "odeo";

END;;


EOF

     
#  cat $1_odeo.$ext.1

##  # Algebraic bits
##  $MATRIX -q  <<EOF  >> $1_ode.$ext
##    %System structure
##    [nx,ny,nu,nz,nyz] = $1_def;
##  if nyz>0
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
##      printf(" mttdx$Lb%i$Rb = mttui%i;\n",i+nx,i);
##    end;
##    printf("\n");
##  end;
##  
##EOF
##  
  cat <<EOF >> $outfile.2
  
  $Lc The differential equations $Rc
EOF
  
  sed 's/mtt_matrix/mttdx/' $outfile.3 > $outfile.4
  rm -f $outfile.3
  
##  # Create the odea.$ext function
##  lang_header $1 odea $ext 'mttui' mttyz 'global mttxx mttt; mttx = mttxx; t=mttt;' > $1_odea.$ext
##  
##  $MATRIX -q  <<EOF  >> $1_odea.$ext
##    %System structure
##    [nx,ny,nu,nz,nyz] = $1_def;







<

<
<
<
<
<







151
152
153
154
155
156
157

158





159
160
161
162
163
164
165
##      printf(" mttdx$Lb%i$Rb = mttui%i;\n",i+nx,i);
##    end;
##    printf("\n");
##  end;
##  
##EOF
##  

  





  
##  # Create the odea.$ext function
##  lang_header $1 odea $ext 'mttui' mttyz 'global mttxx mttt; mttx = mttxx; t=mttt;' > $1_odea.$ext
##  
##  $MATRIX -q  <<EOF  >> $1_odea.$ext
##    %System structure
##    [nx,ny,nu,nz,nyz] = $1_def;
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
##  cat <<EOF >> $1_odea.$ext
##  
##  % The algebraic equations
##EOF
##  sed 's/mtt_matrix/mttyz/' $1_odea.$ext.1 >> $1_odea.$ext
  
  
  # Create the odeo.$ext function
  lang_header $1 odeo $ext 'mttx,mttu,t' mtty > $1_odeo.$ext
  
$MATRIX -q  <<EOF  >> $1_odeo.$ext
    %System structure
    [nx,ny,nu,nz,nyz] = $1_def;
  if nyz>0
    printf("$Lc====== Extract the internal input variables ======$Rc\n");
    for i = 1:nyz
      printf("  mttui$Lb%i$Rb = mttx$Lb%i$Rb;\n",i,i+nx);
    end;
    printf("\n");
  
    printf("$Lc====== Set up the internal input variables ======$Rc\n");
    for i = 1:nyz
      printf("  mttui%i = mttui$Lb%i$Rb;\n",i,i);
    end;
    printf("\n");
  end;
  
EOF


sed 's/mtt_matrix/mtty/' $1_odeo.$ext.1 >> $1_odeo.$ext

# Convert from Pascal syntax to Octave syntax
  mv $1_odeo.m mtt_junk; mtt_p2m<mtt_junk > $1_odeo.m

#  mv $1_odea.m mtt_junk; mtt_p2m<mtt_junk > $1_odea.m

fi
  
if [ "$rep" = "sm" ]||[ "$rep" = "dm" ]; then

if [ "$rep" = "sm" ]; then
   #Header
  lang_header $1 $rep $ext '' [mtta,mttb,mttc,mttd] > $outfile.A







|
<

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

>
|

|
|
>

>







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
##  cat <<EOF >> $1_odea.$ext
##  
##  % The algebraic equations
##EOF
##  sed 's/mtt_matrix/mttyz/' $1_odea.$ext.1 >> $1_odea.$ext
  
  
  # Create the odeo function

  
##$MATRIX -q  <<EOF  >> $1_odeo.p
##    %System structure
##    [nx,ny,nu,nz,nyz] = $1_def;
##  if nyz>0
##    printf("$Lc====== Extract the internal input variables ======$Rc\n");
##    for i = 1:nyz
##      printf("  mttui$Lb%i$Rb = mttx$Lb%i$Rb;\n",i,i+nx);
##    end;
##    printf("\n");
##  
##    printf("$Lc====== Set up the internal input variables ======$Rc\n");
##    for i = 1:nyz
##      printf("  mttui%i = mttui$Lb%i$Rb;\n",i,i);
##    end;
##    printf("\n");
##  end;

##EOF

sed 's/mtt_matrix/mttdx/' <ode  >> $1_ode.p
sed 's/mtt_matrix/mtty/'  <odeo >> $1_odeo.p

# Convert from Pascal syntax to Octave syntax 
   mtt_p2m<$1_odeo.p > $1_odeo.m 
   mtt_p2m<$1_ode.p > $1_ode.m 
#  mv $1_odea.m mtt_junk; mtt_p2m<mtt_junk > $1_odea.m

fi
  
if [ "$rep" = "sm" ]||[ "$rep" = "dm" ]; then

if [ "$rep" = "sm" ]; then
   #Header
  lang_header $1 $rep $ext '' [mtta,mttb,mttc,mttd] > $outfile.A
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318




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

echo "% $Symbol matrix" >$outfile.$Symbol
cat "$outfile.2" >> $outfile.$Symbol
sed "s/mtt_matrix/mtt$Symbol/" < $outfile.1 |\
grep -v '=0\.0;' >> $outfile.$Symbol

done

rm -f $outfile.[12]
fi

# Convert from Pascal syntax to Octave syntax
cat $outfile.?  | mtt_p2m > $outfile

rm -f $outfile.?  
  
  
  











|
|

|



|
|




|



>
>
>
>
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
    mtt_matrix := MTT$Symbol;
    mtt_matrix_n := $N;
    mtt_matrix_m := $M;
    lang_matrix();
    GENTRANSHUT "$outfile.1";
EOF

echo "%$Symbol matrix#" > $outfile.$Symbol
cat "$outfile.2"  >> $outfile.$Symbol
sed "s/mtt_matrix/mtt$Symbol/" < $outfile.1 |\
grep -v '=0\.0;'  >> $outfile.$Symbol

done


fi 

# Convert from Pascal syntax to Octave syntax
cat $outfile.?  | mtt_p2m > $outfile

#rm -f $outfile.?  
  
  
  





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