Artifact 75ad26faec1b7e4edb28343d47b9d4708a3660fd3c5f740a5c2453be117239a7:


#!/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


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