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.

**TSOURCE**- is the source array to use when the corresponding element in the mask is true. It is an expression of any data type.
**FSOURCE**- is 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**- is a logical expression that conforms to TSOURCE and FSOURCE in shape.

**Class**

Elemental function

**Result Value**

The result has the same shape and data type 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)
```