The main documentation of the Valid_State_Character Procedure contains additional explanation of this code listing.
define([REPLICATE_ROUTINE],[
ifelse(POINTER_TOGGLE, [TRUE], [
pushdef([TYPE], [character,*,$1])
pushdef([Valid_State_Character_P_DIM], expand(Valid_State_Character_P_$1))
pushdef([POINTER_ONLY], [])
pushdef([NONPOINTER_ONLY], [!])
],[
pushdef([TYPE], [character,*,$1,np])
pushdef([Valid_State_Character_P_DIM], expand(Valid_State_Character_NP_$1))
pushdef([POINTER_ONLY], [!])
pushdef([NONPOINTER_ONLY], [])
])
function Valid_State_Character_P_DIM (C) result(Valid)
! Use association information.
SCALAR_ONLY use Caesar_Flags_Module, only: finalize_character_flag
! Input variable.
type(TYPE) :: C ! 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(C)
POINTER_ONLY ARRAY_ONLY if (.not.Valid) return
! Make sure the variable has not been finalized.
SCALAR_ONLY Valid = Valid .and. C /= finalize_character_flag
! Quiet compiler warnings by making sure C is always referenced.
! Note the 'or' which means that this test has no effect.
!NONPOINTER_ONLY ARRAY_ONLY Valid = Valid .or. LEN(C) /= 0
return
end function Valid_State_Character_P_DIM
popdef([TYPE])
popdef([Valid_State_Character_P_DIM])
popdef([POINTER_ONLY])
popdef([NONPOINTER_ONLY])
])
define([POINTER_TOGGLE], [TRUE])
REPLICATE
define([POINTER_TOGGLE], [FALSE])
REPLICATE