Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 6/24/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

SPREAD

Transformational Intrinsic Function (Generic): Creates a replicated array with an added dimension by making copies of existing elements along a specified dimension.

result = SPREAD (source,dim,ncopies)

source

(Input) Must be a scalar or array. It may be of any data type. The rank must be less than 31.

dim

(Input) Must be scalar and of type integer. It must have a value in the range 1 to n + 1 (inclusive), where n is the rank of source.

ncopies

Must be scalar and of type integer. It becomes the extent of the additional dimension in the result.

Results

The result is an array of the same type as source and of rank that is one greater than source.

If source is an array, each array element in dimension dim of the result is equal to the corresponding array element in source.

If source is a scalar, the result is a rank-one array with ncopies elements, each with the value source.

If ncopies less than or equal to zero, the result is an array of size zero.

Example

SPREAD ("B", 1, 4) is the character array (/"B", "B", "B", "B"/).

B is the array [3, 4, 5] and NC has the value 4.

SPREAD (B, DIM=1, NCOPIES=NC) produces the array

  [ 3  4  5 ]
  [ 3  4  5 ]
  [ 3  4  5 ]
  [ 3  4  5 ].

SPREAD (B, DIM=2, NCOPIES=NC) produces the array

  [3  3  3  3 ]
  [4  4  4  4 ]
  [5  5  5  5 ].

The following shows another example:


 INTEGER AR1(2, 3), AR2(3, 2)
 AR1 = SPREAD((/1,2,3/),DIM= 1,NCOPIES= 2) ! returns
                                           ! 1 2 3
                                           ! 1 2 3

 AR2 = SPREAD((/1,2,3/), 2, 2)   ! returns   1 1
                                 !           2 2
                                 !           3 3

See Also