rdb_ocean_list_diags Function

public function rdb_ocean_list_diags(c_handle, idx, buf, cap) result(len_out) bind(c, name="rdb_ocean_list_diags")

Name of the registered diagnostic at index idx (0-based). Same snprintf-style contract as rdb_ocean_list_tracers.

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in), value :: c_handle
integer(kind=c_int), intent(in), value :: idx
character(kind=c_char, len=1), intent(out) :: buf(cap)
integer(kind=c_int), intent(in), value :: cap

Return Value integer(kind=c_int)


Calls

proc~~rdb_ocean_list_diags~~CallsGraph proc~rdb_ocean_list_diags rdb_ocean_list_diags proc~resolve_ocean resolve_ocean proc~rdb_ocean_list_diags->proc~resolve_ocean proc~handle_check handle_check proc~resolve_ocean->proc~handle_check

Variables

Type Visibility Attributes Name Initial
type(ocean_handle_t), private, pointer :: h
integer, private :: hstat
integer, private :: i
integer, private :: n
character(len=64), private :: name
integer, private :: ncopy

Source Code

   function rdb_ocean_list_diags(c_handle, idx, buf, cap) result(len_out) &
      bind(c, name="rdb_ocean_list_diags")
      !! Name of the registered diagnostic at index `idx` (0-based).
      !! Same snprintf-style contract as `rdb_ocean_list_tracers`.
      type(c_ptr), intent(in), value :: c_handle
      integer(c_int), intent(in), value :: idx
      integer(c_int), intent(in), value :: cap
      character(kind=c_char), intent(out) :: buf(cap)
      integer(c_int) :: len_out

      type(ocean_handle_t), pointer :: h
      integer :: hstat, n, ncopy, i
      character(len=64) :: name

      len_out = 0_c_int
      hstat = resolve_ocean(c_handle, h)
      if (hstat /= OCEAN_STATUS_OK) return
      if (idx < 0_c_int .or. idx >= int(h%state%diag%nvars, c_int)) return
      if (cap <= 0_c_int) return

      name = h%state%diag%vars(int(idx) + 1)%name
      n = len_trim(name)
      len_out = int(n, c_int)
      ncopy = min(n, int(cap))
      do i = 1, ncopy
         buf(i) = name(i:i)
      end do
      if (ncopy < cap) buf(ncopy + 1) = achar(0)
   end function rdb_ocean_list_diags