-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVectorMath.f90
61 lines (36 loc) · 1.12 KB
/
VectorMath.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
MODULE VectorMath
IMPLICIT NONE
CONTAINS
!**** FUNCTIONS RETURNING SCALARS
PURE REAL(8) FUNCTION DotProduct(p,q,n) result(pdotq); IMPLICIT NONE
integer, intent(in) :: n
real(8), intent(in) :: p(n), q(n)
integer :: i
pdotq = 0.0d0
do i = 1, n
pdotq = pdotq + (p(i) * q(i))
enddo
END FUNCTION DotProduct
!*
PURE REAL(8) FUNCTION EuclideanNorm(vector,n) result(r); IMPLICIT NONE
integer, intent(in) :: n
real(8), intent(in) :: vector(n)
r = dsqrt(DotProduct(vector,vector,n))
END FUNCTION EuclideanNorm
!**** FUNCTIONS RETURNING VECTORS
PURE FUNCTION NormaliseVector(p,n); IMPLICIT NONE
integer, intent(in) :: n
real(8), intent(in) :: p(n)
real(8) :: NormaliseVector(n)
NormaliseVector = p(:) / EuclideanNorm(p,n)
END FUNCTION NormaliseVector
!*
PURE FUNCTION CrossProduct(p,q); IMPLICIT NONE
real(8), intent(in) :: p(3), q(3)
real(8) :: CrossProduct(3)
CrossProduct(1) = p(2)*q(3) - p(3)*q(2)
CrossProduct(2) = p(3)*q(1) - p(1)*q(3)
CrossProduct(3) = p(1)*q(2) - p(2)*q(1)
END FUNCTION CrossProduct
!*
END MODULE VectorMath