File mttroot/mtt/bin/trans/lang_header artifact 01b10f8c3c part of check-in 04d89abdd7


#!/bin/sh

# Generates function header for a computer language
# PJ Gawthrop May 1998

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.2  1998/05/24 12:47:39  peterg
## This still needs worjk doing for c generation!!
##
## Revision 1.1  1998/05/23 16:17:40  peterg
## Initial revision
##
###############################################################


# 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=']';
	;;
    java)
	ext='java';
	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_$rep($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 mtty[%i]; \t $Lc $1_ode output $Rc\n", ny+1);
  printf("  extern double mttdx[%i]; \t $Lc $1_ode state derivative $Rc\n", nx+1);
  printf("  extern double mttx[%i]; \t $Lc $1_ode state $Rc\n", nx+1);
  printf("  extern double mttu[%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");

printf("$Lc Time $Rc\n");
printf("  double t;\n");
printf("\n");

EOF

fi

if [ "$language" = "java" ]; then
cat <<EOF
public class $1_ode{
/*
System $system, representation $rep, language $language;
File $1_$rep.$ext;
Generated by MTT on `date`;
*/

EOF
fi

# Any extra bits ..
if [ -n "$extras" ]; then
cat <<EOF
$Lc Extra bits here $Rc
$extras
EOF
fi

# Globals
sympar2global_txt2lang $1 $language

if [ "$language" = "c" ] || [ "$language" = "m" ]; then
# Common part - ode (c and m)
# 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
fi

#if [ "$language" = "java" ]; then

#$MATRIX -q <<EOF   
#    printf("JAVA\n");
#EOF

#fi



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