NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
w3fb10.f
Go to the documentation of this file.
1C> @file
2C> @brief Lat/long pair to compass bearing, gcd.
3C> @author Peter Chase @date 1988-08-29
4
5C> Given a pair of points (1) and (2) given by latitude and
6C> longitude, w3fb10() computes the bearing and great circle distance
7C> from point (1) to point (2) assuming a spherical Earth. The
8C> north and south poles are special cases. If latitude of point
9C> (1) is within 1e-10 degrees of the north pole, bearing is the
10C> negative longitude of point (2) by convention. If latitude of
11C> point (1) is within 1e-10 degrees of the south pole, bearing is
12C> the longitude of point (2) by convention. If point (2) is within
13C> 1e-6 radians of the antipode of point (1), the bearing will be
14C> set to zero. If point (1) and point (2) are within 1e-10 radians
15C> of each other, both bearing and distance will be set to zero.
16C>
17C> Program history log:
18C> - Peter Chase 1988-08-29
19C> - Peter Chase 1988-09-23 Fix dumb south pole error.
20C> - Peter Chase 1988-10-05 Fix bearing ambiguity.
21C> - Ralph Jones 1990-04-12 Convert to cft77 fortran.
22C>
23C> @param[in] DLAT1 REAL Latitude of point (1) in degrees north.
24C> @param[in] DLON1 REAL Longitude of point (1) in degrees east.
25C> @param[in] DLAT2 REAL Latitude of point (2) in degrees north.
26C> @param[in] DLON2 REAL Longitude of point (2) in degrees east.
27C> @param[out] BEARD REAL Bearing of point (2) from point (1) in
28C> compass degrees with north = 0.0, values from
29C> -180.0 to +180.0 degrees.
30C> @param[out] GCDKM REAL Great circle distance from point (1) to
31C> point (2) in kilometers.
32C>
33C> @note According to the nmc handbook, the Earth's radius is
34C> 6371.2 kilometers. This is what we use, even though the value
35C> recommended by the smithsonian meteorological handbook is
36C> 6371.221 km. (I wouldn't want you to think that I didn't know
37C> what the correct value was.)
38C>
39C> @note Method: The poles are special cases, and handled separately.
40C> otherwise, from spherical trigonometry, the law of cosines is used
41C> to calculate the third side of the spherical triangle having
42C> sides from the pole to points (1) and (2) (the colatitudes).
43C> then the law of sines is used to calculate the angle at point
44C> (1). A test is applied to see whether the arcsine result may be
45C> be used as such, giving an acute angle as the bearing, or whether
46C> the arcsine result should be subtracted from pi, giving an obtuse
47C> angle as the bearing. This test is derived by constructing a
48C> right spherical triangle using the pole, point (2), and the
49C> meridian through point(1). The latitude of the right-angled
50C> vertex then provides a test--if latitude (1) is greater than this
51C> latitude, the bearing angle must be obtuse, otherwise acute.
52C> If the two points are within 1e-6 radians of each other
53C> a flat Earth is assumed, and the four-quadrant arctangent
54C> function is used to find the bearing. The y-displacement is
55C> the difference in latitude and the x-displacement is the
56C> difference in longitude times cosine latitude, both in radians.
57C> distance is then the diagonal.
58C>
59C> @note Fundamental trigonometric identities are used freely, such
60C> as that cos(x) = sin(pi/2 - x), etc. See almost any mathematical
61C> handbook, such as the c.r.c. standard math tables under 'relations
62C> in any spherical triangle', or the national bureau of standards
63C> 'handbook of mathematical functions' under section 4.3.149,
64C> formulas for solution of spherical triangles.
65C>
66C> @note Double precision is used internally because of the wide
67C> range of geographic values that may be used.
68C>
69C> @author Peter Chase @date 1988-08-29
70 SUBROUTINE w3fb10(DLAT1, DLON1, DLAT2, DLON2, BEARD, GCDKM)
71C
72C *** IMPLICIT TYPE DEFAULTS.....
73C
74 IMPLICIT REAL (A-H,O-Z)
75C
76C *** CONSTANTS......
77C
78 REAL PI
79 REAL HALFPI
80 REAL DR
81 REAL RD
82 REAL TDEG, TRAD, TPOD, TFLT
83 REAL EARTHR
84 REAL WHOLCD, HALFCD, QUARCD
85C
86C *** VARIABLES......
87C
88 REAL RLAT1, RLAT2, COSLA1, COSLA2, SINLA1, SINLA2
89 REAL DLOND, RLOND, COSLO, SINLO, SANGG, ABEAR
90 REAL YDISP, XDISP, DDLAT1, DDLAT2, DBANG
91 REAL DLAT1, DLAT2, DLON1, DLON2, BEARD, GCDKM
92C
93C *** CONVERT LATITUDES AND LONGITUDE DIFFERENCE TO RADIANS.
94C
95 DATA pi /3.141592653589793238462643/
96 DATA halfpi/1.570796326794896619231322/
97 DATA dr /0.017453292519943295769237/
98 DATA rd /57.295779513082320876798155/
99 DATA tdeg /1e-10/, trad/1e-10/, tpod/1e-6/, tflt/1e-6/
100 DATA earthr/6371.2/
101 DATA wholcd/360.0/, halfcd/180.0/, quarcd/90.0/
102
103 ddlat1 = dlat1
104 ddlat2 = dlat2
105 rlat1 = dr * ddlat1
106 rlat2 = dr * ddlat2
107 dlond = dlon2 - dlon1
108 IF (dlond .GT. halfcd) dlond = dlond - wholcd
109 IF (dlond .LT. -halfcd) dlond = dlond + wholcd
110 rlond = dr * dlond
111C
112C *** FIRST WE ATTACK THE CASES WHERE POINT 1 IS VERY CLOSE TO THE
113C *** NORTH OR SOUTH POLES.
114C *** HERE WE USE CONVENTIONAL VALUE FOR BEARING.. - LONG (2) AT THE
115C *** NORTH POLE, AND + LONG (2) AT THE SOUTH POLE.
116C
117 IF (abs(ddlat1-quarcd) .LT. tdeg) THEN
118 IF (abs(ddlat2-quarcd) .LT. tdeg) THEN
119 dbang = 0.0
120 sangg = 0.0
121 ELSE IF (abs(ddlat2+quarcd) .LT. tdeg) THEN
122 dbang = 0.0
123 sangg = pi
124 ELSE
125 dbang = -dlon2
126 sangg = halfpi - rlat2
127 ENDIF
128 ELSE IF (abs(ddlat1+quarcd) .LT. tdeg) THEN
129 IF (abs(ddlat2-quarcd) .LT. tdeg) THEN
130 dbang = 0.0
131 sangg = pi
132 ELSE IF (abs(ddlat2+quarcd) .LT. tdeg) THEN
133 dbang = 0.0
134 sangg = 0.0
135 ELSE
136 dbang = +dlon2
137 sangg = halfpi + rlat2
138 ENDIF
139C
140C *** NEXT WE ATTACK THE CASES WHERE POINT 2 IS VERY CLOSE TO THE
141C *** NORTH OR SOUTH POLES.
142C *** HERE BEARING IS SIMPLY 0 OR 180 DEGREES.
143C
144 ELSE IF (abs(ddlat2-quarcd) .LT. tdeg) THEN
145 dbang = 0.0
146 sangg = halfpi - rlat1
147 ELSE IF (abs(ddlat2+quarcd) .LT. tdeg) THEN
148 dbang = halfcd
149 sangg = halfpi + rlat1
150C
151C *** THE CASE REMAINS THAT NEITHER POINT IS AT EITHER POLE.
152C *** FIND COSINE AND SINE OF LATITUDES AND LONGITUDE DIFFERENCE
153C *** SINCE THEY ARE USED IN MORE THAN ONE FORMULA.
154C
155 ELSE
156 cosla1 = cos(rlat1)
157 sinla1 = sin(rlat1)
158 cosla2 = cos(rlat2)
159 sinla2 = sin(rlat2)
160 coslo = cos(rlond)
161 sinlo = sin(rlond)
162C
163C *** FOLLOWING IS FORMULA FOR GREAT CIRCLE SUBTENDED ANGLE BETWEEN
164C *** POINTS IN RADIAN MEASURE.
165C
166 sangg = acos(sinla1*sinla2 + cosla1*cosla2*coslo)
167C
168C *** IF THE GREAT CIRCLE SUBTENDED ANGLE IS VERY SMALL, FORCE BOTH
169C *** BEARING AND DISTANCE TO BE ZERO.
170C
171 IF (abs(sangg) .LT. trad) THEN
172 dbang = 0.0
173 sangg = 0.0
174C
175C *** IF THE GREAT CIRCLE SUBTENDED ANGLE IS JUST SMALL, ASSUME A
176C *** FLAT EARTH AND CALCULATE Y- AND X-DISPLACEMENTS. THEN FIND
177C *** BEARING USING THE ARCTANGENT FUNCTION AND DISTANCE USING THE
178C *** SQUARE ROOT.
179C
180 ELSE IF (abs(sangg) .LT. tflt) THEN
181 ydisp = rlat2-rlat1
182 xdisp = rlond*cosla2
183 abear = atan2(xdisp, ydisp)
184 dbang = rd*abear
185 sangg = sqrt(ydisp**2 + xdisp**2)
186C
187C *** IF THE ANGLE IS RATHER CLOSE TO PI RADIANS, FORCE BEARING TO
188C *** BE ZERO AND DISTANCE TO BE PI.
189C *** THE TEST FOR 'CLOSE TO PI' IS MORE RELAXED THAN THE TEST FOR
190C *** 'CLOSE TO ZERO' TO ALLOW FOR GREATER RELATIVE ERROR.
191C
192 ELSE IF (abs(sangg-pi) .LT. tpod) THEN
193 dbang = 0.0
194 sangg = pi
195C
196C *** OTHERWISE COMPUTE THE PRINCIPAL VALUE OF THE BEARING ANGLE
197C *** USING THE LAW OF SINES. THE DIVISION BY THE SINE FORCES US TO
198C *** LIMIT THE DOMAIN OF THE ARCSINE TO (-1,1).
199C
200 ELSE
201 abear = asin(amax1(-1.0,amin1(+1.0,cosla2*sinlo/
202 & sin(sangg))))
203C
204C *** IF THE LONGITUDE DIFFERENCE IS LESS THAN PI/2 IT IS NECESSARY
205C *** TO CHECK WHETHER THE BEARING ANGLE IS ACUTE OR OBTUSE BY
206C *** COMPARING LATITUDE (1) WITH THE LATITUDE OF THE GREAT CIRCLE
207C *** THROUGH POINT (2) NORMAL TO MERIDIAN OF LONGITUDE (1). IF
208C *** LATITUDE (1) IS GREATER, BEARING IS OBTUSE AND THE ACTUAL
209C *** BEARING ANGLE IS THE SUPPLEMENT OF THE ANGLE CALCULATED ABOVE.
210C
211 IF (0.0 .LE. cosla1*sinla2 .AND. cosla1*sinla2 .LE.
212 & cosla2*sinla1*coslo .OR. cosla1*sinla2 .LE. 0.0 .AND.
213 & cosla2*sinla1*coslo .GE. cosla1*sinla2) abear =
214 & sign(pi,abear) - abear
215 dbang = rd * abear
216 ENDIF
217 ENDIF
218C
219C *** THIS FINISHES THE CASE WHERE POINTS ARE NOT AT THE POLES.
220C *** NOW CONVERT BEARING TO DEGREES IN RANGE -180 TO +180 AND FIND
221C *** GREAT CIRCLE DISTANCE IN KILOMETERS.
222C
223 IF (dbang .LE. -halfcd) dbang = dbang + wholcd
224 IF (dbang .GT. halfcd) dbang = dbang - wholcd
225 gcdkm = earthr * sangg
226 beard = dbang
227 RETURN
228 END
subroutine w3fb10(dlat1, dlon1, dlat2, dlon2, beard, gcdkm)
Given a pair of points (1) and (2) given by latitude and longitude, w3fb10() computes the bearing and...
Definition w3fb10.f:71