Artifact 7ef04b9230e6d4da955c176bdf4c12671e295d23df1a81fc63cb7753984d306d:


#!/bin/sh

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

# Bourne shell script: def2write.r
# Generates r code to write matrices
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.9  2001/07/27 23:29:10  geraint
## Optimises only when requested (-opt).
##
## Revision 1.8  2001/07/13 04:54:04  geraint
## Branch merge: numerical-algebraic-solution back to main.
##
## Revision 1.7.2.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.7  2001/04/11 09:44:26  gawthrop
## Fixed cc and c problems to do with pow(x,y) and integers
## mtt/lib/reduce/fix_c.r is included in rdae2dae and cse2smx_lang for
## -c, -cc and -oct options
##
## Revision 1.6  2000/11/29 20:48:53  peterg
## Zapped unnecessary Npar creation
##
## Revision 1.5  2000/11/09 10:12:24  peterg
## Removed debugging line
##
## Revision 1.4  2000/10/14 16:19:54  peterg
## Just optimize one line at a time ...
##
## Revision 1.3  2000/10/11 09:07:17  peterg
## Added csex rep (cse without E)
##
## Revision 1.2  2000/10/10 21:02:17  peterg
## Added cse reps
##
## Revision 1.1  2000/10/10 09:07:32  peterg
## Initial revision
##
###############################################################

optimise=''
while [ -n "`echo $1 | grep '^-'`" ]; do
    case $1 in
	-optimise)
	    opt='-optimise'
	    optimise_msg=' with optimisation' ;;
	*)
	    echo "$1 is an invalid argument - ignoring" ;;
    esac
    shift
done

sys=$1 # System name
rep=$2 # System representation

# Inform User
echo Creating $1_$2_write.r $optimise_msg

# Find system constants
Nx=`mtt_getsize $sys x` # States
Nxx=`mtt_getsize $sys xx` # States x States
Nu=`mtt_getsize $sys u` # Inputs 
Ny=`mtt_getsize $sys y` # Outputs 
Nyz=`mtt_getsize $sys yz` # Zero outputs
#Npar=`wc -l $sys\_sympar.txt | gawk '{print $1}'`

# Set up representation-specific stuff
case $rep in
    cse)
        matrices='EdX E'
        ns="$Nx $Nx"
        ms="1 $Nx"
	;;
    csex)
        matrices='EdX'
        ns="$Nx"
        ms="1"
	;;
    cseo)
        matrices='Y'
        ns="$Ny"
        ms="1"
	;;
    lde)
        matrices='L'
        ns="$Nyz"
        ms="1"
	;;
    ldeo)
        matrices='Y Yz'
        ns="$Ny $Nyz"
        ms="1 1"
	;;
    ode)
        matrices='dX'
        ns="$Nx"
        ms="1"
	;;
    odeo)
        matrices='Y'
        ns="$Ny"
        ms="1 1"
	;;
    sm)
        matrices='A B C D'
        ns="$Nx $Nx $Ny $Ny"
        ms="$Nx $Nu $Nx $Nu"
	;;
    *)
        echo def2write_r: representation $rep not recognised
        exit
esac

# Write out the code
echo 'off echo$'                    >$1_$2_write.r

if [ ${opt:-""} = "-optimise" ]; then
    echo 'load scope$'
else
    echo 'load gentran$'
fi >> $1_$2_write.r

for matrix in $matrices; do
    n=`first "$ns"`; ns=`rest "$ns"` 
    m=`first "$ms"`; ms=`rest "$ms"`
    is=`n2m 1 $n`; 
    js=`n2m 1 $m`; 
    for i in $is; do
      for j in $js; do
	if [ ${opt:-""} = "-optimise" ]; then
       	    echo 'optimize'
	    name=`echo MTT$matrix'('$i','$j')'`
	    echo '  '$comma$name ':=:' $name
	    echo 'INAME mtt_tmp$'
	    comma=''
	else
	    echo 'write'
	    name=`echo MTT$matrix'('$i','$j')'`
	    echo '  '$comma$name ':=' $name '$'
	fi >> $1_$2_write.r
      done
    done
done
echo 'END$'                           >>$1_$2_write.r


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