182 subroutine direct(a, f, lat1, lon1, azi1, s12a12, flags,
183 + lat2, lon2, azi2, omask, a12s12, m12, MM12, MM21, SS12)
185 double precision a, f, lat1, lon1, azi1, s12a12
188 double precision lat2, lon2, azi2
190 double precision a12s12, m12, MM12, MM21, SS12
192 integer ord, nC1, nC1p, nC2, nA3, nA3x, nC3, nC3x, nC4, nC4x
193 parameter(ord = 6, nc1 = ord, nc1p = ord,
194 + nc2 = ord, na3 = ord, na3x = na3,
195 + nc3 = ord, nc3x = (nc3 * (nc3 - 1)) / 2,
196 + nc4 = ord, nc4x = (nc4 * (nc4 + 1)) / 2)
197 double precision A3x(0:nA3x-1), C3x(0:nC3x-1), C4x(0:nC4x-1),
198 + c1a(nc1), c1pa(nc1p), c2a(nc2), c3a(nc3-1), c4a(0:nc4-1)
200 double precision atanhx, hypotx,
201 + angnm, angrnd, trgsum, a1m1f, a2m1f, a3f, atn2dx, latfix
202 logical arcmod, unroll, arcp, redlp, scalp, areap
203 double precision e2, f1, ep2, n, b, c2,
204 + salp0, calp0, k2, eps,
205 + salp1, calp1, ssig1, csig1, cbet1, sbet1, dn1, somg1, comg1,
206 + salp2, calp2, ssig2, csig2, sbet2, cbet2, dn2, somg2, comg2,
207 + ssig12, csig12, salp12, calp12, omg12, lam12, lon12,
208 + sig12, stau1, ctau1, tau12, t, s, c, serr, e,
209 + a1m1, a2m1, a3c, a4, ab1, ab2,
210 + b11, b12, b21, b22, b31, b41, b42, j12
212 double precision dblmin, dbleps, pi, degree, tiny,
213 + tol0, tol1, tol2, tolb, xthrsh
214 integer digits, maxit1, maxit2
216 common /geocom/ dblmin, dbleps, pi, degree, tiny,
217 + tol0, tol1, tol2, tolb, xthrsh, digits, maxit1, maxit2, init
219 if (.not.init)
call geoini
228 arcmod = mod(flags/1, 2) .eq. 1
229 unroll = mod(flags/2, 2) .eq. 1
231 arcp = mod(omask/1, 2) .eq. 1
232 redlp = mod(omask/2, 2) .eq. 1
233 scalp = mod(omask/4, 2) .eq. 1
234 areap = mod(omask/8, 2) .eq. 1
239 else if (e2 .gt. 0)
then
240 c2 = (a**2 + b**2 * atanhx(sqrt(e2)) / sqrt(e2)) / 2
242 c2 = (a**2 + b**2 * atan(sqrt(abs(e2))) / sqrt(abs(e2))) / 2
248 if (areap)
call c4cof(n, c4x)
251 call sncsdx(angrnd(azi1), salp1, calp1)
253 call sncsdx(angrnd(latfix(lat1)), sbet1, cbet1)
255 call norm2x(sbet1, cbet1)
257 cbet1 = max(tiny, cbet1)
258 dn1 = sqrt(1 + ep2 * sbet1**2)
262 salp0 = salp1 * cbet1
265 calp0 = hypotx(calp1, salp1 * sbet1)
276 somg1 = salp0 * sbet1
277 if (sbet1 .ne. 0 .or. calp1 .ne. 0)
then
278 csig1 = cbet1 * calp1
284 call norm2x(ssig1, csig1)
288 eps = k2 / (2 * (1 + sqrt(1 + k2)) + k2)
292 b11 = trgsum(.true., ssig1, csig1, c1a, nc1)
296 stau1 = ssig1 * c + csig1 * s
297 ctau1 = csig1 * c - ssig1 * s
301 if (.not. arcmod)
call c1pf(eps, c1pa)
303 if (redlp .or. scalp)
then
306 b21 = trgsum(.true., ssig1, csig1, c2a, nc2)
313 call c3f(eps, c3x, c3a)
314 a3c = -f * salp0 * a3f(eps, a3x)
315 b31 = trgsum(.true., ssig1, csig1, c3a, nc3-1)
318 call c4f(eps, c4x, c4a)
320 a4 = a**2 * calp0 * salp0 * e2
321 b41 = trgsum(.false., ssig1, csig1, c4a, nc4)
330 sig12 = s12a12 * degree
331 call sncsdx(s12a12, ssig12, csig12)
336 tau12 = s12a12 / (b * (1 + a1m1))
340 b12 = - trgsum(.true.,
341 + stau1 * c + ctau1 * s, ctau1 * c - stau1 * s, c1pa, nc1p)
342 sig12 = tau12 - (b12 - b11)
345 if (abs(f) .gt. 0.01d0)
then
367 ssig2 = ssig1 * csig12 + csig1 * ssig12
368 csig2 = csig1 * csig12 - ssig1 * ssig12
369 b12 = trgsum(.true., ssig2, csig2, c1a, nc1)
370 serr = (1 + a1m1) * (sig12 + (b12 - b11)) - s12a12 / b
371 sig12 = sig12 - serr / sqrt(1 + k2 * ssig2**2)
379 ssig2 = ssig1 * csig12 + csig1 * ssig12
380 csig2 = csig1 * csig12 - ssig1 * ssig12
381 dn2 = sqrt(1 + k2 * ssig2**2)
382 if (arcmod .or. abs(f) .gt. 0.01d0)
383 + b12 = trgsum(.true., ssig2, csig2, c1a, nc1)
384 ab1 = (1 + a1m1) * (b12 - b11)
387 sbet2 = calp0 * ssig2
389 cbet2 = hypotx(salp0, calp0 * csig2)
390 if (cbet2 .eq. 0)
then
397 somg2 = salp0 * ssig2
402 calp2 = calp0 * csig2
408 + - (atan2( ssig2, csig2) - atan2( ssig1, csig1))
409 + + (atan2(e * somg2, comg2) - atan2(e * somg1, comg1)))
411 omg12 = atan2(somg2 * comg1 - comg2 * somg1,
412 + comg2 * comg1 + somg2 * somg1)
415 lam12 = omg12 + a3c *
416 + ( sig12 + (trgsum(.true., ssig2, csig2, c3a, nc3-1)
418 lon12 = lam12 / degree
422 lon2 = angnm(angnm(lon1) + angnm(lon12))
424 lat2 = atn2dx(sbet2, f1 * cbet2)
425 azi2 = atn2dx(salp2, calp2)
427 if (redlp .or. scalp)
then
428 b22 = trgsum(.true., ssig2, csig2, c2a, nc2)
429 ab2 = (1 + a2m1) * (b22 - b21)
430 j12 = (a1m1 - a2m1) * sig12 + (ab1 - ab2)
434 if (redlp) m12 = b * ((dn2 * (csig1 * ssig2) -
435 + dn1 * (ssig1 * csig2)) - csig1 * csig2 * j12)
437 t = k2 * (ssig2 - ssig1) * (ssig2 + ssig1) / (dn1 + dn2)
438 mm12 = csig12 + (t * ssig2 - csig2 * j12) * ssig1 / dn1
439 mm21 = csig12 - (t * ssig1 - csig1 * j12) * ssig2 / dn2
443 b42 = trgsum(.false., ssig2, csig2, c4a, nc4)
444 if (calp0 .eq. 0 .or. salp0 .eq. 0)
then
446 salp12 = salp2 * calp1 - calp2 * salp1
447 calp12 = calp2 * calp1 + salp2 * salp1
457 if (csig12 .le. 0)
then
458 salp12 = csig1 * (1 - csig12) + ssig12 * ssig1
460 salp12 = ssig12 * (csig1 * ssig12 / (1 + csig12) + ssig1)
462 salp12 = calp0 * salp0 * salp12
463 calp12 = salp0**2 + calp0**2 * csig1 * csig2
465 ss12 = c2 * atan2(salp12, calp12) + a4 * (b42 - b41)
470 a12s12 = b * ((1 + a1m1) * sig12 + ab1)
472 a12s12 = sig12 / degree
524 subroutine invers(a, f, lat1, lon1, lat2, lon2,
525 + s12, azi1, azi2, omask, a12, m12, MM12, MM21, SS12)
527 double precision a, f, lat1, lon1, lat2, lon2
530 double precision s12, azi1, azi2
532 double precision a12, m12, MM12, MM21, SS12
534 integer ord, nA3, nA3x, nC3, nC3x, nC4, nC4x, nC
535 parameter (ord = 6, na3 = ord, na3x = na3,
536 + nc3 = ord, nc3x = (nc3 * (nc3 - 1)) / 2,
537 + nc4 = ord, nc4x = (nc4 * (nc4 + 1)) / 2,
539 double precision A3x(0:nA3x-1), C3x(0:nC3x-1), C4x(0:nC4x-1),
542 double precision atanhx, hypotx,
543 + AngDif, AngRnd, TrgSum, Lam12f, InvSta, atn2dx, LatFix
544 integer latsgn, lonsgn, swapp, numit
545 logical arcp, redlp, scalp, areap, merid, tripn, tripb
547 double precision e2, f1, ep2, n, b, c2,
548 + lat1x, lat2x, salp0, calp0, k2, eps,
549 + salp1, calp1, ssig1, csig1, cbet1, sbet1, dbet1, dn1,
550 + salp2, calp2, ssig2, csig2, sbet2, cbet2, dbet2, dn2,
551 + slam12, clam12, salp12, calp12, omg12, lam12, lon12, lon12s,
552 + salp1a, calp1a, salp1b, calp1b,
553 + dalp1, sdalp1, cdalp1, nsalp1, alp12, somg12, comg12, domg12,
554 + sig12, v, dv, dnm, dummy,
555 + a4, b41, b42, s12x, m12x, a12x, sdomg12, cdomg12
557 double precision dblmin, dbleps, pi, degree, tiny,
558 + tol0, tol1, tol2, tolb, xthrsh
559 integer digits, maxit1, maxit2, lmask
561 common /geocom/ dblmin, dbleps, pi, degree, tiny,
562 + tol0, tol1, tol2, tolb, xthrsh, digits, maxit1, maxit2, init
564 if (.not.init)
call geoini
573 arcp = mod(omask/1, 2) .eq. 1
574 redlp = mod(omask/2, 2) .eq. 1
575 scalp = mod(omask/4, 2) .eq. 1
576 areap = mod(omask/8, 2) .eq. 1
586 else if (e2 .gt. 0)
then
587 c2 = (a**2 + b**2 * atanhx(sqrt(e2)) / sqrt(e2)) / 2
589 c2 = (a**2 + b**2 * atan(sqrt(abs(e2))) / sqrt(abs(e2))) / 2
595 if (areap)
call c4cof(n, c4x)
601 lon12 = angdif(lon1, lon2, lon12s)
603 lonsgn = int(sign(1d0, lon12))
604 lon12 = lonsgn * lon12
605 lon12s = lonsgn * lon12s
606 lam12 = lon12 * degree
608 call sncsde(lon12, lon12s, slam12, clam12)
610 lon12s = (180 - lon12) - lon12s
613 lat1x = angrnd(latfix(lat1))
614 lat2x = angrnd(latfix(lat2))
617 if (abs(lat1x) .lt. abs(lat2x) .or. lat2x .ne. lat2x)
then
622 if (swapp .lt. 0)
then
624 call swap(lat1x, lat2x)
627 latsgn = int(sign(1d0, -lat1x))
628 lat1x = lat1x * latsgn
629 lat2x = lat2x * latsgn
642 call sncsdx(lat1x, sbet1, cbet1)
644 call norm2x(sbet1, cbet1)
646 cbet1 = max(tiny, cbet1)
648 call sncsdx(lat2x, sbet2, cbet2)
650 call norm2x(sbet2, cbet2)
652 cbet2 = max(tiny, cbet2)
663 if (cbet1 .lt. -sbet1)
then
664 if (cbet2 .eq. cbet1) sbet2 = sign(sbet1, sbet2)
666 if (abs(sbet2) .eq. -sbet1) cbet2 = cbet1
669 dn1 = sqrt(1 + ep2 * sbet1**2)
670 dn2 = sqrt(1 + ep2 * sbet2**2)
674 merid = lat1x .eq. -90 .or. slam12 .eq. 0
690 csig1 = calp1 * cbet1
692 csig2 = calp2 * cbet2
695 sig12 = atan2(max(0d0, csig1 * ssig2 - ssig1 * csig2) + 0d0,
696 + csig1 * csig2 + ssig1 * ssig2)
697 call lengs(n, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
698 + cbet1, cbet2, lmask,
699 + s12x, m12x, dummy, mm12, mm21, ep2, ca)
708 if (sig12 .lt. 1 .or. m12x .ge. 0)
then
709 if (sig12 .lt. 3 * tiny .or.
710 + (sig12 .lt. tol0 .and.
711 + (s12x .lt. 0 .or. m12x .lt. 0)))
then
719 a12x = sig12 / degree
730 if (.not. merid .and. sbet1 .eq. 0 .and.
731 + (f .le. 0 .or. lon12s .ge. f * 180))
then
741 m12x = b * sin(sig12)
747 else if (.not. merid)
then
752 sig12 = invsta(sbet1, cbet1, dn1, sbet2, cbet2, dn2, lam12,
753 + slam12, clam12, f, a3x, salp1, calp1, salp2, calp2, dnm, ca)
755 if (sig12 .ge. 0)
then
757 s12x = sig12 * b * dnm
758 m12x = dnm**2 * b * sin(sig12 / dnm)
760 mm12 = cos(sig12 / dnm)
763 a12x = sig12 / degree
764 omg12 = lam12 / (f1 * dnm)
786 do 10 numit = 0, maxit2-1
789 v = lam12f(sbet1, cbet1, dn1, sbet2, cbet2, dn2,
790 + salp1, calp1, slam12, clam12, f, a3x, c3x, salp2, calp2,
791 + sig12, ssig1, csig1, ssig2, csig2,
792 + eps, domg12, numit .lt. maxit1, dv, ca)
799 if (tripb .or. .not. (abs(v) .ge. dummy * tol0))
802 if (v .gt. 0 .and. (numit .gt. maxit1 .or.
803 + calp1/salp1 .gt. calp1b/salp1b))
then
806 else if (v .lt. 0 .and. (numit .gt. maxit1 .or.
807 + calp1/salp1 .lt. calp1a/salp1a))
then
811 if (numit .lt. maxit1 .and. dv .gt. 0)
then
815 nsalp1 = salp1 * cdalp1 + calp1 * sdalp1
816 if (nsalp1 .gt. 0 .and. abs(dalp1) .lt. pi)
then
817 calp1 = calp1 * cdalp1 - salp1 * sdalp1
819 call norm2x(salp1, calp1)
823 tripn = abs(v) .le. 16 * tol0
835 salp1 = (salp1a + salp1b)/2
836 calp1 = (calp1a + calp1b)/2
837 call norm2x(salp1, calp1)
839 tripb = abs(salp1a - salp1) + (calp1a - calp1) .lt. tolb
840 + .or. abs(salp1 - salp1b) + (calp1 - calp1b) .lt. tolb
843 call lengs(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
844 + cbet1, cbet2, lmask,
845 + s12x, m12x, dummy, mm12, mm21, ep2, ca)
848 a12x = sig12 / degree
850 sdomg12 = sin(domg12)
851 cdomg12 = cos(domg12)
852 somg12 = slam12 * cdomg12 - clam12 * sdomg12
853 comg12 = clam12 * cdomg12 + slam12 * sdomg12
860 if (redlp) m12 = 0 + m12x
864 salp0 = salp1 * cbet1
865 calp0 = hypotx(calp1, salp1 * sbet1)
866 if (calp0 .ne. 0 .and. salp0 .ne. 0)
then
869 csig1 = calp1 * cbet1
871 csig2 = calp2 * cbet2
873 eps = k2 / (2 * (1 + sqrt(1 + k2)) + k2)
875 a4 = a**2 * calp0 * salp0 * e2
876 call norm2x(ssig1, csig1)
877 call norm2x(ssig2, csig2)
878 call c4f(eps, c4x, ca)
879 b41 = trgsum(.false., ssig1, csig1, ca, nc4)
880 b42 = trgsum(.false., ssig2, csig2, ca, nc4)
881 ss12 = a4 * (b42 - b41)
887 if (.not. merid .and. somg12 .eq. 2)
then
892 if (.not. merid .and. comg12 .ge. 0.7071d0
893 + .and. sbet2 - sbet1 .lt. 1.75d0)
then
900 alp12 = 2 * atan2(somg12 * (sbet1 * dbet2 + sbet2 * dbet1),
901 + domg12 * ( sbet1 * sbet2 + dbet1 * dbet2 ) )
904 salp12 = salp2 * calp1 - calp2 * salp1
905 calp12 = calp2 * calp1 + salp2 * salp1
910 if (salp12 .eq. 0 .and. calp12 .lt. 0)
then
911 salp12 = tiny * calp1
914 alp12 = atan2(salp12, calp12)
916 ss12 = ss12 + c2 * alp12
917 ss12 = ss12 * swapp * lonsgn * latsgn
923 if (swapp .lt. 0)
then
924 call swap(salp1, salp2)
925 call swap(calp1, calp2)
926 if (scalp)
call swap(mm12, mm21)
929 salp1 = salp1 * swapp * lonsgn
930 calp1 = calp1 * swapp * latsgn
931 salp2 = salp2 * swapp * lonsgn
932 calp2 = calp2 * swapp * latsgn
934 azi1 = atn2dx(salp1, calp1)
935 azi2 = atn2dx(salp2, calp2)
962 subroutine area(a, f, lats, lons, n, AA, PP)
965 double precision a, f, lats(n), lons(n)
967 double precision AA, PP
969 integer i, omask, cross, trnsit
970 double precision s12, azi1, azi2, dummy, SS12, b, e2, c2, area0,
971 + atanhx, aacc(2), pacc(2)
973 double precision dblmin, dbleps, pi, degree, tiny,
974 + tol0, tol1, tol2, tolb, xthrsh
975 integer digits, maxit1, maxit2
977 common /geocom/ dblmin, dbleps, pi, degree, tiny,
978 + tol0, tol1, tol2, tolb, xthrsh, digits, maxit1, maxit2, init
985 call invers(a, f, lats(i+1), lons(i+1),
986 + lats(mod(i+1,n)+1), lons(mod(i+1,n)+1),
987 + s12, azi1, azi2, omask, dummy, dummy, dummy, dummy, ss12)
988 call accadd(pacc, s12)
989 call accadd(aacc, -ss12)
990 cross = cross + trnsit(lons(i+1), lons(mod(i+1,n)+1))
997 else if (e2 .gt. 0)
then
998 c2 = (a**2 + b**2 * atanhx(sqrt(e2)) / sqrt(e2)) / 2
1000 c2 = (a**2 + b**2 * atan(sqrt(abs(e2))) / sqrt(abs(e2))) / 2
1003 call accrem(aacc, area0)
1004 if (mod(abs(cross), 2) .eq. 1)
then
1005 if (aacc(1) .lt. 0)
then
1006 call accadd(aacc, +area0/2)
1008 call accadd(aacc, -area0/2)
1011 if (aacc(1) .gt. area0/2)
then
1012 call accadd(aacc, -area0)
1013 else if (aacc(1) .le. -area0/2)
then
1014 call accadd(aacc, +area0)
1031 integer major, minor, patch
1048 double precision dblmin, dbleps, pi, degree, tiny,
1049 + tol0, tol1, tol2, tolb, xthrsh
1050 integer digits, maxit1, maxit2
1052 common /geocom/ dblmin, dbleps, pi, degree, tiny,
1053 + tol0, tol1, tol2, tolb, xthrsh, digits, maxit1, maxit2, init
1056 dblmin = 0.5d0**1022
1057 dbleps = 0.5d0**(digits-1)
1059 pi = atan2(0d0, -1d0)
1065 tiny = 0.5d0**((1022+1)/3)
1074 xthrsh = 1000 * tol2
1076 maxit2 = maxit1 + digits + 10
1086 double precision dblmin, dbleps, pi, degree, tiny,
1087 + tol0, tol1, tol2, tolb, xthrsh
1088 integer digits, maxit1, maxit2
1091 common /geocom/ dblmin, dbleps, pi, degree, tiny,
1092 + tol0, tol1, tol2, tolb, xthrsh, digits, maxit1, maxit2, init
1095 subroutine lengs(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
1096 + cbet1, cbet2, omask,
1097 + s12b, m12b, m0, MM12, MM21, ep2, Ca)
1099 double precision eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
1103 double precision s12b, m12b, m0, MM12, MM21
1105 double precision Ca(*)
1107 integer ord, nC1, nC2
1108 parameter (ord = 6, nc1 = ord, nc2 = ord)
1110 double precision A1m1f, A2m1f, TrgSum
1111 double precision m0x, J12, A1, A2, B1, B2, csig12, t, Cb(nC2)
1112 logical distp, redlp, scalp
1118 distp = (mod(omask/16, 2) .eq. 1)
1119 redlp = (mod(omask/2, 2) .eq. 1)
1120 scalp = (mod(omask/4, 2) .eq. 1)
1127 if (distp .or. redlp .or. scalp)
then
1130 if (redlp .or. scalp)
then
1139 b1 = trgsum(.true., ssig2, csig2, ca, nc1) -
1140 + trgsum(.true., ssig1, csig1, ca, nc1)
1142 s12b = a1 * (sig12 + b1)
1143 if (redlp .or. scalp)
then
1144 b2 = trgsum(.true., ssig2, csig2, cb, nc2) -
1145 + trgsum(.true., ssig1, csig1, cb, nc2)
1146 j12 = m0x * sig12 + (a1 * b1 - a2 * b2)
1148 else if (redlp .or. scalp)
then
1151 cb(l) = a1 * ca(l) - a2 * cb(l)
1153 j12 = m0x * sig12 + (trgsum(.true., ssig2, csig2, cb, nc2) -
1154 + trgsum(.true., ssig1, csig1, cb, nc2))
1161 m12b = dn2 * (csig1 * ssig2) - dn1 * (ssig1 * csig2) -
1162 + csig1 * csig2 * j12
1165 csig12 = csig1 * csig2 + ssig1 * ssig2
1166 t = ep2 * (cbet1 - cbet2) * (cbet1 + cbet2) / (dn1 + dn2)
1167 mm12 = csig12 + (t * ssig2 - csig2 * j12) * ssig1 / dn1
1168 mm21 = csig12 - (t * ssig1 - csig1 * j12) * ssig2 / dn2
1174 double precision function astrd(x, y)
1178 double precision x, y
1180 double precision cbrt
1181 double precision k, p, q, r, S, r2, r3, disc, u,
1182 + t3, t, ang, v, uv, w
1187 if ( .not. (q .eq. 0 .and. r .lt. 0) )
then
1196 disc = s * (s + 2 * r3)
1198 if (disc .ge. 0)
then
1214 if (t .ne. 0) u = u + t + r2 / t
1217 ang = atan2(sqrt(-disc), -(s + r3))
1220 u = u + 2 * r * cos(ang / 3)
1232 w = (uv - q) / (2 * v)
1236 k = uv / (sqrt(uv + w**2) + w)
1248 double precision function invsta(sbet1, cbet1, dn1,
1249 + sbet2, cbet2, dn2, lam12, slam12, clam12, f, A3x,
1250 + salp1, calp1, salp2, calp2, dnm,
1256 double precision sbet1, cbet1, dn1, sbet2, cbet2, dn2,
1257 + lam12, slam12, clam12, f, A3x(*)
1259 double precision salp1, calp1, salp2, calp2, dnm
1261 double precision Ca(*)
1263 double precision hypotx, A3f, Astrd
1265 double precision f1, e2, ep2, n, etol2, k2, eps, sig12,
1266 + sbet12, cbet12, sbt12a, omg12, somg12, comg12, ssig12, csig12,
1267 + x, y, lamscl, betscl, cbt12a, bt12a, m12b, m0, dummy,
1268 + k, omg12a, sbetm2, lam12x
1270 double precision dblmin, dbleps, pi, degree, tiny,
1271 + tol0, tol1, tol2, tolb, xthrsh
1272 integer digits, maxit1, maxit2
1274 common /geocom/ dblmin, dbleps, pi, degree, tiny,
1275 + tol0, tol1, tol2, tolb, xthrsh, digits, maxit1, maxit2, init
1291 etol2 = 0.1d0 * tol2 /
1292 + sqrt( max(0.001d0, abs(f)) * min(1d0, 1 - f/2) / 2 )
1297 sbet12 = sbet2 * cbet1 - cbet2 * sbet1
1298 cbet12 = cbet2 * cbet1 + sbet2 * sbet1
1299 sbt12a = sbet2 * cbet1 + cbet2 * sbet1
1301 shortp = cbet12 .ge. 0 .and. sbet12 .lt. 0.5d0 .and.
1302 + cbet2 * lam12 .lt. 0.5d0
1305 sbetm2 = (sbet1 + sbet2)**2
1308 sbetm2 = sbetm2 / (sbetm2 + (cbet1 + cbet2)**2)
1309 dnm = sqrt(1 + ep2 * sbetm2)
1310 omg12 = lam12 / (f1 * dnm)
1318 salp1 = cbet2 * somg12
1319 if (comg12 .ge. 0)
then
1320 calp1 = sbet12 + cbet2 * sbet1 * somg12**2 / (1 + comg12)
1322 calp1 = sbt12a - cbet2 * sbet1 * somg12**2 / (1 - comg12)
1325 ssig12 = hypotx(salp1, calp1)
1326 csig12 = sbet1 * sbet2 + cbet1 * cbet2 * comg12
1328 if (shortp .and. ssig12 .lt. etol2)
then
1330 salp2 = cbet1 * somg12
1331 if (comg12 .ge. 0)
then
1332 calp2 = somg12**2 / (1 + comg12)
1336 calp2 = sbet12 - cbet1 * sbet2 * calp2
1337 call norm2x(salp2, calp2)
1339 sig12 = atan2(ssig12, csig12)
1340 else if (abs(n) .gt. 0.1d0 .or. csig12 .ge. 0 .or.
1341 + ssig12 .ge. 6 * abs(n) * pi * cbet1**2)
then
1346 lam12x = atan2(-slam12, -clam12)
1352 eps = k2 / (2 * (1 + sqrt(1 + k2)) + k2)
1353 lamscl = f * cbet1 * a3f(eps, a3x) * pi
1354 betscl = lamscl * cbet1
1359 cbt12a = cbet2 * cbet1 - sbet2 * sbet1
1360 bt12a = atan2(sbt12a, cbt12a)
1363 call lengs(n, pi + bt12a,
1364 + sbet1, -cbet1, dn1, sbet2, cbet2, dn2, cbet1, cbet2, 2,
1365 + dummy, m12b, m0, dummy, dummy, ep2, ca)
1366 x = -1 + m12b / (cbet1 * cbet2 * m0 * pi)
1367 if (x .lt. -0.01d0)
then
1370 betscl = -f * cbet1**2 * pi
1372 lamscl = betscl / cbet1
1376 if (y .gt. -tol1 .and. x .gt. -1 - xthrsh)
then
1379 salp1 = min(1d0, -x)
1380 calp1 = - sqrt(1 - salp1**2)
1382 if (x .gt. -tol1)
then
1387 calp1 = max(calp1, x)
1388 salp1 = sqrt(1 - calp1**2)
1427 omg12a = -x * k/(1 + k)
1429 omg12a = -y * (1 + k)/k
1431 omg12a = lamscl * omg12a
1432 somg12 = sin(omg12a)
1433 comg12 = -cos(omg12a)
1435 salp1 = cbet2 * somg12
1436 calp1 = sbt12a - cbet2 * sbet1 * somg12**2 / (1 - comg12)
1440 if (.not. (salp1 .le. 0))
then
1441 call norm2x(salp1, calp1)
1451 double precision function lam12f(sbet1, cbet1, dn1,
1452 + sbet2, cbet2, dn2, salp1, calp1, slm120, clm120, f, A3x, C3x,
1453 + salp2, calp2, sig12, ssig1, csig1, ssig2, csig2, eps,
1454 + domg12, diffp, dlam12, Ca)
1456 double precision sbet1, cbet1, dn1, sbet2, cbet2, dn2,
1457 + salp1, calp1, slm120, clm120, f, A3x(*), C3x(*)
1460 double precision salp2, calp2, sig12, ssig1, csig1, ssig2, csig2,
1463 double precision dlam12
1465 double precision Ca(*)
1468 parameter(ord = 6, nc3 = ord)
1470 double precision hypotx, A3f, TrgSum
1472 double precision f1, e2, ep2, salp0, calp0,
1473 + somg1, comg1, somg2, comg2, somg12, comg12,
1474 + lam12, eta, b312, k2, dummy
1476 double precision dblmin, dbleps, pi, degree, tiny,
1477 + tol0, tol1, tol2, tolb, xthrsh
1478 integer digits, maxit1, maxit2
1480 common /geocom/ dblmin, dbleps, pi, degree, tiny,
1481 + tol0, tol1, tol2, tolb, xthrsh, digits, maxit1, maxit2, init
1488 if (sbet1 .eq. 0 .and. calp1 .eq. 0) calp1 = -tiny
1491 salp0 = salp1 * cbet1
1493 calp0 = hypotx(calp1, salp1 * sbet1)
1498 somg1 = salp0 * sbet1
1499 csig1 = calp1 * cbet1
1501 call norm2x(ssig1, csig1)
1508 if (cbet2 .ne. cbet1)
then
1509 salp2 = salp0 / cbet2
1517 if (cbet2 .ne. cbet1 .or. abs(sbet2) .ne. -sbet1)
then
1518 if (cbet1 .lt. -sbet1)
then
1519 calp2 = (cbet2 - cbet1) * (cbet1 + cbet2)
1521 calp2 = (sbet1 - sbet2) * (sbet1 + sbet2)
1523 calp2 = sqrt((calp1 * cbet1)**2 + calp2) / cbet2
1530 somg2 = salp0 * sbet2
1531 csig2 = calp2 * cbet2
1533 call norm2x(ssig2, csig2)
1537 sig12 = atan2(max(0d0, csig1 * ssig2 - ssig1 * csig2) + 0d0,
1538 + csig1 * csig2 + ssig1 * ssig2)
1541 somg12 = max(0d0, comg1 * somg2 - somg1 * comg2) + 0d0
1542 comg12 = comg1 * comg2 + somg1 * somg2
1544 eta = atan2(somg12 * clm120 - comg12 * slm120,
1545 + comg12 * clm120 + somg12 * slm120)
1547 eps = k2 / (2 * (1 + sqrt(1 + k2)) + k2)
1548 call c3f(eps, c3x, ca)
1549 b312 = (trgsum(.true., ssig2, csig2, ca, nc3-1) -
1550 + trgsum(.true., ssig1, csig1, ca, nc3-1))
1551 domg12 = -f * a3f(eps, a3x) * salp0 * (sig12 + b312)
1552 lam12 = eta + domg12
1555 if (calp2 .eq. 0)
then
1556 dlam12 = - 2 * f1 * dn1 / sbet1
1558 call lengs(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
1560 + dummy, dlam12, dummy, dummy, dummy, ep2, ca)
1561 dlam12 = dlam12 * f1 / (calp2 * cbet2)
1569 double precision function a3f(eps, A3x)
1571 integer ord, nA3, nA3x
1572 parameter(ord = 6, na3 = ord, na3x = na3)
1575 double precision eps
1577 double precision A3x(0: nA3x-1)
1579 double precision polval
1580 A3f = polval(na3 - 1, a3x, eps)
1585 subroutine c3f(eps, C3x, c)
1588 integer ord, nC3, nC3x
1589 parameter(ord = 6, nc3 = ord, nc3x = (nc3 * (nc3 - 1)) / 2)
1592 double precision eps, C3x(0:nC3x-1)
1594 double precision c(nC3-1)
1597 double precision mult, polval
1601 do 10 l = 1, nc3 - 1
1604 c(l) = mult * polval(m, c3x(o), eps)
1611 subroutine c4f(eps, C4x, c)
1614 integer ord, nC4, nC4x
1615 parameter(ord = 6, nc4 = ord, nc4x = (nc4 * (nc4 + 1)) / 2)
1618 double precision eps, C4x(0:nC4x-1)
1620 double precision c(0:nC4-1)
1623 double precision mult, polval
1627 do 10 l = 0, nc4 - 1
1629 c(l) = mult * polval(m, c4x(o), eps)
1637 double precision function a1m1f(eps)
1640 double precision eps
1643 integer ord, nA1, o, m
1644 parameter(ord = 6, na1 = ord)
1645 double precision polval, coeff(nA1/2 + 2)
1646 data coeff /1, 4, 64, 0, 256/
1650 t = polval(m, coeff(o), eps**2) / coeff(o + m + 1)
1651 a1m1f = (t + eps) / (1 - eps)
1656 subroutine c1f(eps, c)
1659 parameter(ord = 6, nc1 = ord)
1662 double precision eps
1664 double precision c(nC1)
1666 double precision eps2, d
1668 double precision polval, coeff((nC1**2 + 7*nC1 - 2*(nC1/2))/4)
1671 + -9, 64, -128, 2048,
1682 c(l) = d * polval(m, coeff(o), eps2) / coeff(o + m + 1)
1690 subroutine c1pf(eps, c)
1693 parameter(ord = 6, nc1p = ord)
1696 double precision eps
1698 double precision c(nC1p)
1700 double precision eps2, d
1702 double precision polval, coeff((nC1p**2 + 7*nC1p - 2*(nC1p/2))/4)
1704 + 205, -432, 768, 1536,
1705 + 4005, -4736, 3840, 12288,
1707 + -7173, 2695, 7680,
1716 c(l) = d * polval(m, coeff(o), eps2) / coeff(o + m + 1)
1725 double precision function a2m1f(eps)
1727 double precision eps
1730 integer ord, nA2, o, m
1731 parameter(ord = 6, na2 = ord)
1732 double precision polval, coeff(nA2/2 + 2)
1733 data coeff /-11, -28, -192, 0, 256/
1737 t = polval(m, coeff(o), eps**2) / coeff(o + m + 1)
1738 a2m1f = (t - eps) / (1 + eps)
1743 subroutine c2f(eps, c)
1746 parameter(ord = 6, nc2 = ord)
1749 double precision eps
1751 double precision c(nC2)
1753 double precision eps2, d
1755 double precision polval, coeff((nC2**2 + 7*nC2 - 2*(nC2/2))/4)
1758 + 35, 64, 384, 2048,
1769 c(l) = d * polval(m, coeff(o), eps2) / coeff(o + m + 1)
1777 subroutine a3cof(n, A3x)
1779 integer ord, nA3, nA3x
1780 parameter(ord = 6, na3 = ord, na3x = na3)
1785 double precision A3x(0:nA3x-1)
1788 double precision polval, coeff((nA3**2 + 7*nA3 - 2*(nA3/2))/4)
1799 do 10 j = na3 - 1, 0, -1
1800 m = min(na3 - j - 1, j)
1801 a3x(k) = polval(m, coeff(o), n) / coeff(o + m + 1)
1809 subroutine c3cof(n, C3x)
1811 integer ord, nC3, nC3x
1812 parameter(ord = 6, nc3 = ord, nc3x = (nc3 * (nc3 - 1)) / 2)
1817 double precision C3x(0:nC3x-1)
1819 integer o, m, l, j, k
1820 double precision polval,
1821 + coeff(((nc3-1)*(nc3**2 + 7*nc3 - 2*(nc3/2)))/8)
1841 do 20 l = 1, nc3 - 1
1842 do 10 j = nc3 - 1, l, -1
1843 m = min(nc3 - j - 1, j)
1844 c3x(k) = polval(m, coeff(o), n) / coeff(o + m + 1)
1853 subroutine c4cof(n, C4x)
1855 integer ord, nC4, nC4x
1856 parameter(ord = 6, nc4 = ord, nc4x = (nc4 * (nc4 + 1)) / 2)
1861 double precision C4x(0:nC4x-1)
1863 integer o, m, l, j, k
1864 double precision polval, coeff((nC4 * (nC4 + 1) * (nC4 + 5)) / 6)
1866 + 97, 15015, 1088, 156, 45045, -224, -4784, 1573, 45045,
1867 + -10656, 14144, -4576, -858, 45045,
1868 + 64, 624, -4576, 6864, -3003, 15015,
1869 + 100, 208, 572, 3432, -12012, 30030, 45045,
1870 + 1, 9009, -2944, 468, 135135, 5792, 1040, -1287, 135135,
1871 + 5952, -11648, 9152, -2574, 135135,
1872 + -64, -624, 4576, -6864, 3003, 135135,
1873 + 8, 10725, 1856, -936, 225225, -8448, 4992, -1144, 225225,
1874 + -1440, 4160, -4576, 1716, 225225,
1875 + -136, 63063, 1024, -208, 105105,
1876 + 3584, -3328, 1144, 315315,
1877 + -128, 135135, -2560, 832, 405405, 128, 99099/
1881 do 20 l = 0, nc4 - 1
1882 do 10 j = nc4 - 1, l, -1
1884 c4x(k) = polval(m, coeff(o), n) / coeff(o + m + 1)
1893 double precision function sumx(u, v, t)
1895 double precision u, v
1899 double precision up, vpp
1905 if (sumx .eq. 0)
then
1908 t = 0d0 - (up + vpp)
1914 double precision function remx(x, y)
1918 double precision x, y
1921 if (remx .lt. -y/2)
then
1923 else if (remx .gt. +y/2)
then
1930 double precision function angnm(x)
1934 double precision remx
1935 angnm = remx(x, 360d0)
1936 if (abs(angnm) .eq. 180)
then
1937 angnm = sign(180d0, x)
1943 double precision function latfix(x)
1948 if (.not. (abs(x) .gt. 90))
return
1950 latfix = sqrt(90 - abs(x))
1955 double precision function angdif(x, y, e)
1962 double precision x, y
1966 double precision d, t, sumx, remx
1967 d = sumx(remx(-x, 360d0), remx(y, 360d0), t)
1968 d = sumx(remx(d, 360d0), t, e)
1969 if (d .eq. 0 .or. abs(d) .eq. 180)
then
1981 double precision function angrnd(x)
1990 double precision y, z
1994 if (y .lt. z) y = z - (z - y)
2000 subroutine swap(x, y)
2002 double precision x, y
2012 double precision function hypotx(x, y)
2014 double precision x, y
2017 hypotx = sqrt(x**2 + y**2)
2022 subroutine norm2x(x, y)
2024 double precision x, y
2026 double precision hypotx, r
2034 double precision function log1px(x)
2038 double precision y, z
2044 log1px = x * log(y) / z
2050 double precision function atanhx(x)
2055 double precision log1px, y
2057 y = log1px(2 * y/(1 - y))/2
2063 double precision function cbrt(x)
2067 cbrt = sign(abs(x)**(1/3d0), x)
2072 double precision function trgsum(sinp, sinx, cosx, c, n)
2081 double precision sinx, cosx, c(n)
2083 double precision ar, y0, y1
2087 ar = 2 * (cosx - sinx) * (cosx + sinx)
2089 if (mod(n, 2) .eq. 1)
then
2100 y1 = ar * y0 - y1 + c(k)
2101 y0 = ar * y1 - y0 + c(k-1)
2105 trgsum = 2 * sinx * cosx * y0
2108 trgsum = cosx * (y0 - y1)
2114 integer function trnsit(lon1, lon2)
2116 double precision lon1, lon2
2118 double precision lon1x, lon2x, lon12, AngNm, AngDif, e
2119 lon12 = angdif(lon1, lon2, e)
2122 if (lon12 .gt. 0 .and. ((lon1x .lt. 0 .and. lon2x .ge. 0) .or.
2123 + (lon1x .gt. 0 .and. lon2x .eq. 0)))
then
2125 else if (lon12 .lt. 0 .and. lon1x .ge. 0 .and. lon2x .lt. 0)
then
2134 subroutine accini(s)
2137 double precision s(2)
2145 subroutine accadd(s, y)
2150 double precision s(2)
2152 double precision z, u, sumx
2153 z = sumx(y, s(2), u)
2154 s(1) = sumx(z, s(1), s(2))
2155 if (s(1) .eq. 0)
then
2164 subroutine accrem(s, y)
2169 double precision s(2)
2171 double precision remx
2172 s(1) = remx(s(1), y)
2178 subroutine sncsdx(x, sinx, cosx)
2183 double precision sinx, cosx
2185 double precision dblmin, dbleps, pi, degree, tiny,
2186 + tol0, tol1, tol2, tolb, xthrsh
2187 integer digits, maxit1, maxit2
2189 common /geocom/ dblmin, dbleps, pi, degree, tiny,
2190 + tol0, tol1, tol2, tolb, xthrsh, digits, maxit1, maxit2, init
2192 double precision r, s, c
2196 r = (r - 90 * q) * degree
2203 else if (q .eq. 1)
then
2206 else if (q .eq. 2)
then
2215 if (sinx .eq. 0)
then
2216 sinx = sign(sinx, x)
2223 subroutine sncsde(x, t, sinx, cosx)
2226 double precision x, t
2228 double precision sinx, cosx
2230 double precision dblmin, dbleps, pi, degree, tiny,
2231 + tol0, tol1, tol2, tolb, xthrsh, angrnd
2232 integer digits, maxit1, maxit2
2234 common /geocom/ dblmin, dbleps, pi, degree, tiny,
2235 + tol0, tol1, tol2, tolb, xthrsh, digits, maxit1, maxit2, init
2237 double precision r, s, c
2241 r = angrnd(r + t) * degree
2248 else if (q .eq. 1)
then
2251 else if (q .eq. 2)
then
2260 if (sinx .eq. 0)
then
2261 sinx = sign(sinx, x)
2268 double precision function atn2dx(y, x)
2270 double precision x, y
2272 double precision dblmin, dbleps, pi, degree, tiny,
2273 + tol0, tol1, tol2, tolb, xthrsh
2274 integer digits, maxit1, maxit2
2276 common /geocom/ dblmin, dbleps, pi, degree, tiny,
2277 + tol0, tol1, tol2, tolb, xthrsh, digits, maxit1, maxit2, init
2279 double precision xx, yy
2281 if (abs(y) .gt. abs(x)) then
2294 atn2dx = atan2(yy, xx) / degree
2296 atn2dx = sign(180d0, y) - atn2dx
2297 else if (q .eq. 2)
then
2298 atn2dx = 90 - atn2dx
2299 else if (q .eq. 3)
then
2300 atn2dx = -90 + atn2dx
2306 double precision function polval(N, p, x)
2309 double precision p(0:N), x
2318 polval = polval * x + p(i)