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

METHOD(I)=PROGRAME(I)=ENERGY

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

or

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

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

R(2)=[1.25,1.35,1.45]

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

THETA=[100,110,120,130]

set four values

...

THETA(1)=104

replace THETA(1) by a new value; THETA(2:4) are unchanged

...

THETA=[140,150]

old variable THETA is replaced; THETA(3:4) are deleted

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

METHOD=[INT,HF,CASSCF,MRCI]

These could be used as follows:

DO I=1,4
$METHOD(I)
ENDDO

The above input would be equivalent to

INT
HF
CASSCF
MRCI

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:

IF(#SPIN.EQ.0.AND.#NELEC.EQ.1) SET,SPIN=MOD(NELEC,2)

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