reshape

Date:

02-06-2023

NAME

RESHAPE - Constructs an array of a specified shape

SYNOPSIS

RESHAPE ([SOURCE=]source, [SHAPE=]shape [,[PAD=]pad][,[ORDER=]order])

STANDARDS

Fortran

DESCRIPTION

The RESHAPE intrinsic function constructs an array of a specified shape from the elements of a given array. It accepts the following arguments:

NOTE: when -Rc is specified, RESHAPE will be a call to the

runtime library to catch all user semantic errors. Often, RESHAPE is implemented by inline code for performance reasons.

source

May be of any type. It must be array valued. If pad is absent or of size zero, the size of source must be greater than or equal to PRODUCT(shape). The size of the result is the product of the values of the elements of shape.

shape

Must be an integer, of rank one, and of constant size. Its size must be positive and less than 8. It must not have an element whose value is negative.

pad

Must be of the same type as source. It must be array valued.

order

Must be of type integer. It must have the same shape as shape, and its value must be a permutation of (1,2,…,*n*), where n is the size of shape. If absent, the default order is (1,2,…,*n*).

RESHAPE is a transformational function. The name of this intrinsic cannot be passed as an argument.

RETURN VALUES

The type of the result is the same type as source. The result is an array of shape shape, that is, SHAPE(RESHAPE(source,shape,pad,order)) is equal to shape.

The elements of the result, taken in permuted subscript order(1), …, order(n), are those of source in normal array element order followed, if necessary, by those of pad in array element order, followed, if necessary, by additional copies of pad in array element order.

EXAMPLES

Example 1: RESHAPE((/1,2,3,4,5,6/),(/2,3/)) yields the following:

| 1 3 5 |
| 2 4 6 |

Example 2: RESHAPE((/1,2,3,4,5,6,7,8,9/),(/3,4/),(/0,0/)) yields the following:

| 1 4 7 0 |
| 2 5 8 0 |
| 3 6 9 0 |

Example 3: RESHAPE((/1,2,3,4,5,6/),(/2,4/),(/0,0/),(/2,1/)) yields the following:

| 1 2 3 4 |
| 5 6 0 0 |