integer(c_int) function beach_kernel_get_periodic_cache_info( &
handle, hit_ptr, build_count_ptr, fingerprint_ptr, fingerprint_capacity, fingerprint_length_ptr, &
path_ptr, path_capacity, path_length_ptr &
) bind(C, name='beach_kernel_get_periodic_cache_info') result(status)
type(c_ptr), value :: handle
type(c_ptr), value :: hit_ptr, build_count_ptr, fingerprint_ptr, fingerprint_length_ptr
type(c_ptr), value :: path_ptr, path_length_ptr
integer(c_int), value :: fingerprint_capacity, path_capacity
type(field_kernel_handle), pointer :: kernel
integer(c_int), pointer :: hit, build_count, fingerprint_length, path_length
integer :: required_fingerprint_length, required_path_length
logical :: cached_plan
status = get_kernel(handle, kernel)
if (status /= beach_kernel_ok) return
if (.not. kernel%built) then
status = beach_kernel_not_ready
return
end if
if (.not. c_associated(hit_ptr) .or. .not. c_associated(build_count_ptr) .or. &
.not. c_associated(fingerprint_length_ptr) .or. .not. c_associated(path_length_ptr)) then
status = beach_kernel_invalid_argument
return
end if
call c_f_pointer(hit_ptr, hit)
call c_f_pointer(build_count_ptr, build_count)
call c_f_pointer(fingerprint_length_ptr, fingerprint_length)
call c_f_pointer(path_length_ptr, path_length)
cached_plan = trim(kernel%plan%options%periodic_far_correction) == 'cached_kneq0'
if (cached_plan) then
required_fingerprint_length = len_trim(kernel%plan%periodic_cache_fingerprint)
required_path_length = len_trim(kernel%plan%periodic_cache_path)
hit = merge(1_c_int, 0_c_int, kernel%plan%periodic_cache_hit)
build_count = int(kernel%plan%periodic_operator_build_count, c_int)
else
required_fingerprint_length = 0
required_path_length = 0
hit = 0_c_int
build_count = 0_c_int
end if
fingerprint_length = int(required_fingerprint_length, c_int)
path_length = int(required_path_length, c_int)
if (.not. c_associated(fingerprint_ptr) .or. .not. c_associated(path_ptr) .or. &
fingerprint_capacity <= int(required_fingerprint_length, c_int) .or. &
path_capacity <= int(required_path_length, c_int)) then
status = beach_kernel_invalid_argument
return
end if
if (cached_plan) then
call copy_text_to_c_buffer( &
kernel%plan%periodic_cache_fingerprint, required_fingerprint_length, fingerprint_ptr, fingerprint_capacity &
)
call copy_text_to_c_buffer(kernel%plan%periodic_cache_path, required_path_length, path_ptr, path_capacity)
else
call copy_text_to_c_buffer('', 0, fingerprint_ptr, fingerprint_capacity)
call copy_text_to_c_buffer('', 0, path_ptr, path_capacity)
end if
status = beach_kernel_ok
end function beach_kernel_get_periodic_cache_info