manual   quickstart   instguide   update   basis

Next: 8.7 Vector operations Up: 8 VARIABLES Previous: 8.5 Macro definitions using   Contents   Index   PDF

8.6 Indexed Variables (Vectors)

Variables may be indexed, but only one-dimensional arrays (vectors) are supported. The index may itself be a variable. For instance


are valid variable definitions, provided I, PROGRAM, and ENERGY are also defined variables. Indices may be nested to any depth.

Different elements of an array can be of different type (either real or logical). However, only one unit can be assigned to an array. String variables have no associated value and cannot be mixed with the other variable types. Therefore, a given variable name can only be used either for a string variable or a real (logical) variable.

Vectors (arrays) can be conveniently defined using square brackets:

R=[1.0,1.2,1.3] ANG

This defines an array with three elements, which can be accessed using indices; for instance, R(2) has the value 1.2 ANG. A repeat specifier can be given in front of the left bracket: 5[0] is equivalent to [0,0,0,0,0]. Brackets can even be nested: for instance, 2[1,2,2[2.1,3.1]] is equivalent to [1,2,2.1,3.1,2.1,3.1,1,2,2.1,3.1,2.1,3.1].

Arrays can be appended from a given position just by entering additional elements; for instance,

R(4)=[1.4,1.5] ANG


R(4:)=[1.4,1.5] ANG

extends the above array to length 5. Previously defined values can be overwritten. For instance


modifies the above vector to (1.0, 1.25, 1.35, 1.45, 1.5).

If no index is given on the left hand side of the equal sign, an existing variable of the same name is replaced by the new values, and all old values are lost. For instance

set four values
replace THETA(1) by a new value; THETA(2:4) are unchanged
old variable THETA is replaced; THETA(3:4) are deleted

Square brackets can also be used to define an array of strings, e.g.,


These could be used as follows:

DO I=1,4

The above input would be equivalent to


The current length of an array can be accessed by preceding # to the variable name. For instance, in the above examples #R and #METHOD have the values 5 and 4, respectively. If a variable is not defined, zero is returned but no error occurs. This can be used to test for the existence of a variable, for example:


This defines variable SPIN if it is unknown and if NELEC is a scalar (one dimensional) variable.

Next: 8.7 Vector operations Up: 8 VARIABLES Previous: 8.5 Macro definitions using   Contents   Index   PDF

manual   quickstart   instguide   update   basis 2017-12-13