Resolve an opaque c_ptr to a Fortran pointer and verify it.
On success: h is associated and status == HANDLE_OK.
On failure: h is null and status is one of HANDLE_ERR_*.
Callers in rdb_ocean_api translate this into the ocean status
code table (OCEAN_STATUS_ERR_BAD_HANDLE).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(c_ptr), | intent(in) | :: | c_handle | |||
| type(ocean_handle_t), | intent(out), | pointer | :: | h |
function handle_check(c_handle, h) result(status) !! Resolve an opaque `c_ptr` to a Fortran pointer and verify it. !! !! On success: `h` is associated and `status == HANDLE_OK`. !! On failure: `h` is null and `status` is one of `HANDLE_ERR_*`. !! Callers in `rdb_ocean_api` translate this into the ocean status !! code table (`OCEAN_STATUS_ERR_BAD_HANDLE`). type(c_ptr), intent(in) :: c_handle type(ocean_handle_t), pointer, intent(out) :: h integer :: status h => null() if (.not. c_associated(c_handle)) then status = HANDLE_ERR_NULL return end if call c_f_pointer(c_handle, h) if (h%magic /= MAGIC_OCEAN) then h => null() status = HANDLE_ERR_INVALID return end if status = HANDLE_OK end function handle_check