The main documentation of the InSet Procedure contains additional explanation of this code listing.
define([IN_SET_ROUTINE],[
ifelse($1, [character], [
pushdef([TYPE], [$1,*])
pushdef([InSet_TYPE], expand(InSet_$1))
],[
pushdef([TYPE], [$1])
pushdef([InSet_TYPE], expand(InSet_TYPE))
])
function InSet_TYPE (X, Set) result(InSet)
! Input variables.
type(TYPE), intent(in) :: X ! Variable to be checked.
type(TYPE), dimension(:), intent(in) :: Set ! The set to check.
! Output variable.
type(logical) :: InSet ! Result of check.
! Internal variable.
type(integer) :: element ! Element loop counter.
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! Verify requirements - none.
! InSet is true if X is in the set.
InSet = .false.
do element = 1, SIZE(Set)
InSet = InSet .or. X == Set(element)
end do
! Verify guarantees -- none.
return
end function InSet_TYPE
popdef([TYPE])
popdef([InSet_TYPE])
])
fortext([Type],[real integer character],[
IN_SET_ROUTINE(Type)
])