MERGE(TSOURCE, FSOURCE, MASK)

Purpose

Selects between two values, or corresponding elements in two arrays. A logical mask determines whether to take each result element from the first or second argument.

Class

Elemental function

Argument type and attributes

TSOURCE
The source array to use when the corresponding element in the mask is true. It is an expression of any data type.
FSOURCE
The source array to use when the corresponding element in the mask is false. It must have the same data type and type parameters as tsource. It must conform in shape to tsource.
MASK
A logical expression that conforms to TSOURCE and FSOURCE in shape.

Result value

The result has the same shape, data type, and type parameters as TSOURCE and FSOURCE.

For each element in the result, the value of the corresponding element in MASK determines whether the value is taken from TSOURCE (if true) or FSOURCE (if false).

Examples

! TSOURCE is | A D G |, FSOURCE is | a d g |,
!            | B E H |             | b e h |
!            | C F I |             | c f i |
!
! and MASK is the array | T T T |
!                       | F F F |
!                       | F F F |

! Take the top row of TSOURCE, and the remaining elements
! from FSOURCE.
       RES = MERGE(TSOURCE, FSOURCE, MASK)
! The result is  | A D G |
!                | b e h |
!                | c f i |

! Evaluate IF (X .GT. Y) THEN
!             RES=6
!          ELSE
!             RES=12
!          END IF
! in a more concise form.
       RES = MERGE(6, 12, X .GT. Y)