#! /bin/sh
######################################
##### Model Transformation Tools #####
######################################
# Bourne shell script: mtt_r2m
# Reduce to octave conversion
# Based on obsolete ode_r2m and ode_r2lang
# Based on obsolete mtt_r2m_old
# P.J.Gawthrop 14 June 1991, 12 Jan 1994, April 1994, Jan 95, May 1998
# July 1998
# Copyright (c) P.J.Gawthrop 1991, 1994, 1995, 1996, 1998
# Copyright (C) 2000 by Peter J. Gawthrop
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.30.4.1 2002/09/03 23:44:43 geraint
## adding global optimisation (-optg).
##
## Revision 1.30 2002/03/26 11:59:54 geraint
## Added dummy -optimise switch to prevent falling over for -cc generation.
##
## Revision 1.29 2001/09/07 00:25:56 geraint
## Partial fix for insidious bug which eliminates lines of code when parameter
## names of the form (in* or off*) start continuation lines.
##
## Revision 1.28 2001/07/13 04:54:04 geraint
## Branch merge: numerical-algebraic-solution back to main.
##
## Revision 1.27.4.1 2001/05/04 04:07:24 geraint
## Numerical solution of algebraic equations.
## sys_ae.cc written for unsolved inputs.
## Solution of equations using hybrd from MINPACK (as used by Octave fsolve).
##
## Revision 1.27 2001/02/08 00:39:56 geraint
## Removed clear from code generated by: mtt -c -i euler -o
##
## Revision 1.26 2000/11/27 11:52:10 peterg
## Changed some greps to be case insensitive
##
## Revision 1.25 2000/10/14 08:50:07 peterg
## Use new mtt_header
##
## Revision 1.24 2000/10/11 09:07:53 peterg
## Vectorisation
## csex rep.
##
## Revision 1.23 2000/10/10 21:00:43 peterg
## More reps added
##
## Revision 1.22 2000/09/15 08:27:07 peterg
## Removed debugging lines
##
## Revision 1.21 2000/08/30 11:43:40 peterg
## -optimise switch added
##
## Revision 1.20 2000/08/30 10:43:17 peterg
## Simplified version using GENTRAN matrix :=: matrix
## lang_matrix is no longer used at all
##
## Revision 1.19 2000/08/28 20:17:59 peterg
## Put in Winfried Neun's bug fix
## -- prevents segmentation violation using optimised gentran when matrix
## comtains a number
##
## Revision 1.18 2000/08/24 17:11:40 peterg
## Now optimises as well as segmenting - uses the SCOPE package
##
## Revision 1.17 2000/05/20 15:23:56 peterg
## Paramererised version of sm etc etc (using -parameter switch)
##
## Revision 1.16 2000/04/18 11:14:18 peterg
## Put in the -parameters option
##
## Revision 1.15 2000/02/10 14:58:57 peterg
## *** empty log message ***
##
## Revision 1.14 1999/12/08 02:06:00 peterg
## Now incudes csm rep.
##
## Revision 1.13 1999/11/23 00:59:14 peterg
## Now does ssm.m
##
## Revision 1.12 1999/11/15 22:57:20 peterg
## Removed a debugging line
##
## Revision 1.11 1999/11/01 21:20:14 peterg
## Removed the E matrix from the cse file.
##
## Revision 1.10 1999/10/27 07:38:30 peterg
## Now does cse version -- but not needed now exept for Euler integration
##
## Revision 1.9 1999/10/26 23:47:58 peterg
## Now does cse.m file
##
## Revision 1.8 1999/07/26 06:07:19 peterg
## Reinstated removal of the odeo.p file
##
## Revision 1.7 1999/03/16 00:38:06 peterg
## Done some more tidying up
##
## Revision 1.6 1999/03/15 07:29:25 peterg
## Fixed various obscure reduce bugs
## THIS NEEDS A MAJOR REWRITE!!!!
##
## Revision 1.5 1998/08/13 16:25:07 peterg
## Removed some documentation form odeo.m
##
## Revision 1.4 1998/08/13 15:10:47 peterg
## Change temp var name to mtt_t1 etc
##
## Revision 1.3 1998/08/13 12:43:19 peterg
## Cahnged tmp variable to mtt_1 etc
##
## Revision 1.2 1998/07/27 20:26:44 peterg
## Put in correct N and M values for dm rep
##
## Revision 1.1 1998/07/27 16:30:26 peterg
## Initial revision
##
###############################################################
# Args
while [ -n "`echo $1 | grep '^-'`" ]; do
case $1 in
-noglobals)
noglobals='-noglobals';
;;
-parameters)
parameters='-parameters';
par='mttpar'
;;
-optimise_local | -optimise_global )
;;
*)
echo $1 is an unknown option
exit;;
esac
shift
done
# Set up some strings
rep=$2
ext=m
out=$1"_"$rep.$ext
#Inform user
echo Creating $out
# Remove the old log file
rm -f mtt_r2m.log
#Header
case $rep in
ae|csex|cseo|ode|odeo)
vectorise=yes
;;
*)
esac
mtt_header $1 $rep $ext > mtt_junk
#Convert from the (optimised) r file
echo >> mtt_junk
echo '## Code' >> mtt_junk
strip_comments<$1_$2.r | tr [A-Z] [a-z] |\
grep -vi 'MATRIX ' |\
grep -vi 'END;' |\
grep -vi 'clear mtt' |\
grep -v '^off .*\$' |\
grep -v '^in .*\$' |\
sed \
-e "s/^mtt/ mtt/" \
-e "s/:=/=/" \
-e "s/\\$/;/" \
>> mtt_junk
echo '## END Code' >> mtt_junk
echo endfunction >> mtt_junk
# Mend broken lines
mtt_mend_lines < mtt_junk > mtt_junk_mended
# Vectorise (n,1) arrays when appropriate
if [ -n "$vectorise" ]; then
mtt_vectorise <mtt_junk_mended >$out
else
mv mtt_junk_mended $out
fi
# Now invoke the standard error handling.
#mtt_error_r mtt_r2m.log