rdb_ocean_destroy Function

public function rdb_ocean_destroy(c_handle) result(status) bind(c, name="rdb_ocean_destroy")

success (so a Python __del__ can call this blind). On a live handle: unwind device residency (engine_exit_data) then release the god-state’s host-side allocations + the process-global ocean- halo module state (engine_teardown), then free the handle itself and clear the single-live-handle guard.

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(inout) :: c_handle

Return Value integer(kind=c_int)


Calls

proc~~rdb_ocean_destroy~~CallsGraph proc~rdb_ocean_destroy rdb_ocean_destroy proc~engine_exit_data engine_exit_data proc~rdb_ocean_destroy->proc~engine_exit_data proc~engine_teardown engine_teardown proc~rdb_ocean_destroy->proc~engine_teardown proc~handle_check handle_check proc~rdb_ocean_destroy->proc~handle_check proc~handle_destroy handle_destroy proc~rdb_ocean_destroy->proc~handle_destroy proc~ice_ocean_stress_cleanup ice_ocean_stress_cleanup proc~engine_exit_data->proc~ice_ocean_stress_cleanup proc~ocean_state_exit_data ocean_state_exit_data proc~engine_exit_data->proc~ocean_state_exit_data proc~close_stream close_stream proc~engine_teardown->proc~close_stream proc~ocean_fold_exchange_destroy ocean_fold_exchange_destroy proc~engine_teardown->proc~ocean_fold_exchange_destroy proc~ocean_geothermal_destroy ocean_geothermal_t%ocean_geothermal_destroy proc~engine_teardown->proc~ocean_geothermal_destroy proc~ocean_halo_destroy ocean_halo_destroy proc~engine_teardown->proc~ocean_halo_destroy proc~nc_close nc_close proc~close_stream->proc~nc_close proc~fold_plan_destroy fold_plan_t%fold_plan_destroy proc~ocean_fold_exchange_destroy->proc~fold_plan_destroy proc~ocean_bc_state_exit_data ocean_bc_state_exit_data proc~ocean_state_exit_data->proc~ocean_bc_state_exit_data proc~ocean_data_input_exit_data ocean_data_input_t%ocean_data_input_exit_data proc~ocean_state_exit_data->proc~ocean_data_input_exit_data proc~profiler_start profiler_start proc~ocean_state_exit_data->proc~profiler_start proc~profiler_stop profiler_stop proc~ocean_state_exit_data->proc~profiler_stop nf90_close nf90_close proc~nc_close->nf90_close proc~nc_check nc_check proc~nc_close->proc~nc_check proc~ocean_data_input_exit_data_impl ocean_data_input_exit_data_impl proc~ocean_data_input_exit_data->proc~ocean_data_input_exit_data_impl proc~find_or_create_region find_or_create_region proc~profiler_start->proc~find_or_create_region proc~get_wall_time get_wall_time proc~profiler_start->proc~get_wall_time proc~nvtx_range_push nvtx_range_push proc~profiler_start->proc~nvtx_range_push proc~profiler_stop->proc~get_wall_time proc~nvtx_range_pop nvtx_range_pop proc~profiler_stop->proc~nvtx_range_pop nf90_strerror nf90_strerror proc~nc_check->nf90_strerror proc~fail fail proc~nc_check->proc~fail

Variables

Type Visibility Attributes Name Initial
type(ocean_handle_t), private, pointer :: h
integer, private :: hstat

Source Code

   function rdb_ocean_destroy(c_handle) result(status) &
      bind(c, name="rdb_ocean_destroy")
      !! Idempotent: a null/already-destroyed/garbage handle is a no-op
      !! success (so a Python `__del__` can call this blind). On a live
      !! handle: unwind device residency (`engine_exit_data`) then release
      !! the god-state's host-side allocations + the process-global ocean-
      !! halo module state (`engine_teardown`), then free the handle itself
      !! and clear the single-live-handle guard.
      type(c_ptr), intent(inout) :: c_handle
      integer(c_int) :: status

      type(ocean_handle_t), pointer :: h
      integer :: hstat

      hstat = handle_check(c_handle, h)
      if (hstat /= HANDLE_OK) then
         ! Already destroyed, never created, or garbage: idempotent no-op.
         c_handle = c_null_ptr
         status = int(OCEAN_STATUS_OK, c_int)
         return
      end if

      if (h%device_mapped) then
         call engine_exit_data(h%engine)
         h%device_mapped = .false.
      end if
      ! P2.5: a handle that never got past rdb_ocean_create_pending (no
      ! finalize call, abandoned mid-staging) never ran engine_setup —
      ! engine%state was never init_from_config'd, ocean_halo_init/
      ! engine%geo%init never ran, so there is nothing for engine_teardown
      ! to tear down. Guard on engine%is_setup (set only at the tail of
      ! engine_setup) rather than calling it unconditionally.
      if (h%engine%is_setup) call engine_teardown(h%engine)
      h%state => null()

      call handle_destroy(c_handle)
      g_handle_live = .false.
      status = int(OCEAN_STATUS_OK, c_int)
   end function rdb_ocean_destroy