Index: mttroot/mtt/bin/trans/switch_txt2m ================================================================== --- mttroot/mtt/bin/trans/switch_txt2m +++ mttroot/mtt/bin/trans/switch_txt2m @@ -14,19 +14,22 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.6 1998/10/01 18:20:50 peterg +## Split up the three if conditions on the switch and state value into +## three separate ifs. This is because p2c seems to generate incorrect +## code id just the one if is used (???). +## ## Revision 1.5 1998/10/01 16:05:34 peterg ## Separate switch.m file for euler and implicit integration ## ############################################################### echo Creating $1_switch.m -echo Creating $1_switcha.m - # Find system constants Nx=`grep "MTTNx " <$1_def.r | awk '{print $3}' | sed 's/;//'` #Write some file headers lang_header $1 switch m 'mttx' '[mttx]' > $1_switch.m @@ -48,37 +51,66 @@ printf("end;\n"); } }' Nx=$Nx < $1_switch.txt >> $1_switch.m -# Implicit integration version +## Set index version +echo Creating $1_switchopen.m + #Write some file headers -lang_header $1 switcha m 'mttAA,mttx' '[mttAA]' > $1_switcha.m +lang_header $1 switchopen m 'mttx' '[open]' > $1_switchopen.m + +# Set states to zero awk '{ if ($1=="#"){ - printf("#== Switches set row and column of A matrix to zero ==#\n") + printf("#== open - boolean vector of open switches ==#\n") + printf("[open] = zero_vector(%i); # Default to not open\n", Nx); + } else{ - printf("#== Switch: %s ==#\n",$1) + printf("\n#== Switch: %s ==#\n",$1) printf("if (%s==0.0) \n", $1); - printf(" for MTTi=1:%s\n",Nx) - printf(" mttAA(MTTi,%s)=0.0;\n", $2) - printf(" mttAA(%s,MTTi)=0.0;\n", $2) - printf(" end;\n"); - printf(" mttAA(%s,%s) = 1.0;\n", $2,$2); - printf("end;\n\n") - + printf(" open(%s) = 1;\n", $2); + printf("end;\n"); printf("if (%s<0.0)\n",$1); printf(" if (mttx(%s)<=0.0)\n",$2); - printf(" for MTTi=1:%s\n",Nx) - printf(" mttAA(MTTi,%s)=0.0;\n", $2) - printf(" mttAA(%s,MTTi)=0.0;\n", $2) - printf(" end;\n"); - printf(" mttAA(%s,%s) = 1.0;\n", $2,$2); + printf(" open(%s) = 1;\n", $2); printf(" end;\n"); printf("end;\n"); } -}' Nx=$Nx < $1_switch.txt >> $1_switcha.m +}' Nx=$Nx < $1_switch.txt >> $1_switchopen.m + +#echo Creating $1_switcha.m + +# Implicit integration version +#Write some file headers +# lang_header $1 switcha m 'mttAA,mttx' '[mttAA]' > $1_switcha.m +# awk '{ +# if ($1=="#"){ +# printf("#== Switches set row and column of A matrix to zero ==#\n") +# } +# else{ +# printf("#== Switch: %s ==#\n",$1) +# printf("if (%s==0.0) \n", $1); +# printf(" for MTTi=1:%s\n",Nx) +# printf(" mttAA(MTTi,%s)=0.0;\n", $2) +# printf(" mttAA(%s,MTTi)=0.0;\n", $2) +# printf(" end;\n"); +# printf(" mttAA(%s,%s) = 1.0;\n", $2,$2); +# printf("end;\n\n") +# +# printf("if (%s<0.0)\n",$1); +# printf(" if (mttx(%s)<=0.0)\n",$2); +# printf(" for MTTi=1:%s\n",Nx) +# printf(" mttAA(MTTi,%s)=0.0;\n", $2) +# printf(" mttAA(%s,MTTi)=0.0;\n", $2) +# printf(" end;\n"); +# printf(" mttAA(%s,%s) = 1.0;\n", $2,$2); +# printf(" end;\n"); +# printf("end;\n"); +# +# } +# }' Nx=$Nx < $1_switch.txt >> $1_switcha.m