Changes In Branch origin/optimise-algebraic-equations Excluding Merge-Ins

This is equivalent to a diff from e168fd1202 to 324f841c3c

2002-07-10
15:52:17
Updated from main branch. Leaf check-in: 324f841c3c user: geraint@users.sourceforge.net tags: origin/optimise-algebraic-equations, trunk
15:22:30
Updated from main branch. check-in: df5f842a8c user: geraint@users.sourceforge.net tags: origin/optimise-algebraic-equations, trunk
2002-06-10
08:27:33
Updated description check-in: 6c463de05f user: gawthrop@users.sourceforge.net tags: origin/master, trunk
2002-06-05
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 [ec2007c6a1].

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.11.2.4  2002/06/05 23:34:33  geraint
## Eliminated argument list too long warnings.
## Now get a Segmentation Fault with very long equations!
##
## Revision 1.11.2.3  2002/06/05 18:23:38  geraint
## Cosmetic change.
##
## Revision 1.11.2.2  2002/06/05 17:57:47  geraint
## Main part of optimisation routine moved to separate file.
##
## Revision 1.11.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.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'







>
>
>
>
>







99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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'
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
    }'
}

mtt_optimise ()
{
    sys="$1"
    lhs="$2"
    rhs="$3"

    
    crr="${sys}_cr.r"
    dae="${sys}_dae.r"
    tmp="mtt_optimise.tmp"
    tmp2="mtt_optimise2.tmp"
    tmp3="mtt_optimise3.tmp"
    
    {
	cat <<EOF
off echo$
load scope$
on double$
on noconvert$
on rounded$
off int$
off nat$

out "$tmp2"$
EOF
    } > $tmp
    
    echo "optimize" >> $tmp
    grep -i -e "^$lhs" $dae |\
	sed -e 's/;/\ INAME\ mtt_tmp/g' |\
	sed -e 's/:=/:=/g' >> $tmp
    {
	cat <<EOF

shut "$tmp2"$
EOF
    } >> $tmp
 
    ${SYMBOLIC:-reduce} < $tmp >> def2write_r1.log 2>> def2write_r2.log
    cat $tmp2 | gawk -v RS=';' '($2 == ":=") {print $0}' > $tmp3
    cat $tmp3 | mtt_fix_integers
    rm -f $tmp $tmp2 $tmp3
    return
}


# Remove log files
rm -f def2write_r1.log def2write_r2.log

# Write out the code







|
>

<

|
<
<

<
<
<
<
<
<
<
<
<
|
<
<
<
|
<
<
<
<
<
<
|
<
<
|
|
<
<
<
<
|







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
    }'
}

mtt_optimise ()
{
    sys="$1"
    lhs="$2"
    
    lhs=`echo $lhs | sed 's/MTTEdX/MTTdX/'`
    

    dae="${sys}_dae.r"
    tmp=mtt_optimise.tmp


    









    # get rhs and write to tmp file to be processed by mtt_optimise.sh



    eval "grep -i -e \"^$lhs\"" $dae | eval "sed 's/\([.]*\)[;$]*$/\1/'" | eval "sed 's/\ //g'" | eval "sed 's/:=/ /'" > $tmp






    eval mtt_optimise.sh $tmp


    cat $tmp | mtt_fix_integers
    




    return 0
}


# Remove log files
rm -f def2write_r1.log def2write_r2.log

# Write out the code
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
    m=`first "$ms"`; ms=`rest "$ms"`
    is=`n2m 1 $n`; 
    js=`n2m 1 $m`; 
    for i in $is; do
      for j in $js; do
	if [ ${opt:-""} = "-optimise" ]; then
	    name=`echo MTT$matrix'('$i','$j')'`
	    mtt_optimise $1 "$comma$name" "$name"
	    comma=''
	else
	    echo 'write'
	    name=`echo MTT$matrix'('$i','$j')'`
	    echo '  '$comma$name ':=' $name '$'
	fi >> $1_$2_write.r
      done
    done
done
echo ';END;'                           >>$1_$2_write.r







|










207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
    m=`first "$ms"`; ms=`rest "$ms"`
    is=`n2m 1 $n`; 
    js=`n2m 1 $m`; 
    for i in $is; do
      for j in $js; do
	if [ ${opt:-""} = "-optimise" ]; then
	    name=`echo MTT$matrix'('$i','$j')'`
	    mtt_optimise $1 "$comma$name"
	    comma=''
	else
	    echo 'write'
	    name=`echo MTT$matrix'('$i','$j')'`
	    echo '  '$comma$name ':=' $name '$'
	fi >> $1_$2_write.r
      done
    done
done
echo ';END;'                           >>$1_$2_write.r

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;

Modified mttroot/mtt/bin/trans/mtt_header from [b648dacad1] to [22e73f90c4].

8
9
10
11
12
13
14









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

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









## Revision 1.51  2002/05/19 13:01:21  geraint
## Numerical solution of algebraic equations implemented for S-function target.
##
## Equation solving requires the Matlab Optimization Toolbox to be installed.
##
## Code has been changed from C++ to C to allow mex files to be built with LCC,
## the compiler bundled with Matlab.







>
>
>
>
>
>
>
>
>







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

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.53  2002/06/10 23:22:16  geraint
## Fixed problem with Matlab fsolve failing because of "user function returned Inf or Nan" (fsolve.m, line 245).
##
## Revision 1.52  2002/05/27 14:52:15  geraint
## Parameters in sfun reps are now declared using sympar.h at the top of the
## sfun*.c file instead of in individual functions. This causes the optimisation
## variables (mtt_tmp*) to be declared correctly without causing conflicts in the
## scope of parameter declarations.
##
## Revision 1.51  2002/05/19 13:01:21  geraint
## Numerical solution of algebraic equations implemented for S-function target.
##
## Equation solving requires the Matlab Optimization Toolbox to be installed.
##
## Code has been changed from C++ to C to allow mex files to be built with LCC,
## the compiler bundled with Matlab.
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
	;;
    c)
	modeline="/* -*-c-*- Put Emacs into c-mode */";
	Lc='/*'
	Rc='*/'
	Lb='['
	Rb=']'
	parameters=no
	constant_declaration="const double "
	var_declaration="double "
	minusone="-1"
	;;
    *)
	echo Language $language not supported - sorry; exit 1
esac







<







503
504
505
506
507
508
509

510
511
512
513
514
515
516
	;;
    c)
	modeline="/* -*-c-*- Put Emacs into c-mode */";
	Lc='/*'
	Rc='*/'
	Lb='['
	Rb=']'

	constant_declaration="const double "
	var_declaration="double "
	minusone="-1"
	;;
    *)
	echo Language $language not supported - sorry; exit 1
esac

Added mttroot/mtt/bin/trans/mtt_optimise.sh version [51933f155d].









































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#! /bin/sh

set -e
set -x

filename="$1"

# set work file names

tmp="$0.tmp"
log="$0.log"

optimise_with_reduce ()
{
    cat <<EOF | reduce > $log
off echo$
load scope$
on double$
on noconvert$
on rounded$
off int$
off nat$

out "${tmp}"$
optimize mtt_tmp0 :=: `cat ${filename} | gawk '{ print $2 }'` iname mtt_tmp$
write "`cat ${filename} | gawk '{ print $1 }'` := mtt_tmp0"$
shut "${tmp}"$

;end;
EOF
}

optimise_with_maxima ()
{
    cat ${filename}					|\
	tr "\t\n" "  "					|\
	sed -e 's/\ //g'				|\
	sed -e 's/\(MTTdX([0-9.]*,[0-9.]*)\)/\1 /'     	|\
	sed -e 's/\(MTTy([0-9.]*,[0-9.]*)\)/\1 /'     	|\
	sed -e 's/\(MTTYz([0-9.]*,[0-9.]*)\)/\1 /'     	|\
	sed -e 's/[A-Za-z0-9_.:()]*(D2)\(.*\)/\1/'	|\
	sed -e 's/\([A-Za-z0-9_.:()]*\)(C3)/\1/g'	|\
	optimise_max2r.awk				|\
	tr "A-Z" "a-z"					> ${tmp}
}


optimise_with_maxima
#cat $filename
mv ${tmp} ${filename}

exit 0

Modified mttroot/mtt/bin/trans/mtt_txt2m from [cf306685c7] to [ab89c60014].

11
12
13
14
15
16
17







18
19
20
21
22
23
24


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







# %% Revision 1.16  2002/04/18 17:51:11  gawthrop
# %% Put default values in _simpar.m in case of missing values in txt file
# %%
# %% Revision 1.15  2002/03/26 12:00:37  geraint
# %% Escaped characters to eliminate awk warnings.
# %%
# %% Revision 1.14  2001/07/13 04:54:04  geraint







