PROGRAM dotproduct 
! Dot product between two vectors.
! For vectors v and w, where
! v = (v1, v2, v3)
! w = (w1, w2, w3)
! the dot product output is the scalar variable dprod
! the angle between the vectors is given as alpha, where
! alpha = arccos(v*w/|v||w|)
! s is the distance along the arc between the two endpoints
! of vectors v and w, where s=r*theta.  alpha and s are
! valid for angles <= 180 deg
IMPLICIT NONE
REAL(KIND=8), PARAMETER :: pi=3.141592653589793
REAL(KIND=8) :: v1, v2, v3, w1, w2, w3
REAL(KIND=8) :: doprod, alpha, s
REAL(KIND=8) :: rtd, magW, magV, arg, theta

!Define the two vectors
v1 = 0
v2 = 1
v3 = 0

w1 = 1
w2 = 0
w3 = 0

rtd = 180.0/pi                      !conversion from radians to degrees
doprod = v1*w1 + v2*w2 + v3*w3      !dot product of the vectors
magV = SQRT(v1**2 + v2**2 + v3**2)  !magnitude of vector V
magW = SQRT(w1**2 + w2**2 + w3**2)  !magnitude of vector W

arg = doprod/(magV*magW)
theta = ACOS(arg)
s = magV*theta                      !distance
alpha = (ACOS(arg))*rtd             !angle


write(*,*) "Angle = ", alpha



END PROGRAM dotproduct
