oz Function

public pure elemental function oz(expr)

NAME

M_overload(3fm) - [M_overload::LOGICAL] returns One if expression is TRUE, else returns Zero.
(LICENSE:PD)

SYNOPSIS

pure elemental integer function oz(expr)

 logical,intent(in) :: expr

DESCRIPTION

Returns an integer given a logical expression.

OPTIONS

expr  A logical expression

RETURNS

The result is a default INTEGER value of 1 if the expression is TRUE,
and a 0 otherwise.

EXAMPLES

Sample usage:

program demo_oz
use M_overload, only: oz, zo, lt, le, eq, ne, gt, ge
implicit none
   write (*, *) 'is 10 < 20 ?', oz(10 < 20)
   write (*, *) 'elemental', oz([2 > 1, 3 == 4, 10 < 5, 100 > 50])
   if (sum(oz([2 > 1, 3 == 4, 10 < 5, 100 > 50])) >= 2) then
      write (*, *) 'two or more are true'
   endif
end program demo_oz

Results:

 > is 10 < 20 ? 1
 > elemental 1 0 0 1
 > two or more are true

AUTHOR

John S. Urban

LICENSE

Public Domain

Arguments

Type IntentOptional Attributes Name
logical, intent(in) :: expr

Return Value integer


Source Code

pure elemental integer function oz(expr)
! ident_9="@(#) M_strings oz(3f) logical to integer TRUE results in 1 FALSE results in 0"
logical, intent(in) :: expr
   oz = merge(1, 0, expr) ! One and Zero
end function oz