OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
dangle.f
Go to the documentation of this file.
1 **
2 ** INVOCATION NAME: DANGLE
3 **
4 ** PURPOSE: FUNCTION TO COMPUTE THE ANGLE BETWEEN TWO UNIT VECTORS
5 **
6 ** INVOCATION METHOD: X = DANGLE(A, B, TOLER, ANG)
7 **
8 ** ARGUMENT LIST:
9 ** NAME TYPE USE PURPOSE
10 ** A(3) R*8 I FIRST UNIT VECTOR
11 ** B(3) R*8 I SECOND UNIT VECTOR
12 ** TOLER R*8 I MAXIMUM MAGNITUDE OF DOT-PRODUCT BEFORE CROSS-
13 ** PRODUCT IS USED TO COMPUTE ANGLE. IF DOT-PRODUCT
14 ** IS GREATER THAN TOLER, THEN THE ANGLE IS ARCSIN
15 ** OF THE MAGNITUDE OF THE CROSS-PRODUCT, OTHERWISE,
16 ** THE ARCCOS OF THE DOT-PRODUCT IS USED.
17 ** (RECOMMENDED VALUE IS 0.99D0)
18 ** ANG R*8 O ANGLE BETWEEN UNIT VECTORS A AND B IN RADIANS
19 ** DANGLE R*8 O ANGLE BETWEEN UNIT VECTORS A AND B IN RADIANS
20 **
21 ** FILE/RECORD REFERENCES: NONE
22 **
23 ** GLOBAL REFERENCES: NONE
24 **
25 ** EXTERNAL REFERENCES: NONE
26 **
27 ** INTERNAL VARIABLES:
28 ** VAR TYPE PURPOSE
29 ** ACROSB(3) R*8 CROSS-PRODUCT OF A AND B
30 ** ADOTB R*8 DOT-PRODUCT OF A AND B
31 ** CROSMG R*8 MAGNITUDE OF CROSS-PRODUCT
32 **
33 ** NOTES:
34 **
35 ** CHANGE HISTORY:
36 ** AUTHOR CHG-ID MMM.YY CHG-SUMMARY
37 ** B.GROVEMAN JUL.88 PDL
38 ** M.WOOLSEY AUG.88 CERTIFIED PDL
39 ** R.COON NOV.88 ORIGINAL CODE
40 ** B.GROVEMAN NOV.88 CERTIFIED CODE
41 ** M. WOOLSEY AUG.89 CORRECTED ARCSIN METHOD
42 ** RETURNING ANSWERS > PI / 2
43 **
44 ** BEGIN PDL
45 ** COMPUTE DOT-PRODUCT OF A AND B
46 ** IF (DOT-PRODUCT LESS THAN TOLER) THEN
47 ** ANGLE = ARCCOS(DOT-PRODUCT)
48 ** ELSE
49 ** COMPUTE CROSS-PRODUCT OF A AND B
50 ** COMPUTE THE MAGNITUDE OF THE CROSS-PRODUCT
51 ** ANGLE = ARCSIN(MAGNITUDE OF CROSS-PRODUCT)
52 ** IF (DOT-PRODUCT IS LESS THAN ZERO) ANGLE = PI - ANGLE
53 ** END IF
54 **
55 ** RETURN
56 ** END PDL
57 **
58 ** MAIN ENTRY POINT TO DANGLE
59 ************************************************************************
60 C
61  FUNCTION dangle (A, B, TOLER, ANG)
62 C
63 C-----DECLARE ARGUMENTS
64  real*8 a(3), b(3), toler, ang, dangle
65 C
66 C-----DECLARE LOCAL VARIABLES
67  real*8 acrosb(3), adotb, crosmg
68  real*8 pi /3.141592653589793d+00/
69 C
70  adotb = a(1)*b(1) + a(2)*b(2) + a(3)*b(3)
71  IF (abs(adotb) .LE. abs(toler)) THEN
72 C USE DOT-PRODUCT
73  ang = acos(adotb)
74  dangle = ang
75  ELSE
76 C USE CROSS PRODUCT FOR GREATER ACCURACY
77  acrosb(1) = a(2)*b(3) - a(3)*b(2)
78  acrosb(2) = a(3)*b(1) - a(1)*b(3)
79  acrosb(3) = a(1)*b(2) - a(2)*b(1)
80  crosmg = sqrt(acrosb(1)**2 + acrosb(2)**2 + acrosb(3)**2)
81  ang = asin(crosmg)
82  IF (adotb .LT. 0.0d0) ang = pi - ang
83  dangle = ang
84  END IF
85 C
86  RETURN
87  END
#define real
Definition: DbAlgOcean.cpp:26
#define pi
Definition: vincenty.c:23
#define abs(a)
Definition: misc.h:90
real *8 function dangle(A, B, TOLER, ANG)
Definition: dangle.f:62