SHAPE (The GNU Fortran Compiler)

### 8.253 `SHAPE` — Determine the shape of an array ¶

Synopsis:

  `RESULT = SHAPE(SOURCE [, KIND])`

Description:

  Determines the shape of an array.

Class:

  Inquiry function

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) A scalar `INTEGER` constant 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

Standard:

  Fortran 90 and later, with KIND argument Fortran 2003 and later

See also:

  `COSHAPE` — Determine the coshape of a coarray,
  `RESHAPE` — Function to reshape an array,
  `SIZE` — Determine the size of an array