Changes In Branch origin/optimise-algebraic-equations Through [96f269ef83] Excluding Merge-Ins

This is equivalent to a diff from e168fd1202 to 96f269ef83

2002-06-10
08:27:33
Updated description check-in: 6c463de05f user: gawthrop@users.sourceforge.net tags: origin/master, trunk
2002-06-05
17:57:50
Main part of optimisation routine moved to separate file. check-in: 9e8650bb26 user: geraint@users.sourceforge.net tags: origin/optimise-algebraic-equations, trunk
17:28:00
Cosmetic change. check-in: 96f269ef83 user: geraint@users.sourceforge.net tags: origin/optimise-algebraic-equations, trunk
17:27:18
commented out incomplete debugging code. check-in: a7340b2ea2 user: geraint@users.sourceforge.net tags: origin/optimise-algebraic-equations, trunk
10:54:13
Created branch optimise-algebraic-equations check-in: 28ad1630ec user: gawthrop@users.sourceforge.net tags: origin/optimise-algebraic-equations, trunk
10:54:12
#include "useful-functions.hh" added to files. check-in: e168fd1202 user: geraint@users.sourceforge.net tags: origin/master, trunk
2002-05-29
18:40:43
Made file C compliant. check-in: 27de151df7 user: geraint@users.sourceforge.net tags: origin/master, trunk

Deleted CVSROOT/checkoutlist version [db1d2d9b69].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# The "checkoutlist" file is used to support additional version controlled
# administrative files in $CVSROOT/CVSROOT, such as template files.
#
# The first entry on a line is a filename which will be checked out from
# the corresponding RCS file in the $CVSROOT/CVSROOT directory.
# The remainder of the line is an error message to use if the file cannot
# be checked out.
#
# File format:
#
#	[<whitespace>]<filename><whitespace><error message><end-of-line>
#
# comment lines begin with '#'
syncmail
<
<
<
<
<
<
<
<
<
<
<
<
<
<




























Deleted CVSROOT/commitinfo version [85654ac9a8].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# The "commitinfo" file is used to control pre-commit checks.
# The filter on the right is invoked with the repository and a list 
# of files to check.  A non-zero exit of the filter program will 
# cause the commit to be aborted.
#
# The first entry on a line is a regular expression which is tested
# against the directory that the change is being committed to, relative
# to the $CVSROOT.  For the first match that is found, then the remainder
# of the line is the name of the filter to run.
#
# If the repository name does not match any of the regular expressions in this
# file, the "DEFAULT" line is used, if it is specified.
#
# If the name "ALL" appears as a regular expression it is always used
# in addition to the first matching regex or "DEFAULT".
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






























Deleted CVSROOT/config version [28e7a42550].

1
2
3
4
5
6
7
8
9
10
11
# Set this to "no" if pserver shouldn't check system users/passwords
#SystemAuth=no

# Set `PreservePermissions' to `yes' to save file status information
# in the repository.
#PreservePermissions=no

# Set `TopLevelAdmin' to `yes' to create a CVS directory at the top
# level of the new working directory when using the `cvs checkout'
# command.
#TopLevelAdmin=no
<
<
<
<
<
<
<
<
<
<
<






















Deleted CVSROOT/cvswrappers version [9d41597c29].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# This file affects handling of files based on their names.
#
# The -t/-f options allow one to treat directories of files
# as a single file, or to transform a file in other ways on
# its way in and out of CVS.
#
# The -m option specifies whether CVS attempts to merge files.
#
# The -k option specifies keyword expansion (e.g. -kb for binary).
#
# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers)
#
#  wildcard	[option value][option value]...
#
#  where option is one of
#  -f		from cvs filter		value: path to filter
#  -t		to cvs filter		value: path to filter
#  -m		update methodology	value: MERGE or COPY
#  -k		expansion mode		value: b, o, kkv, &c
#
#  and value is a single-quote delimited value.
# For example:
#*.gif -k 'b'
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<














































Deleted CVSROOT/editinfo version [dfa5fb459c].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# The "editinfo" file is used to allow verification of logging
# information.  It works best when a template (as specified in the
# rcsinfo file) is provided for the logging procedure.  Given a
# template with locations for, a bug-id number, a list of people who
# reviewed the code before it can be checked in, and an external
# process to catalog the differences that were code reviewed, the
# following test can be applied to the code:
#
#   Making sure that the entered bug-id number is correct.
#   Validating that the code that was reviewed is indeed the code being
#       checked in (using the bug-id number or a seperate review
#       number to identify this particular code set.).
#
# If any of the above test failed, then the commit would be aborted.
#
# Actions such as mailing a copy of the report to each reviewer are
# better handled by an entry in the loginfo file.
#
# One thing that should be noted is the the ALL keyword is not
# supported.  There can be only one entry that matches a given
# repository.
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










































Deleted CVSROOT/loginfo version [7508d75767].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# The "loginfo" file controls where "cvs commit" log information
# is sent.  The first entry on a line is a regular expression which must match
# the directory that the change is being made to, relative to the
# $CVSROOT.  If a match is found, then the remainder of the line is a filter
# program that should expect log information on its standard input.
#
# If the repository name does not match any of the regular expressions in this
# file, the "DEFAULT" line is used, if it is specified.
#
# If the name ALL appears as a regular expression it is always used
# in addition to the first matching regex or DEFAULT.
#
# You may specify a format string as part of the
# filter.  The string is composed of a `%' followed
# by a single format character, or followed by a set of format
# characters surrounded by `{' and `}' as separators.  The format
# characters are:
#
#   s = file name
#   V = old version number (pre-checkin)
#   v = new version number (post-checkin)
#
# For example:
#DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog
# or
#DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog

# Lines to mail changes
CVSROOT $CVSROOT/CVSROOT/syncmail %{sVv} gawthrop@users.sourceforge.net
DEFAULT $CVSROOT/CVSROOT/syncmail %{sVv} mtt-checkins@lists.sourceforge.net
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




























































Deleted CVSROOT/modules version [84b74e5335].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Three different line formats are valid:
#	key	-a    aliases...
#	key [options] directory
#	key [options] directory files...
#
# Where "options" are composed of:
#	-i prog		Run "prog" on "cvs commit" from top-level of module.
#	-o prog		Run "prog" on "cvs checkout" of module.
#	-e prog		Run "prog" on "cvs export" of module.
#	-t prog		Run "prog" on "cvs rtag" of module.
#	-u prog		Run "prog" on "cvs update" of module.
#	-d dir		Place module in directory "dir" instead of module name.
#	-l		Top-level directory only -- do not recurse.
#
# NOTE:  If you change any of the "Run" options above, you'll have to
# release and re-checkout any working directories of these modules.
#
# And "directory" is a path to a directory relative to $CVSROOT.
#
# The "-a" option specifies an alias.  An alias is interpreted as if
# everything on the right of the "-a" had been typed on the command line.
#
# You can encode a module within a module by using the special '&'
# character to interpose another module into the current module.  This
# can be useful for creating a module that consists of many directories
# spread out over the entire source repository.
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




















































Deleted CVSROOT/notify version [2a5259e3c5].

1
2
3
4
5
6
7
8
9
10
11
12
# The "notify" file controls where notifications from watches set by
# "cvs watch add" or "cvs edit" are sent.  The first entry on a line is
# a regular expression which is tested against the directory that the
# change is being made to, relative to the $CVSROOT.  If it matches,
# then the remainder of the line is a filter program that should contain
# one occurrence of %s for the user to notify, and information on its
# standard input.
#
# "ALL" or "DEFAULT" can be used in place of the regular expression.
#
# For example:
#ALL mail %s -s "CVS notification"
<
<
<
<
<
<
<
<
<
<
<
<
























Deleted CVSROOT/rcsinfo version [c276b88ba1].

1
2
3
4
5
6
7
8
9
10
11
12
13
# The "rcsinfo" file is used to control templates with which the editor
# is invoked on commit and import.
#
# The first entry on a line is a regular expression which is tested
# against the directory that the change is being made to, relative to the
# $CVSROOT.  For the first match that is found, then the remainder of the
# line is the name of the file that contains the template.
#
# If the repository name does not match any of the regular expressions in this
# file, the "DEFAULT" line is used, if it is specified.
#
# If the name "ALL" appears as a regular expression it is always used
# in addition to the first matching regex or "DEFAULT".
<
<
<
<
<
<
<
<
<
<
<
<
<


























Deleted CVSROOT/syncmail version [c9554ab114].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#! /usr/bin/python

# NOTE: Until SourceForge installs a modern version of Python on the cvs
# servers, this script MUST be compatible with Python 1.5.2.

"""Complicated notification for CVS checkins.

This script is used to provide email notifications of changes to the CVS
repository.  These email changes will include context diffs of the changes.
Really big diffs will be trimmed.

This script is run from a CVS loginfo file (see $CVSROOT/CVSROOT/loginfo).  To
set this up, create a loginfo entry that looks something like this:

    mymodule /path/to/this/script %%s some-email-addr@your.domain

In this example, whenever a checkin that matches `mymodule' is made, this
script is invoked, which will generate the diff containing email, and send it
to some-email-addr@your.domain.

    Note: This module used to also do repository synchronizations via
    rsync-over-ssh, but since the repository has been moved to SourceForge,
    this is no longer necessary.  The syncing functionality has been ripped
    out in the 3.0, which simplifies it considerably.  Access the 2.x versions
    to refer to this functionality.  Because of this, the script is misnamed.

It no longer makes sense to run this script from the command line.  Doing so
will only print out this usage information.

Usage:

    %(PROGRAM)s [options] <%%S> email-addr [email-addr ...]

Where options is:

    --cvsroot=<path>
    	Use <path> as the environment variable CVSROOT.  Otherwise this
    	variable must exist in the environment.

    --help / -h
        Print this text.

    --context=#
    -C #
        Include # lines of context around lines that differ (default: 2).

    -c
        Produce a context diff (default).

    -u
        Produce a unified diff (smaller).

    --quiet/-q
        Don't print as much status to stdout.

    <%%S>
        CVS %%s loginfo expansion.  When invoked by CVS, this will be a single
        string containing the directory the checkin is being made in, relative
        to $CVSROOT, followed by the list of files that are changing.  If the
        %%s in the loginfo file is %%{sVv}, context diffs for each of the
        modified files are included in any email messages that are generated.

    email-addrs
        At least one email address.
"""
import os
import sys
import time
import string
import getopt
import smtplib
import pwd
import socket

from cStringIO import StringIO

# Which SMTP server to do we connect to?  Empty string means localhost.
MAILHOST = ''
MAILPORT = 25

# Diff trimming stuff
DIFF_HEAD_LINES = 20
DIFF_TAIL_LINES = 20
DIFF_TRUNCATE_IF_LARGER = 1000

EMPTYSTRING = ''
SPACE = ' '
DOT = '.'
COMMASPACE = ', '

PROGRAM = sys.argv[0]

BINARY_EXPLANATION_LINES = [
    "(This appears to be a binary file; contents omitted.)\n"
    ]


def usage(code, msg=''):
    print __doc__ % globals()
    if msg:
        print msg
    sys.exit(code)



def calculate_diff(filespec, contextlines):
    try:
        file, oldrev, newrev = string.split(filespec, ',')
    except ValueError:
        # No diff to report
        return '***** Bogus filespec: %s' % filespec
    if oldrev == 'NONE':
        try:
            if os.path.exists(file):
                fp = open(file)
            else:
                update_cmd = 'cvs -fn update -r %s -p %s' % (newrev, file)
                fp = os.popen(update_cmd)
            lines = fp.readlines()
            fp.close()
            # Is this a binary file?  Let's look at the first few
            # lines to figure it out:
            for line in lines[:5]:
                for c in string.rstrip(line):
                    if c in string.whitespace:
                        continue
                    if c < ' ' or c > chr(127):
                        lines = BINARY_EXPLANATION_LINES[:]
                        break
            lines.insert(0, '--- NEW FILE: %s ---\n' % file)
        except IOError, e:
            lines = ['***** Error reading new file: ',
                     str(e), '\n***** file: ', file, ' cwd: ', os.getcwd()]
    elif newrev == 'NONE':
        lines = ['--- %s DELETED ---\n' % file]
    else:
        # This /has/ to happen in the background, otherwise we'll run into CVS
        # lock contention.  What a crock.
        if contextlines > 0:
            difftype = "-C " + str(contextlines)
        else:
            difftype = "-u"
        diffcmd = "/usr/bin/cvs -f diff -kk %s --minimal -r %s -r %s '%s'" % (
            difftype, oldrev, newrev, file)
        fp = os.popen(diffcmd)
        lines = fp.readlines()
        sts = fp.close()
        # ignore the error code, it always seems to be 1 :(
##        if sts:
##            return 'Error code %d occurred during diff\n' % (sts >> 8)
    if len(lines) > DIFF_TRUNCATE_IF_LARGER:
        removedlines = len(lines) - DIFF_HEAD_LINES - DIFF_TAIL_LINES
        del lines[DIFF_HEAD_LINES:-DIFF_TAIL_LINES]
        lines.insert(DIFF_HEAD_LINES,
                     '[...%d lines suppressed...]\n' % removedlines)
    return string.join(lines, '')



def getdomain():
    try:
        fqdn = socket.getfqdn()
    except AttributeError:
        # Python 1.5.2 :(
        hostname = socket.gethostname()
        byaddr = socket.gethostbyaddr(socket.gethostbyname(hostname))
        aliases = byaddr[1]
        aliases.insert(0, byaddr[0])
        aliases.insert(0, hostname)
        for fqdn in aliases:
            if '.' in fqdn:
                break
        else:
            fqdn = 'localhost.localdomain'
    parts = string.split(fqdn, DOT)
    return string.join(parts[1:], DOT)



def blast_mail(subject, people, filestodiff, contextlines):
    # cannot wait for child process or that will cause parent to retain cvs
    # lock for too long.  Urg!
    if not os.fork():
        # in the child
        # give up the lock you cvs thang!
        time.sleep(2)
        # Create the smtp connection to the localhost
        conn = smtplib.SMTP()
        conn.connect(MAILHOST, MAILPORT)
        user = pwd.getpwuid(os.getuid())[0]
        domain = getdomain()
        author = '%s@%s' % (user, domain)
        s = StringIO()
        sys.stdout = s
        try:
            print '''\
From: %(author)s
To: %(people)s
Subject: %(subject)s
''' % {'author' : author,
       'people' : string.join(people, COMMASPACE),
       'subject': subject,
       }
            s.write(sys.stdin.read())
            # append the diffs if available
            print
            for file in filestodiff:
                print calculate_diff(file, contextlines)
        finally:
            sys.stdout = sys.__stdout__
        resp = conn.sendmail(author, people, s.getvalue())
        conn.close()
        os._exit(0)



# scan args for options
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'hC:cuq',
                                   ['context=', 'cvsroot=', 'help', 'quiet'])
    except getopt.error, msg:
        usage(1, msg)

    # parse the options
    contextlines = 2
    verbose = 1
    for opt, arg in opts:
        if opt in ('-h', '--help'):
            usage(0)
        elif opt == '--cvsroot':
            os.environ['CVSROOT'] = arg
        elif opt in ('-C', '--context'):
            contextlines = int(arg)
        elif opt == '-c':
            if contextlines <= 0:
                contextlines = 2
        elif opt == '-u':
            contextlines = 0
        elif opt in ('-q', '--quiet'):
            verbose = 0

    # What follows is the specification containing the files that were
    # modified.  The argument actually must be split, with the first component
    # containing the directory the checkin is being made in, relative to
    # $CVSROOT, followed by the list of files that are changing.
    if not args:
        usage(1, 'No CVS module specified')
    subject = args[0]
    specs = string.split(args[0])
    del args[0]

    # The remaining args should be the email addresses
    if not args:
        usage(1, 'No recipients specified')

    # Now do the mail command
    people = args

    if verbose:
        print 'Mailing %s...' % string.join(people, COMMASPACE)

    if specs == ['-', 'Imported', 'sources']:
        return
    if specs[-3:] == ['-', 'New', 'directory']:
        del specs[-3:]
    elif len(specs) > 2:
        L = specs[:2]
        for s in specs[2:]:
            prev = L[-1]
            if string.count(prev, ',') < 2:
                L[-1] = "%s %s" % (prev, s)
            else:
                L.append(s)
        specs = L

    if verbose:
        print 'Generating notification message...'
    blast_mail(subject, people, specs[1:], contextlines)
    if verbose:
        print 'Generating notification message... done.'



if __name__ == '__main__':
    main()
    sys.exit(0)
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






























































































































































































































































































































































































































































































































































































Deleted CVSROOT/taginfo version [364dad5373].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# The "taginfo" file is used to control pre-tag checks.
# The filter on the right is invoked with the following arguments:
#
# $1 -- tagname
# $2 -- operation "add" for tag, "mov" for tag -F, and "del" for tag -d
# $3 -- repository
# $4->  file revision [file revision ...]
#
# A non-zero exit of the filter program will cause the tag to be aborted.
#
# The first entry on a line is a regular expression which is tested
# against the directory that the change is being committed to, relative
# to the $CVSROOT.  For the first match that is found, then the remainder
# of the line is the name of the filter to run.
#
# If the repository name does not match any of the regular expressions in this
# file, the "DEFAULT" line is used, if it is specified.
#
# If the name "ALL" appears as a regular expression it is always used
# in addition to the first matching regex or "DEFAULT".
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<








































Deleted CVSROOT/verifymsg version [cbc796537d].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# The "verifymsg" file is used to allow verification of logging
# information.  It works best when a template (as specified in the
# rcsinfo file) is provided for the logging procedure.  Given a
# template with locations for, a bug-id number, a list of people who
# reviewed the code before it can be checked in, and an external
# process to catalog the differences that were code reviewed, the
# following test can be applied to the code:
#
#   Making sure that the entered bug-id number is correct.
#   Validating that the code that was reviewed is indeed the code being
#       checked in (using the bug-id number or a seperate review
#       number to identify this particular code set.).
#
# If any of the above test failed, then the commit would be aborted.
#
# Actions such as mailing a copy of the report to each reviewer are
# better handled by an entry in the loginfo file.
#
# One thing that should be noted is the the ALL keyword is not
# supported.  There can be only one entry that matches a given
# repository.
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










































Modified mttroot/mtt/bin/mtt from [68d41245b0] to [a4c3c642a3].

13
14
15
16
17
18
19



20
21
22
23
24
25
26
# Copyright (C) 2001 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Header$
## $Log$



## Revision 1.352  2002/05/24 11:04:10  geraint
## Removed unnecessary message about *.log file not existing when -D option is used.
##
## Revision 1.351  2002/05/23 17:08:20  geraint
## `mtt sys sfun zip` now produces an input block and an interface block for MTT models.
## Models can be embedded within larger Simulink models by the 2 ports.
## The user must edit 2 code blocks in <sys>_sfun_interface.c before compiling with mex.







>
>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Copyright (C) 2001 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Header$
## $Log$
## Revision 1.353  2002/05/28 18:08:38  geraint
## Fixed [ 547294 ] CRs are not sought from MTT_CRS.
##
## Revision 1.352  2002/05/24 11:04:10  geraint
## Removed unnecessary message about *.log file not existing when -D option is used.
##
## Revision 1.351  2002/05/23 17:08:20  geraint
## `mtt sys sfun zip` now produces an input block and an interface block for MTT models.
## Models can be embedded within larger Simulink models by the 2 ports.
## The user must edit 2 code blocks in <sys>_sfun_interface.c before compiling with mex.
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713

${sys}_rdae.r: ${sys}_ese.r ${sys}_def.r $1_modpar.r ${Subsystem}_cr.r ${Subsystem}_subs.r
ifneq ($partition,)
	echo Doing subsystems
	mtt_make_subsystems  ${sys} rdae r
endif
	mtt_prepend.sh -p $1_modpar.r $1_ese.r # Add modulated parameters to start
	ese2rdae_r ${cr_first} ${Subsystem}; tidy ${Subsystem}_rdae.r

${sys}_dae.r: ${Subsystem}_rdae.r ${Subsystem}_def.r ${Subsystem}_subs.r ${Subsystem}_cr.r
ifneq ($partition,)
	echo Doing subsystems
	mtt_make_subsystems  ${sys} dae r
endif
ifeq ($rdae_is_dae,1)







|







2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716

${sys}_rdae.r: ${sys}_ese.r ${sys}_def.r $1_modpar.r ${Subsystem}_cr.r ${Subsystem}_subs.r
ifneq ($partition,)
	echo Doing subsystems
	mtt_make_subsystems  ${sys} rdae r
endif
	mtt_prepend.sh -p $1_modpar.r $1_ese.r # Add modulated parameters to start
	ese2rdae_r ${cr_first} ${fixcc} ${Subsystem}; tidy ${Subsystem}_rdae.r

${sys}_dae.r: ${Subsystem}_rdae.r ${Subsystem}_def.r ${Subsystem}_subs.r ${Subsystem}_cr.r
ifneq ($partition,)
	echo Doing subsystems
	mtt_make_subsystems  ${sys} dae r
endif
ifeq ($rdae_is_dae,1)

Modified mttroot/mtt/bin/trans/dae2cse_r from [e055f9ba28] to [4bd66676aa].

11
12
13
14
15
16
17




18
19
20
21
22
23
24
# Copyright (c) P.J.Gawthrop 1991, 1992, 1994.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$




## Revision 1.19  2001/10/26 01:01:49  geraint
## fixcc when rdae_is_dae (-cr).
##
## Revision 1.18  2001/10/05 23:37:32  geraint
## Fixed assignment statement in ae.r when RHS=0.
##
## Revision 1.17  2001/07/27 23:29:10  geraint







>
>
>
>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Copyright (c) P.J.Gawthrop 1991, 1992, 1994.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.20  2002/04/28 18:41:26  geraint
## Fixed [ 549658 ] awk should be gawk.
## Replaced calls to awk with call to gawk.
##
## Revision 1.19  2001/10/26 01:01:49  geraint
## fixcc when rdae_is_dae (-cr).
##
## Revision 1.18  2001/10/05 23:37:32  geraint
## Fixed assignment statement in ae.r when RHS=0.
##
## Revision 1.17  2001/07/27 23:29:10  geraint
125
126
127
128
129
130
131

132
133
134
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
        *)
                echo "$1 is an invalid argument - ignoring" ;;
  esac
  shift
done

# Create the reduce output code

def2write_r $optimise $1 cse 
def2write_r $optimise $1 csex # Version without E matrix
def2write_r $optimise $1 cseo


echo "Creating $1_cse.r $solve_msg $optimise_msg $fix_msg"
echo "Creating $1_csex.r $optimise_msg"
echo "Creating $1_cseo.r $optimise_msg"

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

# Remove some files
rm -f $1_cse.r? $1_cseo.r?

# Use reduce to accomplish the transformation
$SYMBOLIC >dae2cse_r.log << EOF

%Read the formatting function
in "$MTTPATH/trans/reduce_matrix.r";








>




>








|







129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
        *)
                echo "$1 is an invalid argument - ignoring" ;;
  esac
  shift
done

# Create the reduce output code
def2write_r $optimise $1 ae
def2write_r $optimise $1 cse 
def2write_r $optimise $1 csex # Version without E matrix
def2write_r $optimise $1 cseo

echo "Creating $1_ae.r $optimise_msg"
echo "Creating $1_cse.r $solve_msg $optimise_msg $fix_msg"
echo "Creating $1_csex.r $optimise_msg"
echo "Creating $1_cseo.r $optimise_msg"

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

# Remove some files
rm -f $1_ae.r? $1_cse.r? $1_cseo.r?

# Use reduce to accomplish the transformation
$SYMBOLIC >dae2cse_r.log << EOF

%Read the formatting function
in "$MTTPATH/trans/reduce_matrix.r";

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349












350
351
352
353
354
355
356
    set(lhs(MTT_sol_i),rhs(MTT_sol_i));
  END;

  % No algebraic variables left!
  MTTNYz := 0;
END; % IF MTTNyz>0 and $solve

OUT "$1_ae.r";
IF (MTTNyz>0) THEN % not $solve (or perhaps solution failed?)
BEGIN
    WRITE "MATRIX MTTyz(",MTTNyz,",1)";
    WRITE "%File: $1_ae.r";
    FOR i := 1:MTTNyz DO
	WRITE "MTTyz(",i,",1) := ",MTTyz(i,1)," +0";
END; % if MTTNyz>0 (and !$solve)
WRITE ";END;";
SHUT "$1_ae.r";

