ADDED mttroot/mtt/bin/trans/m/printcr.m Index: mttroot/mtt/bin/trans/m/printcr.m ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/m/printcr.m @@ -0,0 +1,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 Index: mttroot/mtt/bin/trans/make_ode2odes ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/make_ode2odes @@ -0,0 +1,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 Index: mttroot/mtt/bin/trans/mtt_m2p ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/mtt_m2p @@ -0,0 +1,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<> $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;k0){ + 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 Index: mttroot/mtt/bin/trans/p/mtt_write.p ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/p/mtt_write.p @@ -0,0 +1,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; +