Index: mttroot/mtt/bin/trans/numpar_txt2c ================================================================== --- mttroot/mtt/bin/trans/numpar_txt2c +++ mttroot/mtt/bin/trans/numpar_txt2c @@ -13,10 +13,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.5 1997/06/13 09:42:25 peterg +## Auto change of () to [] +## # Revision 1.4 1997/05/15 08:33:07 peterg # Declare state array (x). # # Revision 1.3 1997/05/03 15:01:42 peterg # Don't write out RCS headers. @@ -27,11 +30,12 @@ # Revision 1.1 1997/05/01 08:25:31 peterg # Initial revision # ############################################################### - +system=$1 +representation = $2 # Inform user echo "Creating $1_numpar.c" rm -f mtt_error @@ -48,13 +52,14 @@ echo "#include \"$1_sympar.c\"" >> $1_numpar.c echo "$1_numpar()" >> $1_numpar.c echo '{' >> $1_numpar.c #Write out the variables in c format. +sed 's/#C-CODE //'< $1_numpar.txt |\ awk -F# '{ if (NF<2) print $1 if (NF>1) print $1 "/* " $2 " */" -}' $1_numpar.txt | sed 's/(\([0-9]*\))/[\1]/' >> $1_numpar.c +}' | sed 's/(\([0-9]*\))/[\1]/' >> $1_numpar.c echo '}' >> $1_numpar.c Index: mttroot/mtt/bin/trans/numpar_txt2m ================================================================== --- mttroot/mtt/bin/trans/numpar_txt2m +++ mttroot/mtt/bin/trans/numpar_txt2m @@ -12,10 +12,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.3 1998/07/25 18:26:33 peterg +## *** empty log message *** +## # Revision 1.2 1997/05/01 08:24:38 peterg # Now uses # as the comment symbol in the .txt file # # Revision 1.1 1997/05/01 07:45:17 peterg # Initial revision @@ -24,23 +27,20 @@ # Inform user echo Creating $1_numpar.m #Create the numpar file complete with headers. -echo "## Numerical parameter file ($1_numpar.m)" > $1_numpar.m -echo "## Generated by MTT at `date`" >> $1_numpar.m +lang_header $1 numpar m '' MTTpar > $1_numpar.m # Global variable list -echo >> $1_numpar.m -echo "# Global variable list" >> $1_numpar.m -sympar2global_txt2m $1 >> $1_numpar.m +#echo >> $1_numpar.m +#echo "# Global variable list" >> $1_numpar.m +#sympar2global_txt2m $1 >> $1_numpar.m #Write out the variables in m format. awk -F# '{ if (NF==1) print $1 if (NF==2) print $1 "# " $2 }' $1_numpar.txt |\ sed 's/double/global/' >> $1_numpar.m - - Index: mttroot/mtt/bin/trans/ode_r2c ================================================================== --- mttroot/mtt/bin/trans/ode_r2c +++ mttroot/mtt/bin/trans/ode_r2c @@ -18,10 +18,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.5 1997/05/01 13:50:55 peterg +## Replaced float by double. +## # Revision 1.4 1997/05/01 13:44:19 peterg # Changed double to float. # # Revision 1.3 1997/03/20 14:51:11 peterg # Includes the sympar.c file. @@ -51,11 +54,11 @@ %Set up the number of argument variables to zero in case the user has forgotten MTTNVar := 0; %Read the symbolic parameters file -in "$1_sympar.r"; +%%in "$1_sympar.r"; %Read the reduce state-space equations file in "$1_ode.r"; @@ -146,13 +149,16 @@ % Load the general translator package LOAD GENTRAN; GENTRANLANG!* := 'C; ON GENTRANSEG; MAXEXPPRINTLEN!* := 80; +ON DOUBLE; % let it know that sign is a function GENTRAN DECLARE sign : function; +GENTRAN DECLARE r_switch : function; +GENTRAN DECLARE i_switch : function; GENTRANOUT "$1_ode.c2"; %Do the translation %State IF MTTNx>0 THEN Index: mttroot/mtt/bin/trans/struc2input_txt2txt ================================================================== --- mttroot/mtt/bin/trans/struc2input_txt2txt +++ mttroot/mtt/bin/trans/struc2input_txt2txt @@ -12,10 +12,15 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.14 2000/10/16 08:28:56 peterg +## Tidied up: +## SS broken due to incorrect ss.r file +## Switches?? +## ## Revision 1.13 2000/03/03 11:33:19 peterg ## *** empty log message *** ## ## Revision 1.12 1998/08/10 14:29:05 peterg ## Removed -s (switches) stuff @@ -98,15 +103,18 @@ printf("%s =\t%s # MTT initial value from steady state\n", $4, u[i]); } }' >> $1_input.txt else #Write out the defaults -- unit inputs -echo Creating $1_input.txt - default to $default +echo Creating $1_input.txt - using defaults awk '{ if ($1=="input") { - printf("%s = \t%s; # MTT initial value\n", $4, default) + if ($2==1) + printf("%s = \t%s; # MTT initial value\n", $4, default) + else + printf("%s = \t%s; # MTT initial value\n", $4, "0.0") } }' Nu=$Nu default=$default <$1_struc.txt >> $1_input.txt fi #Set some switches Index: mttroot/mtt/bin/trans/sympar_r2c ================================================================== --- mttroot/mtt/bin/trans/sympar_r2c +++ mttroot/mtt/bin/trans/sympar_r2c @@ -2,69 +2,46 @@ ###################################### ##### Model Transformation Tools ##### ###################################### -# Bourne shell script: ode_r2c -# Reduce ordinary differential equations to c differential-algebraic -# equations - -# Euler integration of the state is included. - -# NB Arrays should be defined to be one larger than expected -# - the 0 element is not used. +# Bourne shell script: sympar_r2c +# Convert symbolic parameters to a c declaration list # Copyright (c) P.J.Gawthrop 1997. ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ -# Revision 1.2 1997/01/21 22:57:17 peterg -# Various bug fixes. -# -## Revision 1.1 1997/01/21 10:52:23 peterg -## Initial revision -## +# Revision 1.1 1997/03/01 11:20:36 peterg +# Initial revision ############################################################### # Inform user -echo Creating $1_ode.c - -# Remove the old files -rm -f $1_ode.c1 $1_ode.c2 $1_ode.c3 $1_ode.c +echo Creating $1_sympar.c # Remove the old log file -rm -f ode_r2c.log +rm -f sympar_r2c.log # Use reduce to accomplish the transformation -reduce >ode_r2c.log << EOF +reduce >sympar_r2c.log << EOF -%Read the reduce definitions file -in "$1_def.r"; - -%Set up the number of argument variables to zero in case the user has forgotten -MTTNVar := 0; %Read the symbolic parameters file in "$1_sympar.r"; -%Read the reduce state-space equations file -in "$1_ode.r"; - - -ON BigFloat, NumVal; -PRECISION 16; %Compatible with Matlab -%OFF Nat; - -ON NERO; % Suppress zero elements %Generate the global variable list. OUT "$1_sympar.c"; %External (global) variable list + +write "/* Symbolic paramaters for system $1 */ "$ +write "/* Generated by MTT */ "$ write "/* External (global) variable list */ "$ + IF MTTNvar>0 THEN BEGIN FOR i := 1:MTTNvar DO IF numberp(MTTVar(i,1)) THEN @@ -71,125 +48,13 @@ BEGIN % Do nowt END ELSE BEGIN - write "extern float ", MTTVar(i,1), ";"$ + write "extern double ", MTTVar(i,1), ";"$ END$ END$ SHUT "$1_sympar.c"; -%Generate the Header part -OUT "$1_ode.c1"; - -write "/*"$ -write "Differential algebraic eqns in c form for system $1"$ -write "NB Arrays should be defined to be one larger than expected"$ -write " - the 0 element is not used."$ - -write "File $1_ode.c"$ -write "Generated by MTT"$ -write "*/"$ -write " "$ - - -%Function heading - c style - -write "void $1_ode()"$ - -write " "$ -write "{"$ - -write "/* Declare standard arrays */"$ -write " extern float y[", MTTNy+1, "]; /* $1_ode output */"$ -write " extern float dx[", MTTNx+1, "]; /* $1_ode state derivative */"$ -write " extern float x[", MTTNx+1, "]; /* $1_ode state */"$ -write " extern float u[", MTTNu+1, "]; /* $1_ode input */"$ - -%Declare the dummy variables t0--t9 -write "/* Dummy variable list */ "$ -write " float t0;"$ -FOR i := 1:9 DO -BEGIN - write " float t", i, ";"$ -END$ - -%Declarations$ -write "/* State variable list */ "$ -FOR i := 1:MTTNx DO -BEGIN - write " float mttx", i, ";"$ -END$ - -write "/* Input variable list */ "$ -FOR i := 1:MTTNu DO -BEGIN - write " float mttu", i, ";"$ -END$ - -write "/* Counter */ "$ -write " int i;"$ - -SHUT "$1_ode.c1"; - -OUT "$1_ode.c2"; -write " "$ -write " /*====== Set up the state variables ======*/"$ -FOR i := 1:MTTNx DO -BEGIN - write " mttx", i, " = x[", i, "];"$ -END$ - -write " "$ -write " /*====== Set up the input variables ======*/"$ -IF MTTNu>0 THEN -BEGIN - FOR i := 1:MTTNu DO - BEGIN - write " mttu", i, " = u[", i, "];"$ - END$ -END$ - - -write " "$ -write " /*====== Compute the state derivative and output ======*/"$ -SHUT "$1_ode.c2"; - - -% Load the general translator package -LOAD GENTRAN; -GENTRANLANG!* := 'C; -ON GENTRANSEG; -MAXEXPPRINTLEN!* := 80; - -% let it know that sign is a function -GENTRAN DECLARE sign : function; - -GENTRANOUT "$1_ode.c3"; -%Do the translation -%State -IF MTTNx>0 THEN -BEGIN - FOR i := 1:MTTNx DO - BEGIN - GENTRAN dx(i) ::=: mttdx(i,1)$ - END -END$ - -%Output -IF MTTNy>0 THEN -BEGIN - FOR i := 1:MTTNy DO - BEGIN - GENTRAN y(i) ::=: mtty(i,1)$ - END -END$ - - -GENTRANSHUT "$1_ode.c3"; EOF - -echo '};' > $1_ode.c4 -cat $1_ode.c1 $1_sympar.c $1_ode.c2 $1_ode.c3 $1_ode.c4> $1_ode.c - Index: mttroot/mtt/bin/trans/sympar_txt2m ================================================================== --- mttroot/mtt/bin/trans/sympar_txt2m +++ mttroot/mtt/bin/trans/sympar_txt2m @@ -9,10 +9,10 @@ # Copyright (C) 2000 by Peter J. Gawthrop echo Creating $1_sympar.m -lang_header -noglobal $1 sympar m "" sympar > $1_sympar.m +lang_header -noglobals $1 sympar m "" sympar > $1_sympar.m awk '{ printf(" sympar.%s \t= %i; # %s\n", $1, ++i, $2); }' < $1_sympar.txt >> $1_sympar.m