Overview
Comment:Initial revision
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 960a814037abde4991393615e155109f38f629723a5e73b34e9c80efdb9cdf71
User & Date: gawthrop@users.sourceforge.net on 1998-07-25 09:47:43
Other Links: branch diff | manifest | tags
Context
1998-07-25
09:48:03
*** empty log message *** check-in: aff79ffce8 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
09:47:43
Initial revision check-in: 960a814037 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
09:44:25
Uses Pascal as step on the way to c code -- MUCH nicer!
State and input now use the simple default - no steady states
check-in: e12a4db9ff user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Added mttroot/mtt/bin/trans/m/printcr.m version [cc1770a912].

























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
function  printcr(name,outport,bond_number,cr,args,RHS_cause,eqnfile)
% printcr - prints cr and arguments
% Assumes that the (multiport) component is unicausal.
% 
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%     %%%%% Model Transformation Tools %%%%%
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Matlab function  printcr
% printcr(name,outport,bond_number,cr,args,RHS_cause,eqnfile


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% $Id$
% %% $Log$
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



if nargin<7
  eqnfile = 'stdout';
end;

% Find the number of ports
ports = length(RHS_cause);

% Print the CR
if length(cr) == 0 % No CR given - use unity CR
  fprintf(eqnfile, '%s;\n', varname(name,bond_number(outport), RHS_cause(outport)));
else % CR exists
  fprintf(eqnfile, '%s(', cr); % The CR name
  if ports>1 % Multi ports - port no. is first arg of CR
    fprintf(eqnfile, '%1.0f,', outport);
  end;
  fprintf(eqnfile, '%s', args); % Print the arguments
  for port = 1:ports % Print the input causalities and values
    fprintf(eqnfile, '\n\t\t,%s,%s', cause2name(RHS_cause(port)), ...
    varname(name,bond_number(port), RHS_cause(port)));
  end;
fprintf(eqnfile, '\n\t\t);\n');    
end;

Added mttroot/mtt/bin/trans/make_ode2odes version [5045f4d7b4].







































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#! /bin/sh

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

# Bourne shell script: make_ode2odes

# Copyright (c) P.J.Gawthrop July 1998.

Sys=$1

# Find system constants
Nx=`grep "MTTNx " <$Sys\_def.r | awk '{print $3}' | sed 's/;//'`
Nu=`grep "MTTNu " <$Sys\_def.r | awk '{print $3}' | sed 's/;//'`
Ny=`grep "MTTNy " <$Sys\_def.r | awk '{print $3}' | sed 's/;//'`
 

cat << EOF > $1_ode2odes.m
function $1_ode2odes
EOF

# Do the globals
sympar2global_txt2m $1 >> $1_ode2odes.m

# The rest of the program
cat << EOF >> $1_ode2odes.m

$1_simpar;			# Read in simulation parameters
$1_numpar;			# Read in parameters
MTTx = $1_state;	        # Read in state

iLast = round(Last/DT);         # Total number of steps
 
t = 0.0;
for it = 1:iLast
    MTTu = $1_input(MTTx,t);
    MTTdx = $1_ode(MTTx,MTTu,t);
    for j = 1:$Nx
      MTTx[j] = MTTx[j] + MTTdx[j]*DT;
    end;
    MTTy = $1_odeo(MTTx,MTTu,t);
    t = t + DT;
    mtt_write(t,MTTx,MTTy,$Nx,$Ny);
end;

EOF




Added mttroot/mtt/bin/trans/mtt_m2p version [eafaf239b6].

































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#! /bin/sh


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

# Bourne shell script: mtt_m2p
# Reduce octave 2 Pascal converter for MTT   
# P.J.Gawthrop July 1998
# Copyright (c) P.J.Gawthrop 1998

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



# Set up variables
args=`echo $1 | sed 's/_/ /' | sed 's/\./ /'`
Sys=`echo $args  | awk '{print $1}'`
sys=`echo $Sys  | awk '{print tolower($1)}'`
rep=`echo $args  | awk '{print $2}'`
Sys_rep="$Sys""_""$rep"
Filename="$Sys""_""$rep.p"
filename="$sys""_""$rep.p"

# Inform user
echo Creating $Filename

# Find system constants
Nx=`grep "MTTNx " <$Sys\_def.r | awk '{print $3}' | sed 's/;//'`
Nu=`grep "MTTNu " <$Sys\_def.r | awk '{print $3}' | sed 's/;//'`
Ny=`grep "MTTNy " <$Sys\_def.r | awk '{print $3}' | sed 's/;//'`
 
#Regexps
  name="[a-zA-Z0-9]*"
  fun_name="$name\_$name"
  space="[ \t]*"
  spaces="[ \t][ \t]*"
  non_space="[^ ]*"

# Heading
(case $rep in
    state)
        echo "PROCEDURE $Sys_rep(VAR mttx : StateVector);"
        ;;
    input)
        echo "PROCEDURE $Sys_rep(VAR mttu : InputVector;"
	echo "                       mttx : StateVector;"
	echo "                       mttt : REAL);"
	;;
    ode)
	echo "PROCEDURE $Sys_rep(VAR mttdx: StateVector;"
	echo "                       mttx : StateVector;"
	echo "                       mttu : InputVector;"
	echo "                       mttt : REAL);"
	;;
    odeo)
	echo "PROCEDURE $Sys_rep(VAR mtty : OutputVector;"
	echo "                       mttx : StateVector;"
	echo "                       mttu : InputVector;"
	echo "                       mttt : REAL);"
	;;
    ode2odes)
	echo "PROGRAM $Sys_rep;"
	echo "TYPE"
	echo "    StateVector  =ARRAY[1..$Nx] OF REAL;"
	echo "    InputVector  =ARRAY[1..$Nu] OF REAL;"
	echo "    OutputVector =ARRAY[1..$Ny] OF REAL;"
	echo "VAR"
        echo "    t,LAST,DT : REAL;"
	echo "    mttx,mttdx      : StateVector;"
	echo "    mttu            : InputVector;"
	echo "    mtty            : OutputVector;"
	echo "    i,j,k,it,iLast,STEPFACTOR,METHOD : INTEGER;"
        ;;
    *)	echo "PROCEDURE $Sys_rep;"
        ;;
