2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
6 .. index:: SHAPE, array, shape
10 SHAPE --- Determine the shape of an array
11 *****************************************
13 .. function:: SHAPE(SOURCE , KIND)
15 Determines the shape of an array.
18 Shall be an array or scalar of any type.
19 If :samp:`{SOURCE}` is a pointer it must be associated and allocatable
20 arrays must be allocated.
23 (Optional) An ``INTEGER`` initialization
24 expression indicating the kind parameter of the result.
27 An ``INTEGER`` array of rank one with as many elements as :samp:`{SOURCE}`
28 has dimensions. The elements of the resulting array correspond to the extend
29 of :samp:`{SOURCE}` along the respective dimensions. If :samp:`{SOURCE}` is a scalar,
30 the result is the rank one array of size zero. If :samp:`{KIND}` is absent, the
31 return value has the default integer kind otherwise the specified kind.
34 Fortran 90 and later, with :samp:`{KIND}` argument Fortran 2003 and later
40 .. code-block:: fortran
42 RESULT = SHAPE(SOURCE [, KIND])
45 .. code-block:: fortran
48 INTEGER, DIMENSION(-1:1, -1:2) :: A
49 WRITE(*,*) SHAPE(A) ! (/ 3, 4 /)
50 WRITE(*,*) SIZE(SHAPE(42)) ! (/ /)