>
>
>
>
>
>
>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% Version control history
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% $Id$
# %% $Log$
# %% Revision 1.18  2002/06/17 08:50:00  geraint
# %% Changed pattern to prevent 'max(' from being translated to 'mamttx('.
# %%
# %% Revision 1.17  2002/04/28 18:41:27  geraint
# %% Fixed [ 549658 ] awk should be gawk.
# %% Replaced calls to awk with call to gawk.
# %%
# %% Revision 1.16  2002/04/18 17:51:11  gawthrop
# %% Put default values in _simpar.m in case of missing values in txt file
# %%
# %% Revision 1.15  2002/03/26 12:00:37  geraint
# %% Escaped characters to eliminate awk warnings.
# %%
# %% Revision 1.14  2001/07/13 04:54:04  geraint
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
    statement = $1;

  if (NF<2) print "  " statement
  if (NF>1)  print statement " # " $2
}' | sed\
     -e 's/\[\([0-9]*\)\]/(\1)/g' \
     -e 's/\([^a-zA-Z_0-9]\)t\([^a-zA-Z_0-9]\)/\1mttt\2/g' \
     -e 's/x(/mttx(/g' \
     -e 's/u(/mttu(/g' \
     -e 's/mttmtt/mtt/g' \
| tolower >> $outfile

if [ -n "$arraycode" ]; then
  new_style=`strip_comments < $1_$2.txt| grep "$name(">/dev/null; echo $?`

  if [ "$new_style" = "1" ]; then







|
|







260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
    statement = $1;

  if (NF<2) print "  " statement
  if (NF>1)  print statement " # " $2
}' | sed\
     -e 's/\[\([0-9]*\)\]/(\1)/g' \
     -e 's/\([^a-zA-Z_0-9]\)t\([^a-zA-Z_0-9]\)/\1mttt\2/g' \
     -e 's/\([^a-zA-Z_0-9]\)x(/\1mttx(/g' \
     -e 's/\([^a-zA-Z_0-9]\)u(/\1mttu(/g' \
     -e 's/mttmtt/mtt/g' \
| tolower >> $outfile

if [ -n "$arraycode" ]; then
  new_style=`strip_comments < $1_$2.txt| grep "$name(">/dev/null; echo $?`

  if [ "$new_style" = "1" ]; then

Added mttroot/mtt/bin/trans/optimise_max2r.awk version [d3a19e1a09].



































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#! /usr/bin/awk -f

# Maxima optimized expression format:
# (C1) DISPLAY2D:FALSE$
# (C2) OPTIMIZE(x);
# (D2) x
# (C3) OPTIMIZE((1.0+a*b)/(2.0+a*b));
# (D3) BLOCK([%1],%1:a*b,(%1+1.0)/(%1+2.0))

function decipher_block(lhs,rhs)
{
  s=rhs;
  s=gensub(/BLOCK/, "", "1", s);		# strip BLOCK keyword
  s=gensub(/\(/, "", "1", s);			# strip leading (
  s=gensub(/\)$/, "", "1", s);			# strip trailing )
  s=gensub(/\[.*\],/, "", "g", s);		# strip declarations
  s=gensub(/%/, "mtt_tmp", "g", s);		# rename tmp variables
  s=gensub(/:/, " := ", "g", s);	        # fix assignment operator

  # commas delimit statements in maxima, so
  # preserve commas within function calls
  # replace remaining commas with semi-colons
  # then put commas back in functions and reinstate parentheses
  while (match(s, (/\(([^()]*),([^()]*)\)/))) {
    s=gensub(/\(([^()]*),([^()]*)\)/, "(\\1__MTT_COMMA__\\2)", "g", s);
    s=gensub(/\(([^,()]*)\)/, "__MTT_LPAREN__\\1__MTT_RPAREN__", "g", s);
  }
  s=gensub(/,/, ";\n", "g", s);
  s=gensub(/__MTT_COMMA__/, ",", "g", s);
  s=gensub(/__MTT_LPAREN__/, "(", "g", s);
  s=gensub(/__MTT_RPAREN__/, ")", "g", s);

  # separate statements
  rhs=gensub(/.*;([^;]*)\n/, "\\1", 1, s);
  s=gensub(/;([^;]*)$/, ";", 1, s);

  print s;					# print intermediate statements
  printf "%s := %s;\n", lhs, rhs;		# print final assignment
}  

# pattern matching:

(! /.* BLOCK.*/ ) { 				# unoptimised statement
  print $1" := "$2";";
}

(  /.* BLOCK.*/ ) {				# optimised statement
  decipher_block($1,$2)
}

Modified mttroot/mtt/cc/include/useful-functions.hh from [381e0e03ee] to [f0062089cf].

1
2
3
4







5
6
7
8

9
10
11

12
13
14
15
16
17
18

#ifndef HAVE_USEFUL_FUNCTIONS_HH
#define HAVE_USEFUL_FUNCTIONS_HH









#ifndef __cplusplus
#define inline			/* strip */
#define cast_to_double	(double)

typedef unsigned int bool;
const bool true = 1;
const bool false = 0;

#else
#define cast_to_double	static_cast<double>
#endif /* ! __cplusplus */

static inline double
max (const double x1, const double x2)
{




>
>
>
>
>
>
>




>



>







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

#ifndef HAVE_USEFUL_FUNCTIONS_HH
#define HAVE_USEFUL_FUNCTIONS_HH

/* Code generation directives */
#define STANDALONE 0
#define OCTAVEDLD  1
#define MATLABMEX  2
#if (! defined (CODEGENTARGET))
#define CODEGENTARGET -1
#endif /* (! defined (CODEGENTARGET)) */

#ifndef __cplusplus
#define inline			/* strip */
#define cast_to_double	(double)
/*
typedef unsigned int bool;
const bool true = 1;
const bool false = 0;
*/
#else
#define cast_to_double	static_cast<double>
#endif /* ! __cplusplus */

static inline double
max (const double x1, const double x2)
{
35
36
37
38
39
40
41

42
43
44
45
46
47
48
sign (const double x)
{
  return cast_to_double ((x > 0) ? +1 : (x < 0) ? -1 : 0);
}


/* Octave functions */

#ifdef __cplusplus
static Matrix
ones (const int r = 1, const int c = 1)
{
  Matrix m (r, c, 1.0);
  return m;
}







>







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
sign (const double x)
{
  return cast_to_double ((x > 0) ? +1 : (x < 0) ? -1 : 0);
}


/* Octave functions */
#if ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == OCTAVEDLD))
#ifdef __cplusplus
static Matrix
ones (const int r = 1, const int c = 1)
{
  Matrix m (r, c, 1.0);
  return m;
}
78
79
80
81
82
83
84

85
86
87
88
static Matrix
zeros (const int r, const int c)
{
  Matrix m (r, c, 0.0);
  return m;
}
#endif /* __cplusplus */




#endif /* HAVE_USEFUL_FUNCTIONS_HH */







>




88
89
90
91
92
93
94
95
96
97
98
99
static Matrix
zeros (const int r, const int c)
{
  Matrix m (r, c, 0.0);
  return m;
}
#endif /* __cplusplus */
#endif /* ((CODEGENTARGET == STANDALONE) || (CODEGENTARGET == OCTAVEDLD)) */



#endif /* HAVE_USEFUL_FUNCTIONS_HH */

Modified mttroot/mtt/cc/sympar_txt2h.sh from [9a054e0600] to [d4f156ac26].

1
2
3















4
5
6
7
8
9
10
#! /bin/sh
# $Id$
# $Log$















# Revision 1.5  2002/04/28 18:58:06  geraint
# Fixed [ 549658 ] awk should be gawk.
# Replaced calls to awk with call to gawk.
#
# Revision 1.4  2001/08/24 21:41:04  geraint
# Fixed problem with declaration when there are no numerical parameters.
#



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







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
#! /bin/sh
# $Id$
# $Log$
# Revision 1.7  2002/07/10 11:53:32  geraint
# Replaced shell loop with template expansion - perceptibly quicker generation of sympar.h.
#
# Revision 1.6  2002/05/19 13:01:22  geraint
# Numerical solution of algebraic equations implemented for S-function target.
#
# Equation solving requires the Matlab Optimization Toolbox to be installed.
#
# Code has been changed from C++ to C to allow mex files to be built with LCC,
# the compiler bundled with Matlab.
#
# Parameters are now obtained from numpar.c instead of a dialogue box.
#
# `mtt <sys> sfun zip` creates all necessary files for building the model mex files.
#
# Revision 1.5  2002/04/28 18:58:06  geraint
# Fixed [ 549658 ] awk should be gawk.
# Replaced calls to awk with call to gawk.
#
# Revision 1.4  2001/08/24 21:41:04  geraint
# Fixed problem with declaration when there are no numerical parameters.
#
64
65
66
67
68
69
70


























































































































































































































































































































































































































































































































71
72
73
74
75
76

77
78
79
80
81
82
83
}

declare_temp_vars ()
{
for name in ${TMP_VAR_NAMES}
do
    echo ""


























































































































































































































































































































































































































































































































    i=0
    while [ ${i} -le ${NUM_OF_TMP_VAR} ]
    do
	echo "static double ${name}${i} MTT_UNUSED;"
	i=`expr ${i} + 1`
    done

done
}

echo Creating ${OUT}
cat <<EOF > ${OUT}
#ifndef MTT_UNUSED
#ifdef __GNUC__







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
>







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
}

declare_temp_vars ()
{
for name in ${TMP_VAR_NAMES}
do
    echo ""

    cat <<EOF | head -`expr ${NUM_OF_TMP_VAR} + 1`
static double ${name}0 MTT_UNUSED;
static double ${name}1 MTT_UNUSED;
static double ${name}2 MTT_UNUSED;
static double ${name}3 MTT_UNUSED;
static double ${name}4 MTT_UNUSED;
static double ${name}5 MTT_UNUSED;
static double ${name}6 MTT_UNUSED;
static double ${name}7 MTT_UNUSED;
static double ${name}8 MTT_UNUSED;
static double ${name}9 MTT_UNUSED;
static double ${name}10 MTT_UNUSED;
static double ${name}11 MTT_UNUSED;
static double ${name}12 MTT_UNUSED;
static double ${name}13 MTT_UNUSED;
static double ${name}14 MTT_UNUSED;
static double ${name}15 MTT_UNUSED;
static double ${name}16 MTT_UNUSED;
static double ${name}17 MTT_UNUSED;
static double ${name}18 MTT_UNUSED;
static double ${name}19 MTT_UNUSED;
static double ${name}20 MTT_UNUSED;
static double ${name}21 MTT_UNUSED;
static double ${name}22 MTT_UNUSED;
static double ${name}23 MTT_UNUSED;
static double ${name}24 MTT_UNUSED;
static double ${name}25 MTT_UNUSED;
static double ${name}26 MTT_UNUSED;
static double ${name}27 MTT_UNUSED;
static double ${name}28 MTT_UNUSED;
static double ${name}29 MTT_UNUSED;
static double ${name}30 MTT_UNUSED;
static double ${name}31 MTT_UNUSED;
static double ${name}32 MTT_UNUSED;
static double ${name}33 MTT_UNUSED;
static double ${name}34 MTT_UNUSED;
static double ${name}35 MTT_UNUSED;
static double ${name}36 MTT_UNUSED;
static double ${name}37 MTT_UNUSED;
static double ${name}38 MTT_UNUSED;
static double ${name}39 MTT_UNUSED;
static double ${name}40 MTT_UNUSED;
static double ${name}41 MTT_UNUSED;
static double ${name}42 MTT_UNUSED;
static double ${name}43 MTT_UNUSED;
static double ${name}44 MTT_UNUSED;
static double ${name}45 MTT_UNUSED;
static double ${name}46 MTT_UNUSED;
static double ${name}47 MTT_UNUSED;
static double ${name}48 MTT_UNUSED;
static double ${name}49 MTT_UNUSED;
static double ${name}50 MTT_UNUSED;
static double ${name}51 MTT_UNUSED;
static double ${name}52 MTT_UNUSED;
static double ${name}53 MTT_UNUSED;
static double ${name}54 MTT_UNUSED;
static double ${name}55 MTT_UNUSED;
static double ${name}56 MTT_UNUSED;
static double ${name}57 MTT_UNUSED;
static double ${name}58 MTT_UNUSED;
static double ${name}59 MTT_UNUSED;
static double ${name}60 MTT_UNUSED;
static double ${name}61 MTT_UNUSED;
static double ${name}62 MTT_UNUSED;
static double ${name}63 MTT_UNUSED;
static double ${name}64 MTT_UNUSED;
static double ${name}65 MTT_UNUSED;
static double ${name}66 MTT_UNUSED;
static double ${name}67 MTT_UNUSED;
static double ${name}68 MTT_UNUSED;
static double ${name}69 MTT_UNUSED;
static double ${name}70 MTT_UNUSED;
static double ${name}71 MTT_UNUSED;
static double ${name}72 MTT_UNUSED;
static double ${name}73 MTT_UNUSED;
static double ${name}74 MTT_UNUSED;
static double ${name}75 MTT_UNUSED;
static double ${name}76 MTT_UNUSED;
static double ${name}77 MTT_UNUSED;
static double ${name}78 MTT_UNUSED;
static double ${name}79 MTT_UNUSED;
static double ${name}80 MTT_UNUSED;
static double ${name}81 MTT_UNUSED;
static double ${name}82 MTT_UNUSED;
static double ${name}83 MTT_UNUSED;
static double ${name}84 MTT_UNUSED;
static double ${name}85 MTT_UNUSED;
static double ${name}86 MTT_UNUSED;
static double ${name}87 MTT_UNUSED;
static double ${name}88 MTT_UNUSED;
static double ${name}89 MTT_UNUSED;
static double ${name}90 MTT_UNUSED;
static double ${name}91 MTT_UNUSED;
static double ${name}92 MTT_UNUSED;
static double ${name}93 MTT_UNUSED;
static double ${name}94 MTT_UNUSED;
static double ${name}95 MTT_UNUSED;
static double ${name}96 MTT_UNUSED;
static double ${name}97 MTT_UNUSED;
static double ${name}98 MTT_UNUSED;
static double ${name}99 MTT_UNUSED;
static double ${name}100 MTT_UNUSED;
static double ${name}101 MTT_UNUSED;
static double ${name}102 MTT_UNUSED;
static double ${name}103 MTT_UNUSED;
static double ${name}104 MTT_UNUSED;
static double ${name}105 MTT_UNUSED;
static double ${name}106 MTT_UNUSED;
static double ${name}107 MTT_UNUSED;
static double ${name}108 MTT_UNUSED;
static double ${name}109 MTT_UNUSED;
static double ${name}110 MTT_UNUSED;
static double ${name}111 MTT_UNUSED;
static double ${name}112 MTT_UNUSED;
static double ${name}113 MTT_UNUSED;
static double ${name}114 MTT_UNUSED;
static double ${name}115 MTT_UNUSED;
static double ${name}116 MTT_UNUSED;
static double ${name}117 MTT_UNUSED;
static double ${name}118 MTT_UNUSED;
static double ${name}119 MTT_UNUSED;
static double ${name}120 MTT_UNUSED;
static double ${name}121 MTT_UNUSED;
static double ${name}122 MTT_UNUSED;
static double ${name}123 MTT_UNUSED;
static double ${name}124 MTT_UNUSED;
static double ${name}125 MTT_UNUSED;
static double ${name}126 MTT_UNUSED;
static double ${name}127 MTT_UNUSED;
static double ${name}128 MTT_UNUSED;
static double ${name}129 MTT_UNUSED;
static double ${name}130 MTT_UNUSED;
static double ${name}131 MTT_UNUSED;
static double ${name}132 MTT_UNUSED;
static double ${name}133 MTT_UNUSED;
static double ${name}134 MTT_UNUSED;
static double ${name}135 MTT_UNUSED;
static double ${name}136 MTT_UNUSED;
static double ${name}137 MTT_UNUSED;
static double ${name}138 MTT_UNUSED;
static double ${name}139 MTT_UNUSED;
static double ${name}140 MTT_UNUSED;
static double ${name}141 MTT_UNUSED;
static double ${name}142 MTT_UNUSED;
static double ${name}143 MTT_UNUSED;
static double ${name}144 MTT_UNUSED;
static double ${name}145 MTT_UNUSED;
static double ${name}146 MTT_UNUSED;
static double ${name}147 MTT_UNUSED;
static double ${name}148 MTT_UNUSED;
static double ${name}149 MTT_UNUSED;
static double ${name}150 MTT_UNUSED;
static double ${name}151 MTT_UNUSED;
static double ${name}152 MTT_UNUSED;
static double ${name}153 MTT_UNUSED;
static double ${name}154 MTT_UNUSED;
static double ${name}155 MTT_UNUSED;
static double ${name}156 MTT_UNUSED;
static double ${name}157 MTT_UNUSED;
static double ${name}158 MTT_UNUSED;
static double ${name}159 MTT_UNUSED;
static double ${name}160 MTT_UNUSED;
static double ${name}161 MTT_UNUSED;
static double ${name}162 MTT_UNUSED;
static double ${name}163 MTT_UNUSED;
static double ${name}164 MTT_UNUSED;
static double ${name}165 MTT_UNUSED;
static double ${name}166 MTT_UNUSED;
static double ${name}167 MTT_UNUSED;
static double ${name}168 MTT_UNUSED;
static double ${name}169 MTT_UNUSED;
static double ${name}170 MTT_UNUSED;
static double ${name}171 MTT_UNUSED;
static double ${name}172 MTT_UNUSED;
static double ${name}173 MTT_UNUSED;
static double ${name}174 MTT_UNUSED;
static double ${name}175 MTT_UNUSED;
static double ${name}176 MTT_UNUSED;
static double ${name}177 MTT_UNUSED;
static double ${name}178 MTT_UNUSED;
static double ${name}179 MTT_UNUSED;
static double ${name}180 MTT_UNUSED;
static double ${name}181 MTT_UNUSED;
static double ${name}182 MTT_UNUSED;
static double ${name}183 MTT_UNUSED;
static double ${name}184 MTT_UNUSED;
static double ${name}185 MTT_UNUSED;
static double ${name}186 MTT_UNUSED;
static double ${name}187 MTT_UNUSED;
static double ${name}188 MTT_UNUSED;
static double ${name}189 MTT_UNUSED;
static double ${name}190 MTT_UNUSED;
static double ${name}191 MTT_UNUSED;
static double ${name}192 MTT_UNUSED;
static double ${name}193 MTT_UNUSED;
static double ${name}194 MTT_UNUSED;
static double ${name}195 MTT_UNUSED;
static double ${name}196 MTT_UNUSED;
static double ${name}197 MTT_UNUSED;
static double ${name}198 MTT_UNUSED;
static double ${name}199 MTT_UNUSED;
static double ${name}200 MTT_UNUSED;
static double ${name}201 MTT_UNUSED;
static double ${name}202 MTT_UNUSED;
static double ${name}203 MTT_UNUSED;
static double ${name}204 MTT_UNUSED;
static double ${name}205 MTT_UNUSED;
static double ${name}206 MTT_UNUSED;
static double ${name}207 MTT_UNUSED;
static double ${name}208 MTT_UNUSED;
static double ${name}209 MTT_UNUSED;
static double ${name}210 MTT_UNUSED;
static double ${name}211 MTT_UNUSED;
static double ${name}212 MTT_UNUSED;
static double ${name}213 MTT_UNUSED;
static double ${name}214 MTT_UNUSED;
static double ${name}215 MTT_UNUSED;
static double ${name}216 MTT_UNUSED;
static double ${name}217 MTT_UNUSED;
static double ${name}218 MTT_UNUSED;
static double ${name}219 MTT_UNUSED;
static double ${name}220 MTT_UNUSED;
static double ${name}221 MTT_UNUSED;
static double ${name}222 MTT_UNUSED;
static double ${name}223 MTT_UNUSED;
static double ${name}224 MTT_UNUSED;
static double ${name}225 MTT_UNUSED;
static double ${name}226 MTT_UNUSED;
static double ${name}227 MTT_UNUSED;
static double ${name}228 MTT_UNUSED;
static double ${name}229 MTT_UNUSED;
static double ${name}230 MTT_UNUSED;
static double ${name}231 MTT_UNUSED;
static double ${name}232 MTT_UNUSED;
static double ${name}233 MTT_UNUSED;
static double ${name}234 MTT_UNUSED;
static double ${name}235 MTT_UNUSED;
static double ${name}236 MTT_UNUSED;
static double ${name}237 MTT_UNUSED;
static double ${name}238 MTT_UNUSED;
static double ${name}239 MTT_UNUSED;
static double ${name}240 MTT_UNUSED;
static double ${name}241 MTT_UNUSED;
static double ${name}242 MTT_UNUSED;
static double ${name}243 MTT_UNUSED;
static double ${name}244 MTT_UNUSED;
static double ${name}245 MTT_UNUSED;
static double ${name}246 MTT_UNUSED;
static double ${name}247 MTT_UNUSED;
static double ${name}248 MTT_UNUSED;
static double ${name}249 MTT_UNUSED;
static double ${name}250 MTT_UNUSED;
static double ${name}251 MTT_UNUSED;
static double ${name}252 MTT_UNUSED;
static double ${name}253 MTT_UNUSED;
static double ${name}254 MTT_UNUSED;
static double ${name}255 MTT_UNUSED;
static double ${name}256 MTT_UNUSED;
static double ${name}257 MTT_UNUSED;
static double ${name}258 MTT_UNUSED;
static double ${name}259 MTT_UNUSED;
static double ${name}260 MTT_UNUSED;
static double ${name}261 MTT_UNUSED;
static double ${name}262 MTT_UNUSED;
static double ${name}263 MTT_UNUSED;
static double ${name}264 MTT_UNUSED;
static double ${name}265 MTT_UNUSED;
static double ${name}266 MTT_UNUSED;
static double ${name}267 MTT_UNUSED;
static double ${name}268 MTT_UNUSED;
static double ${name}269 MTT_UNUSED;
static double ${name}270 MTT_UNUSED;
static double ${name}271 MTT_UNUSED;
static double ${name}272 MTT_UNUSED;
static double ${name}273 MTT_UNUSED;
static double ${name}274 MTT_UNUSED;
static double ${name}275 MTT_UNUSED;
static double ${name}276 MTT_UNUSED;
static double ${name}277 MTT_UNUSED;
static double ${name}278 MTT_UNUSED;
static double ${name}279 MTT_UNUSED;
static double ${name}280 MTT_UNUSED;
static double ${name}281 MTT_UNUSED;
static double ${name}282 MTT_UNUSED;
static double ${name}283 MTT_UNUSED;
static double ${name}284 MTT_UNUSED;
static double ${name}285 MTT_UNUSED;
static double ${name}286 MTT_UNUSED;
static double ${name}287 MTT_UNUSED;
static double ${name}288 MTT_UNUSED;
static double ${name}289 MTT_UNUSED;
static double ${name}290 MTT_UNUSED;
static double ${name}291 MTT_UNUSED;
static double ${name}292 MTT_UNUSED;
static double ${name}293 MTT_UNUSED;
static double ${name}294 MTT_UNUSED;
static double ${name}295 MTT_UNUSED;
static double ${name}296 MTT_UNUSED;
static double ${name}297 MTT_UNUSED;
static double ${name}298 MTT_UNUSED;
static double ${name}299 MTT_UNUSED;
static double ${name}300 MTT_UNUSED;
static double ${name}301 MTT_UNUSED;
static double ${name}302 MTT_UNUSED;
static double ${name}303 MTT_UNUSED;
static double ${name}304 MTT_UNUSED;
static double ${name}305 MTT_UNUSED;
static double ${name}306 MTT_UNUSED;
static double ${name}307 MTT_UNUSED;
static double ${name}308 MTT_UNUSED;
static double ${name}309 MTT_UNUSED;
static double ${name}310 MTT_UNUSED;
static double ${name}311 MTT_UNUSED;
static double ${name}312 MTT_UNUSED;
static double ${name}313 MTT_UNUSED;
static double ${name}314 MTT_UNUSED;
static double ${name}315 MTT_UNUSED;
static double ${name}316 MTT_UNUSED;
static double ${name}317 MTT_UNUSED;
static double ${name}318 MTT_UNUSED;
static double ${name}319 MTT_UNUSED;
static double ${name}320 MTT_UNUSED;
static double ${name}321 MTT_UNUSED;
static double ${name}322 MTT_UNUSED;
static double ${name}323 MTT_UNUSED;
static double ${name}324 MTT_UNUSED;
static double ${name}325 MTT_UNUSED;
static double ${name}326 MTT_UNUSED;
static double ${name}327 MTT_UNUSED;
static double ${name}328 MTT_UNUSED;
static double ${name}329 MTT_UNUSED;
static double ${name}330 MTT_UNUSED;
static double ${name}331 MTT_UNUSED;
static double ${name}332 MTT_UNUSED;
static double ${name}333 MTT_UNUSED;
static double ${name}334 MTT_UNUSED;
static double ${name}335 MTT_UNUSED;
static double ${name}336 MTT_UNUSED;
static double ${name}337 MTT_UNUSED;
static double ${name}338 MTT_UNUSED;
static double ${name}339 MTT_UNUSED;
static double ${name}340 MTT_UNUSED;
static double ${name}341 MTT_UNUSED;
static double ${name}342 MTT_UNUSED;
static double ${name}343 MTT_UNUSED;
static double ${name}344 MTT_UNUSED;
static double ${name}345 MTT_UNUSED;
static double ${name}346 MTT_UNUSED;
static double ${name}347 MTT_UNUSED;
static double ${name}348 MTT_UNUSED;
static double ${name}349 MTT_UNUSED;
static double ${name}350 MTT_UNUSED;
static double ${name}351 MTT_UNUSED;
static double ${name}352 MTT_UNUSED;
static double ${name}353 MTT_UNUSED;
static double ${name}354 MTT_UNUSED;
static double ${name}355 MTT_UNUSED;
static double ${name}356 MTT_UNUSED;
static double ${name}357 MTT_UNUSED;
static double ${name}358 MTT_UNUSED;
static double ${name}359 MTT_UNUSED;
static double ${name}360 MTT_UNUSED;
static double ${name}361 MTT_UNUSED;
static double ${name}362 MTT_UNUSED;
static double ${name}363 MTT_UNUSED;
static double ${name}364 MTT_UNUSED;
static double ${name}365 MTT_UNUSED;
static double ${name}366 MTT_UNUSED;
static double ${name}367 MTT_UNUSED;
static double ${name}368 MTT_UNUSED;
static double ${name}369 MTT_UNUSED;
static double ${name}370 MTT_UNUSED;
static double ${name}371 MTT_UNUSED;
static double ${name}372 MTT_UNUSED;
static double ${name}373 MTT_UNUSED;
static double ${name}374 MTT_UNUSED;
static double ${name}375 MTT_UNUSED;
static double ${name}376 MTT_UNUSED;
static double ${name}377 MTT_UNUSED;
static double ${name}378 MTT_UNUSED;
static double ${name}379 MTT_UNUSED;
static double ${name}380 MTT_UNUSED;
static double ${name}381 MTT_UNUSED;
static double ${name}382 MTT_UNUSED;
static double ${name}383 MTT_UNUSED;
static double ${name}384 MTT_UNUSED;
static double ${name}385 MTT_UNUSED;
static double ${name}386 MTT_UNUSED;
static double ${name}387 MTT_UNUSED;
static double ${name}388 MTT_UNUSED;
static double ${name}389 MTT_UNUSED;
static double ${name}390 MTT_UNUSED;
static double ${name}391 MTT_UNUSED;
static double ${name}392 MTT_UNUSED;
static double ${name}393 MTT_UNUSED;
static double ${name}394 MTT_UNUSED;
static double ${name}395 MTT_UNUSED;
static double ${name}396 MTT_UNUSED;
static double ${name}397 MTT_UNUSED;
static double ${name}398 MTT_UNUSED;
static double ${name}399 MTT_UNUSED;
static double ${name}400 MTT_UNUSED;
static double ${name}401 MTT_UNUSED;
static double ${name}402 MTT_UNUSED;
static double ${name}403 MTT_UNUSED;
static double ${name}404 MTT_UNUSED;
static double ${name}405 MTT_UNUSED;
static double ${name}406 MTT_UNUSED;
static double ${name}407 MTT_UNUSED;
static double ${name}408 MTT_UNUSED;
static double ${name}409 MTT_UNUSED;
static double ${name}410 MTT_UNUSED;
static double ${name}411 MTT_UNUSED;
static double ${name}412 MTT_UNUSED;
static double ${name}413 MTT_UNUSED;
static double ${name}414 MTT_UNUSED;
static double ${name}415 MTT_UNUSED;
static double ${name}416 MTT_UNUSED;
static double ${name}417 MTT_UNUSED;
static double ${name}418 MTT_UNUSED;
static double ${name}419 MTT_UNUSED;
static double ${name}420 MTT_UNUSED;
static double ${name}421 MTT_UNUSED;
static double ${name}422 MTT_UNUSED;
static double ${name}423 MTT_UNUSED;
static double ${name}424 MTT_UNUSED;
static double ${name}425 MTT_UNUSED;
static double ${name}426 MTT_UNUSED;
static double ${name}427 MTT_UNUSED;
static double ${name}428 MTT_UNUSED;
static double ${name}429 MTT_UNUSED;
static double ${name}430 MTT_UNUSED;
static double ${name}431 MTT_UNUSED;
static double ${name}432 MTT_UNUSED;
static double ${name}433 MTT_UNUSED;
static double ${name}434 MTT_UNUSED;
static double ${name}435 MTT_UNUSED;
static double ${name}436 MTT_UNUSED;
static double ${name}437 MTT_UNUSED;
static double ${name}438 MTT_UNUSED;
static double ${name}439 MTT_UNUSED;
static double ${name}440 MTT_UNUSED;
static double ${name}441 MTT_UNUSED;
static double ${name}442 MTT_UNUSED;
static double ${name}443 MTT_UNUSED;
static double ${name}444 MTT_UNUSED;
static double ${name}445 MTT_UNUSED;
static double ${name}446 MTT_UNUSED;
static double ${name}447 MTT_UNUSED;
static double ${name}448 MTT_UNUSED;
static double ${name}449 MTT_UNUSED;
static double ${name}450 MTT_UNUSED;
static double ${name}451 MTT_UNUSED;
static double ${name}452 MTT_UNUSED;
static double ${name}453 MTT_UNUSED;
static double ${name}454 MTT_UNUSED;
static double ${name}455 MTT_UNUSED;
static double ${name}456 MTT_UNUSED;
static double ${name}457 MTT_UNUSED;
static double ${name}458 MTT_UNUSED;
static double ${name}459 MTT_UNUSED;
static double ${name}460 MTT_UNUSED;
static double ${name}461 MTT_UNUSED;
static double ${name}462 MTT_UNUSED;
static double ${name}463 MTT_UNUSED;
static double ${name}464 MTT_UNUSED;
static double ${name}465 MTT_UNUSED;
static double ${name}466 MTT_UNUSED;
static double ${name}467 MTT_UNUSED;
static double ${name}468 MTT_UNUSED;
static double ${name}469 MTT_UNUSED;
static double ${name}470 MTT_UNUSED;
static double ${name}471 MTT_UNUSED;
static double ${name}472 MTT_UNUSED;
static double ${name}473 MTT_UNUSED;
static double ${name}474 MTT_UNUSED;
static double ${name}475 MTT_UNUSED;
static double ${name}476 MTT_UNUSED;
static double ${name}477 MTT_UNUSED;
static double ${name}478 MTT_UNUSED;
static double ${name}479 MTT_UNUSED;
static double ${name}480 MTT_UNUSED;
static double ${name}481 MTT_UNUSED;
static double ${name}482 MTT_UNUSED;
static double ${name}483 MTT_UNUSED;
static double ${name}484 MTT_UNUSED;
static double ${name}485 MTT_UNUSED;
static double ${name}486 MTT_UNUSED;
static double ${name}487 MTT_UNUSED;
static double ${name}488 MTT_UNUSED;
static double ${name}489 MTT_UNUSED;
static double ${name}490 MTT_UNUSED;
static double ${name}491 MTT_UNUSED;
static double ${name}492 MTT_UNUSED;
static double ${name}493 MTT_UNUSED;
static double ${name}494 MTT_UNUSED;
static double ${name}495 MTT_UNUSED;
static double ${name}496 MTT_UNUSED;
static double ${name}497 MTT_UNUSED;
static double ${name}498 MTT_UNUSED;
static double ${name}499 MTT_UNUSED;
static double ${name}500 MTT_UNUSED;
EOF

    if [ ${NUM_OF_TMP_VAR} -gt 500 ]; then
	i=501
	while [ ${i} -le ${NUM_OF_TMP_VAR} ]
	do
	  echo "static double ${name}${i} MTT_UNUSED;"
	  i=`expr ${i} + 1`
	done
    fi
done
}

echo Creating ${OUT}
cat <<EOF > ${OUT}
#ifndef MTT_UNUSED
#ifdef __GNUC__

Modified mttroot/mtt/doc/mtt.texi from [95bf219a63] to [677998cd3f].

12
13
14
15
16
17
18









19
20
21
22
23
24
25


@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







>
>
>
>
>
>
>
>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34


@comment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@comment  Version control history
@comment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@comment  $Id$
@comment  $Log$
@comment  Revision 1.9  2002/07/05 13:29:34  geraint
@comment  Added notes about generating dynamically linked functions for Octave and Matlab.
@comment
@comment  Revision 1.8  2002/07/04 21:34:12  geraint
@comment  Updated gnuplot view description to describe Tcl/Tk interface instead of obsolete txt method.
@comment
@comment  Revision 1.7  2002/04/23 09:51:54  gawthrop
@comment  Changed incorrect statement about searching for components.
@comment
@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
431
432
433
434
435
436
437




438
439
440
441
442
443
444
Simulation parameters

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





Simulation output

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

Representations








>
>
>
>







440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
Simulation parameters

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

Simulation code

* Dynamically linked functions::  

Simulation output

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

Representations

658
659
660
661
662
663
664



665
666
667
668
669
670
671
* Text editors::                
* Octave::                      
* LaTeX::                       

Octave

* Octave control system toolbox (OCST)::  




Administration

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







>
>
>







671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
* Text editors::                
* Octave::                      
* LaTeX::                       

Octave

* Octave control system toolbox (OCST)::  
* Creating GNU Octave .oct files::  
* Creating Matlab .mex files::  
* Embedding MTT models in Simulink::  

Administration

* Software components::         
* REDUCE setup::                
* Octave setup::                
* Paths::                       
2313
2314
2315
2316
2317
2318
2319


































2320
2321
2322
2323
2324
2325
2326
@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.







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







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
@end example

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

@menu
* Dynamically linked functions::  
@end menu

@node Dynamically linked functions,  , Simulation code, Simulation code
@comment  node-name,  next,  previous,  up
@subsection Dynamically linked functions

Some model representations can be compiled into dynamically loaded
code (shared objects) which are compiled prior to use in other
modelling and simulation environments; in particular, .oct files can
be generated for use in GNU Octave (@pxref{Creating GNU Octave .oct
files}) and .mex files can be generated for use in Matlab
(@pxref{Creating Matlab .mex files}) or Simulink (@pxref{Embedding MTT
models in Simulink}).  The use of compiled (and possibly
compiler-optimised) code can offer significant processing speed
advantages over equivalent interpreted functions (e.g. .m files) for
computationally intensive procedures.

The C++ code generated by @strong{MTT} allows the same code to be
generated as standalone code, Octave .oct files or Matlab .mexglx
files. Although @strong{MTT} usually takes care of the compilation
options, if it is necessary to compile the code on a machine on which
@strong{MTT} is not installed, the appropriate flag should be passed
to the compiler pre-processor:
@itemize @bullet
@item
@code{-DCODEGENTARGET=STANDALONE}
@item
@code{-DCODEGENTARGET=OCTAVEDLD}
@item
@code{-DCODEGENTARGET=MATLABMEX}
@end itemize

@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.
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
@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







|
|
>





<
|
<

<
<
<
>

<
>


<
<
<
<
<
|
<
<
<
<


<
<
>







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
@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 plots may be conveniently selected, viewed with
@uref{http://www.gnuplot.org,gnuplot} 
and saved to file (in PostScript format) using the command

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


This will cause a menu to be displayed, from which states and outputs may be selected for viewing. Clicking on a @emph{parameter name} will cause a new window to be opened displaying the time history of the selected parameter. Selecting the @emph{print} option in the main window provides the option of saving to file a plot of the last selected parameter. Clicking on the @emph{title bar} of the main window (``Outputs'' or ``States'') will alter the order in which the parameter names are displayed.





It should be noted that unlike other representations, if a simulation has been previously run in a directory, this command will @emph{not} cause @strong{MTT} to re-run a simulation, even if any of the input files have been changed.


If it is desired to re-run a simulation, it is advisable to run the command 

@example





mtt [options] rc odeso view ; mtt [options] rc gnuplot view




@end example



As with @strong{xMTT} (@pxref{Menu-driven interface}), the Wish Tcl/Tk interpreter must be installed to make use of this feature.

@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
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
%% 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 







|







3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
%% 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 
4538
4539
4540
4541
4542
4543
4544









4545
4546
4547
4548
4549
4550
4551
# 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







>
>
>
>
>
>
>
>
>







4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
# Generated by MTT at Mon Jun 16 15:10:17 BST 1997

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% Version control history
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %% $Id$
# %% $Log$
# %% Revision 1.9  2002/07/05 13:29:34  geraint
# %% Added notes about generating dynamically linked functions for Octave and Matlab.
# %%
# %% Revision 1.8  2002/07/04 21:34:12  geraint
# %% Updated gnuplot view description to describe Tcl/Tk interface instead of obsolete txt method.
# %%
# %% Revision 1.7  2002/04/23 09:51:54  gawthrop
# %% Changed incorrect statement about searching for components.
# %%
# %% 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
5812
5813
5814
5815
5816
5817
5818



5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
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







>
>
>


|







5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
step(rc);
bode(rc);
@end example


@menu
* Octave control system toolbox (OCST)::  
* Creating GNU Octave .oct files::  
* Creating Matlab .mex files::  
* Embedding MTT models in Simulink::  
@end menu

@node Octave control system toolbox (OCST), Creating GNU Octave .oct files, 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
5852
5853
5854
5855
5856
5857
5858




5859
































































































































5860
5861
5862
5863
5864
5865
5866
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







>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
The following octave commands then generate the step reponse and bode
diagram respectively:
@example
step(rc);
bode(rc);
@end example

@node Creating GNU Octave .oct files, Creating Matlab .mex files, Octave control system toolbox (OCST), Octave
@comment  node-name,  next,  previous,  up
@subsection Creating GNU Octave .oct files
@cindex Creating GNU Octave .oct files

GNU Octave dynamically loaded functions (.oct files) can be created by
instructing @strong{MTT} to create the ``oct'' representation:

@example
  mtt [options] sys ode oct
@end example

This will cause @strong{MTT} to create the C++ representation of the system
(sys_ode.cc) and to then compile it as a shared object suitable for
use within Octave. The resultant file may be used in an identical
manner to the equivalent, but generally slower, interpreted .m file.

Usage information for the function may be obtained within Octave in the usual manner:

@example
  octave:1> help rc_ode

  rc_ode is the dynamically-linked function from the file
  /home/mttuser/rc/rc_ode.oct

  Usage: [mttdx] = rc_ode(mttx,mttu,mttt,mttpar)
  Octave ode representation of system rc
  Generated by MTT on Fri Jul  5 11:23:08 BST 2002
@end example

Note that the first line of output from Octave identifies whether the
compiled or interpreted function is being used.

Alternatively, standard representations may be generated using the
Octave DLDs by use of the ``-oct'' switch:

@example
  mtt -oct rc odeso view
@end example

In order to successfully generate .oct files, Octave must be correctly
configured prior to compilation and certain headers and libraries must
be correctly installed on the system (@pxref{.oct file dependencies}).

@node  Creating Matlab .mex files, Embedding MTT models in Simulink, Creating GNU Octave .oct files, Octave
@comment  node-name,  next,  previous,  up
@subsection Creating Matlab .mex files
@cindex Creating Matlab .mex files

On GNU/Linux systems, Matlab dynamically linked executables (.mexglx
files) can created by instructing @strong{MTT} to create the
``mexglx'' representation:

@example
  mtt [options] sys ode mexglx
@end example

This will cause @strong{MTT} to create the C++ representation of the
system (sys_ode.cc) and to then compile it as a shared object suitable
for use within Matlab.

If it is necessary to compile mex files for another platform, then the
usual C++ representation (generated with the -cc flag) can be created
and the resultant file compiled with the -DCODEGENTARGET=MATLABMEX
flag on the target platform.

@example
  mtt_machine:
  mtt -cc rc ode cc

  matlab_machine:
  matlab> mex -DCODEGENTARGET=MATLABMEX rc_ode.cc
@end example

@node  Embedding MTT models in Simulink,  , Creating Matlab .mex files, Octave
@comment  node-name,  next,  previous,  up
@subsection Embedding MTT models in Simulink
@cindex Embedding MTT models in Simulink

It is possible to embed @strong{MTT} functions or entire @strong{MTT}
models within Simulink simulations as Sfun blocks. If the zip package
is installed on the system, the command

@example
  mtt sys sfun zip
@end example

will create a compressed archive containing sys.mdl, which may be
embedded into a larger Simulink model. Also contained within the
archive will be four sys_sfun*.c files,

@itemize @bullet
@item
sys_sfun.c
model state and output equations
@item
sys_sfun_ae.c
model algebraic equations
@item
sys_sfun_input.c
model inputs
@item
sys_sfun_interface.c
interface between MTT model and Simulink
@end itemize

The last of these files must be edited to correctly map the inputs and
outputs between the @strong{MTT} and Simulink models. The two sections
to edit are clearly marked with

@example
  @code{/* Start EDIT */}
  @code{....}
  @code{/* End EDIT */}
@end example

These four files should then be compiled with the Matlab ``mex''
compiler as described in the @emph{README} file in the archive.

If it is desired to compile the .mex files directly from within
@strong{MTT} on a machine which has the Matlab header files installed,
this may be done with the command

@example
  mtt sys sfun mexglx 
@end example

which will generated the four .mex files and the .mdl file. In this
case, the user must ensure that @emph{sys_sfun_interface.c} has been
correctly edited prior to compilation.

Note that solution of algebraic equations within Simulink is not
possible unless the @emph{Matlab Optimisation Toolbox} is installed.

@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
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
























5996
5997
5998
5999
6000
6001
6002
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







|
|
|
|



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







6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
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
libraries @code{liboctave}, @code{libcruft} and @code{liboctinterp}
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}.

A number of additional libraries and headers are also required to be
installed on a system. These include,
@itemize @bullet
@item
@emph{ncurses} and @emph{readline}
               terminal control routines
@item
@emph{blas} or @emph{altas}
            basic linear algebra subprograms, usually optimised for the specific processor
@item
@emph{fftw}
        fast Fourier transform routines
@item
@emph{g2c}
        GNU Fortran to C conversion routines
@item
@emph{kpathsea}
        TeX path search routines
@end itemize

Note that on many GNU/Linux distributions, the necessary headers are
contained in development packages which must be installed in addition
to the standard library package.

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

Modified mttroot/mtt/lib/comp/compound/Sensitivity/sEMTF/sEMTF_lbl.txt from [c9d0e3e307] to [9abf0eb7d9].

1
2







3




4
5
6
7
8
9






10
11
12
13
14
15
16
%% Label file for system sEMTF (sEMTF_lbl.txt)
%SUMMARY sEMTF Effort modulated TF - sensitivity version







%DESCRIPTION 





% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% $Id$
% %% $Log$






% %% Revision 1.1  2000/12/28 17:29:10  peterg
% %% To RCS
% %%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% Port aliases


>
>
>
>
>
>
>
|
>
>
>
>






>
>
>
>
>
>







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
%% Label file for system sEMTF (sEMTF_lbl.txt)
%SUMMARY sEMTF Effort modulated TF - sensitivity version
%DESCRIPTION It is assumed that no sensitivity parameter is associated
%DESCRIPTION with this component.
%DESCRIPTION This is a built out of EMTFs and the 4 port AE3 component
%DESCRIPTION There is one argument alias - the transformer (flow) gain 
%DESCRIPTION There are two CR aliases: one for the EMTF and one for
%DESCRIPTION the AE3
%DESCRIPTION Examples:
%DESCRIPTION   lin;slin  n
%DESCRIPTION   lsin;slsin l
%DESCRIPTION   lcos;slcos l



% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% $Id$
% %% $Log$
% %% Revision 1.2  2002/06/10 08:27:33  gawthrop
% %% Updated description
% %%
% %% Revision 1.1  2002/04/17 18:50:35  gawthrop
% %% Sensitivity EMTF components
% %%
% %% Revision 1.1  2000/12/28 17:29:10  peterg
% %% To RCS
% %%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% Port aliases

Modified mttroot/mtt/lib/control/PPP/ppp_optimise.m from [d6b999b722] to [32d0c90e52].

25
26
27
28
29
30
31






32
33
34
35
36
37
38
  ######################################
  
  ###############################################################
  ## Version control history
  ###############################################################
  ## $Id$
  ## $Log$






  ## Revision 1.10  2002/05/13 16:01:09  gawthrop
  ## Addes Q weighting matrix
  ##
  ## Revision 1.9  2002/05/08 10:14:21  gawthrop
  ## Idetification now OK (Moved data range in ppp_optimise by one sample interval)
  ##
  ## Revision 1.8  2002/04/23 17:50:39  gawthrop







>
>
>
>
>
>







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  ######################################
  
  ###############################################################
  ## Version control history
  ###############################################################
  ## $Id$
  ## $Log$
  ## Revision 1.12  2002/06/11 11:25:25  gawthrop
  ## No longer delay the simulated data.
  ##
  ## Revision 1.11  2002/05/20 13:32:36  gawthrop
  ## Sanity check on y_0
  ##
  ## Revision 1.10  2002/05/13 16:01:09  gawthrop
  ## Addes Q weighting matrix
  ##
  ## Revision 1.9  2002/05/08 10:14:21  gawthrop
  ## Idetification now OK (Moved data range in ppp_optimise by one sample interval)
  ##
  ## Revision 1.8  2002/04/23 17:50:39  gawthrop
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
    printf("\n");
  endif
  
  while (abs(reduction)>extras.criterion)&&\
	(abs(err)>extras.criterion)&&\
	(iterations<extras.max_iterations)

    iterations = iterations + 1; # Increment iteration counter

    [y,y_par,x] = eval(sim_command); # Simulate
    [N_data,N_y] = size(y);

    if (N_y!=n_y)
      mess = sprintf("n_y (%i) in data not same as n_y (%i) in model", n_y,N_y);
      error(mess);
    endif



    if ( (N_data-n_data)<1 )
      error(sprintf("y_0 (%i) must be shorter than y (%i)", n_data, N_data));
    endif
    
    ## Use the last part of the simulation to compare with data
    ## And shift back by one data point
    y = y(N_data-n_data:N_data-1,:);
    y_par = y_par(N_data-n_data:N_data-1,:);







    ##Evaluate error, cost derivative J and cost second derivative JJ
    err = 0; 
    J = zeros(n_th,1);
    JJ = zeros(n_th,n_th);
   
    for i = 1:n_y
      E = y(:,i) - y_0(:,i);	#  Error in ith output







|


|






>
>
|
|
|

<
<
|
|

>
>
>
>
>
>







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
    printf("\n");
  endif
  
  while (abs(reduction)>extras.criterion)&&\
	(abs(err)>extras.criterion)&&\
	(iterations<extras.max_iterations)

    iterations = iterations + 1 # Increment iteration counter

    [y,y_par,x] = eval(sim_command); # Simulate
    [N_data,N_y] = size(y)

    if (N_y!=n_y)
      mess = sprintf("n_y (%i) in data not same as n_y (%i) in model", n_y,N_y);
      error(mess);
    endif

    ## Use the last part of the simulation to compare with data
    ## ### Removed #### And shift back by one data point
#     if ( (N_data-n_data)<1 )
#       error(sprintf("y_0 (%i) must be shorter than y (%i)", n_data, N_data));
#     endif
    


    y = y(N_data-n_data+1:N_data,:);
    y_par = y_par(N_data-n_data+1:N_data,:);

    if extras.visual==1
      ## Plot
      title("Optimisation data");
      plot([y y_0])
    endif
    
    ##Evaluate error, cost derivative J and cost second derivative JJ
    err = 0; 
    J = zeros(n_th,1);
    JJ = zeros(n_th,n_th);
   
    for i = 1:n_y
      E = y(:,i) - y_0(:,i);	#  Error in ith output

Modified mttroot/mtt/lib/cr/r/slin.cr from [5d71e66c46] to [ac0389ce2b].

36
37
38
39
40
41
42






















43
44





SUCH THAT sgain EQ 0
LET slin(gain_causality, gain, sgain, other_causality, 2, 
       input, causality, 1,
       sinput, causality, 2)
         = lin(gain_causality, gain, other_causality, 1, 
               sinput, causality, 1);
         






















END;;













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


>
>
>
>
>
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
SUCH THAT sgain EQ 0
LET slin(gain_causality, gain, sgain, other_causality, 2, 
       input, causality, 1,
       sinput, causality, 2)
         = lin(gain_causality, gain, other_causality, 1, 
               sinput, causality, 1);
         

%% This is the version to go with sEMTF
%% It is the CR passed to the AE3 components

%DESCRIPTION four port component - effort i/o
FOR ALL gain, input, junk, m_input, dm_input
LET slin(gain, effort, 2, 
	input, effort, 1,
	junk, flow, 2,
	m_input, effort, 3,
        dm_input,effort, 4)
	 = gain*dm_input*input;

%DESCRIPTION four port component - flow i/o
FOR ALL gain, input, junk, m_input, dm_input
LET slin(gain, flow, 2, 
	input, flow, 1,
	junk, effort, 2,
	m_input, effort, 3,
        dm_input,effort, 4)
	 = gain*dm_input*input;

END;;






Modified mttroot/mtt/lib/reduce/fix_c.r from [551406cfe8] to [d6d8abfc53].

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
%% Fixes for c-code generation

%% Set PI explicitly here to avoid later conflict with cc headers
%% if PI is not already a number (i.e. on rounded has not been set)
IF NOT NUMBERP (pi) THEN LET PI = 3.14159$

ON ROUNDED$ % No integer output

%% Changes x^y to pow(x,y)
 OPERATOR pow$
 FOR ALL x,y LET x^y = pow(x,y)$ % Use the pow function
 
 %% Derivatives
 FOR ALL f,g,x LET df(pow(f,g),x)=
 	   pow(f,g-1) * (df(f,x)*g + df(g,x)*f*log(f))$

 %% Special cases
 FOR ALL x LET pow(x,0) = 1$
 FOR ALL x LET pow(x,1) = x$



OPERATOR fabs$
FOR ALL x let abs(x) = fabs(x)$


END$











|







>
>






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
%% Fixes for c-code generation

%% Set PI explicitly here to avoid later conflict with cc headers
%% if PI is not already a number (i.e. on rounded has not been set)
IF NOT NUMBERP (pi) THEN LET PI = 3.14159$

ON ROUNDED$ % No integer output

%% Changes x^y to pow(x,y)
 OPERATOR pow$
 FOR ALL x,y LET x^y = pow(x,y)$ % Use the pow function

 %% Derivatives
 FOR ALL f,g,x LET df(pow(f,g),x)=
 	   pow(f,g-1) * (df(f,x)*g + df(g,x)*f*log(f))$

 %% Special cases
 FOR ALL x LET pow(x,0) = 1$
 FOR ALL x LET pow(x,1) = x$
 FOR ALL x,y,z LET pow(x,y)*pow(x,z) = pow(x,y+z)$ 
 FOR ALL x,y,z LET pow(pow(x,y),z) = pow(x,y*z)$

OPERATOR fabs$
FOR ALL x let abs(x) = fabs(x)$


END$

Added mttroot/mtt/lib/rep/ident_rep.make version [042982e678].











































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# -*-makefile-*-
# Makefile for representation ident
# File ident_rep.make

#Copyright (C) 2000,2001,2002 by Peter J. Gawthrop

## Model targets
model_reps =  ${SYS}_sympar.m ${SYS}_simpar.m ${SYS}_state.m 
model_reps += ${SYS}_numpar.m ${SYS}_input.m ${SYS}_ode2odes.m  
model_reps += ${SYS}_def.m

## Prepend s to get the sensitivity targets
sensitivity_reps = ${model_reps:%=s%}

## Simulation targets
sims = ${SYS}_sim.m s${SYS}_ssim.m

## m-files needed for ident
ident_m = ${SYS}_ident.m ${SYS}_ident_numpar.m 

## Targets for the ident simulation
ident_reps = ${ident_m} ${sims} ${model_reps} ${sensitivity_reps}

## ps output files
psfiles = ${SYS}_ident.ps ${SYS}_ident.basis.ps ${SYS}_ident.par.ps ${SYS}_ident.U.ps
figfiles = ${psfiles:%.ps=%.fig}

all: ${SYS}_ident.${LANG}

echo:
	echo "sims: ${sims}"
	echo "model_reps: ${model_reps}"
	echo "sensitivity_reps: ${sensitivity_reps}"
	echo "ident_reps: ${ident_reps}"

${SYS}_ident.view: ${SYS}_ident.ps
	ident_rep.sh ${SYS} view

${psfiles}: ${SYS}_ident.fig
	ident_rep.sh ${SYS} ps

${SYS}_ident.gdat: ${SYS}_ident.dat2
	ident_rep.sh ${SYS} gdat

${SYS}_ident.fig ${SYS}_ident.dat2: ${ident_reps}
	ident_rep.sh ${SYS} dat2

${SYS}_ident.m: 
	ident_rep.sh ${SYS} m

${SYS}_ident_numpar.m:
	ident_rep.sh ${SYS} numpar.m

## System model reps
## Generic txt files 
${SYS}_%.txt:
	mtt ${OPTS} -q -stdin ${SYS} $* txt

## Specific m files
${SYS}_ode2odes.m: ${SYS}_rdae.r
	mtt -q -stdin ${OPTS} ${SYS} ode2odes m

${SYS}_sim.m: ${SYS}_ode2odes.m
	mtt ${OPTS} -q -stdin ${SYS} sim m

## Generic txt to m
${SYS}_%.m: ${SYS}_%.txt
	mtt ${OPTS} -q -stdin ${SYS} $* m

## r files
${SYS}_def.r: ${SYS}_abg.fig
	mtt ${OPTS} -q -stdin ${SYS} def r

${SYS}_rdae.r: 
	mtt ${OPTS} -q -stdin ${SYS} rdae r

## Sensitivity model reps
## Generic txt files 
s${SYS}_%.txt:
	mtt ${OPTS} -q -stdin -s s${SYS} $* txt

## Specific m files
s${SYS}_ode2odes.m: s${SYS}_rdae.r
	mtt -q -stdin ${OPTS} -s s${SYS} ode2odes m

s${SYS}_ssim.m:
	mtt -q -stdin ${OPTS} -s s${SYS} ssim m

s${SYS}_def.m:
	mtt -q -stdin ${OPTS} -s s${SYS} def m


## Generic txt to m
s${SYS}_%.m: s${SYS}_%.txt
	mtt ${OPTS} -q -stdin s${SYS} $* m

## r files
s${SYS}_rdae.r: 
	mtt ${OPTS} -q -stdin -s s${SYS} rdae r


Added mttroot/mtt/lib/rep/ident_rep.sh version [509586cb1e].























































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#! /bin/sh

## ident_rep.sh
## DIY representation "ident" for mtt
# Copyright (C) 2002 by Peter J. Gawthrop

sys=$1
rep=ident
lang=$2
mtt_parameters=$3
rep_parameters=$4

## Some names
target=${sys}_${rep}.${lang}
def_file=${sys}_def.r
dat2_file=${sys}_ident.dat2
dat2s_file=${sys}_idents.dat2
ident_numpar_file=${sys}_ident_numpar.m
option_file=${sys}_ident_mtt_options.txt

## Get system information
if [ -f "${def_file}" ]; then
 echo Using ${def_file}
else
  mtt -q ${sys} def r
fi

ny=`mtt_getsize $1 y`
nu=`mtt_getsize $1 u`

check_new_options() {
    if [ -f "${option_file}" ]; then
	old_options=`cat ${option_file}`
        if [ "${mtt_options}" != "${old_options}" ]; then
	   echo ${mtt_options} > ${option_file}
	fi
    else
	echo ${mtt_options} > ${option_file}
    fi
}

## Make the _ident.m file
make_ident() {
filename=${sys}_${rep}.m
echo Creating ${filename}

cat > ${filename} <<EOF    
function [y,u,t] = ${sys}_ident (last, ppp_names, par_names, A_u, A_w, w, Q, extras)

  ## usage:  [y,u,t] = ${sys}_ident (last, ppp_names, par_names, A_u, A_w, w, Q, extras)
  ##
  ## last      last time in run
  ## ppp_names Column vector of names of ppp params
  ## par_names Column vector of names of estimated params
  ## extras    Structure containing additional info

  ##Sanity check
  if nargin<2
    printf("Usage: [y,u,t] = ${sys}_ident(N, ppp_names[, par_names, extras])\n");
    return
  endif

  if nargin<4
    ## Set up optional parameters
    extras.criterion = 1e-3;
    extras.emulate_timing = 0;
    extras.max_iterations = 15;
    extras.simulate = 1;
    extras.v =  1e-6;
    extras.verbose = 0;
    extras.visual = 1;
  endif
  
  ## System info
  [n_x,n_y,n_u,n_z,n_yz] = ${sys}_def;
  sympar  = ${sys}_sympar;
  simpar  = ${sys}_simpar;
  sympars  = s${sys}_sympar;
  simpars  = s${sys}_simpar;
  t_ol = simpar.last;
    
  ## Number of intervals needed
  N = ceil(last/t_ol);

  ## Setpoints
  if extras.verbose
    printf("Open-loop interval %3.2f \n", simpar.last);
    printf(" -- using info in ${sys}_simpar.txt\n");
    printf("PPP optimisation from %3.2f to %3.2f\n", simpars.first, simpars.last);
    printf(" -- using info in s${sys}_simpar.txt\n");
  endif
  
  t_horizon = [simpars.first+simpars.dt:simpars.dt:simpars.last]';
  w_s = ones(length(t_horizon)-1,1)*w';

  ## Setup the indices of the adjustable stuff
  if nargin<2
    i_ppp = []
  else
    i_ppp = ppp_indices (ppp_names,sympar,sympars); # Parameters
  endif

  n_ppp = length(i_ppp(:,1));

  if nargin<3
    i_par = []
  else
    i_par = ppp_indices (par_names,sympar,sympars); # Parameters
  endif
  
    ## Do some simulations to check things out
    ## System itself
    par = ${sys}_numpar;
    x_0_ol = ${sys}_state(par);
    [y_ol,x_ol, t_ol] =  ${sys}_sim(x_0_ol, par, simpar, ones(1,n_u));
    simpar_OL = simpar;
    simpar_OL.last = simpars.last;
    [y_OL,x_OL, t_OL] =  ${sys}_sim(x_0_ol, par, simpar_OL, ones(1,n_u));

    pars = s${sys}_numpar;
    x_0_ppp = s${sys}_state(pars);
    [y_ppp,y_par,x_ppp, t_ppp] =  s${sys}_ssim(x_0_ppp, pars, simpars, ones(1,n_u));

    simpar_PPP = simpars;
    simpar_PPP.first = simpar.first;
    [y_PPP,y_par,x_PPP, t_PPP] =  s${sys}_ssim(x_0_ppp, pars, simpar_PPP, ones(1,n_u));

    ## Basis functions
    Us = ppp_ustar(A_u,1,t_OL',0,0)';


  if extras.visual		#Show some graphs
    figure(2); 	
    grid; title("Outputs of ${sys}_sim and s${sys}_ssim");
    plot(t_ol,y_ol, '*', t_ppp, y_ppp, '+', t_OL, y_OL, t_PPP, y_PPP);


    figure(3); 	
    grid; title("Basis functions");
    plot(t_OL, Us);

  endif



  ## Do it
  [y,u,t,P,U,t_open,t_ppp,t_est,its_ppp,its_est] \
      = ppp_nlin_run ("${sys}",i_ppp,i_par,A_u,w_s,N,Q,extras);

  ## Compute values at ends of ol intervals
  T_open = cumsum(t_open);
  T_open = T_open(1:length(T_open)-1); # Last point not in t
  j=[];
  for i = 1:length(T_open)
    j = [j; find(T_open(i)*ones(size(t))==t)];
  endfor
  y_open = y(j,:);
  u_open = u(j,:);

  ## Plots

    gset nokey
    gset nogrid
    #eval(sprintf("gset xtics %g", simpar.last));
    #gset noytics
    gset format x "%.1f"
    gset format y "%.2f"
    gset term fig monochrome portrait fontsize 20 size 20 20 metric \
	     thickness 4
    gset output "${sys}_ident.fig"

    title("");
    xlabel("Time (s)");
    ylabel("u");
    subplot(2,1,2); plot(t,u,'-',  T_open, u_open,"+");
    #subplot(2,1,2); plot(t,u);   
    ylabel("y");
    subplot(2,1,1); plot(t,y,'-',  T_open, y_open,"+"); 
    #subplot(2,1,1); plot(t,y); 
    oneplot;
    gset term fig monochrome portrait fontsize 20 size 20 10 metric \
	     thickness 4
    gset output "${sys}_ident.basis.fig"
    title("");
    xlabel("Time (s)");
    ylabel("Basis functions");
    plot(t_OL, Us);


    ## Create plot against time
    TTT = [ [0;T_open] [T_open; last] ]';
    TT = TTT(:);

    [n,m] = size(P);
    if m>0
      P = P(1:n-1,:);  # Loose last point
      PP = [];
      for j=1:m
        pp = [P(:,j) P(:,j)]';
        PP = [PP pp(:)];
      endfor

      oneplot;
      gset output "${sys}_ident.par.fig"
      title("");
      xlabel("Time (s)");
      ylabel("Parameters");
      plot(TT,PP);
    endif

    [n,m] = size(U);
    if m>0    oneplot;
      gset output "${sys}_ident.U.fig"
      title("");
      xlabel("Time (s)");
      ylabel("U");
      [n,m] = size(U);
      U = U(1:n-1,:);  # Loose last point
      UU = [];
      for j=1:m
        uu = [U(:,j) U(:,j)]';
        UU = [UU uu(:)];
      endfor
      plot(TT,UU);
    endif

endfunction

EOF
}

make_ident_numpar() {
echo Creating ${ident_numpar_file}
cat > ${sys}_ident_numpar.m <<EOF
function [last, ppp_names, par_names, A_u, A_w, w, Q, extras] = ${sys}_ident_numpar 

## usage:  [last, ppp_names, par_names, A_u, A_w, w, Q, extras] = ${sys}_ident_numpar ()
##
## 

  ## Last time of run
  last = 10;

  ## Specify basis functions
  A_w = zeros(1,1);
  n_ppp = ${nu};
  A_u = ppp_aug(A_w,laguerre_matrix(n_ppp-1,2.0));

 
  ## Names of ppp parameters
  ppp_names = "";
  for i=1:n_ppp
    name = sprintf("ppp_%i", i);
    ppp_names = [ppp_names; name];
  endfor

  ## Estimated parameters
  par_names = [];

  ## Weights
  Q = ones(${ny},1);

  ## Setpoint
  w = zeros(${ny},1); w(1) = 1;

  ## Set up optional parameters
  extras.criterion = 1e-3;
  extras.emulate_timing = 0;
  extras.max_iterations = 15;
  extras.simulate = 1;
  extras.v =  1e-6;
  extras.verbose = 0;
  extras.visual = 0;

endfunction
EOF
}

make_dat2() {

## Inform user
echo Creating ${dat2_file}

## Use octave to generate the data
octave -q <<EOF
  [last, ppp_names, par_names, A_u, A_w, w, Q, extras] = ${sys}_ident_numpar;
  [y,u,t] = ${sys}_ident(last, ppp_names, par_names, A_u, A_w, w, Q, extras);
  data = [t,y,u];
  save -ascii ${dat2_file} data
EOF
}

case ${lang} in
    numpar.m)
        ## Make the numpar stuff
        make_ident_numpar;
	;;
    m)
        ## Make the code
        make_ident;
	;;
    dat2|fig|basis.fig|par.fig|U.fig)
        ## The dat2 language (output data) & fig file
        rm ${sys}_ident*.fig
	make_dat2; 
	;;
    gdat)
        cp ${dat2_file} ${dat2s_file} 
	dat22dat ${sys} ${rep} 
        dat2gdat ${sys} ${rep}
	;;
    ps|basis.ps|par.ps|U.ps)
        figs=`ls ${sys}_ident*.fig | sed -e 's/\.fig//'`
        echo $figs
	for fig in ${figs}; do
            fig2dev -Leps ${fig}.fig > ${fig}.ps
	done
	;;
    view)
	pss=`ls ${sys}_ident*.ps` 
        echo Viewing ${pss}
        for ps in ${pss}; do
          gv ${ps}&
	done
	;;
    *)
	echo Language ${lang} not supported by ${rep} representation
        exit 3
esac


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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#! /bin/sh

set -e

#
# function definitions
#


set_debug ()
{
    debug=$1
    if [ $debug -eq 1 ]; then
	set -x
	make_debug='--debug=a'
    else
	set +x
	make_debug=''
    fi
}












|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#! /bin/sh

set -e

#
# function definitions
#


set_debug ()
{
    debug=$1
    if ( $debug ); then
	set -x
	make_debug='--debug=a'
    else
	set +x
	make_debug=''
    fi
}
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    esac
    echo "#Error: " $message
    exit errno;
}       

