subroutine data_input_read_slab_impl(fld, rec, into_f1)
!! Host-ONLY NetCDF slab read for file record `rec` -> `fld%f0`
!! (default) or `fld%f1` (`into_f1 = .true.`), applying
!! `scale`/`add_offset` once at read. Uses the module-level host
!! workspace (registration/bracket-advance-time only — never a
!! per-step allocation). Deliberately carries NO `!$acc` directive:
!! called both before `enter_data` (STATIC field, at registration)
!! and after it (LINEAR/CYCLIC bracket advance) — the caller pushes
!! to the device itself, only when that is actually correct
!! (`data_input_refresh_brackets`).
type(data_input_field_t), intent(inout) :: fld
integer, intent(in) :: rec
logical, intent(in), optional :: into_f1
integer :: start4(4), count4(4)
logical :: to_f1
to_f1 = .false.
if (present(into_f1)) to_f1 = into_f1
call data_input_workspace_ensure(fld%nx, fld%ny, fld%nz)
if (fld%is_3d) then
start4 = [fld%i0, fld%j0, 1, rec]
count4 = [fld%nx, fld%ny, fld%nz, 1]
call nc_get_var_slab_3d(fld%ncid, fld%varid, start4, count4, data_input_ws)
else
start4(1:3) = [fld%i0, fld%j0, rec]
count4(1:3) = [fld%nx, fld%ny, 1]
call nc_get_var_slab_3d(fld%ncid, fld%varid, start4(1:3), count4(1:3), data_input_ws)
end if
data_input_ws = fld%scale*data_input_ws + fld%add_offset
if (to_f1) then
fld%f1 = data_input_ws(1:fld%nx, 1:fld%ny, 1:fld%nz)
else
fld%f0 = data_input_ws(1:fld%nx, 1:fld%ny, 1:fld%nz)
end if
fld%nreads = fld%nreads + 1
end subroutine data_input_read_slab_impl