M_overload(3fm) - [M_overload::LOGICAL] returns One if expression is TRUE, else returns Zero.
(LICENSE:PD)
pure elemental integer function oz(expr)
logical,intent(in) :: expr
Returns an integer given a logical expression.
expr A logical expression
The result is a default INTEGER value of 1 if the expression is TRUE,
and a 0 otherwise.
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
John S. Urban
Public Domain
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | expr |
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