subroutine ocean_meke_init(this, grid, nz_ml)
!! Allocate the prognostic field, the derived diffusivity, and the
!! Strang-stage workspaces. Always allocates (configure runs after
!! init); setup uses plain host allocation (no `do concurrent` before
!! enter_data).
class(ocean_meke_t), intent(inout) :: this
type(hgrid_t), intent(in) :: grid
integer, intent(in), optional :: nz_ml
integer :: nx, ny, nz
nx = grid%nx_total
ny = grid%ny_total
nz = 1
if (present(nz_ml)) nz = nz_ml
if (nz < 1) nz = 1
if (nz > NZ_STACK_MAX) then
error stop "ocean_meke_init: nz_ml exceeds NZ_STACK_MAX "// &
"(raise NZ_STACK_MAX in rdb_constants)"
end if
this%nx_total = nx
this%ny_total = ny
this%nz_ml = nz
allocate (this%meke(nx, ny), source=0.0_wp)
allocate (this%kh_diff(nx, ny), source=0.0_wp)
allocate (this%le(nx, ny), source=0.0_wp)
allocate (this%ku(nx, ny), source=0.0_wp)
allocate (this%i_mass(nx, ny), source=0.0_wp)
allocate (this%depth_tot(nx, ny), source=0.0_wp)
allocate (this%bottom_fac2(nx, ny), source=0.0_wp)
allocate (this%barotr_fac2(nx, ny), source=0.0_wp)
allocate (this%src(nx, ny), source=0.0_wp)
allocate (this%uflux(nx + 1, ny), source=0.0_wp)
allocate (this%vflux(nx, ny + 1), source=0.0_wp)
allocate (this%del2(nx, ny), source=0.0_wp)
allocate (this%mass_ws(nx, ny), source=0.0_wp)
allocate (this%u_bbl2(nx, ny), source=0.0_wp)
allocate (this%ke_diss_ws(nx, ny), source=0.0_wp)
allocate (this%rd_ws(nx, ny), source=0.0_wp)
allocate (this%f_centre(nx, ny), source=0.0_wp)
allocate (this%sn_u_ws(nx + 1, ny), source=0.0_wp)
allocate (this%sn_v_ws(nx, ny + 1), source=0.0_wp)
allocate (this%baro_hu(nx + 1, ny), source=0.0_wp)
allocate (this%baro_hv(nx, ny + 1), source=0.0_wp)
this%is_init = .true.
end subroutine ocean_meke_init