OUT "$1_aej.r";
IF (MTTNyz>0) THEN % as above
BEGIN
    WRITE "MATRIX MTTyzj(",MTTNyz,",",MTTNyz,")";
    WRITE "%File: $1_aej.r";
    FOR i := 1:MTTNyz DO
	FOR j := 1:MTTNyz DO
	BEGIN
	   didj := df(MTTyz(i,1),mkid('mttui,j));
	   IF (didj NEQ 0) THEN
	      WRITE "MTTyzj(",i,",",j,") := ",didj," +0";
	END;
END;
WRITE ";END;";
SHUT "$1_aej.r";













% Create the matrix declarations
OUT "$1_cse.r1";
write "%";
IF (MTTNx > 0) THEN
BEGIN
    write "MATRIX MTTEdx(", MTTNx, ",", 1, ")$"; 







<
<
<
<
<
<
<
<
<
<
<















>
>
>
>
>
>
>
>
>
>
>
>







323
324
325
326
327
328
329











330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
    set(lhs(MTT_sol_i),rhs(MTT_sol_i));
  END;

  % No algebraic variables left!
  MTTNYz := 0;
END; % IF MTTNyz>0 and $solve












OUT "$1_aej.r";
IF (MTTNyz>0) THEN % as above
BEGIN
    WRITE "MATRIX MTTyzj(",MTTNyz,",",MTTNyz,")";
    WRITE "%File: $1_aej.r";
    FOR i := 1:MTTNyz DO
	FOR j := 1:MTTNyz DO
	BEGIN
	   didj := df(MTTyz(i,1),mkid('mttui,j));
	   IF (didj NEQ 0) THEN
	      WRITE "MTTyzj(",i,",",j,") := ",didj," +0";
	END;
END;
WRITE ";END;";
SHUT "$1_aej.r";

IF MTTNyz>0 THEN % not $solve or solution failed
BEGIN
OUT "$1_ae.r1";
write "MATRIX MTTYZ(", MTTNyz, ",", 1, ")$";
SHUT "$1_ae.r1";
OUT "$1_ae.r2";
write "%File: $1_ae.r";
in ("$1_ae_write.r");
write "END;";
SHUT "$1_ae.r2";
END;

% Create the matrix declarations
OUT "$1_cse.r1";
write "%";
IF (MTTNx > 0) THEN
BEGIN
    write "MATRIX MTTEdx(", MTTNx, ",", 1, ")$"; 
443
444
445
446
447
448
449

450
451

452
453
454
455
456
457
458
in ("$1_cseo_write.r");
write "END;";
SHUT "$1_cseo.r2";
END;
quit;
EOF


touch $1_cseo.r1
touch $1_cseo.r2

cat $1_cse.r1 $1_cse.r2  > $1_cse.r
cat $1_csex.r1 $1_csex.r2  > $1_csex.r
cat $1_cseo.r1 $1_cseo.r2  > $1_cseo.r

if [ "$solve" = "1" ]; then
    echo "Setting MTTNyz=0 in $1_def.r and updating other $1_def files"
    gawk '{







>


>







450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
in ("$1_cseo_write.r");
write "END;";
SHUT "$1_cseo.r2";
END;
quit;
EOF

touch $1_ae.r1 $1_ae.r2
touch $1_cseo.r1
touch $1_cseo.r2
cat $1_ae.r1 $1_ae.r2 > $1_ae.r
cat $1_cse.r1 $1_cse.r2  > $1_cse.r
cat $1_csex.r1 $1_csex.r2  > $1_csex.r
cat $1_cseo.r1 $1_cseo.r2  > $1_cseo.r

if [ "$solve" = "1" ]; then
    echo "Setting MTTNyz=0 in $1_def.r and updating other $1_def files"
    gawk '{

Modified mttroot/mtt/bin/trans/def2write_r from [10c4312f8d] to [83e084d8bc].

9
10
11
12
13
14
15



16
17
18
19
20
21
22
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$



## Revision 1.10  2002/04/28 18:41:27  geraint
## Fixed [ 549658 ] awk should be gawk.
## Replaced calls to awk with call to gawk.
##
## Revision 1.9  2001/07/27 23:29:10  geraint
## Optimises only when requested (-opt).
##







>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.11  2002/05/17 09:14:58  geraint
## Optimises each line in a separate session. Allows larger models to be built.
##
## Revision 1.10  2002/04/28 18:41:27  geraint
## Fixed [ 549658 ] awk should be gawk.
## Replaced calls to awk with call to gawk.
##
## Revision 1.9  2001/07/27 23:29:10  geraint
## Optimises only when requested (-opt).
##
77
78
79
80
81
82
83





84
85
86
87
88
89
90
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'







>
>
>
>
>







80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
ae)
matrices='Yz'
ns="$Nyz"
ms="1"
;;
    cse)
        matrices='EdX E'
        ns="$Nx $Nx"
        ms="1 $Nx"
	;;
    csex)
        matrices='EdX'

Modified mttroot/mtt/bin/trans/ese2rdae_r from [713fa3d927] to [2f139cc4dc].

10
11
12
13
14
15
16













17
18
19
20
21
22
23
# Copyright (c) P.J.Gawthrop, 1991, 1994, 1996

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$













## Revision 1.11  2001/07/06 00:46:50  gawthrop
## Added -cr option -- forces cr to be loaded before the ese.r file
## This avoids causality problems when using multi-port Rs to represent
## arbitary equations
##
## Revision 1.10  2000/11/30 15:23:16  peterg
## Taken out all subsystem stuff - now done in mtt using







>
>
>
>
>
>
>
>
>
>
>
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Copyright (c) P.J.Gawthrop, 1991, 1994, 1996

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.12.2.1  2002/06/05 11:14:51  geraint
## ae.r now generated using def2write_r like cse?.r
## fix_c.r called at ese2rdae stage so that pow gets fixed in ae.r.
##
## These changes produce the desired result (optimised algebraic equations) but
## have highlighted a problem; when optimisation fails, Reduce does not write
## a result. For complicated systems, this can lead to missing assignments in
## the resultant code.
##
## Revision 1.12  2001/07/23 23:31:17  gawthrop
## Added -cr option to load CRs first - avoids alg. loops with R
## implementation of mutiports.
##
## Revision 1.11  2001/07/06 00:46:50  gawthrop
## Added -cr option -- forces cr to be loaded before the ese.r file
## This avoids causality problems when using multi-port Rs to represent
## arbitary equations
##
## Revision 1.10  2000/11/30 15:23:16  peterg
## Taken out all subsystem stuff - now done in mtt using
96
97
98
99
100
101
102




103
104
105
106
107
108
109
  case $1 in
	-I )
                info=info;;
	-cr )
                load_cr=yes;
                blurb2=' using cr and subs first';
                ;;




	-partition )
                partition=yes;
                blurb='with partitioning';
		;;
	*)
		echo "$1 is an invalid argument - ignoring";
                exit ;;







>
>
>
>







109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  case $1 in
	-I )
                info=info;;
	-cr )
                load_cr=yes;
                blurb2=' using cr and subs first';
                ;;
      -fixcc )
		include=`echo 'in "'$MTT_LIB'/reduce/fix_c.r";'`
		blurb3='fixing c and cc code';
		;;
	-partition )
                partition=yes;
                blurb='with partitioning';
		;;
	*)
		echo "$1 is an invalid argument - ignoring";
                exit ;;
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158



159
160
161
162
163
164
165

if [ -n "${load_cr}" ]; then
    load_cr_comm="in \"${crname}\";"
    load_subs_comm="in \"${subsname}\";"
fi

# Inform user
echo Creating $daename $blurb $blurb2

# Remove the old log file
rm -f $logname

# Use symbolic algebra to accomplish the transformation
$SYMBOLIC >$logname  << EOF

%Read in the cr and sub when  -cr is set
$load_cr_comm
$load_subs_comm

%Read the formatting function
in "$MTTPATH/trans/reduce_matrix.r";

% Definitions
in "$defname";

% Elementary system equations
in "$esename";




OFF Echo;
OFF Nat;

%Create the output file
OUT "$daename";








|



















>
>
>







149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

if [ -n "${load_cr}" ]; then
    load_cr_comm="in \"${crname}\";"
    load_subs_comm="in \"${subsname}\";"
fi

# Inform user
echo Creating $daename $blurb $blurb2 $blurb3

# Remove the old log file
rm -f $logname

# Use symbolic algebra to accomplish the transformation
$SYMBOLIC >$logname  << EOF

%Read in the cr and sub when  -cr is set
$load_cr_comm
$load_subs_comm

%Read the formatting function
in "$MTTPATH/trans/reduce_matrix.r";

% Definitions
in "$defname";

% Elementary system equations
in "$esename";

% Fix c code if required
$include

OFF Echo;
OFF Nat;

%Create the output file
OUT "$daename";

Modified mttroot/mtt/bin/trans/m/args2arg.m from [88e206959b] to [b6ee5ada28].

24
25
26
27
28
29
30






















31
% %%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Field separator
if nargin<3
  FS = ';';
end;






























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
% %%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Field separator
if nargin<3
  FS = ';';
end;

arg = '';
if strcmp(args, '')==0
  L = length(args);
  args_count = 0;
  for i=1:n
    arg_count = 0;
    arg = '';
    if args_count == L
      break;
    end;  
    while args_count < L
      args_count = args_count+1;
      arg_count = arg_count+1;
      ch = str2ch(args,args_count);
      if ch==FS
	break;
      end;
      arg = [arg ch];
    end;
  end;
end;

Deleted mttroot/mtt/doc/mtt.texi version [95bf219a63].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
\input texinfo  
@c %**start of header
@setfilename mtt.info
@settitle MTT: Model Transformation Tools
@c %**end of header

@finalout

@c Here is what I use in the Info `dir' file:
@c * Mtt: (mtt).                Model transformation tools.



@comment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@comment  Version control history
@comment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@comment  $Id$
@comment  $Log$
@comment  Revision 1.6  2001/10/15 14:29:50  gawthrop
@comment  Added documentaton on  [1:N] style port labels
@comment
@comment  Revision 1.5  2001/07/23 03:35:29  geraint
@comment  Updated file structure (mtt/bin).
@comment
@comment  Revision 1.4  2001/07/23 03:25:02  geraint
@comment  Added notes on -ae hybrd, rk4, ode2odes.cc, .oct dependencies.
@comment
@comment  Revision 1.3  2001/07/13 03:02:38  geraint
@comment  Added notes on #ICD, gnuplot.txt and odes.sg rep.
@comment
@comment  Revision 1.2  2001/07/03 22:59:10  gawthrop
@comment  Fixed problems with argument passing for CRs
@comment
@comment  Revision 1.1  2001/06/04 08:18:52  gawthrop
@comment  Putting documentation under CVS
@comment
@comment  Revision 1.66  2000/12/05 14:20:55  peterg
@comment  Added the c++  anf m CR info.
@comment
@comment  Revision 1.65  2000/11/27 15:36:15  peterg
@comment  NOPAR --> NOTPAR
@comment
@comment  Revision 1.64  2000/11/16 14:22:48  peterg
@comment  added UNITS declaration
@comment
@comment  Revision 1.63  2000/11/03 14:41:08  peterg
@comment  Added PAR and NOPAR stuff
@comment
@comment  Revision 1.62  2000/10/17 17:53:34  peterg
@comment  Added some simulation details
@comment
@comment  Revision 1.61  2000/09/14 17:13:06  peterg
@comment  New options table
@comment
@comment  Revision 1.60  2000/09/14 17:09:20  peterg
@comment  Tidied up valid name sections
@comment  Tidied up defining represnetations table
@comment  Verion 4.6
@comment
@comment  Revision 1.59  2000/08/30 13:09:00  peterg
@comment  Updated option table
@comment
@comment  Revision 1.58  2000/08/01 13:30:19  peterg
@comment  Version 4.4
@comment  updated STEPFACTOR info
@comment  describes octave and OCST interfaces
@comment
@comment  Revision 1.57  2000/07/20 07:55:44  peterg
@comment  Version 4.3
@comment
@comment  Revision 1.56  2000/05/19 17:49:17  peterg
@comment  Extended the user defined representation section -- new nppp rep.
@comment
@comment  Revision 1.55  2000/03/16 13:53:31  peterg
@comment  Correct date
@comment
@comment  Revision 1.54  2000/03/15 21:22:57  peterg
@comment  Updated to 4.1 -- old style SS no longer supported
@comment
@comment  Revision 1.53  1999/12/22 05:33:10  peterg
@comment  Updated for 4.0
@comment
@comment  Revision 1.52  1999/11/23 00:25:11  peterg
@comment  Added the sensitivity reps
@comment
@comment  Revision 1.51  1999/11/16 04:43:47  peterg
@comment  Added start of sensitivity section
@comment
@comment  Revision 1.50  1999/11/16 00:30:35  peterg
@comment  Updated simulation section
@comment  Added vector components
@comment
@comment  Revision 1.49  1999/07/20 23:44:58  peterg
@comment  V 3.8
@comment
@comment  Revision 1.48  1999/07/19 03:08:33  peterg
@comment  Added documentation for (new) SS lbl fields
@comment
@comment  Revision 1.47  1999/03/09 01:42:22  peterg
@comment  Rearranged the User interface section
@comment
@comment  Revision 1.46  1999/03/09 01:18:01  peterg
@comment  Updated for 3.5 including xmtt
@comment
@comment  Revision 1.45  1999/03/03 02:39:26  peterg
@comment  Minor updates
@comment
@comment  Revision 1.44  1999/02/17 06:52:14  peterg
@comment  New level formula dor artwork
@comment
@comment  Revision 1.43  1998/11/25 16:49:24  peterg
@comment  Put in subs.r documentation (was called params.r)
@comment
@comment  Revision 1.42  1998/11/24 12:24:59  peterg
@comment  Added section on simulation output
@comment  Version 3.4
@comment
@comment  Revision 1.41  1998/09/02 12:04:15  peterg
@comment  Version 3.2
@comment
@comment  Revision 1.40  1998/08/27 08:36:39  peterg
@comment  Removed in. methods except Euler anf implicit
@comment
@comment  Revision 1.39  1998/08/18 10:44:28  peterg
@comment  Typo
@comment
@comment  Revision 1.38  1998/08/18 09:16:38  peterg
@comment  Version 3.1
@comment
@comment  Revision 1.37  1998/08/17 16:14:30  peterg
@comment  Version 3.1 - includes documentation on METHOD=IMPLICIT
@comment
@comment  Revision 1.36  1998/07/30 17:33:15  peterg
@comment  VERSION 3.0
@comment
@comment  Revision 1.35  1998/07/22 11:00:53  peterg
@comment  Correct date!
@comment
@comment  Revision 1.34  1998/07/22 11:00:13  peterg
@comment  Version to BAe
@comment
@comment  Revision 1.33  1998/07/17 19:32:19  peterg
@comment  Added more about aliases
@comment
@comment  Revision 1.32  1998/07/05 14:21:56  peterg
@comment  Further additions (Carlisle-Glasgow)
@comment
@comment  Revision 1.31  1998/07/04 11:35:57  peterg
@comment  Strarted new lbl description
@comment
@comment  Revision 1.30  1998/07/02 18:39:20  peterg
@comment  Started 3.0
@comment  Added alias and default sections.
@comment
@comment  Revision 1.29  1998/05/19 19:46:58  peterg
@comment  Added the odess description
@comment
@comment  Revision 1.28  1998/05/14 09:17:22  peterg
@comment  Added METHOD variable to the simpar file
@comment
@comment  Revision 1.27  1998/05/13 10:03:09  peterg
@comment  Added unknown/zero SS label documentation.
@comment
@comment  Revision 1.26  1998/04/29 15:12:46  peterg
@comment  Version 2.9.
@comment
@comment  Revision 1.25  1998/04/12 17:00:26  peterg
@comment  Added new port features: coerced direction and top-level behaviour.
@comment
@comment  Revision 1.24  1998/04/05 18:27:20  peterg
@comment  This was the 2.6 version
@comment
@comment Revision 1.23  1997/08/24  11:17:51  peterg
@comment This is the released  version 2.5
@comment
@comment  Revision 1.22  1997/08/23 19:38:53  peterg
@comment  Added simulation chapter.
@comment
@comment  Revision 1.21  1997/08/23 16:50:10  peterg
@comment  Added desc section.
@comment  Included named and vector ports
@comment  Completed list of representations.
@comment
@comment Revision 1.20  1997/06/16  15:39:24  peterg
@comment THis is the released 2.4 document.
@comment
@comment Revision 1.19  1997/06/16  09:48:23  peterg
@comment Back under revision control (elm)
@comment
@comment  Revision 1.18  1997/06/14 20:27:41  peterg
@comment  Added complex example section.
@comment
@comment  Revision 1.18  1997/06/13  14:51:07  peterg
@comment  Added report section
@comment 
@comment  Revision 1.17  1997/05/09 15:06:02  peterg
@comment  Changed to version 2.4.
@comment
@comment  Revision 1.16  1996/12/05 10:06:25  peterg
@comment  Modified .octaverc : 'true' --> 1
@comment
@comment  Revision 1.15  1996/11/20 19:02:28  peterg
@comment  Added some system admin stuff.
@comment  Added section on simple models.
@comment
@comment Revision 1.14  1996/11/12  13:19:04  peterg
@comment Put paths as section, not subsection.
@comment
@comment Revision 1.13  1996/11/11  16:53:14  peterg
@comment Added params documentation
@comment Sorted out table bug.
@comment
@comment  Revision 1.12  1996/11/10 20:29:31  peterg
@comment  Added section on help -- needs more
@comment
@comment  Revision 1.11  1996/11/09 21:15:28  peterg
@comment  Rewrite of quick start.
@comment  Update of file structure.
@comment
@comment  Revision 1.10  1996/11/09 20:25:54  peterg
@comment  Final v2.0.
@comment
@comment  Revision 1.9  1996/10/01 10:33:02  peter
@comment  Cleaned up cross references.
@comment
@comment  Revision 1.8  1996/10/01 09:31:00  peter
@comment  Added sections written in Hong Kong.
@comment
@comment  Revision 1.7  1996/09/16 09:49:47  peter
@comment  Added ese section
@comment
@comment  Revision 1.6  1996/09/16 08:33:53  peter
@comment  Added constitutive relationship section etc.
@comment
@comment  Revision 1.5  1996/09/15 20:20:56  peter
@comment  Added abg and rbg stuff
@comment
@comment  Revision 1.4  1996/08/30 19:07:40  peter
@comment  Added some admin stuff.
@comment
@comment  Revision 1.3  1996/08/30 07:50:16  peter
@comment  Added file structure section.
@comment
@comment  Revision 1.2  1996/08/22 14:28:50  peter
@comment  Added stuff about labels.
@comment
@comment  Revision 1.1  1996/08/22 11:52:59  peter
@comment  Initial revision
@comment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


@ifinfo
This file documents MTT a set of Model Transformation Tools.


Copyright (C) Peter J. Gawthrop 1996, 1997, 1998, 1999

Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.

@ignore
Permission is granted to process this file through TeX and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
@end ignore

Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
section entitled ``GNU General Public License'' is included exactly as
in the original, and provided that the entire resulting derived work is
distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that the section entitled ``GNU General Public License'' may be
included in a translation approved by the author instead of in the
original English.
@end ifinfo


@titlepage
@title MTT: Model Transformation Tools
@subtitle December 2000
@subtitle For version 4.9.
@author Peter Gawthrop
@page
@vskip 0pt plus 1filll
Copyright @copyright{} 1996,1997,1998,1999,2000 Peter J. Gawthrop

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that the
section entitled ``GNU General Public License'' is included exactly in
the original, and provided that the entire resulting derived work is
distributed under the terms of a permission notice identical to this
one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that the section entitled ``GNU General Public License'' may be
included in a translation approved by the author instead of in the
original English.

General information  about MTT is available at URL
@example
http://mtt.sourceforge.net
@end example
@ifhtml
<A
HREF="http://mtt.sourceforge.net"> here</A>.
@end ifhtml

@end titlepage


@ifinfo
@node Top, Introduction, (dir), (dir)
@top MTT
@strong{MTT} is a set of Model Transformation Tools based on bond graphs.
@strong{MTT} implements the theory to be found in the book ``Metamodelling: Bond
Graphs and Dynamic Systems'' by Peter Gawthrop and Lorcan Smith
published by Prentice Hall in 1996 (ISBN 0-13-489824-9).

It implements two features not discussed in that book:
@itemize @bullet
@item 
bicausal bond graphs and
@item
hierarchical bond graphs.
@end itemize



@contents

@end ifinfo


@c @include intro.texi
@c Copyright (C) 1996 Peter J. Gawthrop
@c This is part of the MTT manual.
@c For copying conditions, see the file MTT.texi.

@menu
* Introduction::                
* User interface::              
* Creating Models::             
* Simulation::                  
* Sensitivity models::          
* Representations::             
* Extending MTT::               
* Languages::                   
* Language tools::              
* Administration::              
* Glossary::                    
* Index::                       

@detailmenu
 --- The Detailed Node Listing ---

Introduction

* What is a Representation?::   
* What is a Transformation?::   
* Bond graphs::                 What is a bond graph?                
* Variables::                   
* Bonds::                       
* Components::                  
* Algebraic loops::             
* Switched systems::            

Components

* Ports::                       
* Constitutive relationship::   
* Symbolic parameters::         
* Numeric parameters::          

User interface

* Menu-driven interface::       
* Command line interface::      
* Options::                     
* Utilities::                   

Utilities

* Help::                        
* Copy::                        
* Clean::                       
* Version control::             

Help

* help representations::        
* help components::             
* help examples::               
* help crs::                    
* help <name>::                 

Creating Models

* Quick start::                 
* Creating simple models::      
* Creating complex models::     

Creating complex models

* Top level::                   

Simulation

* Steady-state solutions::      
* Simulation parameters::       
* Simulation input::            
* Simulation logic::            
* Simulation initial state::    
* Simulation code::             
* Simulation output::           

Steady-state solutions 

* Steady-state solutions - numerical(odess)::  
* Steady-state solutions - symbolic (ss)::  

Simulation parameters

* Euler integration::           
* Implicit integration::        
* Runge Kutta IV integration::  
* Hybrd algebraic solver::      

Simulation output

* Viewing results with gnuplot::  
* Exporting results to SciGraphica::  

Representations

* Representation summary::      
* Defining representations::    
* Verbal description (desc)::   
* Acausal bond graph (abg)::    
* Stripped acausal bond graph (sabg)::  
* Labels (lbl)::                
* Description (desc)::          
* Structure (struc)::           
* Constitutive Relationship (cr)::  
* Parameters::                  
* Causal bond graph (cbg)::     
* Elementary system equations::  
* Differential-Algebraic Equations::  
* Constrained-state Equations::  
* Ordinary Differential Equations::  
* Descriptor matrices::         
* Report::                      

Acausal bond graph (abg)

* Language fig (abg.fig)::      
* Language m (rbg.m)::          
* Language m (abg.m)::          
* Language tex (abg.tex)::      

Language fig (abg.fig) 

* icon library::                
* bonds::                       
* strokes::                     
* components::                  
* Simple components::           
* SS components::               
* Simple components - implementation::  
* Compound components::         
* Named SS components::         
* Coerced bond direction::      
* Port labels::                 
* Vector port labels::          
* Port label defaults::         
* Vector components::           
* artwork::                     
* Valid names::                 

Simple components

* SS components::               
* Simple components - implementation::  

Compound components

* Named SS components::      

Language m (rbg.m)

* Transformation abg2rbg_fig2m::  

Language m (abg.m)

* Arrow-orientated causality::  
* Component-orientated causality::  
* Transformation rbg2abg_m::    

Stripped acausal bond graph (sabg)

* Language fig (sabg.fig)::     
* Stripped acausal bond graph (view)::  

Labels (lbl)

* SS component labels ::        
* Other component labels ::     
* Component names::             
* Component constitutive relationship::  
* Component arguments::         
* Parameter declarations::      
* Units declarations::          
* Interface Control Definition::  
* Aliases::                     
* Parameter passing::           
* Old-style labels (lbl)::      

Other component labels 

* Component names::             
* Component constitutive relationship::  
* Component arguments::         
* Aliases::                     
* Parameter passing::           
* Old-style labels (lbl)::      

Aliases

* Port aliases::                
* Parameter aliases::           
* CR aliases::                  
* Component aliases::           

Old-style labels (lbl)

* SS component labels (old-style)::  
* Other component labels (old-style)::  
* Parameter passing (old-style)::  

Description (desc)

* Language tex (desc.tex)::     

Structure (struc)

* Language txt (struc.txt)::    
* Language tex (struc.tex)::    
* Structure (view)::            

Constitutive relationship (cr)

* Predefined constitutive relationships::  
* DIY constitutive relationships::  
* Unresolved constitutive relationships::  
* Unresolved constitutive relationships - Octave::  
* Unresolved constitutive relationships - c++::  

Predefined constitutive relationships

* lin::                         
* exotherm::                    

Parameters

* Symbolic parameters (subs.r)::  
* Symbolic parameters for simplification (simp.r)::  
* Numeric parameters (numpar)::  

Numeric parameters (numpar)

* Text form (numpar.txt)::      

Causal bond graph (cbg)

* Language fig (cbg.fig)::      
* Language m (cbg.m)::          

Language m (cbg.m)

* Transformation abg2cbg_m::    

Elementary system equations (ese)

* Transformation cbg2ese_m2r::  

Differential-Algebraic Equations (dae)

* Differential-Algebraic Equations (reduce)::  
* Differential-Algebraic Equations (m)::  

Language reduce (dae.r)

* Transformation ese2dae_r::    

Language m (dae.m)

* Transformation dae_r2m::      

Constrained-state Equations (cse)

* Constrained-state Equations (reduce)::  
* Constrained-state Equations (view)::  

Language reduce (cse.r)

* Transformation dae2cse_r::    

Ordinary Differential Equations

* Ordinary Differential Equations (reduce)::  
* Ordinary Differential Equations (m)::  
* Ordinary Differential Equations (view)::  

Language reduce (ode.r)

* Transformation cse2ode_r::    

Language m (ode.m)

* Transformation ode_r2m::      

Descriptor matrices (dm)

* Descriptor matrices (reduce)::  
* Descriptor matrices (m)::     

Report (rep)

* Report (text)::               
* Report (view)::               

Extending MTT

* Makefiles::                   
* New representations::         
* Component library ::          

Languages

* Fig::                         r
* m::                           
* Reduce::                      
* c::                           

Language tools

* Views::                       
* Xfig::                        
* Text editors::                
* Octave::                      
* LaTeX::                       

Octave

* Octave control system toolbox (OCST)::  

Administration

* Software components::         
* REDUCE setup::                
* Octave setup::                
* Paths::                       
* File structure::              

Octave setup

* .octaverc::                   
* .oct file dependencies::      

Paths

* $MTTPATH::                    
* $MTT_COMPONENTS::             
* $MTT_CRS::                    
* $MTT_EXAMPLES::               
* $OCTAVE_PATH::                

@end detailmenu
@end menu

@node Introduction, User interface, Top, Top
@chapter Introduction

@cindex MTT, purpose of

@pindex MTT

@strong{MTT} is a set of Model Transformation Tools based on bond
graphs.  @strong{MTT} implements the theory to be found in the book
``Metamodelling: Bond Graphs and Dynamic Systems'' by Peter Gawthrop and
Lorcan Smith published by Prentice Hall in 1996 (ISBN 0-13-489824-9).

It implements two features not discussed in that book:
@itemize @bullet
@item 
bicausal bond graphs and
@item
hierarchical bond graphs.
@end itemize

In the context of software, it has been said that one good tool is worth many
packages. UNIX is a good example of this philosophy: the user can put together
applications from a range of ready made tools.
This manual describes the application of this philosophy to dynamic
system modeling embodied in @strong{MTT} - a set of Model Transformation Tools
each of which implements a single transformation between system
representations.


System representations have two attributes. 
@itemize @bullet
@item
 A Form: e.g. acausal bond graph, differential algebraic, linear
                state-space etc.
@item
A Language: e.g. Fig, Matlab, LaTeX, Reduce, postscript etc.
@end itemize

Transformations in @strong{MTT} are accomplished using appropriate software (e.g.
Octave/Matlab, Reduce) encapsulated in UNIX Bourne shell scripts. The
relationships between the tools are encoded in a Make File; thus the
user can specify a final representation and all the necessary
intermediate transformations are automatically generated.

@menu
* What is a Representation?::   
* What is a Transformation?::   
* Bond graphs::                 What is a bond graph?                
* Variables::                   
* Bonds::                       
* Components::                  
* Algebraic loops::             
* Switched systems::            
@end menu


@node What is a Representation?, What is a Transformation?, Introduction, Introduction
@section What is a representation?

@cindex Representations, what are they?

@pindex Representations

Physical systems have many representations. These include
@itemize @bullet
@item
a schematic diagram,
@item
a block diagram,
@item
a bunch of equations,
@item
a single differential(-algebraic) equation,
@item
simulation code,
@item
linearised state-space (or descriptor) equations,
@item
transfer function (of the linearised system),
@item
frequency response  (of the linearised system),
@item
etc...
@end itemize

Each of these representations is related to other representations by an
appropriate transformation (@pxref{What is a Transformation?}. In many cases, a
modeler is presented with a physical system and needs to make a
model. In particular, a model, in this context, is a representation of
the system appropriate to a particular use, for example:
@itemize @bullet
@item
simulation,
@item
control system design,
@item
optimisation
@item
etc.
@end itemize

Indeed, for a given physical system, the modeler would need to derive
a number of models. This process can be viewed as a series of steps;
each involving a transformation between representations (@pxref{What is a Transformation?}.


In this context, the following considerations are relevant.
@itemize @bullet
@item
There is a unique `core' representation of any system.
There are many routes  from this core representation, each leading to
an appropriate model.
There are many possible routes  to this core representation
from the physical system: the route chosen is a matter of convenience.
@item
Because the core representation is unique, it is easy to expand the
tool-box to include additional transformations from the physical system
to the core representation and additional transformations from the core
representation to the mode.
@item
Transformation_1 probably cannot, and certainly should not, be
completely automated.  Engineering insight, knowledge and experience is
essential to capture the essence (with respect to the particular use) of
the physical system whilst discarding irrelevant form.
@item
Representation_1 should be `close' in some sense to the Physical system.
@item
The core representation, and hence the representations leading to it,
must contain enough information to generate all of the required models.
@item
Representations must be easily extensible: it must be possible to add
extra components or attributes without restructuring the representation.
@end itemize

I happen to believe that Bond graphs (@pxref{Bond graphs}) provide the
most convenient and powerful basis for the core representation.

@node What is a Transformation?, Bond graphs, What is a Representation?, Introduction
@comment  node-name,  next,  previous,  up
@section What is a transformation?
@cindex Transformations


Each system representation  (@pxref{What is a Representation?} is related to other representations by an
appropriate transformation as follows:
@itemize @bullet 
@item
 Physical system
@item
 Transformation_1 ---> Representation_1
@item
 Transformation_2 ---> Representation_2
@item
 ...
@item
 Transformation_N ---> Core representation
@item
 Transformation_N+1 ---> Representation_N+1
@item
 Transformation_N+2 ---> Representation_N+2
@item
 ...
@item
 Transformation_N+M ---> Model
@end itemize
Thus modeling is seen as a sequence of transformations between
representations.



@node Bond graphs, Variables, What is a Transformation?, Introduction
@section What is a bond graph?

@cindex Bond graphs, what are they?

@pindex Bond graphs

Bond graphs provide a graphical high-level language for describing
dynamic systems in a precise and unambiguous fashion. 
They make a clear distinction between structure (how components are
connected together), and behavior (the particular constitutive
relationships, or physical laws, describing each component.

They can describe a range of physical systems including:
@itemize @bullet
@item
Electrical systems
@item
Mechanical systems
@item
Hydraulic systems
@item
Chemical process systems
@end itemize

More importantly, they can describe systems which contain subsystems
drawn from all of these domains in a uniform manner.

Bond graphs are made up of components (@pxref{Components}) connected by
bonds (@pxref{Bonds}) which define the relationship between
variables (@pxref{Variables}).

@node Variables, Bonds, Bond graphs, Introduction
@comment  node-name,  next,  previous,  up
@section Variables
@cindex Variables
In bond graph terminology there are four sorts of variables:
@itemize @bullet
@item  @emph{effort} variables
@item  @emph{flow} variables
@item  @emph{integrated effort} variables
@item  @emph{integrated flow} variables
@end itemize

Examples of  @emph{effort} variables are
@itemize @bullet
@item 
voltage
@item 
pressure
@item
force
@item
torque
@item
temperature
@end itemize

Examples of  @emph{flow} variables are
@itemize @bullet
@item 
current
@item 
volumetric flow rate
@item
velocity
@item
angular velocity
@item
heat flow
@end itemize



Examples of integrated  @emph{flow} variables are
@itemize @bullet
@item 
charge
@item 
volume
@item
momentum
@item
angular momentum
@item
heat
@end itemize



@node Bonds, Components, Variables, Introduction
@comment  node-name,  next,  previous,  up
@section Bonds
@cindex Bonds
Bonds connect components (@pxref{Components}) together. Each bond
carries two variables:
@itemize @bullet
@item an effort (@pxref{Variables}) variable and 
@item a flow (@pxref{Variables}) variable.
@end itemize
Each bond has three notations associated with it:
@itemize @bullet
@item a half-arrow,
@item a causal stroke and
@item a causal half-stroke.
@end itemize

The half-arrow indicates two things:
@itemize @bullet
@item the direction of power (or pseudo power) flow and
@item the side of the bond associated with the flow variable.
@end itemize

The causal stroke indicates two things:
@itemize @bullet
@item the effort variable is imposed at the same end as the stroke and
@item the flow variable is imposed at the opposite end to the stroke.
@end itemize

The causal half-stoke indicates one thing:
@itemize @bullet
@item if it is on the effort side of the bond, the effort variable is 
imposed at the same end as the stroke or
@item if it is on the flow side of the bond, the flow variable is 
imposed at the opposite end to the stroke.
@end itemize



@node Components, Algebraic loops, Bonds, Introduction
@comment  node-name,  next,  previous,  up
@section  Components
@cindex Components

Components provide the building blocks of a dynamic system when
connected by bonds (@pxref{bonds}).
Components have the following attributes:
@vtable @code
@item ports 
        provide the connections to other components (@pxref{Ports})
@item constitutive relationships
        define how the port-variables are related (@pxref{Constitutive
relationship})
@end vtable


@menu
* Ports::                       
* Constitutive relationship::   
* Symbolic parameters::         
* Numeric parameters::          
@end menu

@node Ports, Constitutive relationship, Components, Components
@comment  node-name,  next,  previous,  up
@subsection Ports
@cindex ports
Components have one or more ports. Each port carries two variables,
and effort and a flow variable (@pxref{Variables}). Any pair of ports
can be connected by a bond (@pxref{Bonds}); this connection is
equivalent to saying that the effort variables at each port are
identical and that the flow variables at each port are
identical.

Ports are implemented in @strong{MTT} using named SS components.
(@pxref{Named SS components}).

The direction of the named SS components.
(@pxref{Named SS components}) 
is coerced (@pxref{Coerced bond direction}) to have the same direction
as the bons connected to the corresponding port. Thus the direction of
the  direction of the named SS components has no significance unless the
component is at the top level.

@node Constitutive relationship, Symbolic parameters, Ports, Components
@comment  node-name,  next,  previous,  up
@subsection  Constitutive relationship
@cindex Constitutive Relationship

The constitutive relationship of a component defines how the port
variables are related. This relationship may be linear
or non-linear. This typically contains symbolic parameters
(@pxref{Symbolic parameters}) which may be replaced, for the purposes
of numerical analysis by numeric parameters
(@pxref{Numeric parameters}).

@node Symbolic parameters, Numeric parameters, Constitutive relationship, Components
@comment  node-name,  next,  previous,  up
@subsection Symbolic parameters
@cindex Symbolic parameters
The constitutive relationship of a system component (@pxref{Components})
typically contains  symbolic parameters. For example a resistor may have
a symbolic resistance r. It is convenient to leave such parameters as
symbols when viewing equations or when performing symbolic analysis such
as differentiation.

However, @strong{MTT} allows replacement of symbolic parameters by
numeric parameters (@pxref{Numeric parameters}) when appropriate.

@node Numeric parameters,  , Symbolic parameters, Components
@comment  node-name,  next,  previous,  up
@subsection Numeric parameters
@cindex Numeric parameters
Numerical parameters are needed to give specific values to symbolic
parameters (@pxref{Symbolic parameters}) for the purposes of numeric
analysis;
for example: simulation, graph plotting or use within a numerical
package such as Octave (@pxref{Octave}).


@node Algebraic loops, Switched systems, Components, Introduction
@section Algebraic loops
@cindex Algebraic loops
Following Chapter 3 of the book, algebraic loops appear as under-causal
components in the bond graph. It is up to the modeler to indicate how these loops
are to be resolved by adding appropriate SS elements.

For more information, refer to:
``Metamodelling: Bond Graphs and Dynamic Systems'' by Peter Gawthrop and
Lorcan Smith published by Prentice Hall in 1996 (ISBN 0-13-489824-9).

@node Switched systems,  , Algebraic loops, Introduction
@comment  node-name,  next,  previous,  up
@section Switched systems
@cindex Switched systems
@cindex Hybrid systems
@cindex logic

Some systems contain switch-like components. For example an electrical
system may contain on-off switches and diodes and a hydraulic system may
shut-off valves and non-return valves. 

Such systems are sometimes called hybrid systems. The modelling an
simulation of such systems is the subject of current research.
@strong{MTT} implements a simple pragmatic approach to the modelling and
simulation of such systems via two new Bond Graph components:
@vtable @code
@item ISW     
        a switched @code{I} component
@item CSW     
        a switched @code{C} component
@end vtable

These switches are user controlled through the logic representation
(@pxref{Simulation logic}).

@node User interface, Creating Models, Introduction, Top
@comment  node-name,  next,  previous,  up
@chapter User interface
@cindex User interface
@pindex User interface
There are two user interfaces to  @strong{MTT}: a command line interface
(@pxref{Command line interface}) and a menu-driven interface
(@pxref{Menu-driven interface}).

@menu
* Menu-driven interface::       
* Command line interface::      
* Options::                     
* Utilities::                   
@end menu

@node Menu-driven interface, Command line interface, User interface, User interface
@comment  node-name,  next,  previous,  up
@section Menu-driven interface
@cindex Menu-driven interface
@pindex Menu-driven interface
The Menu-driven interface for @strong{MTT} is invoked as:
@example
xmtt
@end example
This will bring up a menu which should be self explanatory :-).
Various messages will be echoed in the window from whence @strong{xMTT}
was invoked.

@node Command line interface, Options, Menu-driven interface, User interface
@comment  node-name,  next,  previous,  up
@section Command line interface
@cindex Command line interface
@pindex Command line interface
The command line interface for @strong{MTT} is of the form:
@example
mtt [options] <system_name> <representation> <language>
@end example
@vtable @code
@item [options]
        the (optional) option switches  (@pxref{Options})
@item <system_name>    
        the name of the system being transformed 
@item <representation>    
        the mnemonic for the system representation (@pxref{Representation summary})
@item <language>    
        the mnemonic for language for the representation (@pxref{Languages})
@end vtable
for example
@example
mtt rc rep view
@end example
creates a view of the report describing system rc and
@example
mtt rc sm m
@end example
creates an m file (suitlable for Octave or Matlab) containing state
matrices describing the system rc.
@node Options, Utilities, Command line interface, User interface
@comment  node-name,  next,  previous,  up
@section Options
@cindex Options

@strong{MTT} has a number of optional switches to control its
operation. These are invoked immediately after `mtt' on the command
line; for example:
@example
mtt -o -s -c syst cbg view
@end example
invokes the @code{-o}, @code{-s}, and @code{-c} options.