check_for_valid_input ()
{
    args="$*"
    if [ $# -neq 4 ]; then
	exit_error "Invalid Input"
    fi
}

#
# file templates
#

# template_README      	compilation instructions







|
<
<
<







29
30
31
32
33
34
35
36



37
38
39
40
41
42
43
    esac
    echo "#Error: " $message
    exit errno;
}       

check_for_valid_input ()
{
    return 0;



}

#
# file templates
#

# template_README      	compilation instructions
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







|




1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383





### main program

set_debug false
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

Modified mttroot/mtt/lib/rep/sfun_rep/Makefile from [144656f589] to [9de61fb76d].

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
#! /usr/bin/make -f

all: $(SYS)_sfun.mexglx

$(SYS)_sfun.mexglx: $(SYS)_sfun.c sfun_debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c $(SYS)_sfun_ae.mexglx $(SYS)_sfun_input.mexglx $(SYS)_sfun_interface.mexglx $(SYS).mdl
	echo Creating $@
	mex $(SYS)_sfun.c
	cp *_sfun*mexglx $(SYS).mdl ..

$(SYS)_sfun.c:: ${MTT_REP}/sfun_rep/sfun.c.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@

$(SYS)_sfun_ae.mexglx: $(SYS)_sfun_ae.c sfun-debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_ae.c
	echo Creating $@
	mex $(SYS)_sfun_ae.c

