]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/fortran/doc/gfortran/intrinsic-procedures/shape.rst
33b1cce85fa117d9da42e45e8c995c45a359740b
[thirdparty/gcc.git] / gcc / fortran / doc / gfortran / intrinsic-procedures / shape.rst
1 ..
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.
5
6 .. index:: SHAPE, array, shape
7
8 .. _shape:
9
10 SHAPE --- Determine the shape of an array
11 *****************************************
12
13 .. function:: SHAPE(SOURCE , KIND)
14
15 Determines the shape of an array.
16
17 :param SOURCE:
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.
21
22 :param KIND:
23 (Optional) An ``INTEGER`` initialization
24 expression indicating the kind parameter of the result.
25
26 :return:
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.
32
33 Standard:
34 Fortran 90 and later, with :samp:`{KIND}` argument Fortran 2003 and later
35
36 Class:
37 Inquiry function
38
39 Syntax:
40 .. code-block:: fortran
41
42 RESULT = SHAPE(SOURCE [, KIND])
43
44 Example:
45 .. code-block:: fortran
46
47 PROGRAM test_shape
48 INTEGER, DIMENSION(-1:1, -1:2) :: A
49 WRITE(*,*) SHAPE(A) ! (/ 3, 4 /)
50 WRITE(*,*) SIZE(SHAPE(42)) ! (/ /)
51 END PROGRAM
52
53 See also:
54 :ref:`RESHAPE`,
55 :ref:`SIZE`