]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/fortran/doc/gfortran/intrinsic-procedures/reshape.rst
de975fdc800675caaefc73122327482f00a98765
[thirdparty/gcc.git] / gcc / fortran / doc / gfortran / intrinsic-procedures / reshape.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:: RESHAPE, array, change dimensions, array, transmogrify
7
8 .. _reshape:
9
10 RESHAPE --- Function to reshape an array
11 ****************************************
12
13 .. function:: RESHAPE(SOURCE, SHAPE, PAD, ORDER)
14
15 Reshapes :samp:`{SOURCE}` to correspond to :samp:`{SHAPE}`. If necessary,
16 the new array may be padded with elements from :samp:`{PAD}` or permuted
17 as defined by :samp:`{ORDER}`.
18
19 :param SOURCE:
20 Shall be an array of any type.
21
22 :param SHAPE:
23 Shall be of type ``INTEGER`` and an
24 array of rank one. Its values must be positive or zero.
25
26 :param PAD:
27 (Optional) shall be an array of the same
28 type as :samp:`{SOURCE}`.
29
30 :param ORDER:
31 (Optional) shall be of type ``INTEGER``
32 and an array of the same shape as :samp:`{SHAPE}`. Its values shall
33 be a permutation of the numbers from 1 to n, where n is the size of
34 :samp:`{SHAPE}`. If :samp:`{ORDER}` is absent, the natural ordering shall
35 be assumed.
36
37 :return:
38 The result is an array of shape :samp:`{SHAPE}` with the same type as
39 :samp:`{SOURCE}`.
40
41 Standard:
42 Fortran 90 and later
43
44 Class:
45 Transformational function
46
47 Syntax:
48 .. code-block:: fortran
49
50 RESULT = RESHAPE(SOURCE, SHAPE[, PAD, ORDER])
51
52 Example:
53 .. code-block:: fortran
54
55 PROGRAM test_reshape
56 INTEGER, DIMENSION(4) :: x
57 WRITE(*,*) SHAPE(x) ! prints "4"
58 WRITE(*,*) SHAPE(RESHAPE(x, (/2, 2/))) ! prints "2 2"
59 END PROGRAM
60
61 See also:
62 :ref:`SHAPE`