array
The array command declares a parameter that holds several values, indexed from 1.
Syntax
array <name> ( <d1> { , <d2> } ) [ <value> { <value> } ] [ ; ]
name is the array’s name. d1, d2 and so on are the dimensions, each a positive integer; their number is the rank. value is optional: none leaves every element unset, one value is given to every element, and a full list gives one value per element. The closing ; is optional.
What it does
James reserves the array and stores the data. A subscript counts from 1, and a data list fills the array in Fortran order, the first subscript varying fastest. A single value is broadcast to every element. Elements are read as %name(i,j) and assigned with para name(i,j) value. Three arrays belong to James, idxlist, jdxlist and kdxlist. They exist only in the Part phase, and no script can assign them.
When James applies it
By the preprocessor, when it is read. It is legal in any phase: Control, Part or Merge.
Rules James adds
- Declaring a name again replaces it, whatever kind it held before, so
array a(2) 1;afterpara a 1;is not an error. - A declaration that fails changes nothing: the name keeps the value it had.
- A dimension, or the whole element count, above 1,000,000 is rejected.
- The closing
;is optional, whether or not data follow.
Diagnostics
- E0205: the name is one of the automatic arrays, which no script may assign.
- E0206: a subscript is outside its dimension.
- E0207: an element is written with the wrong number of subscripts.
- E0214: a dimension is not a positive integer.
- E0215: the data list does not match the element count.
- E0104: a dimension or the element count is above 1,000,000, or the declaration is malformed.
Example
The script tests/corpus/159-array-elements-in-coordinates/input.tg, which make test runs:
c a 2 by 2 array whose four elements, read in Fortran order, give one coordinate list
array xs(2,2) 0 1 2 3;
block 1 2 3 4;1 2;1 2;
%xs(1,1) %xs(2,1) %xs(1,2) %xs(2,2);
0 1;0 1;
endpart
The array is 2 by 2, so its data list 0 1 2 3 fills it in Fortran order. The four %xs(i,j) reads in the coordinate list come out as 0 1 2 3, which the prep dump shows in place, and the IR holds one block with coord [0 1 2 3] along i.
See also
- para: scalars, and the assignment of one element.
- painfo: prints every element, one line each.
- Writing a script: the
%nameand[expr]forms.