[UP]


Manual Reference Pages  - merge (3)

NAME

merge(3f) - [FORTRAN:INTRINSIC:ARRAY CONSTRUCTION] Merge variables

CONTENTS

Syntax
Description
Arguments
Return Value
Examples
Standard
Class

SYNTAX

result = merge(tsource, fsource, mask)

DESCRIPTION

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..

ARGUMENTS

TSOURCE
  - May be of any type.
FSOURCE
  - Shall be of the same type and type parameters as TSOURCE.
MASK - Shall be of type LOGICAL.

RETURN VALUE

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.

EXAMPLES

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)

TSRC(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

Expected result
 

1 3 5 7 4 6

STANDARD

[[Fortran 95]] and later

CLASS

[[Elemental procedure|Elemental function]]


merge (3) March 18, 2019
Generated by manServer 1.08 from f67d30fb-b738-473b-8364-6cc74252879b using man macros.