esac) > $Filename

cat<<EOF >> $Filename

{*** System $Sys, rep $rep, language Pascal, file $Filename ***}
{*** Translated by MTT from $Sys_rep.m on `date` ***}

EOF



# Body	
grep -v '^[ ]*function' < $Sys_rep.m  | sed "s/^$space%/#/" |\
awk -F# '{printf("%s",$1) 
          if (NF>1) printf("{* %s *}", $2)
          printf("\n") 
         }' |\
sed "s/$space\[\($non_space\)\]$spaces=$spaces\($fun_name\)(\([a-zA-Z0-9,]*\))/\2(\1,\3)/" |\
sed "s/$space\[\($non_space\)\]$spaces=$spaces\($fun_name\)/\2(\1)/" |\
sed "s/$space\($non_space\)$spaces=$spaces\($fun_name\)(\([a-zA-Z0-9,]*\))/\2(\1,\3)/" |\
sed "s/$space\($non_space\)$spaces=$spaces\($fun_name\)/\2(\1)/"  |\
awk '
BEGIN{
  comment_regexp = "{"
  doing_header = 1
  doing_globals = 0
  Nt = 9
  inc ="$I"
}
{
  if ($1=="global") 
    doing_globals = 1
  else{ 
    if (doing_globals==1){
      if (match($1,";")==0){
        global[++i]=$1;
      }
      else{
        doing_globals = 0
      }
    }
    else 
    {
      if ((doing_header==1)&&(doing_globals==0)) {
        if (rep=="ode2odes"){
          printf("VAR ");
          for (k=1;k<i;k++) printf("%s,",global[k])
          printf("%s : REAL;\n", global[i])
          printf("VAR "); for (k=1;k<=Nx;k++) printf("mttx%i,", k)
          for (k=1;k<=Nu;k++) printf("mttu%i,", k)
          for (k=0;k<Nt;k++) printf("t%i,", k)
          printf("t%i : REAL;\n",Nt) 
          printf("{%s %s_simpar.p}\n",inc,sys) 
          printf("{%s %s_numpar.p}\n",inc,sys)
          printf("{%s %s_state.p}\n",inc,sys)
          printf("{%s %s_input.p}\n",inc,sys)
          printf("{%s %s_ode.p}\n",inc,sys)
          printf("{%s %s_odeo.p}\n",inc,sys)
          printf("{%s mtt_write.p}\n",inc,sys)
        }
        for (k=1;k<=j;k++) printf("%s\n", comment[k])
        printf("\n")
        printf("\nBEGIN\n")
        doing_header = 0;
      }
      if (match($1,comment_regexp)>0){
        if (doing_header==1)
          comment[++j] = $0
        else
          printf("%s\n", $0)
      }
      else {
        if ($1=="if") {
          print tolower($0)
          print "begin"
        }
        else{ 
          if ($1=="for"){
          sub(/:/," TO ",$0)
          sub(/=/,":=",$0)
          printf("%s DO\n", $0)
          print "begin"
          }
          else {
            sub(/=/,":=",$0)
            sub(/\^/,"**",$0)
            printf("%s\n",$0)
          }
        }
      }
    }
  }
}
END{
  if (rep=="def"){
    printf("EULER = 1,\n")
    printf("IMPLICITL = 2;\n")
    printf("IMPLICIT3 = 3;\n")
    }
    else
      print "END;"
}' sys=$sys rep=$rep Nx=$Nx Nu=$Nu |\
sed 's/(\([0-9]*\))/\[\1\]/' \
>> $Filename

# p2c doesn't like mixed case filenames!
echo Creating $filename
cp $Filename $filename


Added mttroot/mtt/bin/trans/p/mtt_write.p version [3513fd7cdc].







































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
PROCEDURE mtt_write(t	  : REAL;
		    x	  : StateVector;
		    y	  : OutputVector;
		    nx,ny : INTEGER);

{*
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%     %%%%% Model Transformation Tools %%%%%
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
      Pascal function mtt_write
      P.J. Gawthrop July 1998

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


*}
 
VAR
   i : INTEGER;
   
BEGIN
   write(t);
   FOR i := 1 TO nx DO
      write(x[i]);
   FOR i := 1 TO ny DO
      write(y[i]);
   writeln;
END;
   


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