dot Function

public function dot(a, b) result(result)

function that calculates the dot product of two real 3-dimensional vectors and

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in), DIMENSION(:) :: a
real(kind=dp), intent(in), DIMENSION(:) :: b

Return Value real(kind=dp)


Source Code

    FUNCTION dot(a, b) RESULT(result)
        REAL(dp), DIMENSION(:), INTENT(IN) :: a, b
        REAL(dp) :: result
        INTEGER :: i

        IF (SIZE(a) /= SIZE(b)) STOP "Error: Vectors must be of the same size."

        result = 0.0_dp
        DO i = 1, SIZE(a)
            result = result + a(i) * b(i)
        END DO

    END FUNCTION dot