Rank, shape, and size of an array

Rank

The rank of an array is the number of dimensions it has.

INTEGER, DIMENSION (10) :: A     ! Rank = 1
REAL, DIMENSION (-5:5,100) :: B  ! Rank = 2

A scalar is considered to have rank zero.

Shape

The shape of an array is derived from its rank and extents. It can be represented as a rank-one array where each element is the extent of the corresponding dimension:

INTEGER, DIMENSION (10,10) :: A          ! Shape = (/ 10, 10 /)
REAL, DIMENSION (-5:4,1:10,10:19) :: B   ! Shape = (/ 10, 10, 10 /)

Size

The size of an array is the total number of elements in it. The size equals to the product of the extents of all dimensions.

INTEGER A(5)              ! Size = 5
REAL B(-1:0,1:3,4)        ! Size = 2 * 3 * 4 = 24