-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_square_root_wrapper.f90
More file actions
53 lines (36 loc) · 1.78 KB
/
get_square_root_wrapper.f90
File metadata and controls
53 lines (36 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
!> Wrapper for interfacing `m_get_square_root` with python
module m_get_square_root_w
use m_result_dp, only: ResultDP
use m_result_int, only: ResultInt
use m_get_square_root, only: o_get_square_root => get_square_root
! The manager module, which makes this all work
use m_result_dp_manager, only: &
result_dp_manager_get_available_instance_index => get_available_instance_index, &
result_dp_manager_set_instance_index_to => set_instance_index_to, &
result_dp_manager_ensure_instance_array_size_is_at_least => ensure_instance_array_size_is_at_least
implicit none
private
public :: get_square_root
contains
function get_square_root(inv) result(res_instance_index)
! Annoying that this has to be injected everywhere,
! but ok it can be automated.
integer, parameter :: dp = selected_real_kind(15, 307)
real(kind=dp), intent(in) :: inv
!! inv
integer :: res_instance_index
!! Instance index of the result type
type(ResultDP) :: res
type(ResultInt) :: res_get_available_instance_index
res = o_get_square_root(inv)
call result_dp_manager_ensure_instance_array_size_is_at_least(1)
! Get the instance index to return to Python
call result_dp_manager_get_available_instance_index(res_get_available_instance_index)
! Logic here is trickier.
! If you can't create a result type to return to Python,
! then you also can't return errors so you're a bit cooked.
! Set the derived type value in the manager's array,
! ready for its attributes to be retrieved from Python.
call result_dp_manager_set_instance_index_to(res_instance_index, res)
end function get_square_root
end module m_get_square_root_w