Lahey/Fujitsu Fortran

RESHAPE Function


The RESHAPE function constructs an array of a specified shape from a template array.


RESHAPE (source, shape [, pad] [, order] )

Required Arguments

source is an INTENT(IN) array of any type. If pad is absent or of size zero, the size of source must be greater than or equal to the product of the values of the elements of shape.

shape is an INTENT(IN) INTEGER array of rank one. Its size must be positive and less than or equal to seven. It cannot have any negative elements.

Optional Arguments

pad is an INTENT(IN) array of the same type and kind as source.

order is an INTENT(IN) array of type INTEGER with the same shape as shape. Its value must be a permutation of (1, 2, ..., n), where n is the size of order. If order is absent, it is as if it were present with the value (1, 2, ..., n).


The result is an array of the same type and kind as source, with a shape identical to shape.

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


real :: x.(4) real :: x.(2,2)=reshape((/1.,2.,3.,4./),shape(x2)) real :: x.(3,2) x1=reshape(x2,shape(x1)) write(*,*) x. ! writes 1. 2. 3. 4. write(*,*) reshape(x1,shape(x2),order=(/2,1/)) ! writes 1. 3. 2. 4. write(*,*) reshape(x1,shape(x3),pad=(/0./)) ! writes 1. 2. 3. 4. 0. 0.