Transformational Intrinsic Function (Generic): Constructs an array with a different shape from the argument array.
Syntax
Results:
The result is an array of shape shape with the same type and kind parameters as source. The size of the result is the product of the values of the elements of shape.
In the result array, the array elements of source are placed in the order of dimensions specified by order. If order is omitted, the array elements are placed in normal array element order.
The array elements of source are followed (if necessary) by the array elements of pad in array element order. If necessary, additional copies of pad follow until all the elements of the result array have values.
In standard Fortran array element order, the first dimension varies fastest. For example, element order in a two-dimensional array would be (1,1), (2,1), (3,1) and so on. In a three-dimensional array, each dimension having two elements, the array element order would be (1,1,1), (2, 1, 1), (1, 2, 1), (2, 2, 1), (1, 1, 2), (2, 1, 2), (1, 2, 2), (2, 2, 2).
RESHAPE can be used to reorder a Fortran array to match C array ordering before the array is passed from a Fortran to a C procedure.
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
See Also: PACK, SHAPE, TRANSPOSE
Examples
RESHAPE ((/3, 4, 5, 6, 7, 8/), (/2, 3/)) has the value
[ 3 5 7 ]
[ 4 6 8 ].
RESHAPE ((/3, 4, 5, 6, 7, 8/), (/2, 4/), (/1, 1/), (/2, 1/)) has the value
[ 3 4 5 6 ]
[ 7 8 1 1 ].
The following shows another example:
INTEGER AR1( 2, 5)
REAL F(5,3,8)
REAL C(8,3,5)
AR1 = RESHAPE((/1,2,3,4,5,6/),(/2,5/),(/0,0/),(/2,1/))
! returns 1 2 3 4 5
! 6 0 0 0 0
!
! Change Fortran array order to C array order
C = RESHAPE(F, (/8,3,5/), ORDER = (/3, 2, 1/))
END