Array declaration syntax is very simple. The syntax is the same as for a normal variable declaration except the variable name should be followed by subscripts to specify the size of each dimension of the array. The general form for an array declaration would be:
VariableType varName[dim1, dim2, ..., dimN];
VariableType is a Modelica type like
varName is the name of the variable.
Normally, the dimension specifications are simply integers that indicate the size of that dimension. For example:
In this case,
x is an array of real valued numbers with only one
dimension of size 5. It is possible to use parameters or constants
specify the size of an array, e.g.,
parameter Integer d1=5; constant Integer d2=2; Real x[d1, d2];
There are some circumstances where we can leave the size of an array unspecified so that it can be specified by some later context. For example, we will see examples of this later when we discuss Functions that have arguments which are arrays.
To indicate that the size of a given array dimension is not (yet) known, we can use the : symbol as the dimension. So in a declaration like this:
we are declaring an array with two dimensions. The size of the first
dimension is not specified. However, the size of the second dimension
is definitively specified as 2. In effect, we have declared that
A is a matrix with an unspecified number of rows and two columns.
As we saw in our Chemical System examples, another way to specify the dimension for an array is with an enumeration. If an enumeration is used to specify a dimension, then the size of that dimension will be equal to the number of possible values for that enumeration. In our forthcoming discussion on Array Indexing, we’ll see how to properly index an array that uses enumerations as dimensions.
It is also possible to declare an array where a dimension is specified