The main documentation of the Valid_State_Data_Index Procedure contains additional explanation of this code listing.
function Valid_State_Data_Index (Index) result(Valid) ! Input variables. ! Variable to be checked. type(Data_Index_type), intent(in) :: Index ! Output variables. type(logical) :: Valid ! Logical state. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ! Start out true. Valid = .true. ! Check for association of pointered internals. Valid = Valid .and. ASSOCIATED(Index%Many_Structure) Valid = Valid .and. ASSOCIATED(Index%One_Structure) if (.not.Valid) return ! Check for validity of internals. Valid = Valid .and. Initialized(Index) Valid = Valid .and. Valid_State(Index%One_Structure) Valid = Valid .and. Valid_State(Index%Many_Structure) select case (Index%Dimensionality) case (1) Valid = Valid .and. Valid_State(Index%Index1) case (2) Valid = Valid .and. Valid_State(Index%Index2) !case (-1) ! Valid = Valid .and. Valid_State(Index%IndexRR) end select Valid = Valid .and. Valid_State(Index%Off_PE_Index) if (.not.Valid) return ! Checks on the validity of Index. Valid = Valid .and. Index%NOff_PE == SIZE(Index%Off_PE_Index) select case (Index%Dimensionality) case (1) Valid = Valid .and. & SIZE(Index%Index1,1) == Length_PE(Index%One_Structure) case (2) Valid = Valid .and. & SIZE(Index%Index2,1) == Length_PE(Index%One_Structure) !case (-1) ! Valid = Valid .and. & ! SIZE(Index%IndexRR,1) == Length_PE(Index%One_Structure) end select ! All off-PE indices are really off-PE. Valid = Valid .and. & (Index%Off_PE_Index .NotInInterval. Range_PE(Index%Many_Structure)) ! All positive indices are on-PE. (Negative ones pass this test also.) select case (Index%Dimensionality) case (1) Valid = Valid .and. & (ALL(Index%Index1 <= Length_PE(Index%Many_Structure))) case (2) Valid = Valid .and. & (ALL(Index%Index2 <= Length_PE(Index%Many_Structure))) !case (-1) ! Valid = Valid .and. & ! (ALL((Index%IndexRR <= Last_PE(Index%One_Structure) .and. & ! Index%IndexRR >= First_PE(Index%One_Structure)) .or. & ! Index%IndexRR < 0)) end select return end function Valid_State_Data_Index