Index: mttroot/mtt/bin/trans/ode_r2m ================================================================== --- mttroot/mtt/bin/trans/ode_r2m +++ mttroot/mtt/bin/trans/ode_r2m @@ -12,10 +12,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.11 1998/05/21 08:05:23 peterg +## Back under RCS +## ## Revision 1.10 1998/04/14 07:25:02 peterg ## _input now has arguments (x,t) ## ## Revision 1.9 1998/03/30 14:18:07 peterg ## Removed NERO command @@ -46,24 +49,37 @@ ## ############################################################### #Inform user echo Creating $1_ode.m +echo Creating $1_odea.m echo Creating $1_odeo.m # Remove the old log file rm -f ode_r2m.log + +#Remove the temporary files +rm -f $1_ode.mc +rm -f $1_ode.m1 +rm -f $1_ode.m2 +rm -f $1_ode.m3 +rm -f $1_ode.m4 +rm -f $1_odea.m1; # Use reduce to accomplish the transformation reduce >ode_r2m.log << EOF %Read the reduce definitions file in "$1_def.r"; %Read the reduce ODE file in "$1_ode.r"; + +% Matrix output function +in"$MTTPATH/trans/matlab_matrix.r"; + %Set up the number of argument variables to zero in case the user has forgotten MTTNVar := 0; %Read the parameter file @@ -73,27 +89,10 @@ %Define the common part of the functions. PROCEDURE common; BEGIN - IF MTTNvar>0 THEN - BEGIN - write "% Read in the parameters"; - write "global ...;;"; - FOR i := 1:MTTNvar DO - IF numberp(MTTVar(i,1)) - THEN - BEGIN - % Do nowt - END - ELSE - BEGIN - IF i0 THEN FOR i := 1:MTTNu DO BEGIN write "mttu", i, " = u(", i, ");"; END; + END; - -% Firstly do the dx = f(x,t) function. -OUT "$1_ode.m"; - -write "function mttdx = $1_ode(x,t);"; -write "% mttdx = $1_ode(x,t);"; -write "%ODE in Simulab form for system $1;;"; -write "%File $1_ode.m;;"; -write "%Generated by MTT;;"; - + +% The common part +OUT "$1_ode.mc"; common(); +SHUT "$1_ode.mc"; + +% Set up internal inputs (if any) +OUT "$1_ode.m3"; + write "% Set up the Internal Input variables"; + IF MTTNyz>0 THEN + FOR i := 1:MTTNyz DO + BEGIN + write "mttui", i, " = mttui(", i, ");"; + END; +SHUT "$1_ode.m3"; + +OUT "$1_ode.m4"; + write "% Set up the Internal Input variables (saved in the state vector)"; + IF MTTNyz>0 THEN + FOR i := 1:MTTNyz DO + BEGIN + write "mttui(", i, ") = x(", i+MTTNx, ");"; + END; +SHUT "$1_ode.m4"; + +% The body of the ode function + GENTRANOUT "$1_ode.m1"; + mtt_matrix := MTTdX$ + mtt_matrix_n := MTTNx$ + mtt_matrix_m := 1$ + mtt_matrix_name := MTTdX$ + matlab_matrix(); + GENTRAN MTTdx := mtt_matrix; + GENTRANSHUT "$1_ode.m1"; + +% The algebraic equations (if any) + GENTRANOUT "$1_odea.m1"; + mtt_matrix := MTTYz$ + mtt_matrix_n := MTTNYz$ + mtt_matrix_m := 1$ + mtt_matrix_name := MTTYz$ + matlab_matrix(); + GENTRAN MTTYz := mtt_matrix; + GENTRANSHUT "$1_odea.m1"; + %Fortran switches - one line expressions OFF echo; ON fort$ cardno!* := 1$ fortwidth!* := 10000$ @@ -170,11 +204,84 @@ MTTy := MTTy; SHUT "$1_odeo.m"; +EOF + +# Create the ode.m function +cat < $1_ode.m +function mttdx = $1_ode(x,t); +% mttdx = $1_ode(x,t); +%ODE in Octave form for system $1; +%File $1_ode.m; +%Generated by MTT on `date`; +EOF + +# Create the globals +sympar2global_txt2m $1 >> $1_ode.m + +#Common bit +cat $1_ode.mc >> $1_ode.m + +#Extract internal input from state vector +cat $1_ode.m4 >> $1_ode.m + +cat <> $1_ode.m +% Solve the algebraic equations (if any) +if nyz>0 + global xx; + xx = x; + mttui = fsolve('$1_odea',mttui); +end; +EOF + +cat $1_ode.m3 >> $1_ode.m + +cat <> $1_ode.m + +% The differential equations +EOF +cat $1_ode.m1 >> $1_ode.m + +cat <> $1_ode.m + +% Append the internal inputs to the state derivative +mttdx = [mttdx; mttui]; +EOF + + +# Create the odea.m function +cat < $1_odea.m +function mttyz = $1_odea(mttui); +% mttyz = $1_odea(mttui); +%Algebraic equations in Octave form for system $1; +%File $1_odea.m; +%Generated by MTT on `date`; +EOF + +# Create the globals +sympar2global_txt2m $1 >> $1_odea.m + +cat <> $1_odea.m + +global xx t; +x = xx; +EOF + +#Common bit +cat $1_ode.mc >> $1_odea.m + +# Internal inputs +cat $1_ode.m3 >> $1_odea.m + +cat <> $1_odea.m + +% The algebraic equations +EOF +cat $1_odea.m1 >> $1_odea.m