[UP]


Manual Reference Pages  - merge (3)

NAME

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

SYNTAX

result = merge(tsource, fsource, mask)

DESCRIPTION

Select values from two arrays or scalars 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.

Note that (currently) CHARACTER values must be of the same length.

   program demo_merge
   implicit none
   integer :: tsrc(2,3), fsrc(2,3), answer(2,3)
   logical :: mask(2,3)
   integer :: i
      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 11, 2021
Generated by manServer 1.08 from a399a059-0687-429d-b861-64f0121b5f05 using man macros.