Skip to content

Array Extension

Extension introduced in TethysL 1.8.0 (2019)

Declaration

An array declaration defines a sequence of arguments (or outputs) sharing a base name. It consists of the name (e.g., Lat) followed by a range of indices in brackets ([1..4]), then = and the value:

arguments {
  Lat[1..4] = NaN degree
  Lon[1..4] = NaN degree
}

This is equivalent to defining Lat1, Lat2, Lat3, Lat4, and Lon1, ..., Lon4, which are the names in the generated XML (and the ones to use, for example, when setting the mission parameters on the vehicle).

The range limits can be numbers or constants:

const $NUM_WAYPOINTS = 10

arguments {
  Lat[1..$NUM_WAYPOINTS] = NaN degree
  Lon[1..$NUM_WAYPOINTS] = NaN degree
}

Values

The value in the declaration can be given in three ways:

  • A single expression, assigned to all the entries:

    Temp[1..4] = NaN kelvin
    
  • An explicit array, with [ ... ], indicating the value for each entry:

    Lat[1..4] = [36.8 degree, 36.7 degree, NaN degree, NaN degree]
    
  • Sub-ranges, with { ... }, where each component has the range of indices, a colon :, and either a single expression or an explicit array for that sub-range:

    Depth[1..10] = {
      1..4: [10 meter, 20 meter, 30 meter, 40 meter],
      5..10: NaN meter
    }
    

A description given to an array declaration serves as the description of all the expanded elements.

Access

An entry is referenced with the index in brackets, typically using a macro variable:

set latitude = Lat[$k]

The index is a static expression: a number, a macro variable, a constant, or an addition/subtraction of these, e.g., Lat[$k - 1], Depth[$j + 1].

Rules

  • A name can only be declared once. That is, multiple declarations with the same base name are not allowed, even for non-overlapping ranges; use sub-ranges instead.
  • The name of an array cannot be the same as that of another argument or output, even if not an array (e.g., CartridgeType[1..60] and CartridgeType).

Lint

The lint reports groups of definitions that could be replaced with an array declaration, along with a hint to use a constant for the upper limit:

  * Possible use of 'array' extension:

    These 3 definitions: D1, D2, D3
    could probably be replaced with: D[1..3]

    If so, also consider using a constant for the upper limit, e.g.:
       const $MAX_... = 3