data_input_refresh_brackets Subroutine

private subroutine data_input_refresh_brackets(this, id, t)

Host-side registry walk (outer shim) for field id.

Arguments

Type IntentOptional Attributes Name
class(ocean_data_input_t), intent(inout) :: this
integer, intent(in) :: id
real(kind=wp), intent(in) :: t

Calls

proc~~data_input_refresh_brackets~~CallsGraph proc~data_input_refresh_brackets data_input_refresh_brackets error error proc~data_input_refresh_brackets->error info info proc~data_input_refresh_brackets->info proc~data_input_locate data_input_locate proc~data_input_refresh_brackets->proc~data_input_locate proc~data_input_read_slab_impl data_input_read_slab_impl proc~data_input_refresh_brackets->proc~data_input_read_slab_impl to_string to_string proc~data_input_refresh_brackets->to_string warning warning proc~data_input_refresh_brackets->warning proc~data_input_workspace_ensure data_input_workspace_ensure proc~data_input_read_slab_impl->proc~data_input_workspace_ensure proc~nc_get_var_slab_3d nc_get_var_slab_3d proc~data_input_read_slab_impl->proc~nc_get_var_slab_3d nf90_get_var nf90_get_var proc~nc_get_var_slab_3d->nf90_get_var proc~nc_check nc_check proc~nc_get_var_slab_3d->proc~nc_check nf90_strerror nf90_strerror proc~nc_check->nf90_strerror proc~fail fail proc~nc_check->proc~fail proc~fail->error proc~error_ring_push error_ring_push proc~fail->proc~error_ring_push

Called by

proc~~data_input_refresh_brackets~~CalledByGraph proc~data_input_refresh_brackets data_input_refresh_brackets proc~ocean_data_input_update_all ocean_data_input_update_all proc~ocean_data_input_update_all->proc~data_input_refresh_brackets proc~engine_step engine_step proc~engine_step->proc~ocean_data_input_update_all proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_step proc~rdb_ocean_step rdb_ocean_step proc~rdb_ocean_step->proc~engine_step proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean

Variables

Type Visibility Attributes Name Initial
integer, private :: n0
integer, private :: n1
logical, private :: oor
real(kind=wp), private :: t_query
real(kind=wp), private :: w

Source Code

   subroutine data_input_refresh_brackets(this, id, t)
      !! Host-side registry walk (outer shim) for field `id`.
      class(ocean_data_input_t), intent(inout) :: this
      integer, intent(in) :: id
      real(wp), intent(in) :: t
      integer :: n0, n1
      real(wp) :: w, t_query
      logical :: oor

      associate (fld => this%fields(id))
         if (fld%time_mode == DATA_TIME_STATIC) then
            fld%t_last = t
            return
         end if

         t_query = t + fld%t_offset
         call data_input_locate(fld%t_axis, fld%nt, fld%time_mode, fld%cycle_period, &
                                t_query, n0, n1, w, oor)

         if (oor) then
            if (fld%oor == DATA_OOR_ERROR) then
               call logger%error("ocean_data_input: query time "//to_string(t_query)// &
                                 "s is outside the file time axis ["// &
                                 to_string(fld%t_axis(1))//", "// &
                                 to_string(fld%t_axis(fld%nt))//"]s (field id "// &
                                 to_string(id)//"); pass oor=DATA_OOR_CLAMP to clamp instead")
               error stop "ocean_data_input: query time out of range"
            end if
            if (.not. fld%oor_warned) then
               call logger%warning("ocean_data_input: field id "//to_string(id)// &
                                   "clamped at the time-axis boundary (query time "// &
                                   to_string(t_query)//"s out of range)")
               fld%oor_warned = .true.
            end if
         end if

         ! `!$acc update device(...)` is only correct HERE (the runtime
         ! per-step path, always called after `ocean_state_enter_data`
         ! has mapped `fld%f0`/`fld%f1`) — never inside
         ! `data_input_read_slab_impl` itself, which is also called from
         ! `register_common` at SETUP time for a DATA_TIME_STATIC field,
         ! before anything is device-mapped (CLAUDE.md gotcha: an
         ! `update device` on an unmapped array is undefined).
         if (n0 /= fld%rec0) then
            call data_input_read_slab_impl(fld, n0, into_f1=.false.)
            !$acc update device(fld%f0)
         end if
         if (n1 /= fld%rec1) then
            if (n1 == n0) then
               fld%f1 = fld%f0
               !$acc update device(fld%f1)
            else
               call data_input_read_slab_impl(fld, n1, into_f1=.true.)
               !$acc update device(fld%f1)
            end if
         end if
         if (n0 /= fld%rec0 .or. n1 /= fld%rec1) then
            if (this%verbose) then
               call logger%info("ocean_data_input: field id "//to_string(id)// &
                                " bracket advanced to records ("//to_string(n0)//", "// &
                                to_string(n1)//"), w = "//to_string(w)// &
                                ", t = "//to_string(t))
            end if
         end if
         fld%rec0 = n0
         fld%rec1 = n1
         fld%w = w
         fld%t_last = t
      end associate
   end subroutine data_input_refresh_brackets