rdb_ocean_list_tracers Function

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

Name of the tracer at registry index idx (0-based). Same snprintf-style contract as rdb_ocean_last_error: copies up to cap bytes, NUL-terminates if room remains, returns the FULL trimmed name length. Returns 0 (buf untouched) on a bad handle, an out-of-range idx, or cap <= 0.

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_tracers~~CallsGraph proc~rdb_ocean_list_tracers rdb_ocean_list_tracers proc~resolve_ocean resolve_ocean proc~rdb_ocean_list_tracers->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=32), private :: name
integer, private :: ncopy

Source Code

   function rdb_ocean_list_tracers(c_handle, idx, buf, cap) result(len_out) &
      bind(c, name="rdb_ocean_list_tracers")
      !! Name of the tracer at registry index `idx` (0-based). Same
      !! `snprintf`-style contract as `rdb_ocean_last_error`: copies up
      !! to `cap` bytes, NUL-terminates if room remains, returns the FULL
      !! trimmed name length. Returns 0 (buf untouched) on a bad handle,
      !! an out-of-range `idx`, or `cap <= 0`.
      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=32) :: name

      len_out = 0_c_int
      hstat = resolve_ocean(c_handle, h)
      if (hstat /= OCEAN_STATUS_OK) return
      if (.not. allocated(h%state%multilayer%tracers)) return
      if (idx < 0_c_int .or. idx >= int(size(h%state%multilayer%tracers), c_int)) return
      if (cap <= 0_c_int) return

      name = h%state%multilayer%tracers(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_tracers