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: |
d842c7fb53ae2a562eab631429ebcb5d |
User & Date: | gawthrop@users.sourceforge.net on 1998-05-23 16:17:40 |
Other Links: | branch diff | manifest | tags |
Context
1998-05-23
| ||
16:18:37 |
ordinary differential equation.m files generated with the new ode2lang method. check-in: ffb4b91e0b user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
16:17:40 | Initial revision check-in: d842c7fb53 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
15:00:27 | Removed the name = matrix statement - now done by sed. check-in: 2c7fce8980 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
Changes
Added mttroot/mtt/bin/trans/lang_header version [75ad26faec].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | #!/bin/sh # Generates function header for a computer language # PJ Gawthrop May 1998 ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ ############################################################### # Set up the language specific stuff system=$1 rep=$2 language=$3 args=$4 output=$5 extras=$6 case $language in m) ext='m'; Lc='#'; Rc='#'; Lb='('; Rb=')'; ;; c) ext='c'; Lc='/*'; Rc='*/'; Lb='['; Rb=']'; ;; *) echo Language $language not supported - sorry; exit 1 esac ######### Octave (matlab) code if [ "$language" = m ]; then cat <<EOF function $output = $1_$rep($args); % $output = $1_ode($args); %System $system, representation $rep, language $language; %File $1_$rep.$ext; %Generated by MTT on `date`; % EOF fi ######### c code if [ "$language" = c ]; then cat <<EOF void $1_$rep() { /* System $system, representation $rep, language $language; File $1_$rep.$ext; Generated by MTT on `date`; NB Arrays are be defined to be one larger than expected - the 0 element is not used. */ EOF # Declarations $MATRIX -q <<EOF %System structure [nx,ny,nu,nz,nyz] = $1_def; printf("$Lc Declare standard arrays $Rc\n"); printf(" extern double y[%i]; \t $Lc $1_ode output $Rc\n", ny+1); printf(" extern double dx[%i]; \t $Lc $1_ode state derivative $Rc\n", nx+1); printf(" extern double x[%i]; \t $Lc $1_ode state $Rc\n", nx+1); printf(" extern double u[%i]; \t $Lc $1_ode input $Rc\n\n", nu+1); printf("$Lc Dummy variable list $Rc\n"); printf(" double t0;\n\n"); printf("$Lc State variable list $Rc\n"); for i = 1:nx printf(" double mttx%i\n",i); end; printf("\n"); printf("$Lc State variable input list $Rc\n"); for i = 1:nu printf(" double mttu%i\n",i); end; printf("\n"); printf("$Lc Counter $Rc\n"); printf(" int i;\n"); printf("\n"); EOF fi # Any extra bits .. if [ -n "$extras" ]; then cat <<EOF $Lc Extra bits here $Rc $extras EOF fi # Globals sympar2global_txt2lang $1 $language # Common part - ode # Use octave for this bit - needs the definition file $MATRIX -q <<EOF %System structure [nx,ny,nu,nz,nyz] = $1_def; printf("$Lc====== Read in the input ======$Rc\n"); printf("mttu = $1_input(mttx,t)\n"); printf("\n"); printf("$Lc====== Set up the state variables ======$Rc\n"); for i = 1:nx printf(" mttx%i = mttx$Lb%i$Rb;\n",i,i); end; printf("\n"); printf("$Lc====== Set up the input variables ======$Rc\n"); for i = 1:nu printf(" mttu%i = mttu$Lb%i$Rb;\n",i,i); end; printf("\n"); EOF |
Added mttroot/mtt/bin/trans/ode_r2lang version [df7edb9a23].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | #! /bin/sh ###################################### ##### Model Transformation Tools ##### ###################################### # Bourne shell script: ode_r2lang # Reduce ODE to general language ODE # Based on obsolete ode_r2m # P.J.Gawthrop 14 June 1991, 12 Jan 1994, April 1994, Jan 95, May 1998 # Copyright (c) P.J.Gawthrop 1991, 1994, 1995, 1996, 1998 ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ ############################################################### # Set up the language specific stuff language=$2 case $language in m) ext='m'; codegenerator='FORTRAN' Lc='#'; Rc='#'; Lb='('; Rb=')'; ;; c) ext='c'; codegenerator='C' Lc='/*'; Rc='*/'; Lb='['; Rb=']'; ;; *) echo Language $2 not supported - sorry; exit 1 esac #Inform user echo Creating $1_ode.$ext echo Creating $1_odea.$ext echo Creating $1_odeo.$ext # Remove the old log file rm -f ode_r2lang.log #Remove the temporary files rm -f $1_ode.$ext.1 rm -f $1_odea.$ext.1; rm -f $1_odeo.$ext.1; # Use reduce to accomplish the transformation $SYMBOLIC >ode_r2lang.log << EOF %Read the reduce definitions file in "$1_def.r"; %Read the reduce ODE file in "$1_ode.r"; % Set up the code generator % Load the general translator package LOAD GENTRAN; GENTRANLANG!* := '$codegenerator; ON GENTRANSEG; MAXEXPPRINTLEN!* := 40; % Matrix output function in"$MTTPATH/trans/lang_matrix.r"; %Set up the number of argument variables to zero in case the user has forgotten MTTNVar := 0; %Read the parameter file in "$1_sympar.r"; % The body of the ode function GENTRANOUT "$1_ode.$ext.1"; mtt_matrix := MTTdX$ mtt_matrix_n := MTTNx$ mtt_matrix_m := 1$ mtt_matrix_name := MTTdX$ lang_matrix(); GENTRANSHUT "$1_ode.$ext.1"; % 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 # Create the ode.$ext function lang_header $1 ode $ext 'mttx,t' mttdx > $1_ode.$ext # Algebraic bits $MATRIX -q <<EOF >> $1_ode.$ext %System structure [nx,ny,nu,nz,nyz] = $1_def; if nyz>0 printf("global mttxx mttt;\n"); printf("mttxx = mttx; mttt=t;\n"); 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("mttui = fsolve('$1_odea',mttui);\n"); 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"); printf("$Lc====== Put internal input variables at end of state derivative ======$Rc\n"); for i = 1:nyz printf(" mttdx$Lb%i$Rb = mttui%i;\n",i+nx,i); end; printf("\n"); end; EOF cat <<EOF >> $1_ode.$ext % The differential equations EOF sed 's/mtt_matrix/mttdx/' $1_ode.$ext.1 >> $1_ode.$ext # 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; if nyz>0 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 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,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 cat <<EOF >> $1_odeo.$ext % The output equations EOF sed 's/mtt_matrix/mtty/' $1_odeo.$ext.1 >> $1_odeo.$ext |