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 | Intent | Optional | 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 |
| 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 |
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