spread
- Date:
02-06-2023
NAME
SPREAD - Constructs an array from several copies of an argument
SYNOPSIS
SPREAD ([SOURCE=]source, [DIM=]dim, [NCOPIES=]ncopies)
STANDARDS
Fortran
DESCRIPTION
The SPREAD intrinsic function constructs an array from several copies of an argument. This intrinsic function can be used for array construction. It replicates an array by adding a dimension. It broadcasts several copies of source along a specified dimension and thus forms an array of rank one greater. SPREAD accepts the following arguments:
- source
May be of any type. It may be scalar or array valued. The rank of source must be less than 7.
- dim
Must be scalar and an integer with value in the range of 1 <= dim <= n + 1, where n is the rank of source.
- ncopies
Must be scalar and an integer.
SPREAD is a transformational intrinsic function. The name of this intrinsic cannot be passed as an argument.
RETURN VALUES
The result is an array of the same type as source and of rank n+1, where n is the rank of source.
If source is scalar, the shape of the result is MAX(ncopies,0). If source is array valued with shape
(d1, d2, ..., dn)
the shape of the result is
(d1, d2, ..., ddim-1, MAX(ncopies, 0), ddim, ..., dn)
If source is scalar, each element of the result has a value equal to source.
If source is array valued, the element of the result with these subscripts
(r1, r2, ..., rn+1)
has the value
source(r1, r2, ..., rdim-1, rdim+1, ..., rn+1)
EXAMPLES
Example 1: Assume that ISCALR is the scalar value of 8. The following statements are then true:
SPREAD(ISCALR,DIM=1,NCOPIES=0) yields a zero-sized array.
SPREAD(ISCALR,DIM=1,NCOPIES=2) yields (/8,8/).
Example 2: Assume that A is the array [2,3,4]. The following statements are then true:
SPREAD(A,DIM=1,NCOPIES=0) yields a zero-sized array.
SPREAD(A,DIM=1,NCOPIES=3) yields:
| 2 3 4 |
| 2 3 4 |
| 2 3 4 |
SPREAD(A,DIM=2,NCOPIES=3) yields:
| 2 2 2 |
| 3 3 3 |
| 4 4 4 |