The available options are:
@vtable @code
@item -q
        quiet mode -- suppress MTT banner
@item -A 
        solve algebraic equations symbolically
@item -ae 
        <hybrd> solve algebraic equations numerically
 (this option requires -cc or -oct)
@item -D 
        debug -- leave log files etc
@item -I 
        prints more information
@item -abg 
       start at abg.m representation
@item -c 
        c-code generation
@item -cc
       C++ code generation
@item -d 
        <dir>  use directory <dir>
@item -dc 
       Maximise derivative (not integral) causality
@item -dc 
       Maximise derivative (not integral) causality
@item -i 
       <implicit|euler|rk4>   Use implicit, euler or Runge Kutta IVintegration
@item -o 
       ode is same as dae
@item -oct 
       use oct files in place of m files where appropriate
@item -opt 
       optimise code generation
@item -p 
        print environment variables
@item -partition 
       partition hierachical system
@item -r 
        reset time stamp on representation
@item -s 
        try to generate sensitivity BG (experimental)
@item -ss 
       use steady-state info to initialise simulations
@item -stdin 
       read input data from standard input for  simulations
@item -sub 
       <subsystem> operate on this subsystem
@item -t 
        tidy mode (default)
@item -u 
        untidy mode (leaves files in current dir)
@item -v 
        verbose mode (multiple uses increase the verbosity)
@item -viewlevel 
       <N> View N levels of hierachy
@item --version 
       print version and exit
@item --versions 
       print version of mtt and components and exit
@end vtable

@node Utilities,  , Options, User interface
@comment  node-name,  next,  previous,  up
@section Utilities
@cindex Utilities
@pindex Utilities
@strong{MTT} provides some utilities to help you keep track of model
building and to keep things clean and tidy. The commands, and there
purpose are:
@ftable @code
@item mtt help
        Lists the help/browser commands
@item mtt copy <system>
        Copies the system (ie directory and enclosed files) to the
current working directory.
@item mtt rename <old_name> <new_name>
        Renames all of the defining representations (@pxref{Defining
representations}) and textually changes each file appropriately.
@item mtt <system> clean
        Remove all files generated by @strong{MTT} associated with
system `system'.
@item mtt clean
        Remove all files generated by @strong{MTT} associated with
all systems within the current directory.
@item mtt system representation vc
        Apply version control to representation `representation' of
system `system'.
@item mtt system vc
        Apply version control to all representations (under version control)
system `system'.
@end ftable
These are described in more detail in the following sections.

@menu
* Help::                        
* Copy::                        
* Clean::                       
* Version control::             
@end menu

@node Help, Copy, Utilities, Utilities
@comment  node-name,  next,  previous,  up
@subsection Help
@cindex Help
@cindex browser
@strong{MTT} implements a browser to keep track of all the systems,
subsystems and constitutive relationships that you, and others may
write. It is invoked in the following ways:
@example
       mtt help representations
       mtt help components
       mtt help examples 
       mtt help crs
       mtt help representations <match_string>
       mtt help components <match_string>
       mtt help examples  <match_string>
       mtt help crs <match_string>
       mtt help <component_or_example_or_CR_name>
@end example

@menu
* help representations::        
* help components::             
* help examples::               
* help crs::                    
* help <name>::                 
@end menu

@node help representations, help components, Help, Help
@comment  node-name,  next,  previous,  up
@subsubsection help representations
@cindex help
@cindex representations

The command 
@example
mtt help representations
@end example
lists all of the representations  (@pxref{Representations}) available in
@strong{MTT}. These may change as the version number of @strong{MTT}
increases.

The command 
@example
mtt help representations <match_string>
@end example
lists those representation which contain the string @code{match_string}.
This string can be any regular expression  (see standard Linux
documentation under @code{awk}).
For example
@example
mtt help representations descriptor
@end example
gives all representations containing the word @code{descriptor}.

@node help components, help examples, help representations, Help
@comment  node-name,  next,  previous,  up
@subsubsection help components
@cindex help
@cindex components

The command 
@example
mtt help components
@end example
lists all of the components  (@pxref{Components}) available in
@strong{MTT}. These may change as the version number of @strong{MTT}
increases.

The command 
@example
mtt help components <match_string>
@end example
lists those component which contain the string @code{match_string}.
This string can be any regular expression  (see standard Linux
documentation under @code{awk}).
For example
@example
mtt help components source
@end example
gives all components containing the word @code{component}.

@node help examples, help crs, help components, Help
@comment  node-name,  next,  previous,  up
@subsubsection help examples
@cindex help
@cindex examples

This command provides a good way to get started in @strong{MTT}. having
found an interesting example, copy it to your working directory using
@example
mtt copy <example_name>
@end example
(@pxref{Copy})

@example
mtt help examples
@end example
lists all of the examples  available in
@strong{MTT}. 
This list will change as more examples are added.

The command 
@example
mtt help examples <match_string>
@end example
lists those component which contain the string @code{match_string}.
This string can be any regular expression  (see standard Linux
documentation under @code{awk}).
For example
@example
mtt help examples pharmokinetic
@end example
gives all examples containing the word @code{pharmokinetic}.

@node help crs, help <name>, help examples, Help
@comment  node-name,  next,  previous,  up
@subsubsection help crs
@cindex help
@cindex crs

The command 
@example
mtt help crs
@end example
lists all of the constitutive relationships   (@pxref{Constitutive
relationship}) available in
@strong{MTT}. These may change as the version number of @strong{MTT}
increases.

The command 
@example
mtt help crs <match_string>
@end example
lists those constitutive relationships which contain the string @code{match_string}.
This string can be any regular expression  (see standard Linux
documentation under @code{awk}).
For example
@example
mtt help crs sin
@end example
gives all crs containing the word @code{sin}.

@node help <name>,  , help crs, Help
@comment  node-name,  next,  previous,  up
@subsubsection help <name>
@cindex help
@cindex <name>

The command 
@example
mtt help <name>
@end example
gives a detailed description of the entity called @code{name}.

@node Copy, Clean, Help, Utilities
@comment  node-name,  next,  previous,  up
@subsection Copy
@cindex Copy

@strong{MTT} provides a way of copying examples to your working directory:
@example
mtt copy <example_name>
@end example

Use the  command
@example
mtt help examples
@end example
(@pxref{help examples}) to find something of interest.

Note that components and constitutive relationships are automatically
copied when required.

@node Clean, Version control, Copy, Utilities
@comment  node-name,  next,  previous,  up
@subsection Clean
@cindex Clean
@strong{MTT} generates a lot of representations in a number of
languages.
Some of these you will edit yourself; others can always be recreated by
@strong{MTT}. It makes sense, therefore to have a utility that removes
all of these other files when you have finished actively working with a
particular system. These are two versions:
@enumerate
@item
@code{mtt system clean}
@item
@code{mtt clean}
@end enumerate
The first removes all files that can be regenerated with @strong{MTT}
associated with system `system'; the second removes all such files
associated with all systems in the current working directory.

The files which remain after such a clean are the Defining
representations (@pxref{Defining representations}).

@node Version control,  , Clean, Utilities
@comment  node-name,  next,  previous,  up
@subsection Version control
@cindex Version control

When you are working on a modeling project, it is easy to forget what
changes you made to a system and why you made them. Sometimes, you may
regret some changes and wish to revert to an earlier version: even if
you use .old files this may be difficult to achieve safely.

These are very similar problems to those faced by software developers
and can be solved in the same way: using version control.@strong{MTT}
provides version control using the standard GNU Revision Control System
(RCS). This is hidden from the user, but is fully complementary to
direct use of RCS (e.g. via emacs vc commands) to the more experienced
user who wishes to do so.

The only files that you should ever change (i.e. the ones never
overwritten by @strong{MTT}) are the Defining representations
(@pxref{Defining representations}).

All of the files, with the exception of @code{system_abg.fig}, 
are initially created by @strong{MTT} and contain the RCS header for
version control.


The @strong{MTT} version control will automatically expand this part of
the text to include all change comments that you give it -- so will
direct use of RCS (e.g. via emacs vc commands)

The @strong{MTT} version commands are as follows:
@ftable @code
@item mtt system representation vc
        Apply version control to representation `representation' of
system `system'.
@item mtt system vc
        Apply version control to all representations (under version control)
system `system'.
@end ftable

The first is appropriate after you have made a revision to a single
file.  It will prompt you for a change comment; this will be
automatically included in the file header. In addition, enough
information will be saved to enable any  version to be retrieved via
RCS.

The second is appropriate to record the state of the entire model. This
assumes that all relevant files have been recorded by the first version
of the command.  Once again, old versions of the entire model can be
retrieved using the relevant RCS commands.

A subdirectory `RCS' is created to hold this information. You need not
bother about the contents, except that you must not delete any files
within `RCS'.

@node Creating Models, Simulation, User interface, Top
@comment  node-name,  next,  previous,  up
@chapter Creating Models
@cindex  Creating Models

@strong{MTT} helps you to analyse and transform system models --
ultimately the process of capturing the real world in a model is up to
you.  This chapter discusses the @strong{MTT} aspects of creating a
model. For convenience, this is divided into creating simple models and
creating complex models.

@menu
* Quick start::                 
* Creating simple models::      
* Creating complex models::     
@end menu

@node Quick start, Creating simple models, Creating Models, Creating Models
@section Quick start
@cindex Quick start
@pindex Quick start

It is probably worth a quick skim though @strong{MTT} to get a flavour of
what it can do before plunging into the detail of the rest of this
document. Here is a series of commands to do this.

Copy an initial set of files describing the bond graph.
@example
mtt copy rc
@end example
@noindent 
Move to it.
@example
cd rc
@end example
@noindent 
@noindent 
View the acausal bond graph (the system is called ``rc'').
@example
mtt rc abg view
@end example
@noindent 
View the causal bond graph of the system.
@example
mtt rc cbg view
@end example
@noindent 
View the corresponding ordinary differential equations (ode).
@example
mtt rc ode view
@end example
@noindent 
View the system (output) step response
@example
mtt rc sro view
@end example

@noindent 
An alternative (but more general) way of achieving the same result is
@example
mtt -c rc odeso view
@end example

@noindent 
View the system transfer function
@example
mtt rc tf view
@end example
@noindent 
View the log modulus frequency response of the system.
@example
mtt rc lmfr view
@end example

@noindent 
View the log modulus frequency response of the system for 100
logarithmically spaced frequencies in the range 0.1 to 10
radians per second.
@example
mtt rc lmfr view 'W=logspace(-1,1,100);'
@end example

