Purpose
Returns the extent of an array
along a specified dimension or the total number of elements in the
array.
Argument type and attributes
- ARRAY
- An array of any data type or
an assumed-rank object. The corresponding actual argument
must not be a scalar, disassociated pointer, or allocatable array
that is not allocated. The actual argument can be an assumed-size
array if DIM is present and has a value
that is less than the rank of ARRAY.
- DIM (optional)
- An INTEGER scalar. Its value must be in the range
1 ≤ DIM ≤ RANK(ARRAY). It must not be present
if ARRAY is an assumed-rank object that
is associated with a scalar.
- KIND (optional)
- An INTEGER scalar. Its value must be specified
by a constant expression.
Result type and attributes
- It is of type scalar integer.
- If KIND is present,
the KIND type parameter is that specified
by the value of KIND; otherwise, the KIND type
parameter is that of default integer type.
Result value
The result equals
the extent of ARRAY along dimension DIM;
or, if DIM is not specified, it is the total
number of array elements in ARRAY.
- If ARRAY is an assumed-rank object that
is associated with a scalar, the result is 1.
- If ARRAY is an assumed-rank object that
is associated with an assumed-size array, and
- If DIM is present and equal to the rank
of ARRAY, the result is -1.
- If DIM is not present, the result is
a negative value that is equal to PRODUCT([(SIZE(ARRAY, I, KIND), I=1, RANK(ARRAY))]).
Examples
! A is the array | 1 -4 7 -10 |
! | 2 5 -8 11 |
! | 3 6 9 -12 |
RES = SIZE( A )
! The result is 12 because there are 12 elements in A.
RES = SIZE( A, DIM = 1)
! The result is 3 because there are 3 rows in A.
RES = SIZE( A, DIM = 2)
! The result is 4 because there are 4 columns in A.