ocean_state_restart_read Subroutine

public subroutine ocean_state_restart_read(state, grid, decomp, filename, t, step, ierr)

Read a per-rank ocean restart into the (host) prognostic arrays. MUST run BEFORE ocean_state_enter_data — the subsequent H->D copy carries the restored values to the device. Restores dyn%outer_step_count (dt_therm alignment).

Error policy (review #4): when the caller PASSES ierr, a decomp/schema/grid mismatch returns it non-zero (the test path). When the caller OMITS ierr (the production driver path), a mismatch is FATAL — error stop naming the kind + the file — so a mismatched resume dies loudly instead of silently cold-starting and then clobbering the good checkpoint at the next cadence.

Arguments

Type IntentOptional Attributes Name
type(ocean_state_t), intent(inout), target :: state
type(hgrid_t), intent(in) :: grid
type(decomp_t), intent(in) :: decomp
character(len=*), intent(in) :: filename
real(kind=wp), intent(out) :: t
integer, intent(out) :: step
integer, intent(out), optional :: ierr

Calls

proc~~ocean_state_restart_read~~CallsGraph proc~ocean_state_restart_read ocean_state_restart_read proc~fail fail proc~ocean_state_restart_read->proc~fail proc~ocean_restart_read_local ocean_restart_read_local proc~ocean_state_restart_read->proc~ocean_restart_read_local proc~ocean_state_build_restart_registry ocean_state_build_restart_registry proc~ocean_state_restart_read->proc~ocean_state_build_restart_registry proc~ocean_state_fill_restart_metadata ocean_state_fill_restart_metadata proc~ocean_state_restart_read->proc~ocean_state_fill_restart_metadata proc~registry_entry_found restart_registry_t%registry_entry_found proc~ocean_state_restart_read->proc~registry_entry_found proc~restart_mismatch_kind restart_mismatch_kind proc~ocean_state_restart_read->proc~restart_mismatch_kind proc~restart_mismatch_status_code restart_mismatch_status_code proc~ocean_state_restart_read->proc~restart_mismatch_status_code error error proc~fail->error proc~error_ring_push error_ring_push proc~fail->proc~error_ring_push proc~ocean_restart_read_local->error info info proc~ocean_restart_read_local->info nf90_get_var nf90_get_var proc~ocean_restart_read_local->nf90_get_var nf90_inq_varid nf90_inq_varid proc~ocean_restart_read_local->nf90_inq_varid proc~ocean_restart_read_local->proc~error_ring_push proc~nc_check nc_check proc~ocean_restart_read_local->proc~nc_check proc~nc_close nc_close proc~ocean_restart_read_local->proc~nc_close proc~nc_get_varid nc_get_varid proc~ocean_restart_read_local->proc~nc_get_varid proc~nc_open_read nc_open_read proc~ocean_restart_read_local->proc~nc_open_read proc~ocean_restart_check_decomp ocean_restart_check_decomp proc~ocean_restart_read_local->proc~ocean_restart_check_decomp to_string to_string proc~ocean_restart_read_local->to_string warning warning proc~ocean_restart_read_local->warning proc~register_full_3d register_full_3d proc~ocean_state_build_restart_registry->proc~register_full_3d proc~register_full_3d_opt register_full_3d_opt proc~ocean_state_build_restart_registry->proc~register_full_3d_opt proc~registry_clear restart_registry_t%registry_clear proc~ocean_state_build_restart_registry->proc~registry_clear proc~registry_register_2d restart_registry_t%registry_register_2d proc~ocean_state_build_restart_registry->proc~registry_register_2d proc~registry_register_3d restart_registry_t%registry_register_3d proc~ocean_state_build_restart_registry->proc~registry_register_3d proc~registry_register_scalar restart_registry_t%registry_register_scalar proc~ocean_state_build_restart_registry->proc~registry_register_scalar proc~ocean_state_build_restart_registry->to_string proc~vcoord_type_name vcoord_type_name proc~ocean_state_fill_restart_metadata->proc~vcoord_type_name proc~nc_check->proc~fail nf90_strerror nf90_strerror proc~nc_check->nf90_strerror proc~nc_close->proc~nc_check nf90_close nf90_close proc~nc_close->nf90_close proc~nc_get_varid->nf90_inq_varid proc~nc_get_varid->proc~nc_check proc~nc_open_read->proc~nc_check nf90_open nf90_open proc~nc_open_read->nf90_open proc~ocean_restart_check_decomp->error proc~ocean_restart_check_decomp->proc~error_ring_push proc~ocean_restart_check_decomp->proc~nc_close proc~ocean_restart_check_decomp->proc~nc_open_read proc~ocean_restart_check_decomp->to_string proc~nc_get_att_int nc_get_att_int proc~ocean_restart_check_decomp->proc~nc_get_att_int proc~register_full_3d->proc~registry_register_3d proc~register_full_3d_opt->proc~registry_register_3d proc~registry_register_2d->error proc~registry_register_2d->to_string proc~registry_register_3d->error proc~registry_register_3d->to_string proc~registry_register_scalar->error proc~registry_register_scalar->to_string proc~vcoord_type_name->to_string proc~nc_get_att_int->proc~nc_check nf90_get_att nf90_get_att proc~nc_get_att_int->nf90_get_att

Called by

proc~~ocean_state_restart_read~~CalledByGraph proc~ocean_state_restart_read ocean_state_restart_read proc~engine_setup engine_setup proc~engine_setup->proc~ocean_state_restart_read proc~complete_ocean_create complete_ocean_create proc~complete_ocean_create->proc~engine_setup proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_setup proc~driver_validate driver_validate proc~driver_validate->proc~engine_setup proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean proc~rdb_ocean_create_finalize rdb_ocean_create_finalize proc~rdb_ocean_create_finalize->proc~complete_ocean_create proc~rdb_ocean_create_from_string rdb_ocean_create_from_string proc~rdb_ocean_create_from_string->proc~complete_ocean_create

Variables

Type Visibility Attributes Name Initial
integer, private :: local_ierr
type(ocean_restart_metadata_t), private :: meta
integer, private :: osc
type(restart_registry_t), private :: reg

Source Code

   subroutine ocean_state_restart_read(state, grid, decomp, filename, t, step, ierr)
      !! Read a per-rank ocean restart into the (host) prognostic arrays.
      !! MUST run BEFORE `ocean_state_enter_data` — the subsequent H->D
      !! copy carries the restored values to the device.  Restores
      !! `dyn%outer_step_count` (dt_therm alignment).
      !!
      !! Error policy (review #4): when the caller PASSES `ierr`, a
      !! decomp/schema/grid mismatch returns it non-zero (the test path).
      !! When the caller OMITS `ierr` (the production driver path), a
      !! mismatch is FATAL — `error stop` naming the kind + the file —
      !! so a mismatched resume dies loudly instead of silently
      !! cold-starting and then clobbering the good checkpoint at the next
      !! cadence.
      type(ocean_state_t), intent(inout), target :: state
      type(hgrid_t), intent(in) :: grid
      type(decomp_t), intent(in) :: decomp
      character(len=*), intent(in) :: filename
      real(wp), intent(out) :: t
      integer, intent(out) :: step
      integer, intent(out), optional :: ierr
#ifndef RDB_NO_NETCDF
      type(restart_registry_t) :: reg
      type(ocean_restart_metadata_t) :: meta
      integer :: osc, local_ierr

      call ocean_state_build_restart_registry(state, grid, reg)
      call ocean_state_fill_restart_metadata(state, grid, meta)
      call ocean_restart_read_local(filename, reg, decomp, meta, t, step, osc, &
                                    ierr=local_ierr)
      if (present(ierr)) then
         ! Translate the INTERNAL 1/2/3 restart_mismatch_kind convention
         ! (private to `ocean_restart_check_decomp`/`ocean_restart_read_local`)
         ! into a named `OCEAN_STATUS_ERR_RESTART_*` code before it reaches
         ! the caller — the raw integers collide with
         ! `OCEAN_STATUS_ERR_CONFIG_PARSE`/`_CONFIG_VALIDATE`/`_SETUP`
         ! (P0.1 review F4).
         if (local_ierr /= 0) then
            ierr = restart_mismatch_status_code(local_ierr)
         else
            ierr = OCEAN_STATUS_OK
         end if
      else if (local_ierr /= 0) then
         call fail("Ocean restart resume aborted: "// &
                   restart_mismatch_kind(local_ierr)//" mismatch reading "// &
                   trim(filename)//".  A mismatched resume would cold-start "// &
                   "and then overwrite the good checkpoint; refusing.", &
                   code=restart_mismatch_status_code(local_ierr))
      end if
      if (local_ierr == 0) then
         state%dyn%outer_step_count = osc
         ! PR-2 (bt-rem-from-av-rem review): record whether THIS read
         ! actually found vmix_kv (vs. an older checkpoint without it, or
         ! this call never running at all on a mismatch) -- read by
         ! `configure_ocean_lateral`'s config-copy to decide whether to
         ! skip reseeding `kv` (see `ocean_vmix_t%kv_from_restart`).
         state%vmix%kv_from_restart = reg%entry_found("vmix_kv")
      end if
#else
      t = 0.0_wp
      step = 0
      call fail("ocean restart requires RDB_ENABLE_NETCDF=ON", ierr, OCEAN_STATUS_ERR_IO)
      return
#endif
   end subroutine ocean_state_restart_read