subroutine mirror_latlon(lon1, lat1, lon2, lat2, lon0, lat0, lon3, lat3)
!
! Given the "mirror" as defined by (lon1, lat1), (lon2, lat2), and center
! of the sphere, compute the mirror image of (lon0, lat0) as (lon3, lat3)
real(ESMF_KIND_R8), intent(in):: lon1, lat1, lon2, lat2, lon0, lat0
real(ESMF_KIND_R8), intent(out):: lon3, lat3
!
real(ESMF_KIND_R8) p0(3), p1(3), p2(3), nb(3), pp(3), sp(2)
real(ESMF_KIND_R8) pdot
integer k
call latlon2xyz2(lon0, lat0, p0)
call latlon2xyz2(lon1, lat1, p1)
call latlon2xyz2(lon2, lat2, p2)
call vect_cross(nb, p1, p2)
pdot = sqrt(nb(1)**2+nb(2)**2+nb(3)**2)
do k=1,3
nb(k) = nb(k) / pdot
enddo
pdot = p0(1)*nb(1) + p0(2)*nb(2) + p0(3)*nb(3)
do k=1,3
pp(k) = p0(k) - 2.*pdot*nb(k)
enddo
call cart_to_latlon(1, pp, sp(1), sp(2))
lon3 = sp(1)
lat3 = sp(2)
end subroutine mirror_latlon