Index: mttroot/mtt/bin/trans/mtt_p2cc ================================================================== --- mttroot/mtt/bin/trans/mtt_p2cc +++ mttroot/mtt/bin/trans/mtt_p2cc @@ -9,136 +9,109 @@ # Pascal to .oct (octave loadable binary). # P.J.Gawthrop Feb 2000 # Copyright (C) 2000 by Peter J. Gawthrop #$Id$ + +## Extract the system and rep names. +sys=`mtt_sysname $1` +rep=`mtt_repname $1` +sys_rep=$sys"_"$rep # Find system constants -Nx=`mtt_getsize $1 x` # States -Nu=`mtt_getsize $1 u` # Inputs -Ny=`mtt_getsize $1 y` # Inputs - -# Create numpar code -#mtt_p2C $1 numpar - -# Create input code -#mtt_p2C $1 input +Nx=`mtt_getsize $sys x` # States +Nu=`mtt_getsize $sys u` # Inputs +Ny=`mtt_getsize $sys y` # Inputs # Create the representation code -mtt_p2C $1 $2 +mtt_p2C $sys $rep # Inform user -echo Creating $1_$2.cc +echo Creating $sys_rep.cc # Create the c++ code # Heading date=`date` -cat > $1_$2.cc < $sys_rep.cc < -DEFUN_DLD ($1_$2, args, , - "$1_$2 was generated by MTT on $date") +DEFUN_DLD ($sys_rep, args, , + "$sys_rep was generated by MTT on $date") { ColumnVector mttx = args(0).vector_value (); ColumnVector mttu = args(1).vector_value (); double mttt = args(2).double_value (); ColumnVector mttpar = args(3).vector_value (); EOF -case "$2" in +case "$rep" in ode) - echo " ColumnVector mttdx ($Nx);" >> $1_$2.cc + echo " ColumnVector mttdx ($Nx);" >> $sys_rep.cc ;; odeo) - echo " ColumnVector mtty ($Ny);" >> $1_$2.cc + echo " ColumnVector mtty ($Ny);" >> $sys_rep.cc ;; cse) - echo " ColumnVector mttdx ($Nx);" >> $1_$2.cc + echo " ColumnVector mttdx ($Nx);" >> $sys_rep.cc ;; cseo) - echo " ColumnVector mtty ($Ny);" >> $1_$2.cc + echo " ColumnVector mtty ($Ny);" >> $sys_rep.cc ;; smx | smxa | smxax) Nxx=`echo "$Nx*$Nx" | bc` - echo " ColumnVector mtta ($Nxx);" >> $1_$2.cc - echo " ColumnVector mttax ($Nx);" >> $1_$2.cc + echo " ColumnVector mtta ($Nxx);" >> $sys_rep.cc + echo " ColumnVector mttax ($Nx);" >> $sys_rep.cc ;; *) esac #Extract Type info -echo '/* Types */' >> $1_$2.cc -grep typedef $1_$2.C >> $1_$2.cc - -#Extract any additional mtt_tmp variables -#awk 'BEGIN{ -# writing = 1; -#} -#{ -# if (match($1,"mtt")==1) writing=0; -# if ( (writing)&&(match($0,"mtt_t[0-9]")>0) ) print $0; -#}' < $1_$2.C >> $1_$2.cc - -#Extract the numpar code -#echo '/* Numerical parameters */' >> $1_$2.cc -#awk '{ -# if ($1=="}") writing=0; -# if (writing) print $0; -# if ($1=="{") writing=1; -#}' <$1_numpar.C >> $1_$2.cc - -#Extract the input code converting [] to () -#echo "/* Input information */" >> $1_$2.cc -#awk '{ -# if ($1=="}") writing=0; -# if (match($1,"mtt")==1) writing=1; -# if (writing) print $0; -#}' <$1_input.C |\ -#sed 's/\[\([0-9]*\)\]/(\1)/g' >> $1_$2.cc +echo '/* Types */' >> $sys_rep.cc +grep typedef $sys_rep.C >> $sys_rep.cc #Extract the rep code and converting [] to () and deleting mtt variables etc -echo "/* Representation $2 information */" >> $1_$2.cc +echo "/* Representation $rep information */" >> $sys_rep.cc awk '{ if ($1=="}") writing=0; if ( (writing)&&(match($2,"mtt")!=1) ) print $0; if (match($1,"{")==1) writing=1; -}' <$1_$2.C |\ +}' <$sys_rep.C |\ sed 's/\[\([0-9]*\)\]/(\1)/g' |\ -sed 's/\[\(mmtti\)\]/(\1)/g' >> $1_$2.cc +sed 's/\[\(mmtti\)\]/(\1)/g' >> $sys_rep.cc # Tail -cat >> $1_$2.cc <> $sys_rep.cc <> $1_$2.cc; + echo "return octave_value (mttdx);" >> $sys_rep.cc; ;; odeo) - echo "return octave_value (mtty); " >> $1_$2.cc; + echo "return octave_value (mtty); " >> $sys_rep.cc; ;; cse) - echo "return octave_value (mttdx);" >> $1_$2.cc; + echo "return octave_value (mttdx);" >> $sys_rep.cc; ;; cseo) - echo "return octave_value (mtty); " >> $1_$2.cc; + echo "return octave_value (mtty); " >> $sys_rep.cc; ;; smxa) - echo "return octave_value (mtta); " >> $1_$2.cc; + echo "return octave_value (mtta); " >> $sys_rep.cc; ;; smxax) - echo "return octave_value (mttax); " >> $1_$2.cc; + echo "return octave_value (mttax); " >> $sys_rep.cc; ;; *) esac # Terminating } -echo "}" >> $1_$2.cc; +echo "}" >> $sys_rep.cc; # Convert to octave loadable code -echo Creating $1_$2.oct -mkoctfile $1_$2.cc +echo Creating $sys_rep.oct +mkoctfile $sys_rep.cc