merge(3f) - [FORTRAN:INTRINSIC:ARRAY CONSTRUCTION] Merge variables
Syntax
Description
Arguments
Return Value
Examples
Standard
Class
result = merge(tsource, fsource, mask)
Select values from two arrays according to a logical mask. The result is equal to TSOURCE if MASK is .true., or equal to FSOURCE if it is .false..
TSOURCE - May be of any type. FSOURCE - Shall be of the same type and type parameters as TSOURCE. MASK - Shall be of type LOGICAL.
The result is of the same type and type parameters as TSOURCE. For any element the result is TSOURCE if MASK is true and FSOURCE otherwise.
The value of
MERGE (1.0, 0.0, K > 0)
is 1.0 for K = 5 and 0.0 for K = 2. program demo_merge integer :: TSRC(2,3), FSRC(2,3), ANSWER(2,3) logical :: MASK(2,3)Expected resultTSRC(1,:)=[ 1,6,5 ]; FSRC(1,:)=[ 0,3,2 ]; MASK(1,:)=[.TRUE., .FALSE.,.TRUE.] TSRC(2,:)=[ 2,4,6 ]; FSRC(2,:)=[ 7,4,8 ]; MASK(2,:)=[.FALSE.,.FALSE.,.TRUE.]
ANSWER=MERGE(TSRC,FSRC,MASK) write(*,(3i2))(answer(i,:),i=1,size(answer,dim=1)) end program demo_merge
1 3 5 7 4 6
[[Fortran 95]] and later
[[Elemental procedure|Elemental function]]
merge (3) | March 18, 2019 |