The main documentation of the Valid_State_Logical Procedure contains additional explanation of this code listing.
define([REPLICATE_ROUTINE],[
ifelse(POINTER_TOGGLE, [TRUE], [
pushdef([TYPE], [logical,$1])
pushdef([Valid_State_Logical_P_DIM], expand(Valid_State_Logical_P_$1))
pushdef([POINTER_ONLY], [])
],[
pushdef([TYPE], [logical,$1,np])
pushdef([Valid_State_Logical_P_DIM], expand(Valid_State_Logical_NP_$1))
pushdef([POINTER_ONLY], [!])
])
function Valid_State_Logical_P_DIM (L) result(Valid)
! Input variable.
type(TYPE) :: L ! Variable to be checked.
! Output variable.
type(logical) :: Valid ! Logical state.
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! Start out true.
Valid = .true.
! First, make sure that the variable has been allocated.
POINTER_ONLY ARRAY_ONLY Valid = Valid .and. ASSOCIATED(L)
POINTER_ONLY ARRAY_ONLY if (.not.Valid) return
! All logicals should be valid, so this tautology should always work.
Valid = Valid .and. ALL(L .or. .not. L)
return
end function Valid_State_Logical_P_DIM
popdef([TYPE])
popdef([Valid_State_Logical_P_DIM])
popdef([POINTER_ONLY])
])
define([POINTER_TOGGLE], [TRUE])
REPLICATE
define([POINTER_TOGGLE], [FALSE])
REPLICATE