Artifact 1b58ea9614517c4d929836771167f936f1c9877ece414232adec66564df3bdeb:


#! /bin/sh

     ###################################### 
     ##### Model Transformation Tools #####
     ######################################

# Bourne shell script: switch_txt2m

# Convert switch file from txt to m
# P.J.Gawthrop May 1997
# Copyright (c) P.J.Gawthrop, 1997.


###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.15  2000/12/04 08:23:25  peterg
## Put logic in-line - avoids the if statements
##
## Revision 1.14  2000/11/09 10:29:21  peterg
## open --> mtt_open
##
## Revision 1.13  2000/11/09 10:19:12  peterg
## Explicitly write out the open switches ....
##
## Revision 1.12  2000/11/09 09:52:07  peterg
## Removed [] from zero_state output
##
## Revision 1.11  2000/10/17 09:55:55  peterg
## Now writes to standard output
## Write the name, not the array
##
## Revision 1.10  2000/10/17 09:04:12  peterg
## *** empty log message ***
##
## Revision 1.9  1999/08/02 12:44:21  peterg
## zero_vector --> zero_state.
##
## Revision 1.8  1999/04/20 00:55:40  peterg
## Changed <= to < in switchopen.m
## Removed switch.m generation - redundant
##
## Revision 1.7  1999/04/02 06:30:37  peterg
## New _switchopen
## Removed switcha
##
## 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
##
###############################################################


# Find system constants
Nx=`mtt_getsize $1 x` # States

#Write some file headers
#lang_header $1 switch m 'mttx' '[mttx]' > $1_switch.m

#echo Creating  $1_switch.m
# Set states to zero
# gawk '{
#   if ($1=="#"){
#     printf("#== Switches set element of state vector to zero ==#\n")
#   }
#   else{
#   printf("\n#== Switch: %s ==#\n",$1)
#   printf("if (%s==0.0) \n", $1);
#   printf("  mttx(%s)=0.0;\n", $2);
#   printf("end;\n");
#   printf("if (%s<0.0)\n",$1);
#   printf("  if (mttx(%s)<=0.0)\n",$2);
#   printf("    mttx(%s)=0.0;\n", $2);
#   printf("  end;\n");
#   printf("end;\n");

#   }
# }' Nx=$Nx < $1_switch.txt >> $1_switch.m

## Set index version
#echo Creating  $1_switchopen.m

#Write some file headers
#lang_header $1 switchopen m 'mttx' '[open]' > $1_switchopen.m

## Add the switching logic
#cat  >> $1_switchopen.m <<EOF

## User defined logic (from $1_logic.m)

#EOF
#cat $1_logic.txt >> $1_switchopen.m

# Set states to zero
gawk '{
  if ($1=="#"){
    printf("#== mttopen - boolean vector of open switches ==#\n")
    for (i=1;i<=Nx;i++)
     printf("mttopen(%i) = 0; # Default to not open\n", i);
  }
  else{
  printf("\n#== Switch: %s ==#\n",$1)
   printf("mttopen(%s) = (abs(%s_logic)<0.5)||((%s_logic<0.0)&&(%s<0.0));\n", $2, $1, $1, $1);
#   printf("if (%s_logic==0.0) \n", $1);
#   printf("  mttopen(%s) = 1;\n", $2);
#   printf("end;\n");
#   printf("if (%s_logic<0.0)\n",$1);
#   printf("  if (%s<0.0)\n",$1);
#   printf("    mttopen(%s) = 1;\n", $2);
#   printf("  end;\n");
#   printf("end;\n");

  }
}' 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
# gawk '{
#   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





MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]