Error Messages/46195
Example Error Message
- The subscript expression x[...] does not explicitly name the indexes to subscript on and specifies only 2 coordinates. However, x is declared to have 3 indexes. The number of coordinates must match the number of declared indexes when you don't explicitly indicate which index(es) to subscript over.
- If you want to subscript on fewer indexes, list the indexes explicitly, e.g., x[K=«expr»].
Background -- Explicit vs implicit index naming
The Subscript operator is used to access a slice of a higher-dimensional array. The usual syntax is x[ J = v ]
. You specify the index explicitly, telling it that you want to obtain a slice or subscript over the index J
. This way, if other indexes are added to your model later, adding another index to x
, the subscript still operates on the correct index.
Consider this snippet where we declare x to be a local value:
Local x[I, J, K] := A+B Do
x[ K='banana', I='a', J=5 ]
Although A+B
might have more than 3 dimensions, within its lexical context, its declaration ensures that x
will have only three indexes -- I, J
and K
. Since the subscript on the second line again specifies each index explicitly, they order that the indexes are listed can differ from the order they were declared. However, since the indexes have been declared and an ordering of these indexes specified in the declaration for x
, it is a bit redundant to specify the index names again, especially if the index names happen to be long (which they aren't here). So to save on characters in the expression, you can omit the index names, as long as you specify every coordinate and list them in the same order they were declared. So the previous expression is equivalent to
Local x[I, J, K] := A+B Do
x[ 'a', 5, 'banana' ]
Description of this error
You wrote an expression like
Local x[I, J, K] := A+B Do
x[ 'a', 5 ]
Notice that x
is declared to have 3 indexes, but the subscript specifies only 2 coordinates. Because the subscript indexes are not explicit, it is ambiguous. Do you intend x[ J='a', K=5 ]
or x[ I='a', J=5 ]
or something else? When you omit the indexes to subscript, you have to specify one coordinate for each declared index.
If you really want to subscript on only 2 of the three indexes, then specify the indexes explicitly.
Enable comment auto-refresher