subroutine tides_build_struct(this, geolat, geolon, nx, ny)
!! Build the (nx,ny,3) cos/sin spatial-structure arrays from cell-
!! centre latitude/longitude (degrees), via the angle-sum fold
!! cos(theta + n*lambda) = cos(theta)cos(n*lambda) - sin(theta)sin(n*lambda).
!! Plain host loop over all cells incl. ghosts (before enter_data).
!! slice 1 diurnal (n=1): G1 = sin(2 phi)
!! slice 2 semidiurnal(n=2): G2 = cos^2 phi
!! slice 3 long-period(n=0): G0 = 1/2 - 3/2 sin^2 phi
class(ocean_tides_t), intent(inout) :: this
integer, intent(in) :: nx, ny
real(wp), intent(in) :: geolat(nx, ny), geolon(nx, ny)
integer :: i, j
real(wp) :: phi, lam, s2phi, c2phi
do j = 1, ny
do i = 1, nx
phi = geolat(i, j)*TIDE_DEG2RAD
lam = geolon(i, j)*TIDE_DEG2RAD
s2phi = sin(2.0_wp*phi)
c2phi = cos(phi)**2
! slice 1 diurnal (n=1)
this%cos_struct(i, j, 1) = s2phi*cos(lam)
this%sin_struct(i, j, 1) = -s2phi*sin(lam)
! slice 2 semidiurnal (n=2)
this%cos_struct(i, j, 2) = c2phi*cos(2.0_wp*lam)
this%sin_struct(i, j, 2) = -c2phi*sin(2.0_wp*lam)
! slice 3 long-period (n=0)
this%cos_struct(i, j, 3) = 0.5_wp - 1.5_wp*sin(phi)**2
this%sin_struct(i, j, 3) = 0.0_wp
end do
end do
end subroutine tides_build_struct