File mttroot/mtt/bin/trans/dm_r2m artifact c980f7fdc8 part of check-in f00154448a


#! /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.6  1997/04/16  13:43:29  peterg
# Added matrix dimenensions
#
# Revision 1.5  1997/02/24  14:44:28  peterg
# Ignores numerical parameters in global list.
#
## Revision 1.4  1996/08/24 14:16:25  peter
## Global parameter passing.
##
## 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";

IF MTTNvar>0 THEN
BEGIN
  write "% Set the parameters";
  write "global ...;;";
  FOR i := 1:MTTNvar DO
    BEGIN
      IF numberp(MTTVar(i,1)) 
      THEN 
      BEGIN
        % Do nowt
      END
      ELSE  
      BEGIN
        write MTTVar(i,1), " ...";
      END;
    END;
    write " ";
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, ");";

OUT "$1_dm.1";

ON NERO;	% Suppress zero elements.
MTTA := MTTA;
MTTB := MTTB;
MTTC := MTTC;
MTTD := MTTD;
MTTE := MTTE;

SHUT "$1_dm.1";


EOF

# Header
matlab_header $1 dm> $1_dm.m

#Define array sizes.
grep -v 'function' $1_def.m | grep -v '%' >>  $1_dm.m
echo 'mtta = zeros(nx+nyz+2*nz,nx+nyz+2*nz);' >>  $1_dm.m
echo 'mttb = zeros(nx+nyz+2*nz,nu);' >>  $1_dm.m
echo 'mttc = zeros(ny,nx+nyz+2*nz);' >>  $1_dm.m
echo 'mttd = zeros(ny,nu);' >>  $1_dm.m
echo 'mtte = zeros(nx+nyz+2*nz,nx+nyz+2*nz);' >>  $1_dm.m


#Code
cat $1_dm.1 >> $1_dm.m


rm -f $1_dm.1




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