#! /bin/sh
######################################
##### Model Transformation Tools #####
######################################
# Bourne shell script: dm_r2m
# Reduce descriptor state-space A,B,C,D and E matrices to Matlab
# P.J.Gawthrop 29th July 1990, 6th Feb 1991, 28 May 1991, Dec 1993, Jan 94
# Copyright (c) P.J.Gawthrop, 1989, 1990, 1991, 1993,1994.
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.3 1996/08/18 12:02:46 peter
## Fixed bug when some matrices are empty.
##
## Revision 1.2 1996/08/12 20:22:20 peter
## Paramaters passed via an internal call to _numpar.
## _args script can overide these parameters - sneaky.
##
## Revision 1.1 1996/08/12 19:09:13 peter
## Initial revision
##
###############################################################
#Inform user
echo Creating $1_dm.m
# Remove the old log file
rm -f dm_r2m.log
# Use reduce to accomplish the transformation
reduce >dm_r2m.log << EOF
ON BigFloat, NumVal;
PRECISION 16; %Compatible with Matlab
%Read in the definitions file
in "$1_def.r";
%Set up the number of argument variables to zero in case the user has forgotten
MTTNVar := 0;
%Read in the parameter file
in "$1_sympar.r";
%Read the reduce state-space A,B,C and D matrices file
in "$1_dm.r";
OUT "$1_dm.m";
%Headings - Matlab style
%(Note. The ;; are deleted by for2mat)
write "function [MTTA,MTTB,MTTC,MTTD,MTTE] = $1_dm;;";
write "% [MTTA,MTTB,MTTC,MTTD,MTTE] = $1_dm;;";
write "% Linearised descriptor matrices for system $1";
write "% File $1_dm.m";
write "% Generated by MTT";
IF MTTNvar>0 THEN
BEGIN
write "% Parameters";
write "global ...;;";
FOR i := 1:MTTNvar DO
BEGIN
IF i<MTTNvar THEN write MTTVar(i,1), " ..."
ELSE write MTTVar(i,1), ";"
END;
END;
%Fortran switches - one line expressions
OFF echo;
ON fort$
cardno!* := 1$
fortwidth!* := 100$
OFF period$
MTTN := MTTNx + 2*MTTNz + MTTNyz;
write "MTTA = zeros(", MTTN, ",", MTTN, ");";
write "MTTB = zeros(", MTTN, ",", MTTNu, ");";
write "MTTC = zeros(", MTTNy, ",", MTTN, ");";
write "MTTD = zeros(", MTTNy, ",", MTTNu, ");";
write "MTTE = zeros(", MTTN, ",", MTTN, ");";
ON NERO; % Suppress zero elements.
MTTA := MTTA;
MTTB := MTTB;
MTTC := MTTC;
MTTD := MTTD;
MTTE := MTTE;
SHUT "$1_dm.m";