Those declarations sections which declare items that are listed in a window of values (sensors, controls, variables and smartcabs) can have one or more groups defined before the actual items themselves.
A group instruction defines the order in which the items are displayed in the appropriate window, and possibly groups items together on a single line.
The best way to explain this is with an example:
Lets suppose that our layout is made up of several track sections (and possibly other things we are not considering here). Each track section has the following variables associated with it:
We have sections called s1, s2, s3 etc.
Therefore we might have the following variables declaration:
Variables: s1state, s2state, s3state s1train, s2train, s3train s1next, s2next, s3next s1prev, s2prev, s3prev
We would naturally like the variables to be grouped in the variables window like this:
s1state |
s1train |
s1next |
s1prev |
s2state |
s2train |
s2next |
s2prev |
s3state |
s3train |
s3next |
s3prev |
To achieve this we would use the following group statement:
Variables: group tracks (state, train, next, prev)=(s1, s2, s3) s1state, s2state,
This would produce a window like this:
In the group statement the first list is a list of column names, and the second is a list of row names.
The mechanism for group is a bit wild and magical... it tries to look for variables that contain the bits you give it, in any way that works, so the following:
GROUP: xx (c1, c2)=(r1, r2)
Would find and display:
Variables: c1r1, c1r2, c2r1, c2r2
or:
Variables: r1c1, r2c1, r1c2, r2c2
or even:
Variables: cr11, cr12, cr21, cr22
but it would not match:
Variables: rc11, rc12, rc21, rc22
In general it looks through all the variables that have been declared (including all elements in all structures and all elements in arrays) and finds variables with names which contain items from the second list (the row names), and when that portion is removed from the name, the remainder matches something in the first list (the column names)
The identified items are displayed in the order defined in the group statement, with the row and column labels attached.
Note that the group statement merely tells Tcc how to arrange some variables (or sensors or controls) in their window. It does NOT declare the variables themselves. For a short form of variable declaration see the STRUCT statement.
The row name list could instead be an array name, such as in:
Variables: Group: trains (cab, len, sp)=(tr[]) cabtr [6], lentr [6], sptr [6]
This declares six cab-for-train (cabtr) variables, six length of train variables and six speed of train variables, and is similar to:
Group: trains (cab, len, sp)=(tr1, tr2, tr3, tr4, tr5, tr6) cabtr1, cabtr2, cabtr3, cabtr4, cabtr5, cabtr6 lentr1, lentr2, ...
Except that the first declaration makes an array that can be accessed as an array, and the second for would simple make 18 independent variables.
Any items not defined in any group are shown at the end of the window, in the order they appear in the rest of the declaration.
As a special case, if the first column name begins with a period then it is assumed to be an element in a structure. So the following declarations go together:
Group: trains (.cab, .len, .sp)=(tr1, tr2, tr3) Struct (cab, len, sp)=(tr1, tr2, tr3)
Back to declarations page
Last updated 24 Feb 2009
© Howard Amos 2006-2009