Fortran Wiki
shape

Description

Determines the shape of an array.

Standard

Fortran 95 and later; with kind argument Fortran 2003 and later

Class

Inquiry function

Syntax

result = shape(source[, kind])

Arguments

  • source - Shall be an array or scalar of any type. If source is a pointer it must be associated and allocatable arrays must be allocated.
  • kind - (Optional) An integer initialization expression indicating the kind parameter of the result.

Return value

An integer array of rank one with as many elements as source has dimensions. The elements of the resulting array correspond to the extend of source along the respective dimensions. If source is a scalar, the result is the rank one array of size zero. If kind is absent, the return value has the default integer kind otherwise the specified kind.

Example

program test_shape
  integer, dimension(-1:1, -1:2) :: a
  write(*,*) shape(a)             ! (/ 3, 4 /)
  write(*,*) size(shape(42))      ! (/ /)
end program

See also

reshape, size

category: intrinsics