subroutine varmix_compute(grid, metrics, this, slopes, wavespeed, ms)
!! Fill `res_fn_*`, `sn_*`, `khth_*`, `khtr_*` (the pre-CFL base face
!! coefficients) from the static grid terms, the slopes/N^2 slot, and
!! the first-mode wave speed `cg1`. No-op when disabled / the deps are
!! absent. The CFL cap is applied downstream by GM.
type(hgrid_t), intent(in) :: grid
type(ocean_metrics_t), intent(in) :: metrics
type(ocean_varmix_t), intent(inout) :: this
type(ocean_slopes_t), intent(in) :: slopes
type(ocean_wave_speed_t), intent(in) :: wavespeed
type(multilayer_state_t), intent(in) :: ms
integer :: nx, ny, nz
logical :: do_visbeck
if (.not. this%is_init) return
if (.not. this%enable) return
if (.not. slopes%is_init) return
if (.not. wavespeed%is_init) return
if (.not. allocated(wavespeed%cg1)) return
if (.not. allocated(ms%h_layer)) return
if (.not. allocated(slopes%slope_x)) return
nx = grid%nx_total
ny = grid%ny_total
nz = ms%nz_ml
if (this%nz_ml /= nz) return
if (slopes%nz_ml /= nz) return
! Eady SN only when a Visbeck coefficient is on (item 8).
do_visbeck = this%use_visbeck .and. &
(this%khth_slope_cff > 0.0_wp .or. this%khtr_slope_cff > 0.0_wp)
call varmix_compute_impl(nx, ny, nz, this%kh_res_fn_power, &
this%kh_res_scale_coef, this%resoln_scaled_khth, &
this%resoln_scaled_khtr, this%interpolate_res_fn, &
do_visbeck, this%visbeck_max_slope, &
this%khth, this%khtr, this%khth_slope_cff, &
this%khtr_slope_cff, this%khth_min, this%khth_max, &
this%khtr_min, this%khtr_max, &
this%f2_dx2_u, this%f2_dx2_v, &
this%beta_dx2_u, this%beta_dx2_v, &
this%l2_u, this%l2_v, &
wavespeed%cg1, ms%h_layer, &
slopes%slope_x, slopes%slope_y, &
slopes%n2_u, slopes%n2_v, &
this%res_fn_u, this%res_fn_v, &
this%sn_u, this%sn_v, &
this%khth_u, this%khth_v, &
this%khtr_u, this%khtr_v)
end subroutine varmix_compute