#! /bin/sh

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

# Bourne shell script: lde_r2tex
# Reduce differential-algebraic to LaTex differential-algebraic equations.
# P.J.Gawthrop 10th May 1991, April 1994
# Copyright (c) P.J.Gawthrop, 1991, 1994, 1996.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.3  1998/01/23 15:51:01  peterg
## Repleace eqnarray by equation + aligned -- this works with Latex2html
##
## Revision 1.2  1996/12/20 08:59:10  peterg
## Now writes out mtti instead of mtt_{i} -- lets latex_tidy do the
## conversion.
##
## Revision 1.1  1996/12/20 08:53:57  peterg
## Initial revision
##
###############################################################

# Inform user
echo Creating $1_lde.tex

# Remove the old log file
rm -f lde_r2tex.log

# Use reduce to accomplish the transformation
reduce >lde_r2tex.log << EOF

%Read the definitions file
in "$1_def.r";

%Read the differential-algebraic equations file
in "$1_lde.r";

%Read the symbolic parameter file
%%in "$1_sympar.r";



OFF Echo;
OFF Nat;

%Read the substitution file
IN "$1_subs.r";

%Read the simplifying expressions file
IN "$1_simp.r";

OUT "$1_lde.tex";

%Write out the  differential-algebraic equations.

write "%File: $1_lde.tex";

write "%ordinary differential equations";
write "% Generated by MTT";

IF MTTNyz>0 THEN
BEGIN
  write"\begin{equation} \label{eq_$1_lde_x}";
  write"\begin{aligned}";
  FOR Row := 1:MTTNx DO
  BEGIN
	write "{";
	write MTTl(Row,1);
	write "}";
	write " &= 0";
        IF Row<MTTNx THEN write "\cr";
  END;
  write"\end{aligned}";
  write"\end{equation}";
END;


IF MTTNy>0 THEN
BEGIN
  write"\begin{equation} \label{eq_$1_lde_y}";
  write"\begin{aligned}";
  FOR Row := 1:MTTNy DO
  BEGIN
	write "MTTy", Row, " &= ";
	write "{";
	write MTTy(Row,1);
	write "}";
        IF Row<MTTNy THEN write "\cr";
  END;
  write"\end{aligned}";
  write"\end{equation}";
END;





SHUT "$1_lde.tex";
quit;
EOF
