SHAPE(SOURCE, KIND)

Purpose

Returns the shape of an array or scalar.

Class

Inquiry function

Argument type and attributes

SOURCE
An INTENT(IN) argument. The corresponding actual argument can be an array or scalar of any data type. The actual argument must not be a disassociated pointer, allocatable object that is not allocated, or assumed-size array.
Fortran 2003 begins KIND (optional)
An INTEGER scalar. The actual argument corresponding to KIND must be a constant expression.Fortran 2003 ends

Result type and attributes

Result value

The extent of each dimension in SOURCE is returned in the corresponding element of the result array.

TS beginsIf ARRAY is an assumed-rank object that is associated with an assumed-size array, the result has a value equal to [(SIZE(ARRAY, I, KIND), I=1, RANK(ARRAY))]. If KIND is omitted from SHAPE, KIND is also omitted from SIZE.TS ends

Related information

RESHAPE(SOURCE, SHAPE, PAD, ORDER).

Examples

! A is the array  | 7 6 3 1 |
!                 | 2 4 0 9 |
!                 | 5 7 6 8 |
!
       RES = SHAPE( A )
! The result is | 3  4 | because A is a rank-2 array
! with 3 elements in each column and 4 elements in
! each row.