subroutine test_spherical_to_cartesian_north_wind(this)
class (ESMF_TestMethod), intent(inout) :: this
type (LatLonGridFactory) :: factory
real, allocatable :: north_wind_u(:,:)
real, allocatable :: north_wind_v(:,:)
real, allocatable :: xyz(:,:,:,:)
real, allocatable :: longitudes(:)
real, allocatable :: latitudes(:)
integer, parameter :: IM=12, JM=6
integer :: status
type (ESMF_Grid) :: grid
_UNUSED_DUMMY(this)
factory = LatLonGridFactory(im_world=IM, jm_world=JM, lm=1, nx=1, ny=1, pole='PE', dateline='GC')
grid = factory%make_grid()
allocate(north_wind_u(IM,JM))
allocate(north_wind_v(IM,JM))
allocate(xyz(3,1,IM,JM))
north_wind_u = 0
north_wind_v = 1
call factory%spherical_to_cartesian(north_wind_u, north_wind_v, xyz, basis='north-south', rc=status)
@assertEqual(0, status)
! Note: longitudes return as REAL64.
longitudes = real(factory%get_longitudes())
latitudes = real(factory%get_latitudes())
do j = 1, JM
@assertEqual(-cos(longitudes)*sin(latitudes(j)), xyz(1,1,:,j), 10*epsilon(1.))
@assertEqual(-sin(longitudes)*sin(latitudes(j)), xyz(2,1,:,j), 10*epsilon(1.))
@assertEqual(+cos(latitudes(j)), xyz(3,1,:,j), 10*epsilon(1.))
end do
end subroutine test_spherical_to_cartesian_north_wind