Index: mttroot/mtt/bin/trans/mtt_txt2m ================================================================== --- mttroot/mtt/bin/trans/mtt_txt2m +++ mttroot/mtt/bin/trans/mtt_txt2m @@ -13,10 +13,13 @@ # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # %% Version control history # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # %% $Id$ # %% $Log$ +# %% Revision 1.9 2000/10/13 11:07:33 peterg +# %% Started conversion to new style state, input ext +# %% # %% Revision 1.8 2000/09/30 13:53:07 peterg # %% Default to empty matix in numpar.m -- avoids probs for parameter-free systems # %% # %% Revision 1.7 2000/05/19 17:46:17 peterg # %% Give argument to state @@ -106,52 +109,48 @@ # %% # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% system=$1 representation=$2 - -if [ "$representation" = "state" ]; then - name='mttx'; - arg=''; -fi -if [ "$representation" = "input" ]; then - name='mttu'; - arg='(mttt,mttx,mtty)' -fi +outfile=$1_$2.m # Inform user echo Creating $1_$2.m -#Create the $2 file complete with headers. +#Create the rep file complete with headers. case $representation in simpar) - lang_header -noglobals $1 simpar m '' mttsimpar > $1_simpar.m + arraycode=no ;; numpar) - lang_header $1 numpar m '' mttpar > $1_numpar.m; - echo "## Set parameters to zero" >> $1_numpar.m; - sympar2par_txt2m $1 zero >> $1_numpar.m; + name=mttpar + arraycode=yes ;; state) - lang_header $1 $2 m 'mttpar' mttx > $1_$2.m; - echo " if nargin>0" >> $1_$2.m; - echo " ## Set parameters" >> $1_$2.m; - sympar2par_txt2m $1 >> $1_$2.m; - echo " endif" >> $1_$2.m; + name=mttx + arraycode=yes + ;; + input) + name=mttu + arraycode=yes ;; *) - echo "function $name = $1_$2$arg" > $1_$2.m - echo "%% $2 file ($1_$2.m)" >> $1_$2.m - echo "%% Generated by MTT at `date`" >> $1_$2.m - echo "% Global variable list" >> $1_$2.m - sympar2global_txt2m $1 >> $1_$2.m + echo Representation $representation not supported + exit + #echo "function $name = $1_$2$arg" > $outfile + #echo "%% $2 file ($1_$2.m)" >> $outfile + #echo "%% Generated by MTT at `date`" >> $outfile + #echo "% Global variable list" >> $outfile + #sympar2global_txt2m $1 >> $outfile ;; esac -if [ "$representation" = "simpar" ]; then -#Write out the variables in m format. -cat $1_$2.txt | grep -v METHOD |\ +# Generate the header +mtt_header $system $representation m > $outfile + +# Write out the code from the txt file +cat $1_$2.txt | strip_comments | grep -v METHOD |\ awk -F# 'BEGIN{ quote = "\047"; doublequote = "\042"; } { @@ -183,47 +182,32 @@ statement = tolower($1); # Lower case globals as well } else statement = $1; - if (NF<2) print statement + if (NF<2) print " " statement if (NF>1) print statement " # " $2 }' | sed\ -e 's/\[\([0-9]*\)\]/(\1)/g' \ -e 's/\([^a-zA-Z_]\)t\([^a-zA-Z_]\)/\1mttt\2/g' \ -e 's/x(/mttx(/g' \ -e 's/u(/mttu(/g' \ -e 's/mttmtt/mtt/g' \ - -e 's/#/%/g' \ ->> $1_$2.m - -exit -fi - - -#if [ "$2" = "numpar" ]; then -# echo "## Set up the parameter vector" >> $1_numpar.m; -# echo "mttpar = []; # Default to empty matrix (Remove in mtt_m2p)" >> $1_numpar.m; -# sympar2par_txt2m $1 set >> $1_numpar.m; -#fi -case $2 in - numpar) - name=mttpar - ;; - state) - name=mttx - ;; - input) - name=mttu - ;; - *) -esac - -new_style=`strip_comments < $1_$2.txt| grep "$name(">/dev/null; echo $?` - -if [ "$new_style" = "1" ]; then - echo "## Set up the $name vector" >> $1_$2.m; - echo "name = []; # Default to empty matrix (Remove in mtt_m2p)" >> $1_$2.m; - mtt_name2array $1 $2 set >> $1_$2.m -else - echo "Old-style file detected: not creating array translations" -fi + >> $outfile + +if [ "$arraycode" = "yes" ]; then + new_style=`strip_comments < $1_$2.txt| grep "$name(">/dev/null; echo $?` + + if [ "$new_style" = "1" ]; then + echo >> $outfile + echo " ## Set up the $name vector" >> $outfile + echo " $name = []; # Default to empty matrix (Remove in mtt_m2p)" >> $outfile + mtt_name2array $1 $2 set >> $outfile + else + echo "Old-style file detected: not creating array translations" + fi +fi + +# End of the function +echo '## END Code' >> $outfile +echo 'endfunction' >> $outfile +