G.1.7 DotProduct_Mathematic_Vector Procedure

The main documentation of the DotProduct_Mathematic_Vector Procedure contains additional explanation of this code listing.

  function DotProduct_Mathematic_Vector (MV1, MV2) result(DotProduct)
  
    ! Input variables.

    ! Mathematic Vectors to be dotted.
    type(Mathematic_Vector_type), intent(in) :: MV1, MV2 
  
    ! Output variable.
  
    type(real) :: DotProduct            ! Result of dot product.
  
    !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
    ! Verify requirements.
  
    VERIFY(Valid_State(MV1),5)          ! MV1 is valid.
    VERIFY(Valid_State(MV2),5)          ! MV2 is valid.

    ! Calculate the global dot product.
  
    DotProduct = Global_Dot_Product(MV1%Values, MV2%Values)

    ! Verify guarantees.

    ! Cauchy-Schwartz inequality must be satisfied (only checked if the
    ! Two Norms have already been calculated). The inequality is:
    !
    !   |DotProduct| <= ||MV1||_2 * ||MV2||_2
    !
    ! but is coded in a more convoluted form below to handle close to equal
    ! comparisons correctly.

    if (MV1%Two_Norm_is_Updated .and. MV2%Two_Norm_is_Updated) then
      VERIFY(MV1%Two_Norm*MV2%Two_Norm - ABS(DotProduct) >= dnl
             -EPSILON(DotProduct)*ABS(DotProduct),5)
    end if

    return
  end function DotProduct_Mathematic_Vector



Michael L. Hall