$(SYS)_sfun_ae.c:: ${MTT_REP}/sfun_rep/mex_ae.c.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@

$(SYS)_sfun_input.mexglx: $(SYS)_sfun_input.c sfun_debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_input.c $(SYS)_numpar.c
	echo Creating $@
	mex $(SYS)_sfun_input.c

$(SYS)_sfun_input.c:: ${MTT_REP}/sfun_rep/sfun_input.c.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@

$(SYS)_sfun_interface.mexglx: $(SYS)_sfun_interface.c sfun_debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_numpar.c
	echo Creating $@
	mex $(SYS)_sfun_interface.c

$(SYS)_sfun_interface.c: ${MTT_REP}/sfun_rep/sfun_interface.c.tmpl $(SYS)_struc.c
	echo Creating $@
	cat ${MTT_REP}/sfun_rep/sfun_interface.c.tmpl	|\
	 sed 's/<mtt_model_name>/$(SYS)/g'		|\
	 ${MTT_REP}/sfun_rep/insert_file.sh > $@

$(SYS)_sfun.zip: $(SYS)_sfun.c sfun_debug.h useful-functions.hh $(SYS)_sfun_ae.c $(SYS)_sfun_input.c $(SYS)_sfun_interface.c \
	 $(SYS)_def.h $(SYS)_sympar.h \
	 $(SYS)_ae.c $(SYS)_input.c $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c \
	 $(SYS).mdl README
	echo Creating $@
	zip $@ $^