@strong{MTT} has a report generation ((@pxref{Report}) facility which
can generate a hypertext description of the system.
@example
mtt rc rep hview
@end example

The report contents are specified by the rep representation
(@pxref{Report}), in this case the corresponding file is:
@example
% %% Outline report file for system rc (rc_rep.txt)

mtt rc abg tex
mtt rc struc tex
mtt rc cbg ps
mtt rc ode tex
mtt rc ode dvi
mtt rc sm tex
mtt rc tf tex
mtt rc tf dvi
mtt rc sro ps
mtt rc lmfr ps
mtt rc odes h
mtt rc numpar txt
mtt rc input txt
mtt -c rc odeso ps
mtt rc rep txt
@end example
A non-hypertext version can be viewed using:
@example
mtt rc rep view
@end example

Now have a go at modifying the bond graph.
@example
mtt rc abg fig
@end example
This brings up the bond graph in Xfig (@pxref{Xfig}).  Try creating a
system with two rs and 2 cs.

More examples can be found using
@example
mtt help examples
@end example
Details of an example can be found using
@example
mtt help <example_name>
@end example
and copied using
@example
mtt copy <example_name>
@end example

Lots of examples are available.
@example
mtt help examples
@end example
lists them and
@example
mtt copy <name>
@end example
gets you an example.

@ifhtml
A number of examples are to be found
<A
HREF="http://www.mech.gla.ac.uk/~peterg/software/MTT/examples/Examples/Examples.html"> here</A>.
@end ifhtml

@node Creating simple models, Creating complex models, Quick start, Creating Models
@comment  node-name,  next,  previous,  up
@section Creating simple models
@cindex Creating simple models

For then purposes of this section, simple models are those which are
built up from bond graphs involving predefined components. In contrast,
more complex systems (@pxref{Creating complex models}) need to be built
up hierarchically.

The recommended sequence of steps to create a simple model is:
@enumerate
@item Decide on a name for the system; let us call it `syst' for the
  purposes of this discussion. 
@item Invoke the Bond Graph editor to draw the acausal Bond Graph.
@example
  mtt syst abg fig
@end example
@item Draw the Bond Graph  (@pxref{Language fig (abg.fig)}), including
  the bonds (@pxref{Bonds}), the components (@pxref{Components}) and any
  artwork (@pxref{artwork}) to make the Bond Graph more readable. The
  graphical editor xfig is (@pxref{Xfig}) is self-explanatory.
  The icon library is helpful here (see @pxref{icon library}).
@item Add causal strokes (@pxref{strokes}) where needed to define
  causality. As a general rule, use the minimum number of strokes needed
  to define the problem; this will often be only on the @code{SS} components.
  (@pxref{SS components}).
  
  Save the bond graph.
  
@item View the corresponding causal bond graph.
@example
  mtt syst cbg view
@end example
@enumerate
@item 
    At this stage, @strong{MTT} will warn you that the labeled components do
    not appear in the label file - this can safely be ignored.
@item
  @strong{MTT} will indicate the percentage of components which are
    causally complete -- ideally this will be 100\%. Components which are
    not causally complete will be listed.
@item
    A view of the causal bond graph will be created. The added causal
    strokes are indicated in blue, undercausal components in green and
    overcausal components in red.
@item
    If the bond graph is causally complete, proceed to the next step,
    otherwise think hard and return to the first step.
@end enumerate

@item
At this stage, no constitutive relationships have been
defined. Nevertheless, @strong{MTT} will proceed in a semi-qualitative
fashion by assuming that all constitutive relationships are unity (and
therefore linear). It may be useful at this stage to view various
derived representations to check the overall model properties before
proceeding further. For example:
@enumerate
@item
View the system Differential-algebraic equations
@example
mtt syst dae view
@end example
@item
View the system state matrices
@example
mtt syst sm view
@end example
@item
View the system transfer function
@example
mtt syst tf view
@end example
@item
View the system step response
@example
mtt syst sro view
@end example
@end enumerate

@item
As well as creating the causal bond graph, @strong{MTT} has also
generated templates for other text files 
(@pxref{Defining representations})
used to further specify the
system.
These can now be edited using your favorite text editor (@pxref{Text
editors}).

@item @strong{MTT} will now generate the representations
(@pxref{Representation summary})that you desire.
For example the system can be simulated by
@example
mtt syst odeso view
@end example
@strong{MTT} will complain if a component is named in the bond graph but
not in the label file and vice versa. This mainly to catch typing errors.

@end enumerate

@node Creating complex models,  , Creating simple models, Creating Models
@comment  node-name,  next,  previous,  up
@section Creating complex models
@cindex Creating complex models

Complex models -- in distinction to simple models (@pxref{Creating
simple models}) -- have a hierarchical structure. In particular, bond
graph components can be created by specifying their bond
graph. Typically, such components will have more than one port
(@pxref{Ports}); within each component, ports are represented by
named SS components (@pxref{Named SS components}); outwith
each component, ports are unambiguously identified by 
labels (@pxref{Port labels}) and vector labels (@pxref{Vector port labels}).

Complex models are thus created by conceptually decomposing the system
into simple subsystems, and then creating the corresponding bond graphs.
The procedure for simple systems (@pxref{Creating simple models}) is
then followed using the top level system (@pxref{Top level}); @strong{MTT} then recursively
operates on the lower level systems.

The report representation (@pxref{Report}) provides a convenient way of
viewing a complex system.

An example of such a system can be created as follows:
@example
mtt copy twolink
mtt twolink rep hview
@end example

@ifhtml
The result is <A
HREF="./examples/twolink/twolink_rep/twolink_rep.html"> here</A>.
@end ifhtml

@menu
* Top level::                   
@end menu

@node Top level,  , Creating complex models, Creating complex models
@comment  node-name,  next,  previous,  up
@subsection Top level
@cindex Top level
The top level of a complex model contains subsystems but is not, itself,
contained by other systems. 
It has the following special features:
@itemize @bullet
@item
its name is used in the mtt command as the system name.
@item
all named SS componenents (@pxref{Named SS components}) are treated as
ordinary SS components (@pxref{SS components}).
@end itemize



@c      node   next  prev  up
@node Simulation, Sensitivity models, Creating Models, Top
@chapter Simulation
@cindex Simulation
@pindex Simulation
One purpose of modelling is to simulate the modeled dynamic
system. Although this is just another transformation (@pxref{What is a
Transformation?}) and therefore is covered in the appropriate chapter
(@pxref{Representations}), it is important enough to be given its own
chapter.

Simulation is typically performed using an appropriate simulation
language (which is often inappropriately conflated with modelling
tools). @strong{MTT} provides a number of alternative routes to
simulation based on the following representations (@pxref{Representations}):
@ftable @code
@item cse
        constrained-state differential equation form
@item ode
        ordinary differential (or state-space) equations
@c  @item dae
@c          differential-algebraic (or generalised state-space) equations --
@c  these may be linear or nonlinear.
@end ftable
in each case these equations may be
linear or nonlinear.

Special cases of numerical simulation, appropriate to @emph{linear}
systems, are:
@ftable @code
@item   ir
        impulse response - state 
@item   iro
        impulse response - output 
@item   sr
        impulse response - state 
@item   sro
        impulse response - output 
@end ftable

There are a number of languages (@pxref{Languages}) which can be used to describe these
representations for the purposes of numerical simulation:
@ftable @code
@item m
        @code{octave} a high-level interactive language for numerical
        computation.
@item c
        @code{gcc} a c compiler.
@item cc
        @code{g++} a C++ front-end to gcc.
@end ftable

There are a number solution algorithms available:
@itemize @bullet
@item
explicit solution via the matrix exponential
@item
backward Euler integration (explicit)
@item
forward Euler integration (implicit)
@item
Runge Kutta IV integration (explicit, fixed step)
@item
Hybrd algebraic solver (MINPACK, Octave fsolve)
@c  @item
@c  LSODE (Hindmarsh's ODE solver as implemented in Octave)
@c  @item
@c  DASSL (Petzold's DAE solver as implemented in Octave) (Unavailable just now)
@end itemize

 However, all combinations of representation, language and solution
method are not supported by @strong{MTT} at the moment. Given a system
`system', some recommended commands are:
@ftable @code
@item mtt system iro view
        creates the impulse response of a @emph{linear} system via the
system_sm.m representation using explicit solution via the matrix exponential.
@item mtt system sro view
        creates the step response of a @emph{linear} system via the system_sm.m
representation using explicit solution via the matrix exponential.
@c  @item mtt system odeso view
@c          creates the step response of a @emph{nonlinear} system via the
@c  system_ode.m representation using either METHOD=Euler or
@c  METHOD=LSODE in the parameter file (@pxref{Simulation parameters}).
@item mtt -c system odeso view
        creates the response of a @emph{nonlinear} system via the
system_ode.c representation using implicit integration.
@item mtt -c -i euler system odeso view
        creates the response of a @emph{nonlinear} system via the
system_ode.c representation using euler integration.
@end ftable

Simulation parameters are described in the system_simpar.txt file
(@pxref{Simulation parameters}).

The steady-state solution of a system can also be
``simulated''(@pxref{Steady-state solutions}).
@menu
* Steady-state solutions::      
* Simulation parameters::       
* Simulation input::            
* Simulation logic::            
* Simulation initial state::    
* Simulation code::             
* Simulation output::           
@end menu

@node Steady-state solutions, Simulation parameters, Simulation, Simulation
@comment  node-name,  next,  previous,  up
@section Steady-state solutions 
@cindex Steady-state solutions

@menu
* Steady-state solutions - numerical(odess)::  
* Steady-state solutions - symbolic (ss)::  
@end menu

@node Steady-state solutions - numerical(odess), Steady-state solutions - symbolic (ss), Steady-state solutions, Steady-state solutions
@comment  node-name,  next,  previous,  up
@subsection Steady-state solutions (odess)
@cindex Steady-state solutions - numerical

@strong{MTT} can compute the steady-state solutions of an ordinary
differential equation; this used the octave function `fsolve'. The
solution is computed as a function of time using the input specified in
the input file. The simulation parameter file (@pxref{Simulation
parameters}) is used to provide the time scales.

For example
@example
mtt copy rc
cd rc
mtt rc odess view
@end example

@node Steady-state solutions - symbolic (ss),  , Steady-state solutions - numerical(odess), Steady-state solutions
@comment  node-name,  next,  previous,  up
@subsection Steady-state solutions (ss) 
@cindex Steady-state solutions - symbolic
A rudimentary form of steady-state solution exists in mtt.
The steady states and inouts are supplied by the user in the file
system_simpar.r and the corresponding output and sate derivative
computed by @strong{MTT} using
@example
mtt system ss view
@end example

For example
@example
mtt copy rc
cd rc
mtt rc sspar view
mtt rc ss view
@end example


@node Simulation parameters, Simulation input, Steady-state solutions, Simulation
@comment  node-name,  next,  previous,  up
@section Simulation parameters
@cindex Simulation parameters

Simulation parameters are set in the system_simpar.txt file. At the
moment this sets the following variables:
@itemize @bullet
@item LAST
        the last simulation time
@item DT
        the incremental time (for plotting)
@item STEPFACTOR
        the number of integration steps per DT -- thus the integration
        interval is DT/STEPFACTOR
@c ; for sparse implicit integration (@pxref{Sparse
@c implicit integration}) the number of conjugate-gradient minimisation
@c steps.
@c  @item METHOD
@c          The integration methods available appear in the following table
@item WMIN
        Minimum frequency = 10^WMIN
@item WMAX
        Maximum frequency = 10^WMAX
@item WSTEPS
        Number of Frequency steps.
@item INPUT
        The input index for frequency response
@end itemize

There are a number of solution algorithms
@itemize @bullet
@item Euler
        basic Euler integration (@pxref{Euler integration}). This method
is simple, but not recommended for stiff systems.
@item Implicit
        semi-implicit integration  (@pxref{Implicit integration}) - uses the smx representation to give
        stability.
@item Runge Kutta IV
        fixed step Runge Kutta fourth order integration (@pxref{Runge Kutta IV integration}).
@item Hybrd
        numerical algebraic equation solver
        

@c @item ImplicitS
@c         Sparse semi-implicit integration  (@pxref{Sparse implicit integration})
@c -- takes advantage of the sparsity of the A matrix.
@c @item LSODE
@c         the variable step-size method that comes with Octave (@pxref{Octave}).
@end itemize

@menu
* Euler integration::           
* Implicit integration::        
* Runge Kutta IV integration::  
* Hybrd algebraic solver::      
@end menu

@node Euler integration, Implicit integration, Simulation parameters, Simulation parameters
@comment  node-name,  next,  previous,  up
@subsection Euler integration
@cindex Euler integration
Euler integration approximates the solution of the Ordinary Differential Equation 
@example
dx/dt = f(x,u)
@end example
by
@example
x := x + f(x,u)*DDT
@end example
where
@example
DDT = DT/STEPFACTOR
@end example
If the system is linear, stability is ensured if the integer STEPFACTOR
is chosen to be greater than the real number
@example
(maximum eigenvalue of -A)*DT/2
@end example
where A is the nxn matrix appearing in
@example
f(x,u) = Ax + Bu
@end example
If the system is non linear, the linearised system matrix A should act
as a guide to the choice of STEPFACTOR.

@node Implicit integration, Runge Kutta IV integration, Euler integration, Simulation parameters
@comment  node-name,  next,  previous,  up
@subsection Implicit integration
@cindex Implicit integration
Implicit integration approximates the solution of the Ordinary Differential Equation 
@example
dx/dt = f(x,u)
@end example
by
@example
(I-A*DT)x := (I-A*DT)x + f(x,u)DT
@end example
where A is the linearised system matrix. This implies the solution of N
(=number of states) linear equations at each sample interval. The OCTAVE
version used the `\' operator to solve the set of linear equations, the
C version uses LU decomposition.

If the system is linear, stability is ensured unconditionaly. If the
system is non-linear, then the method still works well.

This method is nice in that choice of DT trades of accuracy against
computation time without compromising stability. In addition, the
correct stready-state values are achieved.

This approach can also be used for constrained state equations of the
form:
@example
E(x) dx/dt = f(x,u)
@end example
where E(x) is a state-dependent matrix. The approximate solution is then
given by:
@example
(E(x)-A*DT)x := (E(x)-A*DT)x + f(x,u)DT
@end example
which reduces to the ordinary differential equation case when E(x)=I.

The _smx representation includes the E matrix.

@node Runge Kutta IV integration, Hybrd algebraic solver, Implicit integration, Simulation parameters
@comment  node-name,  next,  previous,  up
@subsection Runge Kutta IV integration
Runge Kutta IV approximates the solution of the Ordinary Differential Equation

@example
dx/dt = f(x,t)
@end example

by

@example
x := x + (DT/6)*(k1 + 2*k2 + 2*k3 + k4)
@end example

where

@example
k1 := f(x,t)
k2 := f(x+(1/2)*k1,t+(1/2)*DT)
k3 := f(x+(1/2)*k2,t+(1/2)*DT)
k4 := f(x+k3,t+DT)
@end example

The @strong{MTT} implementation of Runge-Kutta integration
is a fourth order, fixed-step, explicit integration method.

For some systems of equations, the increased accuracy of using a fourth order
method can allow larger step-lengths to be used than would allowed by the
 lower order Euler integration method.

It should be noted that during the interemediate calculations (k1...k4),
 the input vector @code{u} is not advanced w.r.t. time; the system inputs are
assumed to be constant over the period of the integration step-length.

@node Hybrd algebraic solver,  , Runge Kutta IV integration, Simulation parameters
@comment  node-name,  next,  previous,  up
@subsection Hybrd algebraic solver

The hybrd algebraic solver of @uref{http://www.netlib.org/minpack/hybrd.f,MINPACK},
which is used by Octave in the @code{fsolve} routine, may be used in conjunction
with one of the other integration methods to solve semi-explicit, index 1, differential
algebraic equations; these may be generated in @strong{MTT} models by use of 
@code{unknown} SS Components @pxref{SS component labels}.

This method requires that compiled simulation code is used; either -cc or -oct.
To perform a simulation based on a model @code{sys},

@example
mtt -cc -ae hybrd -i euler sys odeso view
@c XXX: should be daeso view?
@end example

@strong{MTT} will attempt to minimise the residual error at each integration time-step
using the hybrd routine.

This method of simulation is particularly well suited to stiff systems where very fast
dynamics are of little interest. Care must be taken to ensure that an acceptable level
of convergence is achieved by the solver for the system under investigation.
@c XXX: tolerance option

@c @node Sparse implicit integration,  , Implicit integration, Simulation parameters
@c @comment  node-name,  next,  previous,  up
@c @subsection Sparse implicit integration
@c @cindex Sparse implicit integration
@c This is an experimental approach for large (N>50) systems.

@c Implicit integration (@pxref{Implicit integration}) requires the
@c solution of N linear equations at each step. This is an O(N^3) operation
@c which can be time consuming for large (N>50) systems. However, the A
@c matrix (and hence the (I-A*DT) matrix) is often sparse - most elements
@c are zero.

@c This method uses a conjugate-gradient optimisation method to solve the
@c linear equations
@c @example
@c (I-A*DT)x := (I-A*DT)x + f(x,u)DT
@c @end example
@c by recasting them as the minimisation of the quadratic function
@c @example
@c [(I-A*DT)x_new - (I-A*DT)x_old + f(x,u)DT]^2
@c @end example
@c with respect to x_new. This is solved by the conjugate gradient method.
@c MTT generates two representations _smxx.m and _smxtx to compute
@c (I-A*DT)x and (I-A*DT)'x respectively making full use of the sparsity of
@c the (I-A*DT) matrices to speed up the minimisation procedure.

@c A fixed number of iterations (STEPFACTOR) are used in each optimisation
@c to give a fixed simulation time. This must be chosen by the user, but
@c between 5N and 10N seems ok. Note that the initial value of the
@c optimisation is x_old.

@node Simulation input, Simulation logic, Simulation parameters, Simulation
@comment  node-name,  next,  previous,  up
@section Simulation input
@cindex Simulation input
This is defined in the system_input.txt file. A default file is created
automatically by @strong{MTT}. This is done explicitly by
@example
mtt system input txt
@end example
If the file already exists, the same command checks that all inputs are
defined and that all defined inputs exist in the system and promts the
user to correct discrepancies.

Inputs are defined by the full system name appearing in the structure
file (@pxref{Structure (struc)}). They can depend on states (again defined by
name), time (defined by t) and parameters

For example:
@example
system_pump_l_1_u	= 4e5*atm;
system_pump_r_1_u	= 4e5*(t<10)*atm;
system_ss_i	        = 0*kg;
system_ss_o	        = 3e-3*kg;
system_v_1_u	        = (t>10);
system_v_ll_1_u         = 1;
system_v_lr_1_u         = (t<10);
system_v_ul_1_u         = 0;
system_v_ur_1_u         = (t>10);
@end example

@node Simulation logic, Simulation initial state, Simulation input, Simulation
@comment  node-name,  next,  previous,  up
@section Simulation logic
@cindex Simulation logic
This is defined in the system_logic.txt file. A default file is created
automatically by @strong{MTT}. This is done explicitly by
@example
mtt system logic txt
@end example
If the file already exists, the same command checks that the logic
corresponding to all switch states (@pxref{Switched systems}) are
defined and that all defined logic exists in the system and promts the
user to correct discrepancies.

Logical inputs are defined by the full system name corresponding to
MTT_switch components appearing in the structure file (@pxref{Structure
(struc)}) @emph{with `_logic' appended}. They can depend on states (again defined by name), time
(defined by t) and parameters

For example:
@example
bounce_ground_1_mtt_switch_logic	= bounce_intf_1_mtt3<0;
@end example

@node Simulation initial state, Simulation code, Simulation logic, Simulation
@comment  node-name,  next,  previous,  up
@section Simulation initial state
@cindex Simulation initial state
This is defined in the system_state.txt file. A default file is created
automatically by @strong{MTT}. This is done explicitly by
@example
mtt system state txt
@end example
If the file already exists, the same command checks that all states are
defined and that all defined states exist in the system and prompts the
user to correct discrepancies.

States are defined by the full system name appearing in the structure
file (@pxref{Structure (struc)}). They can depend on parameters.
For example
@example
system_c_l	= (1e4/k_l)/kg;
system_c_ll	= (1e4/k_s)/kg;
system_c_lr	= (1e4/k_s)/kg;
system_c_u	= (1e4/k_l)/kg;
@end example


@c  The initial state of a simulation of is set in the @code{state}
@c  representation with the language @code{txt}.

@c  As usual, @strong{MTT} defaults this for you. There are two
@c  possibilities
@c  @itemize @bullet
@c  @item
@c  The -ss switch is not present: the states default to zero
@c  @item
@c  The -ss switch is present: the states default to those set in the
@c  sspar.r file.
@c  @end itemize

@node Simulation code, Simulation output, Simulation initial state, Simulation
@comment  node-name,  next,  previous,  up
@section Simulation code
simulation code can be generated by @strong{MTT} in the form
of the @code{ode2odes} transformation. This can be produced in a number
of languages, including .m, .oct, C and C++ @pxref{Languages}.

To generate simulation code in C:
@example
mtt -c [options] sys ode2odes c
@end example

Similarly, to generate C++ code:
@example
mtt -cc [options] sys ode2odes cc
@end example

To generate an executable based on the C++ representation:
@example
mtt -cc [options] sys ode2odes exe
@end example

@node Simulation output,  , Simulation code, Simulation
@comment  node-name,  next,  previous,  up
@section Simulation output
@cindex Simulation output
The view (@pxref{Views}) representation provides a graphical
representation of the results of a simulation; the postscript language
provides the same thing in a form that can be included in a document.

These are two simulation output representations
@ftable @code
@item odes 
        ordinary differential equation solution (states)
@item odeso
         ordinary differential equation solution (output)
@end ftable    

Particular output variables can be selected by adding a fourth argument
in one of 2 forms
@ftable @code
@item 'name1;name2;..;namen' 
        plot the variables with names na1 .. namen against time
@item 'name1:name2'
                plot the variable with  name2 against that with name 1
@end ftable    

An example of plotting a single variable against time is:
@example
mtt -o -c -ss OttoCycle odeso ps 'OttoCycle_cycle_V'
@end example
An example of plotting one variable against another is:
@example
mtt -o -c -ss OttoCycle odeso ps 'OttoCycle_cycle_V:OttoCycle_cycle_P'
@end example

@menu
* Viewing results with gnuplot::  
* Exporting results to SciGraphica::  
@end menu

@node Viewing results with gnuplot, Exporting results to SciGraphica, Simulation output, Simulation output
@comment  node-name,  next,  previous,  up@subsection
@subsection Viewing results with gnuplot
@cindex gnuplot

Simulation results may be viewed in
@uref{http://www.gnuplot.org,gnuplot} with the command

@example
mtt [options] rc gnuplot view
@end example

The plot format is controlled by the file @emph{sys_gnuplot.txt}. A default version
of this file, which will cause gnuplot to plot the time-history of each state
and each output individually, may be created with the command

@example
mtt rc gnuplot txt
@end example

resulting in

@example
wait=-1
set data style lines
set xlabel "time"
set grid
set term X11

plot "rc_odes.dat2" using 1:4 axes x1y1 title "rc_c_c;
pause(wait);
plot "rc_odes.dat2" using 1:2 axes x1y1 title "rc_e2_e2
; pause(wait);
@end example

The file is used as an input to the gnuplot program and may therefore be
edited to contain any valid gnuplot commands.

@node Exporting results to SciGraphica,  , Viewing results with gnuplot, Simulation output
@comment  node-name,  next,  previous,  up
@subsection Exporting results to SciGraphica
@cindex SciGraphica

Simulation results can be converted into an XML-format
@uref{http://scigraphica.sourceforge.net,SciGraphica} (version 0.61)
@emph{.sg} file with the command

@example
mtt [options] sys odes sg
@end example

The SciGraphica file will contain two worksheets, X_sys and Y_sys, containing
the state and output time-histories from the simulation.

@c      node   next  prev  up
@node   Sensitivity models, Representations, Simulation, Top
@chapter Sensitivity models
@cindex Sensitivity models
@pindex Sensitivity models

The sensitivity model of a system is a set of equations giving the
sensitivity of the system outputs with respect to system parameters.
@strong{MTT} has built in methods for assisting with the development of
such models.

This feature is experimental at the moment, but the following example
gives an idea of what can be achieved.
@example
mtt copy rc
cd rc
mtt -s src ode view
mtt -s src odeso view
@end example
The sensitivity system src is automatically created from the system rc
using the predefined sR and sC components together with vector junctions
(@pxref{Vector components}).  The four outputs are the two system
outputs plus the two sensitivity functions.

An alternative route is to create the sensitivity functions by symbolic
differentiation.
The following sensitivity representations are available:
@ftable @code
@item   scse
        sensitivity constrained-state equations
@item   sm
        sensitivity state matrices
@item   scsm
        sensitivity constrained-state matrices
@end ftable



@c      node   next  prev  up
@node   Representations, Extending MTT, Sensitivity models, Top
@chapter Representations
@cindex Representations
@pindex Representations
@cindex Defining representations
@cindex Representations, defining

As discussed in @ref{What is a Representation?}, a system has many
representations. The purpose of @strong{MTT} is to provide an easy way to
generate such representation by applying the appropriate sequence of 
transformations. The representations supported by @strong{MTT} are
summarised in @ref{Representation summary}.

There is a two-fold division of representations into those with which the user
defines the system and its various attributes, and those which are
derived from these. The @emph{defining representations} are listed in
@ref{Defining representations}. 

Each representation is implemented in one or more languages depending on
its use. These languages are discussed in @ref{Languages} and are
associated with appropriate tools for modifying or viewing the
representations. 

@menu
* Representation summary::      
* Defining representations::    
* Verbal description (desc)::   
* Acausal bond graph (abg)::    
* Stripped acausal bond graph (sabg)::  
* Labels (lbl)::                
* Description (desc)::          
* Structure (struc)::           
* Constitutive Relationship (cr)::  
* Parameters::                  
* Causal bond graph (cbg)::     
* Elementary system equations::  
* Differential-Algebraic Equations::  
* Constrained-state Equations::  
* Ordinary Differential Equations::  
* Descriptor matrices::         
* Report::                      
@end menu

@node Representation summary, Defining representations, Representations, Representations
@comment  node-name,  next,  previous,  up
@section Representation summary
@cindex Representation summary

Some of the the representations 
available in @strong{MTT} are (in alphabetical order):
@ftable @code
@item   abg
        acausal bond graph 
@item   cbg
        causal bond graph 
@item   cr
        constitutive relationship for each subsystem 
@item   cse
        constrained-state equations 
@item   csm
        constrained-state matrices 
@item   dae
        differential-algebraic equations 
@item   daes
        dae solution - state 
@item   daeso
        dae solution - output 
@item   def
        definitions - system orders etc. 
@item   desc
        Verbal description of system 
@item   dm
        descriptor matrices 
@item   ese
        elementary system equations 
@item   fr
        frequency response 
@item   input        
        numerical input declaration 
@item   ir
        impulse response - state 
@item   iro
        impulse response - output 
@item   lbl
        label file 
@item   lmfr
        loglog modulus frequency response 
@item   lpfr
        semilog phase frequency response 
@item   nifr
        Nichols style frequency response 
@item   numpar
        numerical parameter declaration 
@item   nyfr
        Nyquist style frequency response 
@item   obs
        observer equations for CGPC 
@item   ode
        ordinary differential equations 
@item   odes
        ode solution - state 
@item   odes
        ODE simulation header file 
@item   odeso
        ode solution - output 
@item   odess
        ode numerical steady-states - states 
@item   odesso
        ode numerical steady-states - outputs 
@item   rbg
        raw bond graph 
@item   rep
        report 
@item   rfe
        robot-form equations 
@item   sabg
        stripped acausal bond graph 
@item   simp
        simplification information 
@item   sm
        state matrices 
@item   smx
        state matrices containing explicit states and inputs
@item   sms
        ode 
@item   smss
        SM simulation header file 
@item   sr
        step response - state 
@item   sro
        step response - output 
@item   ss
        steady-state equations 
@item   sspar
        steady-state definition 
@item   struc
        structure - list of inputs, outputs and states 
@item   sub
        Executable subsystem list 
@item   sub
        LaTeX subsystem list 
@item   sympar
        symbolic parameters 
@item   tf
        transfer function 
@end ftable
A complete list can be found via the @code{help representations} command
(@pxref{help representations}). 

Many of these representations have more than one language (@pxref{Representations}) associated
with them.

Some of these representations define the system (@pxref{Defining
representations}).

@node Defining representations, Verbal description (desc), Representation summary, Representations
@comment  node-name,  next,  previous,  up
@section Defining representations
@cindex Defining representations

The following representations define the system and therefore must,
ultimately, be defined by the user. However, all of these are assigned
default values by @strong{MTT} and may then be subsequently edited
(@pxref{Text editors}) viewed or operated on by the appropriate tools
(@pxref{Language tools}).
@vtable @code
@item system_abg.fig
        the acausal bond graph (@pxref{Acausal bond graph (abg)})
@item system_lbl.txt
        the label file (@pxref{Labels (lbl)})
@item system_desc.tex
        the description file (@pxref{Description (desc)})
@item system_simp.r
        algebraic simplifications to make output more readable
        (@pxref{Symbolic parameters for simplification (simp.r)})
@item system_subs.r
        algebraic substitutions to resolve, eq trig. identities
        (@pxref{Symbolic parameters (subs.r)})
@item system_simpar.txt
        simulation parameters (@pxref{Simulation parameters})
@item system_numpar.txt
        numerical parameters (@pxref{Numeric parameters (numpar)})
@item system_input.txt
        the system input for simulations (@pxref{Simulation input})
@item system_logic.txt
        the  switching logic for simulations (@pxref{Simulation logic})
@item system_sspar.r
        defines the system steady-state (@pxref{Steady-state solutions - symbolic (ss)})
@end vtable

@node Verbal description (desc), Acausal bond graph (abg), Defining representations, Representations
@comment  node-name,  next,  previous,  up
@section Verbal description (desc)
@cindex Verbal description (desc)

Systems can be documented in LaTeX using the _desc.tex file. This file
is included in the report (@pxref{Report}) if the abg tex option
is included in the rep.txt file.  As usual, @strong{MTT} provides a
default text file to be edited by the user (@pxref{Text editors}).


@c      node   next  prev  up
@node   Acausal bond graph (abg), Stripped acausal bond graph (sabg), Verbal description (desc), Representations
@section Acausal bond graph (abg)
@cindex Acausal bond graph (abg)
@pindex Acausal bond graph (abg)

The acausal bond graph is the main input to @strong{MTT}. It is up to you, as a
system modeler, to distill the essential aspects of the system that you
wish to model and capture this information in the form of a bond graph.

The inexperienced modeler may wish to look in one of the standard
textbooks and copy some bond graphs of  systems to get going.


To create the acausal bond graph of system `sys' in language fig type:
@example
mtt sys abg fig
@end example
To create the acausal bond graph of system `sys' in language m type:
@example
mtt sys abg m
@end example
To view the acausal bond graph of system `sys' type:
@example
mtt sys abg view
@end example

@menu
* Language fig (abg.fig)::      
* Language m (rbg.m)::          
* Language m (abg.m)::          
* Language tex (abg.tex)::      
@end menu

@node Language fig (abg.fig), Language m (rbg.m), Acausal bond graph (abg), Acausal bond graph (abg)
@subsection Language fig (abg.fig) 
@cindex Language fig (abg.fig) 
@pindex Language fig (abg.fig) 

A bond graph is made up of:
@ftable @code
@item bonds
        To connect components together.
@item strokes
        To indicate causality.
@item components
        Either simple or compound.
@item artwork
        Irrelevant to the system but useful to the user.
@end ftable

An icon library of bonds, components and other symbols is available
within xfig (@pxref{icon library}).




@menu
* icon library::                
* bonds::                       
* strokes::                     
* components::                  
* Simple components::           
* SS components::               
* Simple components - implementation::  
* Compound components::         
* Named SS components::         
* Coerced bond direction::      
* Port labels::                 
* Vector port labels::          
* Port label defaults::         
* Vector components::           
* artwork::                     
* Valid names::                 
@end menu

@node icon library, bonds, Language fig (abg.fig), Language fig (abg.fig)
@subsubsection Icon library
@cindex Icon
@cindex library
A number of predefined iconic symbols are available within xfig. 
@example
Click onto the library icon
Click onto the library pull-down menu and select BondGraph
Select iconic symbols from the presented list
@end example

@node bonds, strokes, icon library, Language fig (abg.fig)
@subsubsection Bonds
@cindex bonds
@pindex bonds

Bonds are represented by polylines with two segments. They must be the
default style (i.e. plain not dashed or dotted). The shortest segment is
taken to be the half-arrow. its positioning is significant because:
@itemize @bullet
@item
It points in the direction of power flow; thus a bond normally points
towards C, I and R components.
@item
the corresponding side of the bond indicates flow causality; the other
side represents effort causality. This is significant when using casual
half-strokes (@pxref{strokes}). Please adopt the convention of having
the half-arrows below horizontal bonds and to the right of vertical bonds.
@end itemize



@c      node   next  prev  up
@node strokes, components, bonds, Language fig (abg.fig)
@subsubsection Strokes
@cindex strokes
@pindex strokes

Causal strokes are represented by single-segment polylines.
There are two sorts of strokes:
@itemize @bullet
@item
@emph{Full} strokes: these are the usual bond-graph strokes and determine
both the effort and flow causality in the usual way. The @emph{centre} of the
stroke should be at about one end of the bond and be at right angles to
it.
@item
@emph{Half} strokes: these are an innovation in @strong{MTT} and allow you to
specify the effort and flow causality independently. The @emph{end} of the
stroke should be at about one end of the bond and be at right angles to
it. If the causal half-stroke is on the @emph{same} side as the half-arrow
(@pxref{bonds}) then it determines @emph{flow} causality; if, on the other
hand, it is on the @emph{opposite} side to the half-arrow
(@pxref{bonds}) then it determines @emph{effort} causality.
Two half strokes on the @emph{same}, but on @emph{opposite} sides of the
bond are equivalent to a a full stroke at the same end of the bond.
@end itemize

@strong{MTT} is reasonably forgiving; but a neat diagram will be less ambiguous to
you as well as to @strong{MTT}.

Causality is indicated as follows:
@itemize @bullet
@item 
@emph{Effort} is imposed at the @emph{same} end as the stroke.
@item 
@emph{Flow} is imposed at the @emph{opposite} end as the stroke.
@end itemize



@c      node   next  prev  up
@node components, Simple components, strokes, Language fig (abg.fig)
@subsubsection Components
@cindex components
@pindex components

Components are represented by a text string in fig.  The recommended
style is: 20pt, Times-Roman and centre justified.

The component text string can be of the following forms:
@ftable @code
@item type
Just the type of the component is indicated. Components may be either
Simple components (@pxref{Simple components}) or Compound components
(@pxref{Compound components}).  For example:
@example
R
@end example
@item type:label
Both the type and the label of the component are given. The type must be
a valid name (@pxref{Valid names}.The name provides a link to more
information to be found in @xref{Labels (lbl)}. For example:
@example
R:r
@end example
@item type:label:cr
Not only are the type and the label of the component given, but also the
component cr argument. The type must be
a valid name (@pxref{Valid names}.The name provides a link to more
information to be found in @xref{Labels (lbl)}. For example:
@example
R:r:flow,r
@end example
@item type:label:expression
Expression is a mathematical expression relating the effort (called
mtt_e) to the flow (called mtt_f).
For example the following three forms are equivalent
@example
R:r:mtt_e=r*mtt_f
R:r:mtt_e-r*mtt_f=0
R:r:mtt_f=mtt_e/r
@end example
A non-linear example is:
@example
R:r:mtt_e = sin(mtt_f)
@end example

@item type*n
The name, together with the number @samp{n} of repetitions of the
component, are given. This repetition only makes sense if the component
has an even number of ports (@pxref{Port labels}); n copies of the component
are concatenated with odd Named ports (@pxref{Port labels}) of the
component being connected to the even Named ports of the previous
component in the chain in numerical order.  This feature is particularly
useful if the component is compound and can be used for, example to give
a lumped approximation of a distributed system. For example:
@example
MySystem*25
@end example
@item type:label*n
This complete form and is a combination of the simpler forms. For
example:
@example
MySystem:MyLabel*25
@end example

@end ftable

@node Simple components, SS components, components, Language fig (abg.fig)
@comment  node-name,  next,  previous,  up
@subsubsection Simple components
@cindex Simple components

The following simple components are defined in MTT.

@ftable @code
@item R
         Standard one-port R
@item C
         Standard one-port I
@item I
         Standard one-port I
@item SS
        Source-sensor
@item TF
        Transformer
@item GY
        Gyrator
@item AE
        Effort amplifier
@item AF
        Flow amplifier
@item CSW
         Switched one-port I
@item ISW
         Switched one-port I
@end ftable

@menu
* SS components::               
* Simple components - implementation::  
@end menu

@node SS components, Simple components - implementation, Simple components, Language fig (abg.fig)
@comment  node-name,  next,  previous,  up
@subsubsection SS components
@cindex SS components

@iftex
$$

@end iftex


@code{SS} components provide input and output variables for a system;
Named SS components (@pxref{Named SS components}) provide this for
subsystems.

@node Simple components - implementation, Compound components, SS components, Language fig (abg.fig)
@comment  node-name,  next,  previous,  up
@subsubsection Simple components - implementation
@cindex  Simple components - implementation

Each simple component, with name NAME, is defined by two m files:
@ftable @code
@item NAME_cause.m
        defines the possible causal patterns for the component
@item NAME_eqn.m
        defines the equations generated 
@end ftable
Only the experienced user would normally define simple components -
Compound components (@pxref{Compound components}) are recommended for
DIY components.

@node Compound components, Named SS components, Simple components - implementation, Language fig (abg.fig)
@comment  node-name,  next,  previous,  up
@subsubsection Compound components
@cindex  Compound components
@cindex Named SS
Compound components are systems described by bond graphs and implemented
by MTT. They have special SS components, Named SS components
(@pxref{Named SS components}), to indicate connections to the
encapsulating system.

Like any other system, they are described by a graphical Bond Graph description
(@pxref{Language fig (abg.fig) }), and a label file (@pxref{Labels (lbl)}).

By convention, all of the files describing a component live in a
directory with the same name as the component.

@menu
* Named SS components::      
@end menu

@node Named SS components, Coerced bond direction, Compound components, Language fig (abg.fig)
@comment  node-name,  next,  previous,  up
@subsubsection Named SS components
@cindex Named SS components

Named SS components provide the link from the system which @emph{defines} 
compound component to the system which @emph{uses} a compound
component @pxref{Compound components}.
A named SS components is of the form
@code{SS:[name]};

Where `name' is a name consisting of alphanumeric characters and
underscore; for example:
@example
SS:[Mechanical_1]
@end example
Each such named SS provides one of the ports
(@pxref{Ports}).
The direction of the named SS components.
(@pxref{Named SS components}) 
is coerced (@pxref{Coerced bond direction}) to have the same direction
as the bond connected to the corresponding port. Thus the direction of
the  direction of the named SS components has no significance unless the
component is at the top level of a system.

If a named SS component exists at the top level (@pxref{Top level})
and is treated as an
ordinary SS component with the given direction and with the attributes
specified in the label file (@pxref{Labels (lbl)}).

@node Coerced bond direction, Port labels, Named SS components, Language fig (abg.fig)
@comment  node-name,  next,  previous,  up
@subsubsection Coerced bond direction
@cindex Coerced bond direction
@pindex Coerced bond direction
Named SS components (@pxref{Named SS components}) provide the mechanism
for declaring the ports (@pxref{Ports}) of a component. The
corresponding bond has a direction. However, under some circumstances,
it may be useful to reverse this direction. @strong{MTT} provides a
coercion mechanism for this: the the direction of the bond attached to
the named SS component (@pxref{Named SS components}) is replaced by the
direction of the bond attached to the component port.

@node Port labels, Vector port labels, Coerced bond direction, Language fig (abg.fig)
@comment  node-name,  next,  previous,  up
@subsubsection Port labels
@cindex ports
@pindex ports
Most multi-port components have ports 
@pxref{Ports})which display different
behaviors; the exception to this is the junction (@code{0} and @code{1})
components. For this reason, @strong{MTT} provides a method for unambiguously
identifying the ports of a multi-port component by port labels.

A port label is indicated by a name within parentheses of the form
@code{[name]}, where `name' is a name consisting of alphanumeric
characters and underscore; for example:
@example
[Mechanical_1]
@end example
This provides a label for corresponding to the component to which the
nearest bond-end is attached.

The following rules must be be obeyed:
@itemize @bullet
@item
If a component has any port labels at all, there must be one for each
port of the component.
@c @item
@c If a component is to be used repetitively (see @ref{components}), it
@c must have an even number of ports and the odd ports are connected to the
@c even points within the chain of components.
@end itemize

Port labels may be grouped into vector port labels (@pxref{Vector port
labels}). Components with compatible (ie containing the same number of ports)
vector ports may be connected by a @emph{single} bond
(@pxref{Bonds}); such a bond implies the corresponding number of bonds
(one for each element of the vector port label). All such bonds inherit
the same direction and any @emph{explicit} causal strokes (@pxref{strokes})

@node Vector port labels, Port label defaults, Port labels, Language fig (abg.fig)
@comment  node-name,  next,  previous,  up
@subsubsection Vector port labels
@cindex vector port labels
@cindex port labels
Port labels (@pxref{Port labels}) may be grouped into vector port
labels of the form @code{[name1,name2,name3]}. 
@example
[Mechanical_1,Electrical,Hydraulic_5]
@end example

@node Port label defaults, Vector components, Vector port labels, Language fig (abg.fig)
@comment  node-name,  next,  previous,  up
@subsubsection Port label defaults
@cindex Port label defaults
@pindex Port label defaults
Whether impicitly or explicity, all ports of components (with the
exception of 0 and 1 junctions) must have lables  (@pxref{Port
labels}). However, these can be omitted from the bond graph in the
following circumstances and default labels are supplied by @strong{MTT}.
@enumerate
@item A single unlabled inport defaults to [in]
@item A single unlabled outport defaults to [out]
@end enumerate

These defaults may, in turn be aliases (@pxref{Aliases}) for port labels
(@pxref{Port labels}) or vector port labels (@pxref{Vector port
labels}).  Combining the default and alias mechanism is a powerful tool
for creating uncluttered, yet complex, bond graph models.

@node Vector components, artwork, Port label defaults, Language fig (abg.fig)
@subsubsection Vector Components
@cindex Vector components
@pindex Vector components
Vectors of components can be created in four cases:
@code{0} junctions,
@code{1} junctions,
@code{SS} components and
@code{SS} port components.


In each case, the presence of a vector component is indicated by a
single port label  (@pxref{Port labels}) of one of two forms:
@enumerate
@item containing numerals from 1 to
the order of the vector. Thus a vector of 3 components is indicated by a
port label of the form [1,2,3].
@item  1: followed by
the order of the vector. Thus a vector of 3 components is indicated by a
port label of the form [1:3].
@end enumerate


Within the corresponding label file (@pxref{Labels (lbl)}), the
components of a vector port can be accessed using _i where i is the
corresponding index. Thus a port SS:[Electrical] appearing near the port
label  [1,2,3] could contain the port alias (@pxref{Port aliases})
@example
%ALIAS  in Electrical_1,Electrical_2,Electrical_3
@end example

@node artwork, Valid names, Vector components, Language fig (abg.fig)
@subsubsection Artwork
@cindex artwork
@pindex artwork
You are encouraged to annotate your bond graphs extensively - this makes
them an immediately readable document whilst retaining the precise and
unambiguous expressive power of the bond graph.

You may add any Fig (@pxref{Fig}) object to the bond graph as long as it
will not be interpreted as part of the bond graph.  
The reccommended way to acheive this is to put the  Bond Graph at depth
0,10,20 etc (ie depth modulo 10 is zero) and artwork at any other depth. 
@c  The recommended way to do this is to @emph{put all artwork at or below
@c  Depth 1} in the figure. @strong{MTT} ignores all objects not at depth 0.


For compatibility with earlier versions of @strong{MTT}, the following
objects are ignored even at level 0. However, their use is strongly
discouraged.
@itemize @bullet
@item
Adding text is OK as long as it cannot be confused with components
(@pxref{components}). In particular, you can include invalid component
characters such as white space, @code{"}, @code{'}, @code{!} etc.
@item
Adding boxes, arcs etc is always OK.
@item
Adding dotted or dashes lines is always OK.
@end itemize

The stripped abg file (sabg) (@pxref{Stripped acausal bond graph
(sabg)})
shows only those parts of the diagram recognised by @strong{MTT} and is
therefore useful for distinguishing artwork.
 
@node Valid names,  , artwork, Language fig (abg.fig)
@subsubsection Valid Names
@cindex valid name
@pindex valid name
A valid name is a text string containing alphanumeric characters.  It
must @strong{NOT} contain underscore @samp{_}, hyphen @samp{-}, @samp{:}
or @samp{*}.

The following reserved words in reduce should also be avoided (with any case)
@example

Commands ALGEBRAIC ANTISYMMETRIC ARRAY BYE CLEAR CLEARRULES COMMENT
CONT DECOMPOSE DEFINE DEPEND DISPLAY ED EDITDEF END EVEN FACTOR FOR
FORALL FOREACH GO GOTO IF IN INDEX INFIX INPUT INTEGER KORDER LET
LINEAR LISP LISTARGP LOAD LOAD PACKAGE MASS MATCH MATRIX MSHELL
NODEPEND NONCOM NONZERO NOSPUR ODD OFF ON OPERATOR ORDER OUT PAUSE
PRECEDENCE PRINT PRECISION PROCEDURE QUIT REAL REMFAC REMIND RETRY
RETURN SAVEAS SCALAR SETMOD SHARE SHOWTIME SHUT SPUR SYMBOLIC
SYMMETRIC VECDIM VECTOR WEIGHT WRITE WTLEVEL

Boolean Operators EVENP FIXP FREEOF NUMBERP ORDP PRIMEP

Infix Operators := = >= > <= < => + * / ^ ** . WHERE SETQ OR AND
MEMBER MEMQ EQUAL NEQ EQ GEQ GREATERP LEQ LESSP PLUS DIFFERENCE MINUS
TIMES QUOTIENT EXPT CONS Numerical Operators ABS ACOS ACOSH ACOT ACOTH
ACSC ACSCH ASEC ASECH ASIN ASINH ATAN ATANH ATAN2 COS COSH COT COTH
CSC CSCH EXP FACTORIAL FIX FLOOR HYPOT LN LOG LOGB LOG10 NEXTPRIME
ROUND SEC SECH SIN SINH SQRT TAN TANH

Prefix Operators APPEND ARGLENGTH CEILING COEFF COEFFN COFACTOR CONJ
DEG DEN DET DF DILOG EI EPS ERF FACTORIZE FIRST GCD G IMPART INT
INTERPOL LCM LCOF LENGTH LHS LINELENGTH LTERM MAINVAR MAT MATEIGEN MAX
MIN MKID NULLSPACE NUM PART PF PRECISION RANDOM RANDOM NEW SEED RANK
REDERR REDUCT REMAINDER REPART REST RESULTANT REVERSE RHS SECOND SET
SHOWRULES SIGN SOLVE STRUCTR SUB SUM THIRD TP TRACE VARNAME

Reserved Variables CARD NO E EVAL MODE FORT WIDTH HIGH POW I INFINITY
K!* LOW POW NIL PI ROOT MULTIPLICITY T

Switches ADJPREC ALGINT ALLBRANCH ALLFAC BFSPACE COMBINEEXPT
COMBINELOGS COMP COMPLEX CRAMER CREF DEFN DEMO DIV ECHO ERRCONT
EVALLHSEQP EXP EXPANDLOGS EZGCD FACTOR FORT FULLROOTS GCD IFACTOR INT
INTSTR LCM LIST LISTARGS MCD MODULAR MSG MULTIPLICITIES NAT NERO
NOSPLIT OUTPUT PERIOD PRECISE PRET PRI RAT RATARG RATIONAL RATIONALIZE
RATPRI REVPRI RLISP88 ROUNDALL ROUNDBF ROUNDED SAVESTRUCTR
SOLVESINGULAR TIME TRA TRFAC TRIGFORM TRINT

Other Reserved Ids BEGIN DO EXPR FEXPR INPUT LAMBDA LISP MACRO PRODUCT
REPEAT SMACRO SUM UNTIL WHEN WHILE WS


@end example



@node Language m (rbg.m), Language m (abg.m), Language fig (abg.fig), Acausal bond graph (abg)
@comment  node-name,  next,  previous,  up
@subsection Language m (rbg.m)
The raw bond graph of system `sys' is represented as
 an m file with heading:
@example
function [rbonds, rstrokes,rcomponents,rports,n_ports] = sys_rbg
@end example
This representation is a half-way house between the fig 
(@pxref{Language fig (abg.fig)}) and m 
(@pxref{Language m (abg.m)}) representations. It contains the
geometric information from the fig file in a form digestible by Octave
(@pxref{Octave}).

The five outputs of this function are:
@itemize @bullet
@item
rbonds
@item
rstrokes
@item
rcomponents
@item
rports
@item
n_ports
@end itemize

@emph{rbonds} is  a matrix with
@itemize @bullet
@item
one row for each bond (@pxref{bonds})
@item
columns 1 and 2 containing the x,y coordinates for one end of the bond
@item
columns 3 and 4 containing the x,y coordinates for the corner of the bond
@item
columns 5 and 6 containing the x,y coordinates for the other end of the bond
@end itemize

@emph{rstrokes} is  a matrix with (@pxref{strokes})
@itemize @bullet
@item
one row for each stroke or half-stroke
@item
columns 1 and 2 containing the x,y coordinates for one end of the stroke
@item
columns 3 and 4 containing the x,y coordinates for the other end of the stroke
@end itemize

@emph{rcomponents} is  a matrix with (@pxref{components})
@itemize @bullet
@item
one row for each component
@item
columns 1 and 2 containing the x,y coordinates of the component
@item
the remaining columns containing fig file information
@end itemize

@emph{rports} is  a matrix with (@pxref{Port labels})
@itemize @bullet
@item
one row for each component port that is explicitly labeled
@item
columns 1 and 2 containing the x,y coordinates of the port label
@item
column 3 contains the port number.
@end itemize

@emph{n_ports} is the number of ports associated with the system -- i.e. the
number of Named SS components (@pxref{Named SS components}).

@menu
* Transformation abg2rbg_fig2m::  
@end menu

@node Transformation abg2rbg_fig2m,  , Language m (rbg.m), Language m (rbg.m)
@comment  node-name,  next,  previous,  up
@subsubsection Transformation abg2rbg_fig2m
@cindex Transformation abg2rbg_fig2m

This transformation takes the acausal bond graph as a fig file 
(@pxref{Language fig (abg.fig)}) and transforms it into a raw bond graph in
m-file format (@pxref{Language m (rbg.m)}).

This transformation is implemented in GNU awk (gawk).
It scans both the fig file (@pxref{Language fig (abg.fig)})
and the label file (@pxref{Labels (lbl)}) and generates the rbg
 (@pxref{Language m (rbg.m)}) with components sorted according to the
label file.
It also generates a file sys_fig.fig containing details of the bond
graph with the components removed.


@node Language m (abg.m), Language tex (abg.tex), Language m (rbg.m), Acausal bond graph (abg)
@comment  node-name,  next,  previous,  up
@subsection Language m (abg.m)
@cindex Language m (abg.m) 
@cindex bonds
@cindex components
@cindex n_ports

The acausal bond graph of system `sys' is represented as
 an m file with heading:
@example
function [bonds,components,n_ports] = sys_abg
@end example
The three outputs of this function are:
@itemize @bullet
@item
bonds
@item
components
@item
n_ports
@end itemize

@emph{bonds} is  a matrix with
@itemize @bullet
@item
one row for each bond
@item
the first column contains the arrow-orientated 
(@pxref{Arrow-orientated causality}) 
causality of the @emph{effort} variable.
@item
the second column contains the arrow-orientated 
(@pxref{Arrow-orientated causality}) 
causality of the @emph{flow} variable.
@end itemize

@emph{components} is  a matrix with
@itemize @bullet
@item
one row for each component
@item
one column for each bond impinging on the component. The
@emph{magnitude} of each entry corresponds to the bond number (the
appropriate row index of` bonds'); the sign is positive if the bond
arrow points into the component and negative otherwise.
@end itemize

@emph{n_ports} is the number of ports associated with the system -- i.e. the
number of Named SS components (@pxref{Named SS components}).

@menu
* Arrow-orientated causality::  
* Component-orientated causality::  
* Transformation rbg2abg_m::    
@end menu

@node  Arrow-orientated causality, Component-orientated causality, Language m (abg.m), Language m (abg.m)
@comment  node-name,  next,  previous,  up
@subsubsection  Arrow-orientated causality
@cindex Arrow-orientated causality

The  arrow-orientated causality convention assigns -1, 0 or 1 
to both the effort and flow (@pxref{Variables}) sides of a bond 
to represent the causal stroke (@pxref{strokes})
as follows:
@vtable @code
@item 0
        if there is no causality set.
@item 1
       if the causal stroke is at the arrow end of the bond.
@item -1 
     if the causal stroke is at the other end of the bond.
@end vtable
@pxref{Component-orientated causality}.

@node  Component-orientated causality, Transformation rbg2abg_m, Arrow-orientated causality, Language m (abg.m)
@comment  node-name,  next,  previous,  up
@subsubsection  Component-orientated causality
@cindex Component-orientated causality

The  component-orientated causality convention assigns -1, 0 or 1 
to both the effort and flow (@pxref{Variables}) sides of a bond 
to represent the causal stroke (@pxref{strokes})
as follows:
@vtable @code
@item 0
        if there is no causality set.
@item 1 
      if the causal stroke is at the component end of the bond.
@item -1
      if the causal stroke is at the other end of the bond.

@end vtable
@pxref{Arrow-orientated causality}.

@node Transformation rbg2abg_m,  , Component-orientated causality, Language m (abg.m)
@comment  node-name,  next,  previous,  up
@subsubsection Transformation rbg2abg_m
@cindex Transformation rbg2abg_m
This transformation takes the raw bond graph and, by doing some
geometrical computation, determines the topology of the bond graph -- ie
what is close to what.

@node Language tex (abg.tex),  , Language m (abg.m), Acausal bond graph (abg)
@comment  node-name,  next,  previous,  up
@subsection Language tex (abg.tex)
@cindex Language tex (abg.tex)

For the purpose of producing a report (@pxref{Report}), @strong{MTT}
generates a LaTeX (@pxref{LaTeX}) file describing the bond graph and its
subsystems. Additional information may be supplied using the description
representation (@pxref{Description (desc)}).

@c      node   next  prev  up
@node   Stripped acausal bond graph (sabg), Labels (lbl), Acausal bond graph (abg), Representations
@section Stripped acausal bond graph (sabg)
@cindex Stripped acausal bond graph (sabg)
@pindex Stripped acausal bond graph (sabg)
The stripped acausal bond graph is the acausal bond graph representation
(@pxref{Acausal bond graph (abg)}) without the artwork
(@pxref{artwork}). It is useful to check for mistakes by showing
precisely what is recognised by @strong{MTT}.

@menu
* Language fig (sabg.fig)::     
* Stripped acausal bond graph (view)::  
@end menu

@node Language fig (sabg.fig), Stripped acausal bond graph (view), Stripped acausal bond graph (sabg), Stripped acausal bond graph (sabg)
@subsection Language fig (sabg.fig) 
@cindex Language fig (sabg.fig) 
@pindex Language fig (sabg.fig) 
The stripped acausal bond graph can be generated as a fig (@pxref{Fig})
file using
@example
mtt syst sabg fig
@end example

@node Stripped acausal bond graph (view),  , Language fig (sabg.fig), Stripped acausal bond graph (sabg)
@subsection Stripped acausal bond graph (view)
@cindex Language m (view)
@cindex view  Constrained-state Equations
This representation has the standard text view
(@pxref{Views}).


@node Labels (lbl), Description (desc), Stripped acausal bond graph (sabg), Representations
@comment  node-name,  next,  previous,  up
@section Labels (lbl)
@cindex Labels
@cindex lbl
Bond graph components have optional labels. These provide pointers to
further information relating to the component; this avoids clutter on
the bond graph.

The label file contains the following non-blank lines (blank lines are ignored)
@itemize @bullet
@item Summary - lines beginning with %SUMMARY
@item Description - lines beginning with %DESCRIPTION
@item Alias - lines beginning with %ALIAS
@item Comments - lines beginning with % 
@item Labels - other non-blank lines
@end itemize

Each lable contains three fields (in the following order) separated by
white space and on one line:
@enumerate
@item The component name @pxref{Component names}. This must be a valid
name  (@pxref{Valid names}.
@item The component constitutive relationship @pxref{Component constitutive relationship}
@item The component arguments @pxref{Component arguments}
@end enumerate

Not each component @pxref{components} needs a label, only those which are explicitly
labeled on the Bond Graph @pxref{Acausal bond graph (abg)}.
@strong{MTT} checks whether all  components labelled on the bond graph
have labels and vice versa.

If no lbl file exists, @strong{MTT} will create a valid one for you;
including a default set of arguments and crs for both simplae and
compound components.

If wish to create one to edit yourself, type
@example
mtt system_name lbl txt
@end example
An example lbl file (for the RC system is):
@example
%% Label file for system RC (RC_lbl.txt)
%SUMMARY RC
%DESCRIPTION <Detailed description here>
% Port aliases
%ALIAS  in      in
%ALIAS  out     out

% Argument aliases
%ALIAS  $1      c
%ALIAS  $2      r

%% Each line should be of one of the following forms:
%            a comment (ie starting with %)
%            component-name     cr_name arg1,arg2,..argn
%            blank

% ---- Component labels ----

% Component type C
        c               lin     effort,c

% Component type R
        r               lin     flow,r

% Component type SS
        [in]    SS              external,external
        [out]   SS              external,external

@end example


The old-style lbl files (@pxref{Old-style labels (lbl)}) are NO LONGER
supported -- you are encouraged to convert them ASAP.

@menu
* SS component labels ::        
* Other component labels ::     
* Component names::             
* Component constitutive relationship::  
* Component arguments::         
* Parameter declarations::      
* Units declarations::          
* Interface Control Definition::  
* Aliases::                     
* Parameter passing::           
* Old-style labels (lbl)::      
@end menu

@node SS component labels , Other component labels , Labels (lbl), Labels (lbl)
@comment  node-name,  next,  previous,  up
@subsection SS component labels 
@cindex SS component labels 
In addition to the label there are two information fields, @pxref{Labels
(lbl)}. The first must be `SS', the second contains two information
fields of the form info_field_1,info_field_2.

These two information
fields correspond to the effort and flow variables of the of the SS components as follows
@vtable @code
@item info_field_1
        effort
@item info_field_2
        flow
@end vtable
Each of these two fields contains one of the following @emph{attributes}:
@vtable @code
@item external
        indicates that the corresponding variable is a system input or
output
@item internal
        indicates that the variable does not appear as a system output;
        it is an error to label an input in this way.
@item a number
        the value of the input; or the value of the (imposed) output
@item a symbol
        the symbolic value of the input; or the value of the (imposed) output
@item unknown
        used for the SS method of solving algebraic loops. This
        indicates that the corresponding system input (SS output) is to
        be chosen to set the corresponding system output (SS input) to zero.
@item zero
        used for the SS method of solving algebraic loops. This
        indicates that the corresponding system output (SS input) is to
        be set to zero using the variable indicted by the corresponding
        `unknown' label.
@end vtable

Some examples are:
@example
%% ss1 is both a source and sensor
ss1     SS              external,external
%% ss1 acts as a flow sensor - it imposes zero effort.
ss2     SS              0,external
@end example


@node Other component labels , Component names, SS component labels , Labels (lbl)
@comment  node-name,  next,  previous,  up
@subsection Other component labels 
@cindex Other component labels 

In addition to the label there are two information fields,
@pxref{Labels (lbl)}.
They correspond to the constitutive relationship 
(see @pxref{Constitutive relationship} and arguments of the
component as follows
@vtable @code
@item info_field_1
        constitutive relationship 
@item info_field_2
        parameters
@end vtable

Some examples are:
@example
%Armature resistance
r_a     lin     effort,r_a

%Gearbox ratio
n       lin     effort,n
@end example

@strong{MTT} supports parameter-passing to  (@pxref{Parameter passing })
subsystems.

@menu
* Component names::             
* Component constitutive relationship::  
* Component arguments::         
* Aliases::                     
* Parameter passing::           
* Old-style labels (lbl)::      
@end menu

@node Component names, Component constitutive relationship, Other component labels , Labels (lbl)
@comment  node-name,  next,  previous,  up
@subsection Component names
@cindex  Component names
The component name field must contain a valid name  (@pxref{Valid names} corresponding to the
name (the bit after the :) of each named component (@pxref{components})
on  the bond graph (@pxref{Acausal bond graph (abg)}).

@node Component constitutive relationship, Component arguments, Component names, Labels (lbl)
@comment  node-name,  next,  previous,  up
@subsection Component constitutive relationship
@cindex  Component constitutive relationship
The constitutive relationship field contains the name of a constitutive
relationship for the component. There are three sorts of constitutive
relationship recognised by @strong{MTT}:
@enumerate
@item A generic constitutive relationship such as @var{lin} (the generic
linear constitutive relationship.
@item A local constitutive relationship with the same name as the
component type
@item The @var{SS} constitutive relationship reserved for @var{SS}
components.
All labels for @var{SS} components must contain SS in this field.
@end enumerate


@node Component arguments, Parameter declarations, Component constitutive relationship, Labels (lbl)
@comment  node-name,  next,  previous,  up
@subsection Component arguments
@cindex  Component arguments

@node Parameter declarations, Units declarations, Component arguments, Labels (lbl)
@comment  node-name,  next,  previous,  up
@subsection Parameter declarations
@cindex parameter declarations
@pindex parameter declarations
@pindex PAR 
@pindex NOTPAR 
@pindex VAR 
@pindex NOTVAR 

It is sometimes useful to use parameters (in addition to those implied by
the Component arguments @pxref{Component arguments}) to compute values
in, for example the numpar file. These can be declared in the label
file;
for examples , the two parameters par1 and par 2 can be declared as:
@example
#PAR par1
#PAR par2
@end example

On the other hand, some CR arguments (eg foo and bar) may not correspond to
parameters. These can be excluded from the sympar list  using
the NOTPAR declaration
@example
#NOTPAR foo
#NOTPAR bar
@end example

For comapability with old code, VAR may be used in place of PAR, but
this usage is deprecated.

@node Units declarations, Interface Control Definition, Parameter declarations, Labels (lbl)
@comment  node-name,  next,  previous,  up
@subsection Units declarations
@cindex units declarations
@pindex units declarations
@pindex UNITS
The units and domains of ports (@pxref{Ports}) are declared as:
@example
#UNITS Port_name domain effort_units flow_units
@end example
where "Port_name" is the name of the port, domain is one of:
@vtable @code
@item electrical
         the electrical domain
@item translational
         the translational mechanical domain
@item rotational
         the rotational mechanical domain
@item fluid
         the fluid domain
@item thermal
         the thermal domain 
@end vtable
and effort_units and flow_units are corresponding units for the effort
and the flow.

Allowed units are those defined in the @strong{units} package.



@strong{MTT} checks that units are 
@itemize  @bullet
@item defined consistently with the domain
@item the same for connected ports when both ports have defined units.
@end itemize
No checks are done if one or both ends of a bond are not connected to a
port with defined units.



@node Interface Control Definition, Aliases, Units declarations, Labels (lbl)
@comment  node-name,  next,  previous,  up
@subsection Interface Control Definition
@cindex ICD (label file directive)
It is sometimes useful to be able to automatically generate a set of 
assignments mapping @strong{MTT} inputs and outputs to an external interface
definition. This can be achieved with use of the @emph{#ICD} directive.

@example
#ICD    PressureSensor		PUMP1_PRESSURE_SENSOR,Pa;null,none
#ICD    Electrical		PUMP1_VOLTAGE,volt;PUMP1_CURRENT,amp

% Component type De
	PressureSensor	SS      external

% Component type SS
	Electrical	SS	external,external
@end example


The ICD directive consists of 3 whitespace delimited fields:

@enumerate
@item [%|#]ICD
@item component name
@item Four comma (,) or semi-colon (;) delimited fields:

@enumerate
@item name of effort parameter
@item unit of effort parameter
@item name of flow parameter
@item unit of flow parameter
@end enumerate
@end enumerate

If no parameter name is required, a value of "null" should be used.
If the parameter does not have any units, a value of "none" should be used.

ICD parameters may be aliased @pxref{Aliases} in the same way as normal
parameters, thus it is possible to define some or all of the ICD in higher
level components.

The command

@example
mtt sys ICD txt
@end example

will generate a text file containing a list of mappings:

@example
## Interface Control Definition for System sys
## sys_ICD.txt: Generated by MTT Thu Jul 12 21:21:21 CDT 2001

Input:  PUMP1_VOLTAGE           sys_P1_1_Electrical      Causality: Effort   Units: volt
Output: PUMP1_CURRENT           sys_P1_1_Electrical      Causality: Flow     Units: amp
Output: PUMP1_PRESSURE_SENSOR   sys_P1_1_PressureSensor  Causality: Effort   Units: Pa
@end example

A set of assignments can be generated with the command
@example
mtt sys ICD m
@end example

resulting in:

@example
# Interface Control Definition mappings for system sys
# sys_ICD.m: Generated by MTT Thu Jul 12 21:26:56 CDT 2001

# Inputs

        mttu(1) = PUMP1_VOLTAGE;

# Outputs

        PUMP1_CURRENT                  = mtty(1);
        PUMP1_PRESSURE_SENSOR          = mtty(2);
@end example

A similar file will be generated by the command
@example
mtt sys ICD cc
@end example



@node Aliases, Parameter passing, Interface Control Definition, Labels (lbl)
@comment  node-name,  next,  previous,  up
@subsection Aliases
@cindex aliases
@pindex aliases

Aliases provide a convenient mechanism for relabelling words appearing
in the label file (@pxref{Labels (lbl)}). There are three contexts in
which the alias mechanism is used:

@enumerate
@item renaming ports (@pxref{Port aliases}),
@item renaming parameters (@pxref{Parameter aliases}) and
@item renaming components (@pxref{Component aliases}).
@end enumerate

All three mechanisms use the same form of statement within the label
file
@example
%ALIAS short_label       real_label
@end example

@strong{MTT} distinguishes between the three forms as follows:

@itemize @bullet
@item Parameter aliases: `short_label' starts with a `$'
@item Component aliases: `real_label' contains the directory separator
`/'
@item Port aliases: neither of the above
@end itemize

@menu
* Port aliases::                
* Parameter aliases::           
* CR aliases::                  
* Component aliases::           
@end menu


@node Port aliases, Parameter aliases, Aliases, Aliases
@comment  node-name,  next,  previous,  up
@subsubsection Port aliases
@cindex port aliases
@pindex port aliases
Aliases provide a way of refering to (@pxref{Port labels}) or vector port labels (@pxref{Vector
port labels}) on the bond graph using a short-hand notation. With in a
component label file (@pxref{Labels (lbl)}) statements of the following
forms can occur 

@example
%ALIAS short_label       real_label
@end example

When the component is used within another component, the short_lable may
be used in place of the real_label.
More than one alias per label can be used, for example

@example
%ALIAS short_label_1       real_label
%ALIAS short_label_2       real_label
%ALIAS short_label_3       real_label
@end example

The port can then be refered to in four ways: as real_label,
short_label_1, short_label_2 or short_label_3.
An alternative notation for the ALIAS statement in this case is

@example
%ALIAS short_label_1|short_label_2|short_label_3       real_label
@end example

The alias feature is particularly powerful in conjunction with vector
port labels (@pxref{Vector port labels}) and the port label default 
(@pxref{Port label defaults}) mechanisms. For example, a component with
5 ports appearing in the lbl file as:

@example
        [Hydraulic_in]  external        external
        [Hydraulic_out] external        external
        [Power_Shaft]           external        external
        [Thermal_in]    external        external
        [Thermal_out]   external        external
@end example

together with the following statements in the label file:

@example
%ALIAS  in              Thermal_in,Hyydraulic_in
%ALIAS  out             Thermal_out,Hydraulic_out
%ALIAS  shaft|power     Power_Shaft
@end example

can appear in the bond graph containing that component with one bond
labeled either [shaft] or [power] or [Power_Shaft], one unlabeled vector
bond pointing in and one unlabeled vector bond pointing out.

@node Parameter aliases, CR aliases, Port aliases, Aliases
@comment  node-name,  next,  previous,  up
@subsubsection Parameter aliases
@cindex parameter aliases
@pindex parameter aliases

Parameter aliases are of the form
@example
%ALIAS $n       actual parameter
@end example
where n is an integer (unique within the label file).
For example

@example
%ALIAS  $1              c_v
%ALIAS  $2              density,ideal_gas,r
%ALIAS  $3              alpha
%ALIAS  $4              flow,k_p
@end example

Assigns four symbolic parameters to the corresponding strings These four
parameters (@code{$1}--@code{$4}) can then be used for parameter
passing(@pxref{Parameter passing}).

@node CR aliases, Component aliases, Parameter aliases, Aliases
@comment  node-name,  next,  previous,  up
@subsubsection CR aliases
@cindex CR aliases
@pindex CR aliases

CR aliases are of the form
@example
%ALIAS $an       actual parameter
@end example
where n is an integer (unique within the label file).
For example
@example
%ALIAS  $a1  lin           
@end example
assigns the symbolic parameter to be lin. This parameter @code{$1} can
then be used for passing a diofferent cr to the
component (@pxref{Parameter passing}).

@node Component aliases,  , CR aliases, Aliases
@comment  node-name,  next,  previous,  up
@subsubsection Component aliases
@cindex component aliases
@pindex component aliases

Component aliases are of the form
@example
%ALIAS Component_name   Component_location       
@end example

An example appears in the following label file fragment
@example
...
%ALIAS  wPipe   CompressibleFlow/wPipe
%ALIAS  Poly    CompressibleFlow/Poly
....

@end example
The two components `wPipe' and `Poly' are both to be found within the
library `Compressible flow' and the respective subdirectories. This
follows the @strong{MTT} convention that compound components
(@pxref{Compound components}) live within a directory of the same name.
 

@node Parameter passing, Old-style labels (lbl), Aliases, Labels (lbl)
@comment  node-name,  next,  previous,  up
@subsection Parameter passing
@cindex Parameter passing
@strong{MTT} supports parameter-passing to subsystems within label files
(@pxref{Labels (lbl)}). Within a subsystem, explicit constitutive
relationships and parameters (or groups thereof) can be replaced by
postitional parameters such as @code{$1}, @code{$2} etc.  Although this
can be done directly, it is recommended that this is done via the alias
mechanism (@pxref{Parameter aliases}).

In a subsystem
@code{$i}, is replaced by the ith field of a colon @code{;} separated
field in the calling label file. This field may include commas @code{,}
and the four arithmetic operators @code{+}, @code{-}, @code{*} and
@code{/}.

For example, consider the following example label file fragment (associated with a
component called Pump:
@example
...

%ALIAS  $1              c_v
%ALIAS  $2              density,ideal_gas,r
%ALIAS  $3              alpha
%ALIAS  $4              flow,k_p

%ALIAS  wPipe   CompressibleFlow/wPipe
%ALIAS  Poly    CompressibleFlow/Poly

% Component type wPipe
        pipe    none                    c_v;density,ideal_gas,r

% Component type Poly
        poly            Poly            alpha

@end example

The 4 parameters @code{$1}, @code{$2}, @code{$3}, and @code{$4} can be
passed from a higher level component as in the following label file
fragment:

@example
% Component type Pump
        comp            none            c_v;rho,ideal_gas,r;alpha;effort,k_c
        turb            none            c_v;rho,ideal_gas,r;alpha;effort,k_t
@end example

Thus in component `comp':
@itemize @bullet
@item @code{$1} is replaced by c_v
@item @code{$2} is replaced by rho,ideal_gas
@item @code{$3} is replaced by alpha
@item @code{$4} is replaced by effort,k_c
@end itemize
whereas in component `turb' the first three parameters are the same but
@itemize @bullet
@item @code{$4} is replaced by effort,k_t
@end itemize



@node Old-style labels (lbl),  , Parameter passing, Labels (lbl)
@comment  node-name,  next,  previous,  up
@subsection Old-style labels (lbl)
@cindex Old-style labels
@cindex lbl

Old syle labels (mtt version 2.x) are supported by mtt version
3.x. However, you are advised to use the new form (@pxref{Labels
(lbl)}).

Each line of the @code{_label.txt} file is of one of three forms:
@enumerate
@item
Contains three fields (separated by white space) of the form
@example
label   field_1   field_2
@end example
@item
Blank
@item
Preceded by %
@end enumerate
Only the first is noticed by @strong{MTT}; the second and third are for
providing helpful commenting.

The role of the two information fields depends on the component with the
corresponding label. In particular the classes of components are:
@itemize @bullet
@item
SS components, @pxref{SS components}.
@item
Other components,  @pxref{components}.
@end itemize
Named SS component, @pxref{Named SS components} never have labels.
@menu
* SS component labels (old-style)::  
* Other component labels (old-style)::  
* Parameter passing (old-style)::  
@end menu


@node SS component labels (old-style), Other component labels (old-style), Old-style labels (lbl), Old-style labels (lbl)
@comment  node-name,  next,  previous,  up
@subsubsection SS component labels (old-style)
@cindex SS component labels (old-style)
In addition to the label there are two information fields,
@pxref{Labels (lbl)}.
They correspond to the effort and flow of the components as follows
@vtable @code
@item info_field_1
        effort
@item info_field_2
        flow
@end vtable
Each of these two fields contains one of the following @emph{attributes}:
@vtable @code
@item
external
        indicates that the corresponding variable is a system input or
output
@item internal
        indicates that the variable does not appear as a system output;
        it is an error to label an input in this way.
@item a number
        the value of the input; or the value of the (imposed) output
@item a symbol
        the symbolic value of the input; or the value of the (imposed) output
@item unknown
        used for the SS method of solving algebraic loops. This
        indicates that the corresponding system input (SS output) is to
        be chosen to set the corresponding system output (SS input) to zero.
@item zero
        used for the SS method of solving algebraic loops. This
        indicates that the corresponding system output (SS input) is to
        be set to zero using the variable indicted by the corresponding
        `unknown' label.
@end vtable

Some examples are:
@example
%Label  field1          field2
ss1     external        external
ss2     0               external
@end example


@node Other component labels (old-style), Parameter passing (old-style), SS component labels (old-style), Old-style labels (lbl)
@comment  node-name,  next,  previous,  up
@subsubsection Other component labels (old-style)
@cindex Other component labels (old-style)

In addition to the label there are two information fields,
@pxref{Labels (lbl)}.
They correspond to the constitutive relationship 
(see @pxref{Constitutive relationship} and arguments of the
component as follows
@vtable @code
@item info_field_1
        constitutive relationship 
@item info_field_2
        parameters
@end vtable

Some examples are:
@example
%Armature resistance
r_a     lin     effort,r_a

%Gearbox ratio
n       lin     effort,n
@end example

@strong{MTT} supports parameter-passing to  (@pxref{Parameter passing (old-style)})
subsystems.


@node Parameter passing (old-style),  , Other component labels (old-style), Old-style labels (lbl)
@comment  node-name,  next,  previous,  up
@subsubsection Parameter passing (old-style)
@cindex Parameter passing (old-style)
@strong{MTT} supports parameter-passing to  (@pxref{Parameter passing (old-style)})
subsystems within label files (@pxref{Labels (lbl)}). Within a subsystem,
explicit constitutive relationships and parameters (or groups thereof)
can be replaced by 
@code{$1}, @code{$2}, etc.

In a subsystem
@code{$i}, is replaced by the ith field of a colon @code{;} separated
field in the calling label file. This field may include commas @code{,}.

For example subsystem ROD contains the following lines in the label
file:
@example

%DESCRIPTION    Parameter 1:    length from end 1 to mass centre
%DESCRIPTION    Parameter 2:    length from end 2 to mass centre
%DESCRIPTION    Parameter 3:    inertia about mass centre
%DESCRIPTION    Parameter 4:    mass
%DESCRIPTION    See Section 10.2 of "Metamodelling"


%Inertias
J       lin     flow,$3
m_x     lin     flow,$4
m_y     lin     flow,$4

%Integrate angular velocity to get angle
th

%Modulated transformers
s1      lsin    flow,$1
s2      lsin    flow,$2
c1      lcos    flow,$1
c2      lcos    flow,$2

@end example

This can be used in a higher-level lbl (@pxref{Labels (lbl)}) file as:
@example
%SUMMARY Pendulum example from Section 10.3 of "Metamodelling"

%Rod parameters
rod     none    l;l;j;m

@end example

@node Description (desc), Structure (struc), Labels (lbl), Representations
@comment  node-name,  next,  previous,  up
@section Description (desc)
@cindex Description
@cindex desc

The bond graph can be described textually in LaTeX (.tex) description
file; this is the only language for this representation. This
representation is used by the LaTeX language version (@pxref{Language tex
(abg.tex)}) of the acausal bond graph representation (@pxref{Acausal
bond graph (abg)}).

@menu
* Language tex (desc.tex)::     
@end menu

@node Language tex (desc.tex),  , Description (desc), Description (desc)
@comment  node-name,  next,  previous,  up
@subsection Language tex (desc.tex)
@cindex Language tex (desc.tex)
This file may contain any LaTeX compatible commands. Any mathematics
should conform to the AMSmath package.

@node Structure (struc), Constitutive Relationship (cr), Description (desc), Representations
@comment  node-name,  next,  previous,  up
@section Structure (struc)
@cindex Structure
@cindex struc

The causal bond graph implies a set of equations describing the
system. The Structure (struc) representation describes the structure of
these equations in terms of the input, outputs, states and non-states of
the system.

@menu
* Language txt (struc.txt)::    
* Language tex (struc.tex)::    
* Structure (view)::            
@end menu

@node Language txt (struc.txt), Language tex (struc.tex), Structure (struc), Structure (struc)
@comment  node-name,  next,  previous,  up
@subsection Language txt (struc.txt)
@cindex Language txt (struc.txt)
This text tile contains a description of the system structure
(@pxref{Structure (struc)} with 5 tab-separated columns containing the
following information:
@vtable @code
@item type
        input, output state or nonstate
@item   
index
        an integer corresponding to the array index
@item 
component name
        the name of the component corresponding to the variable
@item system name
        the name of the system containing the component
@item repetition
        an integer corresponding to the repetition of a repeated subsystem.
@end vtable

An example of such a file (corresponding to rc) (@pxref{Quick start}) is:
@example
input           1       e1      rc      1
output          1       e2      rc      1
state           1       c       rc      1
@end example


@node Language tex (struc.tex), Structure (view), Language txt (struc.txt), Structure (struc)
@comment  node-name,  next,  previous,  up
@subsection Language tex (struc.tex)
@cindex Language tex (struc.tex)
This LaTeX  (@pxref{LaTeX}) file contains  a description of the system structure
(@pxref{Structure (struc)} in @code{longtable} format. It is a useful
item to include in a report(@pxref{Report}).

@node Structure (view),  , Language tex (struc.tex), Structure (struc)
@subsection Language tex (view)
@cindex Structure (view)
@cindex view Structure
This representation has the standard text view
(@pxref{Views}).

@node Constitutive Relationship (cr), Parameters, Structure (struc), Representations
@comment  node-name,  next,  previous,  up
@section Constitutive relationship (cr)
@cindex Constitutive relationship

The constitutive relationship (@pxref{Constitutive relationship})
of a simple component (@pxref{Simple components} is
defined in the symbolic algebra language Reduce (@pxref{Reduce}).
The constitutive relationship of a compound components 
(@pxref{Compound components})
is implied by the constitutive relationships of its constituent components.

@menu
* Predefined constitutive relationships::  
* DIY constitutive relationships::  
* Unresolved constitutive relationships::  
* Unresolved constitutive relationships - Octave::  
* Unresolved constitutive relationships - c++::  
@end menu

@node Predefined constitutive relationships, DIY constitutive relationships, Constitutive Relationship (cr), Constitutive Relationship (cr)
@comment  node-name,  next,  previous,  up
@subsection  Predefined constitutive relationships
@cindex Predefined constitutive relationships

Some common cr's are predefined by MTT; these are:
@vtable @code
@item lin
        a linear constitutive relationship   
@item exotherm
        an exothermic reaction
@end vtable

@menu
* lin::                         
* exotherm::                    
@end menu

@node lin, exotherm, Predefined constitutive relationships, Predefined constitutive relationships
@comment  node-name,  next,  previous,  up
@subsubsection lin
@findex lin
The constitutive relationship @code{lin} is predefined for the following
components.
@vtable @code
@item R
        (one-port) R component
@item TF
        transformer
@item GY
        gyrator
@item MTF
        modulated transformer
@item MGY
        modulated gyrator
@item FMR
        flow-modulated resistor
@end vtable
Lin takes two arguments in the form causality,gain
@vtable @code
@item causality
        the causality (effort or flow) of the @emph{input} to the
constitutive relationship
@item gain
        the gain of the component when the input causality is as
specified in the first argument.
@end vtable
For example the arguments
@example
flow,r
@end example
given to an R component corresponds to
@example
e = rf
@end example
if if the input causality is flow
or
@example
f = e/r
@end example
if if the input causality is effort.

@node exotherm,  , lin, Predefined constitutive relationships
@comment  node-name,  next,  previous,  up
@subsubsection exotherm
@findex exotherm

@node DIY constitutive relationships, Unresolved constitutive relationships, Predefined constitutive relationships, Constitutive Relationship (cr)
@comment  node-name,  next,  previous,  up
@subsection  DIY constitutive relationships
@cindex DIY constitutive relationships
You can write your own constitutive relationships using Reduce
(@pxref{Reduce}). This requires some understanding as to how
@strong{MTT} represent the elementary system equations
(@pxref{Elementary system equations}). Looking at the predefined
constitutive relationships is a good way to get started
(@pxref{File structure}).

@node Unresolved constitutive relationships, Unresolved constitutive relationships - Octave, DIY constitutive relationships, Constitutive Relationship (cr)
@subsection Unresolved constitutive relationships
@cindex Unresolved constitutive relationships

Consider the following CR file.
@example
FOR ALL rho,g,vol,h,topt,bott,flowin,press
LET tktf2(rho,g,vol,h,topt,bott,effort,2,press,effort,1)
        = tank(rho,g,vol,h,topt,bott,press);      
@end example
Assuming that `tank' is not defined in a
reduce file, MTT will leave it unresolved when generating m or c code.

The resulting function can then be expressed as octave
(@pxref{Unresolved constitutive relationships - Octave}) or c++ code as
(@pxref{Unresolved constitutive relationships - c++}) appropriate.

@node Unresolved constitutive relationships - Octave, Unresolved constitutive relationships - c++, Unresolved constitutive relationships, Constitutive Relationship (cr)
@subsection  Unresolved constitutive relationships - Octave
@cindex Unresolved constitutive relationships - Octave
Following the example of the previous section, the unresolved CR `tank'
can be expressed as an Octave m-file. For example:
@example
function p = tank (rho,g,vol,h,topt,bott,press)

  ## usage:  p = tank (vol,h,topt,bott,press)
  ##
  ## 

   val = press; zt = topt; zb = bott; 
   zval = 0.5*(abs(zb+(zt-zb)*val-h)+(zb+(zt-zb)*val-h));

   p = rho*g*zval + 0.5*(1+tanh((press-0.98)*500))*100000;

endfunction
@end example
This will be automatically loaded into octave.

@node Unresolved constitutive relationships - c++,  , Unresolved constitutive relationships - Octave, Constitutive Relationship (cr)
@subsection  Unresolved constitutive relationships - c++
@cindex Unresolved constitutive relationships - Octave
Following the example of the previous section, the unresolved CR `tank'
can be expressed in c++ code. For example:
@example
inline double tank(const double rho, 
		   const double g, 
		   const double vol, 
		   const double h, 
		   const double topt, 
		   const double bott, 
		   const double press)


  /*  ## usage:  p = tank (vol,h,topt,bott,press)
    ##
    ##
  */
  double p, val, zval, zt, zb;

  val = press;
  zt = topt;
  zb = bott;
  zval = 0.5 * (abs(zb + (zt - zb) * val - h) + zb + (zt - zb) * val - h);

  p = rho * g * zval + 0.5 * (1 + tanh((press - 0.98) * 500)) * 100000L;

  return p;

@end example

To make sure that this is used in system `model', the model_cr.h file
must be as follows:
@example
// CR headers for system model
#include "tank.c"
@end example

@node Parameters, Causal bond graph (cbg), Constitutive Relationship (cr), Representations
@comment  node-name,  next,  previous,  up
@section Parameters
@cindex Parameters

In general, lbl (@pxref{Labels (lbl)}) files contain symbolic
parameters. @strong{MTT} provides three ways of substituting for these
parameters:
@itemize @bullet
@item
symbolic substitution
@item
symbolic substitution for simplification of displayed equations
@item
numeric
@end itemize

@menu
* Symbolic parameters (subs.r)::  
* Symbolic parameters for simplification (simp.r)::  
* Numeric parameters (numpar)::  
@end menu

@node Symbolic parameters (subs.r), Symbolic parameters for simplification (simp.r), Parameters, Parameters
@comment  node-name,  next,  previous,  up
@subsection Symbolic parameters (subs.r)
@cindex  Symbolic parameters
@vindex subs.r
This file contains reduce statements to symbolically change the
expressions describing the system.
For example, a useful set of trig substitutions is:
@example
LET cos(~x)*cos(~y) = (cos(x+y)+cos(x-y))/2;
LET cos(~x)*sin(~y) = (sin(x+y)-sin(x-y))/2;
LET sin(~x)*sin(~y) = (cos(x-y)-cos(x+y))/2;
LET cos(~x)^2       = (1+cos(2*x))/2;
LET sin(~x)^2       = (1-cos(2*x));
@end example

@node Symbolic parameters for simplification (simp.r), Numeric parameters (numpar), Symbolic parameters (subs.r), Parameters
@comment  node-name,  next,  previous,  up
@subsection Symbolic parameters for simplification  (simp.r)
@cindex  Symbolic parameters for simplification 
@vindex simp.r
This file contains reduce statements to symbolically change the
expressions describing the system. Unlike the subs.r file
(@pxref{Symbolic parameters (subs.r)}) it does not affect all system
transformations; only those converting to LaTeX form.

@node Numeric parameters (numpar),  , Symbolic parameters for simplification (simp.r), Parameters
@comment  node-name,  next,  previous,  up
@subsection Numeric parameters (numpar)
@cindex  Numeric parameters

When computing time and frequency responses; or when evaluating
functions in Octave (@pxref{Octave}); symbolic parameters need numerical
instantiations. 

The numpar representation provides the relevant @emph{numerical}
information. It comes in a number of languages:
@ftable @code
@item txt
        a textual description of the parameter values -- this is the
defining representation (@pxref{Defining representations}).
@item m
        readable by @code{octave} a high-level interactive language for numerical
        computation -- translated by @strong{mtt} from the txt version.
@item c
        readable by @code{gcc} a c compiler -- translated by @strong{mtt} from the txt version.

@end ftable

@menu
* Text form (numpar.txt)::      
@end menu

@node Text form (numpar.txt),  , Numeric parameters (numpar), Numeric parameters (numpar)
@comment  node-name,  next,  previous,  up
@subsubsection Text form (numpar.txt)
@cindex  Numeric parameters
This is the textual form of the numerical parameters representation
(@pxref{Numeric parameters (numpar)}). Lines are either
@ftable @code
@item assignment statements
        variable = value
@item comments
        lines beginning with #
@item commented assignment statements
        variable = value # comments
@end ftable
An example file is:
@example
# Numerical parameter file (rc_numpar.txt)
# Generated by MTT at Mon Jun 16 15:10:17 BST 1997

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% Version control history
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% $Id$
# %% $Log$
# %% Revision 1.6  2001/10/15 14:29:50  gawthrop
# %% Added documentaton on  [1:N] style port labels
# %%
# %% Revision 1.5  2001/07/23 03:35:29  geraint
# %% Updated file structure (mtt/bin).
# %%
# %% Revision 1.4  2001/07/23 03:25:02  geraint
# %% Added notes on -ae hybrd, rk4, ode2odes.cc, .oct dependencies.
# %%
# %% Revision 1.3  2001/07/13 03:02:38  geraint
# %% Added notes on #ICD, gnuplot.txt and odes.sg rep.
# %%
# %% Revision 1.2  2001/07/03 22:59:10  gawthrop
# %% Fixed problems with argument passing for CRs
# %%
# %% Revision 1.1  2001/06/04 08:18:52  gawthrop
# %% Putting documentation under CVS
# %%
# %% Revision 1.66  2000/12/05 14:20:55  peterg
# %% Added the c++  anf m CR info.
# %%
# %% Revision 1.65  2000/11/27 15:36:15  peterg
# %% NOPAR --> NOTPAR
# %%
# %% Revision 1.64  2000/11/16 14:22:48  peterg
# %% added UNITS declaration
# %%
# %% Revision 1.63  2000/11/03 14:41:08  peterg
# %% Added PAR and NOTPAR stuff
# %%
# %% Revision 1.62  2000/10/17 17:53:34  peterg
# %% Added some simulation details
# %%
# %% Revision 1.61  2000/09/14 17:13:06  peterg
# %% New options table
# %%
# %% Revision 1.60  2000/09/14 17:09:20  peterg
# %% Tidied up valid name sections
# %% Tidied up defining represnetations table
# %% Verion 4.6
# %%
# %% Revision 1.59  2000/08/30 13:09:00  peterg
# %% Updated option table
# %%
# %% Revision 1.58  2000/08/01 13:30:19  peterg
# %% Version 4.4
# %% updated STEPFACTOR info
# %% describes octave and OCST interfaces
# %%
# %% Revision 1.57  2000/07/20 07:55:44  peterg
# %% Version 4.3
# %%
# %% Revision 1.56  2000/05/19 17:49:17  peterg
# %% Extended the user defined representation section -- new nppp rep.
# %%
# %% Revision 1.55  2000/03/16 13:53:31  peterg
# %% Correct date
# %%
# %% Revision 1.54  2000/03/15 21:22:57  peterg
# %% Updated to 4.1 -- old style SS no longer supported
# %%
# %% Revision 1.53  1999/12/22 05:33:10  peterg
# %% Updated for 4.0
# %%
# %% Revision 1.52  1999/11/23 00:25:11  peterg
# %% Added the sensitivity reps
# %%
# %% Revision 1.51  1999/11/16 04:43:47  peterg
# %% Added start of sensitivity section
# %%
# %% Revision 1.50  1999/11/16 00:30:35  peterg
# %% Updated simulation section
# %% Added vector components
# %%
# %% Revision 1.49  1999/07/20 23:44:58  peterg
# %% V 3.8
# %%
# %% Revision 1.48  1999/07/19 03:08:33  peterg
# %% Added documentation for (new) SS lbl fields
# %%
# %% Revision 1.47  1999/03/09 01:42:22  peterg
# %% Rearranged the User interface section
# %%
# %% Revision 1.46  1999/03/09 01:18:01  peterg
# %% Updated for 3.5 including xmtt
# %%
# %% Revision 1.45  1999/03/03 02:39:26  peterg
# %% Minor updates
# %%
# %% Revision 1.44  1999/02/17 06:52:14  peterg
# %% New level formula dor artwork
# %%
# %% Revision 1.43  1998/11/25 16:49:24  peterg
# %% Put in subs.r documentation (was called params.r)
# %%
# %% Revision 1.42  1998/11/24 12:24:59  peterg
# %% Added section on simulation output
# %% Version 3.4
# %%
# %% Revision 1.41  1998/09/02 12:04:15  peterg
# %% Version 3.2
# %%
# %% Revision 1.40  1998/08/27 08:36:39  peterg
# %% Removed in. methods except Euler anf implicit
# %%
# %% Revision 1.39  1998/08/18 10:44:28  peterg
# %% Typo
# %%
# %% Revision 1.38  1998/08/18 09:16:38  peterg
# %% Version 3.1
# %%
# %% Revision 1.37  1998/08/17 16:14:30  peterg
# %% Version 3.1 - includes documentation on METHOD=IMPLICIT
# %%
# %% Revision 1.36  1998/07/30 17:33:15  peterg
# %% VERSION 3.0
# %%
# %% Revision 1.35  1998/07/22 11:00:53  peterg
# %% Correct date!
# %%
# %% Revision 1.34  1998/07/22 11:00:13  peterg
# %% Version to BAe
# %%
# %% Revision 1.33  1998/07/17 19:32:19  peterg
# %% Added more about aliases
# %%
# %% Revision 1.32  1998/07/05 14:21:56  peterg
# %% Further additions (Carlisle-Glasgow)
# %%
# %% Revision 1.31  1998/07/04 11:35:57  peterg
# %% Strarted new lbl description
# %%
# %% Revision 1.30  1998/07/02 18:39:20  peterg
# %% Started 3.0
# %% Added alias and default sections.
# %%
# %% Revision 1.29  1998/05/19 19:46:58  peterg
# %% Added the odess description
# %%
# %% Revision 1.28  1998/05/14 09:17:22  peterg
# %% Added METHOD variable to the simpar file
# %%
# %% Revision 1.27  1998/05/13 10:03:09  peterg
# %% Added unknown/zero SS label documentation.
# %%
# %% Revision 1.26  1998/04/29 15:12:46  peterg
# %% Version 2.9.
# %%
# %% Revision 1.25  1998/04/12 17:00:26  peterg
# %% Added new port features: coerced direction and top-level behaviour.
# %%
# %% Revision 1.24  1998/04/05 18:27:20  peterg
# %% This was the 2.6 version
# %%
# Revision 1.23  1997/08/24  11:17:51  peterg
# This is the released  version 2.5
#
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# Parameters
c =     1.0; # Default value
r =     1.0; # Default value
# Initial states
x(1) =  0.0; # Initial state for rc (c)
@end example
As usual, @strong{MTT} provides a default text file to be edited by the
user (@pxref{Text editors}).

@node Causal bond graph (cbg), Elementary system equations, Parameters, Representations
@comment  node-name,  next,  previous,  up
@section Causal bond graph (cbg)
@cindex Causal bond graph (cbg)
The causal bond graph is the causally complete version of the
Acausal bond graph (@pxref{Acausal bond graph (abg)}).

To create the causal bond graph of system `sys' in language fig type:
@example
mtt sys cbg fig
@end example
To create the causal bond graph of system `sys' in language m type:
@example
mtt sys cbg m
@end example
To view the causal bond graph of system `sys' type:
@example
mtt sys cbg view
@end example

@menu
* Language fig (cbg.fig)::      
* Language m (cbg.m)::          
@end menu

@node Language fig (cbg.fig), Language m (cbg.m), Causal bond graph (cbg), Causal bond graph (cbg)
@subsection Language fig (cbg.fig) 
@cindex Language fig (cbg.fig) 
@pindex Language fig (cbg.fig) 
The fig file is created by @strong{MTT}. It is identical to the
corresponding acausal representation (@pxref{Language fig (abg.fig)})
except that
@itemize @bullet
@item
the new causal strokes are added (using a double thickness line in blue)
@item
components that are undercausal are bold and green
@item
components that are overcausal are bold and red
@end itemize

@node Language m (cbg.m),  , Language fig (cbg.fig), Causal bond graph (cbg)
@comment  node-name,  next,  previous,  up
@subsection Language m (cbg.m)
@cindex Language m (cbg.m) 
@cindex cbonds
@cindex status


The causal bond graph of system `sys' is represented as
 an m file with heading:
@example
function [cbonds,status] = sys_cbg
@end example
The two outputs of this function are:
@itemize @bullet
@item
cbonds
@item
status
@end itemize

@emph{cbonds} is  a matrix with
@itemize @bullet
@item
one row for each bond
@item
the first column contains the arrow-orientated 
(@pxref{Arrow-orientated causality}) 
causality of the @emph{effort} variable.
@item
the second column contains the arrow-orientated 
(@pxref{Arrow-orientated causality}) 
causality of the @emph{flow} variable.
@end itemize

@emph{status} is  a matrix with
@itemize @bullet
@item
one row for each component
@item
the first column contains 1 if the component is overcausal; 0 if the
component is causally complete and -1 if the component is undercausal.
@end itemize
A successful model would therefore have all zeros in the status matrix.

@menu
* Transformation abg2cbg_m::    
@end menu

@node Transformation abg2cbg_m,  , Language m (cbg.m), Language m (cbg.m)
@comment  node-name,  next,  previous,  up
@subsubsection Transformation abg2cbg_m
@cindex Transformation abg2cbg_m

This transformation takes the acausal bond graph as an m file 
(@pxref{Language m (abg.m)}) and transforms it into a causal bond graph in
m-file format (@pxref{Language m (cbg.m)}).

It is based on the m-function abg2cbg.m which iteratively tries to
complete causality whilst recursively searching the bond graph
structure.
If causality is incomplete, it picks the first acausal dynamic (C or I)
component, asserts integral causality, and tries again.

This is essentially the sequential causality assignment procedure of
Karnopp and Rosenberg.

The transformation informs the user of the final status in terms of the
percentage of causally complete components; a successful model will
yield 100% here.

@node Elementary system equations, Differential-Algebraic Equations, Causal bond graph (cbg), Representations
@comment  node-name,  next,  previous,  up
@section Elementary system equations (ese)
@cindex Elementary system equations

The elementary system equations are a complete set of assignment statements
describing the dynamic system corresponding to the bond graph.
They are in the Reduce (@pxref{Reduce}) language.

Because these are based on a causally complete system, these assignment
statements are directly soluble by substitution.

Unlike early versions of @strong{MTT}, @strong{MTT} does @emph{not} sort
the equations in order of solution, but rather leaves them sorted by
component and subsystem.

These are not supposed to be read by the user, so there is no view
facility as such. However, you may read these with your favourite text
editor and, to this end,  helpful comment lines have been added.

Wherever components have an explicit constitutive relationship, the
corresponding RHS of the equation has a standard form.

@example
cr(arguments,out_causality,outport,
        input_1, causality_1, port_1,
        ....
        input_i, causality_i, port_i,
        ....
        input_n, causality_n, port_n
        );
@end example
where the symbols have the following meaning
@vtable @code
@item arguments
        the constitutive relationship arguments
@item out_causality
        the causality (effort or flow) of the output variable
        (@pxref{Variables})
@item outport
        the number (integer) of the output port of the system
@item input_i
        the ith input to the component
@item causality_i
        the causality (effort or flow) of the ith input variable
        (@pxref{Variables})
@item port_i
        the number (integer) of the ith input port of the system
@end vtable

An example for a resistor with linear constitutive relationship is:
@example
rc_1_bond4_flow := lin(flow,r,flow,1,
        rc_1_bond4_effort,effort,1
        );
@end example

@menu
* Transformation cbg2ese_m2r::  
@end menu

@node Transformation cbg2ese_m2r,  , Elementary system equations, Elementary system equations
@comment  node-name,  next,  previous,  up
@subsubsection Transformation cbg2ese_m2r
@cindex Transformation cbg2ese_m2r
@cindex Structure
@cindex def.r
This transformation takes the causal bond graph as an m file 
(@pxref{Language m (cbg.m)}) and transforms it into elementary system
equations
in Reduce (@pxref{Reduce})
form.

It is based on the m-function cbg2ese.m which iteratively traverses the
causal bond graph writing equations as it goes.

It also writes out the system structure as the file @file{sys_def.r}.


@node Differential-Algebraic Equations, Constrained-state Equations, Elementary system equations, Representations
@section Differential-Algebraic Equations (dae)
@cindex Differential-Algebraic Equations
@cindex DAE

The system differential algebraic equations describe the system dynamics together 
together with any algebraic constraints. 

They are generated in language @code{lang} for system 
@code{sys} by:
@example
mtt sys dae lang
@end example
Valid languages are:
@vtable @code
@item r
        reduce (@pxref{Reduce}).
@item m
        m  (@pxref{m}).
@item view
        reduce (@pxref{Views}).
@end vtable


There are five sets of variables describing the system:
@vtable @code
@item x
        the system states (corresponding to C and I components with integral
        causality.
@item z
        the system nonstates (corresponding to C and I components with derivative
        causality.
@item u
        the system inputs  (corresponding to SS components
        with external attribute).
@item ui
        the @emph{internal} system inputs (corresponding to SS components
        with internal attribute) used to solve algebraic loops
        (@pxref{Algebraic loops}).
@item y
        the  system outputs (corresponding to SS components
        with external attribute).
        @end vtable

In general there are four sets of equations. The right-hand side of
 each is a function of x, dz/dt,  u and ui and the left hand sides are:
@enumerate
@item
the derivative of x (dx/dt)
@item
z
@item
w=0 (the algebraic equations)
@item
y
@end enumerate

@menu
* Differential-Algebraic Equations (reduce)::  
* Differential-Algebraic Equations (m)::  
@end menu

@node Differential-Algebraic Equations (reduce), Differential-Algebraic Equations (m), Differential-Algebraic Equations, Differential-Algebraic Equations
@subsection Language reduce (dae.r)
@cindex Differential-Algebraic Equations (reduce)
@cindex dae.r 

The system DAEs (@pxref{Differential-Algebraic Equations})
are represented in the reduce  (@pxref{Reduce}) language as 
arrays containing the algebraic expressions for the 
right hand sides of each set of equations. The arrays are:
@vtable @code
@item MTTx
        x -- the system states (corresponding to C and I components with integral
        causality.

@item MTTz
        z -- the system nonstates (corresponding to C and I components with derivative
        causality.
@item MTTu
        u -- the system inputs  (corresponding to SS components
        with external attribute).
@item mttv
        ui -- the @emph{internal} system inputs (corresponding to SS components
        with internal attribute) used to solve algebraic loops
        (@pxref{Algebraic loops}).
@item MTTy
        y -- the  system outputs (corresponding to SS components
        with external attribute).
        @end vtable

@menu
* Transformation ese2dae_r::    
@end menu

@node Transformation ese2dae_r,  , Differential-Algebraic Equations (reduce), Differential-Algebraic Equations (reduce)
@subsubsection Transformation ese2dae_r
@cindex Transformation ese2dae_r
@pindex  ese2dae_r

This transformation (@pxref{What is a Transformation?}) 
uses Reduce (@pxref{Reduce}) to combine the elementary system
equations (@pxref{Elementary system equations}) with the
constitutive relationships (@pxref{Constitutive relationship})
and simplify the result. 

@node Differential-Algebraic Equations (m),  , Differential-Algebraic Equations (reduce), Differential-Algebraic Equations
@subsection Language m (dae.m)
@cindex Differential-Algebraic Equations (m)
@cindex dae.m
The system DAEs (@pxref{Differential-Algebraic Equations})
are represented in the m (@pxref{m}) language as  
two m-functions of the form:

@example
function resid = sys_dae(dx,x,t)
function y  = sys_dae(dx,x,t)
@end example
Where x is the dae @emph{descriptor} vector and dx its 
time derivative; t is the time.
The first function is of a form suitable for solution by DASSL;  
the second function can then be used to find the coresponding system
output.

@menu
* Transformation dae_r2m::      
@end menu

@node Transformation dae_r2m,  , Differential-Algebraic Equations (m), Differential-Algebraic Equations (m)
@subsubsection Transformation dae_r2m
@cindex Transformation dae_r2m
@pindex  dae_r2m

This transformation (@pxref{What is a Transformation?}) 
uses Reduce (@pxref{Reduce}) to rewrite the elementary system
equations (@pxref{Elementary system equations}) in m-file 
format  (@pxref{m}) . Numerical parameters are declared as global.


@node Constrained-state Equations, Ordinary Differential Equations, Differential-Algebraic Equations, Representations
@section Constrained-state Equations (cse)
@cindex Constrained-state Equations
@cindex ODE

The system constrained-state equations describe the system dynamics for
a special class of systems (see the book for details). The resuting
equations are of the form:
@example
E(x) dx/dt = f(x,u)
y = g(x,u)
@end example
They typically occure where two or more states are constrained to be equal, or
proportional, to each other. For example, two capacitors in parallel or
two inertias connected by a stiff shaft.


They are generated in language @code{lang} for system 
@code{sys} by:
@example
mtt sys cse lang
@end example
Valid languages are:
@vtable @code
@item r
        reduce (@pxref{Reduce}).
@item m
        m  (@pxref{m}).
@item view
        reduce (@pxref{Views}).
@end vtable

There are three sets of variables describing the system:
@vtable @code
@item x
        the system states (corresponding to C and I components with integral
        causality.
@item u
        the system inputs  (corresponding to SS components
        with external attribute).
@item y
        the  system outputs (corresponding to SS components
        with external attribute).
        @end vtable

In general there are two sets of equations. The right-hand side of
 each is a function of x and  u  and the left hand sides are:
@enumerate
@item
the derivative of x (dx/dt)
y
@end enumerate

@menu
* Constrained-state Equations (reduce)::  
* Constrained-state Equations (view)::  
@end menu

@node Constrained-state Equations (reduce), Constrained-state Equations (view), Constrained-state Equations, Constrained-state Equations
@subsection Language reduce (cse.r)
@cindex Constrained-state Equations (reduce)
@cindex cse.r 

The system CSEs (@pxref{Constrained-state Equations})
are represented in the reduce  (@pxref{Reduce}) language as 
arrays containing the algebraic expressions for the 
right hand sides of each set of equations. The arrays are:
@vtable @code
@item MTTx
        x -- the system states (corresponding to C and I components with integral
        causality.
@item MTTu
        u -- the system inputs  (corresponding to SS components
        with external attribute).
@item MTTy
        y -- the  system outputs (corresponding to SS components
        with external attribute).
@end vtable
together with the array containing the elements of the E matrix.
@menu
* Transformation dae2cse_r::    
@end menu

@node Transformation dae2cse_r,  , Constrained-state Equations (reduce), Constrained-state Equations (reduce)
@subsubsection Transformation dae2cse_r
@cindex Transformation dae2cse_r
@pindex  dae2cse_r

This transformation (@pxref{What is a Transformation?}) 
Reduce (@pxref{Reduce}) to find various Jacobians which are combined to
find the E matrix and the
constrained-state equations (@pxref{Constrained-state Equations}).

@node Constrained-state Equations (view),  , Constrained-state Equations (reduce), Constrained-state Equations
@subsection Language m (view)
@cindex Constrained-state Equations (view)
@cindex view Constrained-state Equations
This representation has the standard text view
(@pxref{Views}).

@node Ordinary Differential Equations, Descriptor matrices, Constrained-state Equations, Representations
@section Ordinary Differential Equations
@cindex Ordinary Differential Equations
@cindex ODE

The system ordinary differential equations describe the system dynamics.

They are generated in language @code{lang} for system 
@code{sys} by:
@example
mtt sys ode lang
@end example
Valid languages are:
@vtable @code
@item r
        reduce (@pxref{Reduce}).
@item m
        m  (@pxref{m}).
@item view
        reduce (@pxref{Views}).
@end vtable

There are three sets of variables describing the system:
@vtable @code
@item x
        the system states (corresponding to C and I components with integral
        causality.
@item u
        the system inputs  (corresponding to SS components
        with external attribute).
@item y
        the  system outputs (corresponding to SS components
        with external attribute).
        @end vtable

In general there are two sets of equations. The right-hand side of
 each is a function of x and  u  and the left hand sides are:
@enumerate
@item
the derivative of x (dx/dt)
y
@end enumerate

@menu
* Ordinary Differential Equations (reduce)::  
* Ordinary Differential Equations (m)::  
* Ordinary Differential Equations (view)::  
@end menu

@node Ordinary Differential Equations (reduce), Ordinary Differential Equations (m), Ordinary Differential Equations, Ordinary Differential Equations
@subsection Language reduce (ode.r)
@cindex Ordinary Differential Equations (reduce)
@cindex ode.r 

The system ODEs (@pxref{Ordinary Differential Equations})
are represented in the reduce  (@pxref{Reduce}) language as 
arrays containing the algebraic expressions for the 
right hand sides of each set of equations. The arrays are:
@vtable @code
@item MTTx
        x -- the system states (corresponding to C and I components with integral
        causality.
@item MTTu
        u -- the system inputs  (corresponding to SS components
        with external attribute).
@item MTTy
        y -- the  system outputs (corresponding to SS components
        with external attribute).
        @end vtable

@menu
* Transformation cse2ode_r::    
@end menu

@node Transformation cse2ode_r,  , Ordinary Differential Equations (reduce), Ordinary Differential Equations (reduce)
@subsubsection Transformation cse2ode_r
@cindex Transformation cse2ode_r
@pindex  cse2ode_r

This transformation (@pxref{What is a Transformation?}) 
uses Reduce (@pxref{Reduce}) to invert the E matrix of the 
constrained-state equations (@pxref{Constrained-state Equations})
and simplify the result. 

@node Ordinary Differential Equations (m), Ordinary Differential Equations (view), Ordinary Differential Equations (reduce), Ordinary Differential Equations
@subsection Language m (ode.m)
@cindex Ordinary Differential Equations (m)
@cindex ode.m
The system ODEs (@pxref{Ordinary Differential Equations})
are represented in the m (@pxref{m}) language as  
two m-functions of the form:

@example
function dx = sys_ODE(x,t)
function y  = sys_ODE(dx,x,t)
@end example
Where x is the ODE @emph{state} vector and dx its 
time derivative; t is the time.
The first function is of a form suitable for solution by odesol;  
the second function can then be used to find the corresponding system
output.

@menu
* Transformation ode_r2m::      
@end menu

@node Transformation ode_r2m,  , Ordinary Differential Equations (m), Ordinary Differential Equations (m)
@subsubsection Transformation ode_r2m
@cindex Transformation ode_r2m
@pindex  ode_r2m

This transformation (@pxref{What is a Transformation?}) 
uses Reduce (@pxref{Reduce}) to rewrite the
ordinary differential equations
(@pxref{Ordinary Differential Equations}) in m-file 
format  (@pxref{m}) . Numerical parameters are declared as global.

@node Ordinary Differential Equations (view),  , Ordinary Differential Equations (m), Ordinary Differential Equations
@subsection Language m (view)
@cindex Ordinary Differential Equations (view)
@cindex view Ordinary Differential Equations
This representation has the standard text view
(@pxref{Views}).

@node Descriptor matrices, Report, Ordinary Differential Equations, Representations
@section Descriptor matrices (dm)
@cindex Descriptor matrices
@cindex dm

The system descriptor matrices A, B, C, D and E describe the 
@emph{linearised} system dynamics in the form
@example
E dx/dt = Ax + Bu
y = Cx + Du
@end example

They are generated in language @code{lang} for system 
@code{sys} by:
@example
mtt sys dm lang
@end example
Valid languages are:
@vtable @code
@item r
        reduce (@pxref{Reduce}).
@item m
        m  (@pxref{m}).
@item view
        reduce (@pxref{Views}).
@end vtable


@menu
* Descriptor matrices (reduce)::  
* Descriptor matrices (m)::     
@end menu

@node Descriptor matrices (reduce), Descriptor matrices (m), Descriptor matrices, Descriptor matrices
@subsection Language reduce (dm.r)
@cindex Descriptor matrices (reduce)
@cindex dm.r 

The system  descriptor matrices (@pxref{Descriptor matrices})
are represented in the reduce  (@pxref{Reduce}) language as 
arrays containing the four matrices. The arrays are:
@vtable @code
@item MTTA
        A 
@item MTTB
        B 
@item MTTA
        C
@item MTTD
        D
@item MTTE
        E
@end vtable

@node Descriptor matrices (m),  , Descriptor matrices (reduce), Descriptor matrices
@subsection Language m (dm.m)
@cindex Descriptor matrices (m)
@cindex dm.m
The system descriptor matrices (@pxref{Descriptor matrices})
are represented in the m (@pxref{m}) language as  
an m-function of the form:

@example
function [A,B,C,D,E] = sys_dm
@end example

System numeric parameters (@pxref{Numeric parameters})
are passed via global variables defined in the _numpar.m file.
@c (@pxref{numpar.m}). 
Thus the system descriptor matrices are
typically generated in Octave (@pxref{Octave}) as follows:

@example
sys_numpar
[A,B,C,D,E] = sys_dm
@end example

Parameters can be changed from their default values by entering
their values directly into Octave (@pxref{Octave})  and then invoking
@code{sys_dm}; for example
@example
sys_numpar
par_1 = 25
par_2 = par_1 + 3
[A,B,C,D,E] = sys_dm
@end example


@node Report,  , Descriptor matrices, Representations
@section Report (rep)
@cindex Report
@cindex rep

@strong{MTT} has a report-generator feature. The user specifies the
report contents in a text file (@pxref{Report (text)}) using an
appropriate text editor (@pxref{Text editors}).

For example, the report can be viewed by typing
@example
mtt system rep view
@end example


@menu
* Report (text)::               
* Report (view)::               
@end menu

@node Report (text), Report (view), Report, Report
@subsection Language text (rep.txt)
@cindex Report (text)
@cindex rep.txt 

The user specifies the report contents in a text file (@pxref{Report
(text)}) using an appropriate text editor (@pxref{Text editors}).
The text file contains lines which are either comments (indicated by %)
or valid @strong{MTT} commands. The report will then contain appropriate
sections. The following languages are supported by the report generator:
@ftable @code
@item m
        @code{octave} a high-level interactive language for numerical
        computation.
@item r
        @code{reduce}  a high-level interactive language for symbolic
        computation.
@item tex
        @code{latex} a text processor.
@item ps
        @code{ghostview} another document viewer.
@item c
        @code{gcc} a c compiler.
@end ftable
For example:
@example
mtt rc abg tex
mtt rc cbg ps
mtt rc struc tex
mtt rc ode tex
mtt rc sro ps
mtt rc tf tex
mtt rc lmfr ps
@end example

The acausal bond graph (abg) (@pxref{Acausal bond graph (abg)}) with the
tex language is handled in a special way: the acausal Bond Graph  in
fig format (@pxref{Language fig (abg.fig)}), the label file (@pxref{Labels (lbl)})
the description file (@pxref{Description (desc)}), together with
corresponding subsystems are included in the report. It is recommended
that the first (non-comment line) in the file should be:
@example
mtt <system> abg tex
@end example
where @code{<system>} is the name of the (top-level) system.

As usual, @strong{MTT} provides a default text file to be edited by the
user (@pxref{Text editors}).

In the special case that the first argument to mtt (normally the system)
is a directory, a default text file is provided which generates a report
for all systems to be found in that directory tree.

@node Report (view),  , Report (text), Report
@subsection Language view
@cindex Report (view)
@cindex view Report
This representation has the standard text view
(@pxref{Views}).

@node Extending MTT, Languages, Representations, Top
@comment  node-name,  next,  previous,  up
@chapter Extending MTT
@cindex Extending MTT
@cindex Make

@strong{MTT} has a number of built-in mechanisms for the user to extend
its capabilities. As @strong{MTT} is based on `Make' it is unsurprising
that some of these  involve the creation of `make files'. 

@menu
* Makefiles::                   
* New representations::         
* Component library ::          
@end menu

@node Makefiles, New representations, Extending MTT, Extending MTT
@comment  node-name,  next,  previous,  up
@section Makefiles
@cindex Makefiles

If a file called `Makefile' exists in the current directory,
@strong{MTT} executes it using make before doing anything else. This is
useful if one of the .txt files contains a reference to, for example, an
octave function of which @strong{MTT} unaware. Such a function can be
created using the makefile. An example `Makefile' is
@example
# Makefile for the Two link GMV example

all: msdP_tf.m TwoLinkP_obs.m TwoLinkP_sm.m twolinkp_sm.m TwoLinkGMV_numpar.m 

msdP_tf.m: msdP_abg.fig 
        mtt -q msdP tf m

TwoLinkP_obs.m: TwoLinkP_abg.fig TwoLinkP_lbl.txt
        mtt -q TwoLinkP obs m

TwoLinkP_sm.m: TwoLinkP_abg.fig TwoLinkP_lbl.txt
        mtt -q TwoLinkP sm m

twolinkp_sm.m: TwoLinkP_sm.m
        cp -v TwoLinkP_sm.m twolinkp_sm.m

TwoLinkGMV_numpar.m: TwoLinkGMV_numpar.txt
        mtt -q TwoLinkGMV numpar m
@end example
All of the files in the line stating `all:' are created when
@strong{MTT} is executed (if they don't already exist).

@node New representations, Component library , Makefiles, Extending MTT
@comment  node-name,  next,  previous,  up
@section New representations
@cindex New representations

It may be convenient to create new representations for @strong{MTT}; in
particular, it is nice to be able to include the result of some
numerical or symbolic computations within an @strong{MTT} report
(@pxref{Report}).

To create a new representation `myrep' in a language `mylang', create a
file with the name
@example
myrep_rep.make
@end example
This file must contain text in `make' syntax. It is executed by
@strong{MTT} and the two arguments `SYS' (the system name) and `LANG'
(the language) are passed to it by @strong{MTT}. Note that @strong{MTT}
cannot know of any prerequisites, but these can be explicitly included in
the makefile (which may include execution of @strong{MTT} itself.

The following example declares the new representation `nppp' which is
created with the Octave script sys_nppp.m where `sys' is the system
name.  This needs a number of files (for exaample `sys_ode2odes.out')
which are themselves created by @strong{MTT}.
@example
# -*-makefile-*-
# Makefile for representation nppp
# File nppp_rep.make

#Copyright (C) 2000 by Peter J. Gawthrop

all: $(SYS)_nppp.$(LANG)

$(SYS)_nppp.view: $(SYS)_nppp.ps
        echo Viewing $(SYS)_nppp.ps; ghostview $(SYS)_nppp.ps&

$(SYS)_nppp.ps: $(SYS)_ode2odes.out s$(SYS)_ode2odes.out \
                $(SYS)_sim.m s$(SYS)_sim.m \
                $(SYS)_state.m $(SYS)_sympar.m $(SYS)_numpar.m  \
                s$(SYS)_state.m s$(SYS)_sympar.m s$(SYS)_numpar.m \
                $(SYS)_sm.m $(SYS)_def.m  s$(SYS)_def.m
        octave $(SYS)_nppp.m

$(SYS)_ode2odes.out: 
        mtt -q -c -stdin $(SYS) ode2odes out

s$(SYS)_ode2odes.out:
        mtt -q -c -stdin -s s$(SYS) ode2odes out

$(SYS)_sim.m:
        mtt -q -c $(SYS) sim m

s$(SYS)_sim.m:
        mtt -q -c -s s$(SYS) sim m

$(SYS)_state.m:
        mtt -q $(SYS) state m

$(SYS)_sympar.m :
        mtt -q $(SYS) sympar m 

$(SYS)_numpar.m:
        mtt -q $(SYS) numpar m

s$(SYS)_state.m:
        mtt -q -s s$(SYS) state m

s$(SYS)_sympar.m :
        mtt -q -s s$(SYS) sympar m 

s$(SYS)_numpar.m:
        mtt -q -s s$(SYS) numpar m

$(SYS)_sm.m:
        mtt -q $(SYS) sm m

$(SYS)_def.m:
        mtt -q $(SYS) def m

s$(SYS)_def.m:
        mtt -q -s s$(SYS) def m

@end example

Future extensions of @strong{MTT} will use such representations stored
in $MTT_REP.

@node Component library ,  , New representations, Extending MTT
@comment  node-name,  next,  previous,  up
@section Component library
@cindex Component library
@cindex component
@cindex Component library

If @strong{MTT} does not recognise a component (eg named MyComponent) as
a simple component (@pxref{Simple components}) or as already existing,
it searches the library search path $MTT_COMPONENTS
(@pxref{$MTT_COMPONENTS}) for a directory called MyComponent containing
MyComponent_lbl.txt. It then copies the @emph{entire} directory into the
current working directory. Thus, for example, the directory could
contain MyComponent_desc.tex MyComponent_abg.fig MyComponent_lbl.txt and MyComponent_cr.r in
addition to MyComponent_lbl.txt.

@c      node   next  prev  up
@node   Languages, Language tools, Extending MTT, Top
@chapter Languages
@cindex Languages
@pindex Languages


@c      node   next  prev  up
@menu
* Fig::                         r
* m::                           
* Reduce::                      
* c::                           
@end menu

These are a number of languages used by @strong{MTT} to implement the
various representations.
Each has associated Language tools (@pxref{Language tools}) to
manipulate and/or view the representation.

@ftable @code
@item fig
        @code{Fig} a graphical description language.
@item m
        @code{octave} a high-level interactive language for numerical
        computation.
@item r
        @code{reduce}  a high-level interactive language for symbolic
        computation.
@item tex
        @code{latex} a text processor.
@item dvi
        @code{xdvi} a document viewer.
@item ps
        @code{ghostview} another document viewer.
@item gdat
        @code{gnuplot} a data viewer.
@item c
        @code{gcc} a c compiler.
@item sg
	@code{scigraphica} a plotting package.
@end ftable

These tools are automatically invoked as appropriate by @strong{MTT};
but for more advanced use, these tools can be used directly on files
(with the appropriate suffix) generated by @strong{MTT}.



@node   Fig, m, Languages, Languages
@section Fig
@cindex Fig
@pindex Fig
Please see xfig documentation.

@node   m, Reduce, Fig, Languages
@section m
@cindex m
@pindex m
Please see Octave documentation 
@ifhtml
<A HREF="http://www.che.wisc.edu/octave/">Octave</A> documentation.
<A HREF="http://www.mathworks.com/homepage.html">Matlab</A> documentation.
@end ifhtml


@node   Reduce, c, m, Languages
@section Reduce
@cindex Reduce
@pindex Reduce
Please see the reduce documentation.

@node c,  , Reduce, Languages
@comment  node-name,  next,  previous,  up
@section c
@cindex c
@pindex c
Please see the gcc documentation.
@node Language tools, Administration, Languages, Top
@comment  node-name,  next,  previous,  up
@chapter Language tools
@cindex  Language tools

@menu
* Views::                       
* Xfig::                        
* Text editors::                
* Octave::                      
* LaTeX::                       
@end menu

@node Views, Xfig, Language tools, Language tools
@comment  node-name,  next,  previous,  up
@section Views
@cindex views

A number of representations (@pxref{Representations}) have a language
representation which is particularly useful for viewing by the
user. These views are
invoked, where appropriate by the command:
@example
mtt sys rep view
@end example
where @code{sys} is the system name and @code{rep} a corresponding representation.

@node Xfig, Text editors, Views, Language tools
@comment  node-name,  next,  previous,  up
@section Xfig
@cindex Xfig

@node Text editors, Octave, Xfig, Language tools
@comment  node-name,  next,  previous,  up
@section Text editors
@cindex Text editors
All representations live in text files and thus may be edited using your
favourite text editor; however, the Fig (@pxref{Fig}) representation is
pretty meaningless in this form and so you should use Xfig
(@pxref{Xfig}) for representation in this language.

Its up to you which text editor to use. I recommend emacs, but simpler
(and less powerful) editors such as xedit, textedit and vi are also ok.

I usually run @strong{MTT} out of an emacs shell window and keep the
rest of the files in emacs buffers.

@node Octave, LaTeX, Text editors, Language tools
@comment  node-name,  next,  previous,  up
@section Octave
@cindex Octave
@cindex Matlab
@cindex m-files
@cindex Octave interface
@cindex mtt.m

Octave is a numerical matrix-based language @xref{Top,
,Octave,Octave,Octave}.  It is similar to Matlab in many ways. In most
cases, m-files generated by @strong{MTT} can be understood by both
Matlab and Octave (and no doubt other Matlab lookalikes).

 @strong{MTT} provides the octave function @code{mtt}. The octave
 command
@example
help mtt
@end example
gives the following information:
@example
 usage:  mtt (system[,representation,language])

 Invokes mtt from octave to generate system_representation.language
 Ie equivalent to "mtt system representation language" at the shell
 Representation and language defualt to "sm" and "m" respectively

@end example

Thus for example, if octave is in the directory containing the system
rc the following session generates the state matrices of the system "rc"
with the defaut capacitance but resitance r=0.1.
@example
octave> mtt("rc");
Creating rc_rbg.m
Creating rc_cmp.m
Creating rc_fig.fig
Creating rc_sabg.fig
Creating rc_alias.txt
Creating rc_alias.m
Creating rc_sub.sh
Creating rc_abg.m
Creating rc_cbg.m (maximise integral causality)
Creating rc_type.sh
Creating rc_ese.r
Creating rc_def.r
Creating rc_struc.txt
Creating rc_rdae.r
Creating rc_subs.r
Creating rc_cr.txt
Creating rc_cr.r
Copying CR SS to here from
Copying CR lin to here from
Creating rc_dae.r
Creating rc_sympar.txt
Creating rc_sympar.r
Creating rc_cse.r
Creating rc_sspar.r
Creating rc_csm.r
Creating rc_ode.r
Creating rc_ss.r
Creating rc_sm.r
Creating rc_switch.txt
0 switches found
Creating rc_sympars.txt
Creating rc_sm.m
Copying rc_sm.m
octave> mtt("rc","numpar");
Creating rc_numpar.txt
Creating rc_numpar.m
Copying rc_numpar.m
octave> mtt("rc","sympar");
Creating rc_sympar.m
Copying rc_sympar.m
octave> par = rc_numpar
par =

  1
  1

octave> sym = rc_sympar;

octave> par(sym.r) = 0.1;
octave> [A,B,C,D] = rc_sm(par)
A = -10

B = 10

C = 1

D = 0

octave> 
@end example
generates the data structure rc corresponding the the bond graph of the
system called `rc'.
The following octave commands then generate the step reponse and bode
diagram respectively:
@example
step(rc);
bode(rc);
@end example


@menu
* Octave control system toolbox (OCST)::  
@end menu

@node Octave control system toolbox (OCST),  , Octave, Octave
@comment  node-name,  next,  previous,  up
@subsection Octave control system toolbox (OCST)
@cindex Octave
@cindex toolbox
@cindex OCST
@cindex control systems
@cindex mtt2sys

@strong{MTT} provides an interface to the Octave control system toolbox
(OCST) using the mfile @code{mtt2sys}. the octave command
@example
help mtt2sys
@end example
gives the following information.
@example
 usage:  sys = mtt2sys (Name[,par])

 Creates a sys structure for the Octave Control Systems Toolbox
 from an MTT system with name "Name"
 Optional second argument is system parameter list
 Assumes that Name_sm.m, Name_struc.m and Name_numpar.m exist
@end example

Thus for example, if octave is in the directory containing the system
rc:
@example
rc = mtt2sys("rc");
@end example
generates the data structure rc corresponding the the bond graph of the
system called `rc'.
The following octave commands then generate the step reponse and bode
diagram respectively:
@example
step(rc);
bode(rc);
@end example

 

@node LaTeX,  , Octave, Language tools
@comment  node-name,  next,  previous,  up
@section LaTeX
@cindex LaTeX

LaTeX is a powerful text processor which @strong{MTT} uses to provide
visual output.

@node Administration, Glossary, Language tools, Top
@comment  node-name,  next,  previous,  up
@chapter  Administration
@cindex  Administration

@menu
* Software components::         
* REDUCE setup::                
* Octave setup::                
* Paths::                       
* File structure::              
@end menu

@node Software components, REDUCE setup, Administration, Administration
@comment  node-name,  next,  previous,  up
@section  Software components
@cindex  Software components

@strong{MTT} is built from a set of readily-available  software tools.
These are:
@itemize @bullet
@item General purpose software tools.
@item Octave (@pxref{Octave setup})
@item REDUCE  (@pxref{REDUCE setup})
@end itemize

The General purpose tools are (these will all be available with a
standard Linux distribution):
@vtable @code
@item sh
        Bourne shell
@item gmake
        Gnu make
@item gawk
        Gnu awk
@item sed
        Gnu sed
@item grep
        Gnu grep
@item comm
        Gnu Compare sorted files by line
@item xfig
        Figure editor, version 3 or greater.        
@item fig2dev
        Fig file conversion, version 3 or greater. 
@item ghostview
        postscript viewer
@item xdvi
        dvi viewer
@item dvips
        dvi to postscript conversion
@item latex
        the text processor (LaTeX2e needed)
@item latex2html
        converts latex to html
@item perl
        needed for latex2html
@item gnuplot
        a graph plotting program
@item gnuscape
        or other web/html browser such as netscape, Red Baron etc.
@item gcc
        GNU c compiler
@end vtable

@ifhtml
<A HREF="http://home.pages.de/~GNU/">GNU</A> documentation.
@end ifhtml



@node REDUCE setup, Octave setup, Software components, Administration
@comment  node-name,  next,  previous,  up
@section  REDUCE setup
@cindex REDUCE setup

Symbolic algebra is performed by REDUCE, which although not free
software is the the result of international collaboration. The version I
use is obtained from:
@quotation
ZIB ( http://www.zib.de )
@end quotation
@ifhtml
<A HREF="http://www.rrz.uni-koeln.de/REDUCE/">REDUCE</A> documentation.
<A HREF="http://www.zib.de">ZIB</A> documentation.
@end ifhtml

@node Octave setup, Paths, REDUCE setup, Administration
@comment  node-name,  next,  previous,  up
@section Octave setup
@cindex  Octave setup

Octave is available at various web sites including:
@uref{http://www.octave.org}

@menu
* .octaverc::                   
* .oct file dependencies::      
@end menu

@node .octaverc, .oct file dependencies, Octave setup, Octave setup
@comment  node-name,  next,  previous,  up
@subsection .octaverc
@vindex  .octaverc


The @file{.octaverc} file should contain the following lines:
@example
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Startup file for Octave for use with MTT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

implicit_str_to_num_ok = 1;
empty_list_elements_ok = 1;

@end example

@node .oct file dependencies,  , .octaverc, Octave setup
@comment  node-name,  next,  previous,  up Additionally, it is necessary to
@subsection .oct file dependencies
Successful compilation of .oct code requires that Octave has been configured
to use dynamically linked libraries and that the Octave library @code{liboctave}
and the Octave modified version of @code{libkpathsea} are available on the
 system.

This can be acheived by compiling Octave from the source code, configured
with the options @code{--enable-shared} and @code{--enable-dl}.

Further information on configuring and installing Octave to handle dynamic
libraries (DLDs) can be found in the
@uref{http://www.octave.org/docs.html,Octave documentation}.


@node Paths, File structure, Octave setup, Administration
@comment  node-name,  next,  previous,  up
@section Paths
@cindex paths
@cindex mttrc

There are a number of paths that must be set correctely for @strong{MTT}
to work. These are normally set up by sourcing the file @code{mttrc} that
lives in the @strong{MTT} home directory.

@menu
* $MTTPATH::                    
* $MTT_COMPONENTS::             
* $MTT_CRS::                    
* $MTT_EXAMPLES::               
* $OCTAVE_PATH::                
@end menu

@node $MTTPATH, $MTT_COMPONENTS, Paths, Paths
@comment  node-name,  next,  previous,  up
@subsection $MTTPATH
@vindex $MTTPATH
The environment variable $MTTPATH points to the mtt home directory.
This is usually @code{/usr/local/lib/mtt}.

@node $MTT_COMPONENTS, $MTT_CRS, $MTTPATH, Paths
@comment  node-name,  next,  previous,  up
@subsection $MTT_COMPONENTS
@vindex $MTT_COMPONENTS
The environment variable $MTT_COMPONENTS is a colon-separated path
pointing to directories containing components and subsystems.
By default
@example
MTT_COMPONENTS=.:$MTT_LIB/lib/comp/
@end example
but you may wish to add your own component libraries:
@example
MTT_COMPONENTS=my_library_path:$MTT_COMPONENTS
@end example

@node $MTT_CRS, $MTT_EXAMPLES, $MTT_COMPONENTS, Paths
@comment  node-name,  next,  previous,  up
@subsection $MTT_CRS
@vindex $MTT_CRS
The environment variable $MTT_CRS is a colon-separated path
pointing to directories containing constitutive relationships.
By default
@example
MTT_CRS=$MTTPATH/lib/cr
@end example
but you may wish to add your own component libraries:
@example
MTT_CRS=my_cr_path:$MTT_CRS
@end example

@node $MTT_EXAMPLES, $OCTAVE_PATH, $MTT_CRS, Paths
@comment  node-name,  next,  previous,  up
@subsection $MTT_EXAMPLES
@vindex $MTT_EXAMPLES
The environment variable $MTT_EXAMPLES is a colon-separated path
pointing to directories containing EXAMPLES and subsystems.
By default
@example
MTT_EXAMPLES=$MTTPATH/lib/examples
@end example
but you may wish to add your own component libraries:
@example
MTT_EXAMPLES=my_examples_path:$MTT_EXAMPLES
@end example

@node $OCTAVE_PATH,  , $MTT_EXAMPLES, Paths
@comment  node-name,  next,  previous,  up
@subsection $OCTAVE_PATH
@vindex $OCTAVE_PATH

The @code{$OCTAVE_PATH} path must include the relevant paths for mtt to
work properly. In particular, it must include:
@example
$MTTPATH/trans/m
$MTTPATH/lib/comp/simple
$MTTPATH/lib/comp/compound
@end example

@node File structure,  , Paths, Administration
@comment  node-name,  next,  previous,  up
@section  File structure
@cindex File structure
The recommended installation of @strong{MTT} uses the following
directory structure with corresponding contents. Normally, each of the
listed directories is a subdirectory of @file{/usr/local}. The directory
@code{mtt} is pointed to by $MTTPATH (@pxref{$MTTPATH}).

@vtable @file
@item mtt/bin
        This is the home directory for @strong{MTT}. @strong{MTT}  itself lives
        here along with @file{mttrc}.
@item mtt/bin/trans
        The transformations executed by @strong{MTT}.
@item mtt/bin/trans/m
        The  @code{m-files} associated with the transformations.
@item mtt/bin/trans/awk
        The  @code{awk} scripts associated with the transformations.
@item mtt/lib
        The place for components, examples and CRs which will be updated.
@item mtt/lib/comp/simple
@cindex simple components
        The  @code{m-files} defining the simple components.
@cindex compound components
@item mtt/lib/comp/compound
        The  @code{m-files} defining the compound components.
@item mtt/lib/cr/r
        constitutive relationship definitions
@item mtt/lib/examples
        Some examples. 
@item mtt/examples/metamodelling
        Examples from the book.
@item mtt/doc
        The  documentation files for @strong{MTT}.
@item mtt/doc/Examples
        Examples used in the documentation.
@end vtable

@node Glossary, Index, Administration, Top
@comment  node-name,  next,  previous,  up
@unnumbered Glossary
@printindex fn

@node Index,  , Glossary, Top
@comment      node-name, next,       previous, up
@unnumbered Index
@printindex cp

@contents

@bye


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Modified mttroot/mtt/lib/rep/sfun_rep.sh from [91c3b4a28b] to [63c5879b48].

1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386





### main program

set_debug 0
check_for_valid_input "$*"

OPTS="$1" SYS="$2" REP="$3" LANG="$4" make $make_debug -f ${MTT_REP}/sfun_rep/Makefile ${2}_${3}.${4}
exit 0







|
|



1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386





### main program

#set_debug 0
#check_for_valid_input "$*"

OPTS="$1" SYS="$2" REP="$3" LANG="$4" make $make_debug -f ${MTT_REP}/sfun_rep/Makefile ${2}_${3}.${4}
exit 0


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