beach_kernel_set_periodic_cache Function

public function beach_kernel_set_periodic_cache(handle, path_ptr, path_len, tolerance) result(status) bind(C, name='beach_kernel_set_periodic_cache'))

Arguments

Type IntentOptional Attributes Name
type(c_ptr), value :: handle
type(c_ptr), value :: path_ptr
integer(kind=c_int), value :: path_len
real(kind=c_double), value :: tolerance

Return Value integer(kind=c_int)


Source Code

  integer(c_int) function beach_kernel_set_periodic_cache(handle, path_ptr, path_len, tolerance) &
    bind(C, name='beach_kernel_set_periodic_cache') result(status)
    type(c_ptr), value :: handle
    type(c_ptr), value :: path_ptr
    integer(c_int), value :: path_len
    real(c_double), value :: tolerance
    type(field_kernel_handle), pointer :: kernel
    character(kind=c_char), pointer :: path_bytes(:)
    character(len=periodic_cache_path_max_bytes) :: validated_path
    integer :: i

    status = get_kernel(handle, kernel)
    if (status /= beach_kernel_ok) return
    if (.not. c_associated(path_ptr) .or. path_len <= 0_c_int .or. &
        path_len > int(periodic_cache_path_max_bytes, c_int) .or. &
        .not. ieee_is_finite(tolerance) .or. tolerance <= 0.0_c_double) then
      status = beach_kernel_invalid_argument
      return
    end if

    call c_f_pointer(path_ptr, path_bytes, [int(path_len)])
    if (.not. valid_utf8_bytes(path_bytes) .or. c_byte_value(path_bytes(int(path_len))) == 32) then
      status = beach_kernel_invalid_argument
      return
    end if

    validated_path = ''
    do i = 1, int(path_len)
      validated_path(i:i) = transfer(path_bytes(i), ' ')
    end do
    kernel%periodic_cache_dir = validated_path
    kernel%periodic_generation_tolerance = real(tolerance, dp)
    status = beach_kernel_ok
  end function beach_kernel_set_periodic_cache