$(SYS).mdl: ${MTT_REP}/sfun_rep/mdl.tmpl
	echo Creating $@




|








|







|


















|







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
#! /usr/bin/make -f

all: $(SYS)_sfun.mexglx

$(SYS)_sfun.mexglx: $(SYS)_sfun.c sfun_debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_cr.h $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c $(SYS)_sfun_ae.mexglx $(SYS)_sfun_input.mexglx $(SYS)_sfun_interface.mexglx $(SYS).mdl
	echo Creating $@
	mex $(SYS)_sfun.c
	cp *_sfun*mexglx $(SYS).mdl ..

$(SYS)_sfun.c:: ${MTT_REP}/sfun_rep/sfun.c.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@

$(SYS)_sfun_ae.mexglx: $(SYS)_sfun_ae.c sfun_debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_cr.h $(SYS)_ae.c
	echo Creating $@
	mex $(SYS)_sfun_ae.c

$(SYS)_sfun_ae.c:: ${MTT_REP}/sfun_rep/mex_ae.c.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@

$(SYS)_sfun_input.mexglx: $(SYS)_sfun_input.c sfun_debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_cr.h $(SYS)_input.c $(SYS)_numpar.c
	echo Creating $@
	mex $(SYS)_sfun_input.c

$(SYS)_sfun_input.c:: ${MTT_REP}/sfun_rep/sfun_input.c.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@

$(SYS)_sfun_interface.mexglx: $(SYS)_sfun_interface.c sfun_debug.h useful-functions.hh $(SYS)_def.h $(SYS)_sympar.h $(SYS)_numpar.c
	echo Creating $@
	mex $(SYS)_sfun_interface.c

$(SYS)_sfun_interface.c: ${MTT_REP}/sfun_rep/sfun_interface.c.tmpl $(SYS)_struc.c
	echo Creating $@
	cat ${MTT_REP}/sfun_rep/sfun_interface.c.tmpl	|\
	 sed 's/<mtt_model_name>/$(SYS)/g'		|\
	 ${MTT_REP}/sfun_rep/insert_file.sh > $@

$(SYS)_sfun.zip: $(SYS)_sfun.c sfun_debug.h useful-functions.hh $(SYS)_sfun_ae.c $(SYS)_sfun_input.c $(SYS)_sfun_interface.c \
	 $(SYS)_def.h $(SYS)_sympar.h $(SYS)_cr.h\
	 $(SYS)_ae.c $(SYS)_input.c $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c \
	 $(SYS).mdl README
	echo Creating $@
	zip $@ $^

$(SYS).mdl: ${MTT_REP}/sfun_rep/mdl.tmpl
	echo Creating $@

Modified mttroot/mtt/lib/rep/sfun_rep/mdl.tmpl from [16ba1b6745] to [97145b618f].

1
2
3
4
5
6
7
8
9
Model {
  Name			  "<mtt_model_name>"
  Version		  4.00
  SampleTimeColors	  off
  LibraryLinkDisplay	  "all"
  WideLines		  off
  ShowLineDimensions	  on
  ShowPortDataTypes	  off
  ShowStorageClass	  off

|







1
2
3
4
5
6
7
8
9
Model {
  Name			  "mdl"
  Version		  4.00
  SampleTimeColors	  off
  LibraryLinkDisplay	  "all"
  WideLines		  off
  ShowLineDimensions	  on
  ShowPortDataTypes	  off
  ShowStorageClass	  off
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  BrowserLookUnderMasks	  off
  Created		  "Mon May 20 13:21:21 2002"
  Creator		  "geraint"
  UpdateHistory		  "UpdateHistoryNever"
  ModifiedByFormat	  "%<Auto>"
  LastModifiedBy	  "geraint"
  ModifiedDateFormat	  "%<Auto>"
  LastModifiedDate	  "Thu May 23 16:35:42 2002"
  ModelVersionFormat	  "1.%<AutoIncrement:13>"
  ConfigurationManager	  "None"
  SimParamPage		  "Solver"
  StartTime		  "0.0"
  StopTime		  "10.0"
  SolverMode		  "Auto"
  Solver		  "ode45"
  RelTol		  "1e-3"







|
|







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  BrowserLookUnderMasks	  off
  Created		  "Mon May 20 13:21:21 2002"
  Creator		  "geraint"
  UpdateHistory		  "UpdateHistoryNever"
  ModifiedByFormat	  "%<Auto>"
  LastModifiedBy	  "geraint"
  ModifiedDateFormat	  "%<Auto>"
  LastModifiedDate	  "Tue Jun 18 18:49:28 2002"
  ModelVersionFormat	  "1.%<AutoIncrement:14>"
  ConfigurationManager	  "None"
  SimParamPage		  "Solver"
  StartTime		  "0.0"
  StopTime		  "10.0"
  SolverMode		  "Auto"
  Solver		  "ode45"
  RelTol		  "1e-3"
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
  LineDefaults {
    FontName		    "Helvetica"
    FontSize		    9
    FontWeight		    "normal"
    FontAngle		    "normal"
  }
  System {
    Name		    "<mtt_model_name>"
    Location		    [51, 441, 346, 574]
    Open		    on
    ModelBrowserVisibility  off
    ModelBrowserWidth	    200
    ScreenColor		    "white"
    PaperOrientation	    "landscape"
    PaperPositionMode	    "auto"
    PaperType		    "usletter"







|
|







150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
  LineDefaults {
    FontName		    "Helvetica"
    FontSize		    9
    FontWeight		    "normal"
    FontAngle		    "normal"
  }
  System {
    Name		    "mdl"
    Location		    [61, 487, 356, 620]
    Open		    on
    ModelBrowserVisibility  off
    ModelBrowserWidth	    200
    ScreenColor		    "white"
    PaperOrientation	    "landscape"
    PaperPositionMode	    "auto"
    PaperType		    "usletter"
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
      ShowPortLabels	      on
      TreatAsAtomicUnit	      off
      RTWSystemCode	      "Auto"
      RTWFcnNameOpts	      "Auto"
      RTWFileNameOpts	      "Auto"
      System {
	Name			"MTT Model\n<mtt_model_name>"
	Location		[45, 448, 1008, 720]
	Open			off
	ModelBrowserVisibility	off
	ModelBrowserWidth	200
	ScreenColor		"white"
	PaperOrientation	"landscape"
	PaperPositionMode	"auto"
	PaperType		"usletter"







|







186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
      ShowPortLabels	      on
      TreatAsAtomicUnit	      off
      RTWSystemCode	      "Auto"
      RTWFcnNameOpts	      "Auto"
      RTWFileNameOpts	      "Auto"
      System {
	Name			"MTT Model\n<mtt_model_name>"
	Location		[55, 494, 1018, 766]
	Open			off
	ModelBrowserVisibility	off
	ModelBrowserWidth	200
	ScreenColor		"white"
	PaperOrientation	"landscape"
	PaperPositionMode	"auto"
	PaperType		"usletter"
252
253
254
255
256
257
258
















259
260
261
262
263
264
265
	    Name		    "MTT Model Outputs: MTTY"
	    TestPoint		    off
	    LinearAnalysisOutput    off
	    LinearAnalysisInput	    off
	    RTWStorageClass	    "Auto"
	  }
	}
















	Block {
	  BlockType		  "S-Function"
	  Name			  "S-Function"
	  Ports			  [4, 2]
	  Position		  [710, 47, 840, 238]
	  BackgroundColor	  "lightBlue"
	  DropShadow		  on







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







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
	    Name		    "MTT Model Outputs: MTTY"
	    TestPoint		    off
	    LinearAnalysisOutput    off
	    LinearAnalysisInput	    off
	    RTWStorageClass	    "Auto"
	  }
	}
	Block {
	  BlockType		  Memory
	  Name			  "Memory"
	  Position		  [870, 80, 900, 110]
	  X0			  "0"
	  InheritSampleTime	  off
	  RTWStateStorageClass	  "Auto"
	}
	Block {
	  BlockType		  Memory
	  Name			  "Memory1"
	  Position		  [860, 175, 890, 205]
	  X0			  "0"
	  InheritSampleTime	  off
	  RTWStateStorageClass	  "Auto"
	}
	Block {
	  BlockType		  "S-Function"
	  Name			  "S-Function"
	  Ports			  [4, 2]
	  Position		  [710, 47, 840, 238]
	  BackgroundColor	  "lightBlue"
	  DropShadow		  on
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
	  Name			  "MTT  Model Inputs: MTTU"
	  Labels		  [1, 0]
	  SrcBlock		  "MTT Model Inputs"
	  SrcPort		  1
	  DstBlock		  "S-Function"
	  DstPort		  1
	}
	Line {
	  SrcBlock		  "S-Function"
	  SrcPort		  1
	  Points		  [30, 0; 0, -70; -850, 0; 0, 105]
	  DstBlock		  "MTT Plant Model"
	  DstPort		  1
	}
	Line {
	  SrcBlock		  "In1"
	  SrcPort		  1
	  DstBlock		  "S-Function"
	  DstPort		  4
	}
	Line {
	  SrcBlock		  "S-Function"
	  SrcPort		  2













	  DstBlock		  "Out1"
	  DstPort		  1
	}






      }
    }
    Block {
      BlockType		      Outport
      Name		      "Out1"
      Position		      [185, 43, 215, 57]
      Port		      "1"







<
<
<
<
<
<
<








|
>
>
>
>
>
>
>
>
>
>
>
>
>



>
>
>
>
>
>







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
	  Name			  "MTT  Model Inputs: MTTU"
	  Labels		  [1, 0]
	  SrcBlock		  "MTT Model Inputs"
	  SrcPort		  1
	  DstBlock		  "S-Function"
	  DstPort		  1
	}







	Line {
	  SrcBlock		  "In1"
	  SrcPort		  1
	  DstBlock		  "S-Function"
	  DstPort		  4
	}
	Line {
	  SrcBlock		  "S-Function"
	  SrcPort		  1
	  DstBlock		  "Memory"
	  DstPort		  1
	}
	Line {
	  SrcBlock		  "Memory"
	  SrcPort		  1
	  Points		  [0, -55; -855, 0]
	  DstBlock		  "MTT Plant Model"
	  DstPort		  1
	}
	Line {
	  SrcBlock		  "Memory1"
	  SrcPort		  1
	  DstBlock		  "Out1"
	  DstPort		  1
	}
	Line {
	  SrcBlock		  "S-Function"
	  SrcPort		  2
	  DstBlock		  "Memory1"
	  DstPort		  1
	}
      }
    }
    Block {
      BlockType		      Outport
      Name		      "Out1"
      Position		      [185, 43, 215, 57]
      Port		      "1"

Modified mttroot/mtt/lib/rep/sfun_rep/mex_ae.c.tmpl from [4178a7adf7] to [797312fca9].

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
/* -*-c-*-	Put emacs into c-mode
 * <mtt_model_name>_sfun_ae.c:
 * Matlab mex algebraic equations for <mtt_model_name>
 */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <mex.h>
#include "sfun_debug.h"
#include "useful-functions.hh"
#include "<mtt_model_name>_def.h"
#include "<mtt_model_name>_sympar.h"


/* utility procedures */

double *
array_of_double (size_t n)
{
  void *p = calloc (n, sizeof (double));













>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* -*-c-*-	Put emacs into c-mode
 * <mtt_model_name>_sfun_ae.c:
 * Matlab mex algebraic equations for <mtt_model_name>
 */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <mex.h>
#include "sfun_debug.h"
#include "useful-functions.hh"
#include "<mtt_model_name>_def.h"
#include "<mtt_model_name>_sympar.h"
#include "<mtt_model_name>_cr.h"

/* utility procedures */

double *
array_of_double (size_t n)
{
  void *p = calloc (n, sizeof (double));

Modified mttroot/mtt/lib/rep/sfun_rep/sfun.c.tmpl from [e8393fa8d4] to [79b281c10a].

10
11
12
13
14
15
16

17
18
19
20
21
22
23
#include <stdio.h>
#include <stdlib.h>
#include "simstruc.h"
#include "sfun_debug.h"
#include "useful-functions.hh"
#include "<mtt_model_name>_def.h"
#include "<mtt_model_name>_sympar.h"


static double *mttdx;		/* pointer to rates */
static double *mttu;		/* pointer to inputs */
static double *mttpar;		/* pointer to parameters */
static double *mttx;		/* pointer to states */
static double *mtty;		/* pointer to outputs */
static double *mttyz;		/* pointer to residuals */







>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <stdlib.h>
#include "simstruc.h"
#include "sfun_debug.h"
#include "useful-functions.hh"
#include "<mtt_model_name>_def.h"
#include "<mtt_model_name>_sympar.h"
#include "<mtt_model_name>_cr.h"

static double *mttdx;		/* pointer to rates */
static double *mttu;		/* pointer to inputs */
static double *mttpar;		/* pointer to parameters */
static double *mttx;		/* pointer to states */
static double *mtty;		/* pointer to outputs */
static double *mttyz;		/* pointer to residuals */
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
  mxSetName (MTT_MATLAB_P, "MTT_P");
  p = mxGetPr (MTT_MATLAB_P);
  for (i = 0; i < MTTNPAR; i++) {
    p[i] = mttpar[i];
  }
  mexPutArray (MTT_MATLAB_P, "base");

  /* call fsolve */
  mexEvalString ("MTT_Ui = fsolve (@<mtt_model_name>_sfun_ae, MTT_Ui, optimset('display','off'), MTT_X, MTT_U, MTT_T, MTT_P);");

  /* retrieve result */
  MTT_MATLAB_Ui = mexGetArray ("MTT_Ui", "base");
  p = mxGetPr (MTT_MATLAB_Ui);
  for (i = 0; i < MTTNYZ; i++) {
    mttu[MTTNU + i] = p[i];
  }







|
|







161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
  mxSetName (MTT_MATLAB_P, "MTT_P");
  p = mxGetPr (MTT_MATLAB_P);
  for (i = 0; i < MTTNPAR; i++) {
    p[i] = mttpar[i];
  }
  mexPutArray (MTT_MATLAB_P, "base");

  /* call solver */
  mexEvalString ("MTT_Ui = lsqnonlin (@<mtt_model_name>_sfun_ae, MTT_Ui, [], [], optimset('display','off','diagnostics','off','TolX',1e-2,'TolFun',1e-2), MTT_X, MTT_U, MTT_T, MTT_P);");

  /* retrieve result */
  MTT_MATLAB_Ui = mexGetArray ("MTT_Ui", "base");
  p = mxGetPr (MTT_MATLAB_Ui);
  for (i = 0; i < MTTNYZ; i++) {
    mttu[MTTNU + i] = p[i];
  }

Modified mttroot/mtt/lib/rep/sfun_rep/sfun_input.c.tmpl from [1b479e7eb4] to [37d9259f60].

10
11
12
13
14
15
16

17
18
19
20
21
22
23
#include <stdio.h>
#include <stdlib.h>
#include "simstruc.h"
#include "sfun_debug.h"
#include "useful-functions.hh"
#include "<mtt_model_name>_def.h"
#include "<mtt_model_name>_sympar.h"


static double *mttu;		/* pointer to inputs */
static double *mttpar;		/* pointer to parameters */
static double *mttx;		/* pointer to states */
static double *mtty;		/* pointer to outputs */
static double  mttt;		/* time */








>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <stdlib.h>
#include "simstruc.h"
#include "sfun_debug.h"
#include "useful-functions.hh"
#include "<mtt_model_name>_def.h"
#include "<mtt_model_name>_sympar.h"
#include "<mtt_model_name>_cr.h"

static double *mttu;		/* pointer to inputs */
static double *mttpar;		/* pointer to parameters */
static double *mttx;		/* pointer to states */
static double *mtty;		/* pointer to outputs */
static double  mttt;		/* time */


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