|
| 1 | +!> Wrapper for interfacing `m_error_v_passing` with Python |
| 2 | +!> |
| 3 | +!> Written by hand here. |
| 4 | +!> Generation to be automated in future (including docstrings of some sort). |
| 5 | +module m_error_v_passing_w |
| 6 | + |
| 7 | + ! => allows us to rename on import to avoid clashes |
| 8 | + ! "o_" for original (TODO: better naming convention) |
| 9 | + use m_error_v_passing, only: & |
| 10 | + o_pass_error => pass_error, & |
| 11 | + o_pass_errors => pass_errors |
| 12 | + use m_error_v, only: ErrorV |
| 13 | + |
| 14 | + ! The manager module, which makes this all work |
| 15 | + use m_error_v_manager, only: & |
| 16 | + error_v_manager_get_instance => get_instance |
| 17 | + ! error_v_manager_get_available_instance_index => get_available_instance_index, & |
| 18 | + ! error_v_manager_set_instance_index_to => set_instance_index_to, & |
| 19 | + ! error_v_manager_ensure_instance_array_size_is_at_least => ensure_instance_array_size_is_at_least |
| 20 | + |
| 21 | + implicit none |
| 22 | + private |
| 23 | + |
| 24 | + public :: pass_error, pass_errors |
| 25 | + |
| 26 | +contains |
| 27 | + |
| 28 | + function pass_error(inv_instance_index) result(res) |
| 29 | + !! Wrapper around `m_error_v_passing.pass_error` (TODO: x-ref) |
| 30 | + |
| 31 | + integer, intent(in) :: inv_instance_index |
| 32 | + !! Input values |
| 33 | + !! |
| 34 | + !! See docstring of `m_error_v_passing.pass_error` for details. |
| 35 | + !! [TODO: x-ref] |
| 36 | + !! The trick here is to pass in the instance index, not the instance itself |
| 37 | + |
| 38 | + logical :: res |
| 39 | + !! Whether the instance referred to by `inv_instance_index` is an error or not |
| 40 | + |
| 41 | + type(ErrorV) :: instance |
| 42 | + |
| 43 | + instance = error_v_manager_get_instance(inv_instance_index) |
| 44 | + |
| 45 | + ! Do the Fortran call |
| 46 | + res = o_pass_error(instance) |
| 47 | + |
| 48 | + end function pass_error |
| 49 | + |
| 50 | + function pass_errors(inv_instance_indexes, n) result(res) |
| 51 | + !! Wrapper around `m_error_v_passing.pass_errors` (TODO: x-ref) |
| 52 | + |
| 53 | + integer, dimension(n), intent(in) :: inv_instance_indexes |
| 54 | + !! Input values |
| 55 | + !! |
| 56 | + !! See docstring of `m_error_v_passing.pass_errors` for details. |
| 57 | + !! [TODO: x-ref] |
| 58 | + |
| 59 | + integer, intent(in) :: n |
| 60 | + !! Number of values to pass |
| 61 | + |
| 62 | + logical, dimension(n) :: res |
| 63 | + !! Whether each instance in the array backed by `inv_instance_indexes` is an error or not |
| 64 | + ! |
| 65 | + ! This is the major trick for wrapping. |
| 66 | + ! We pass instance indexes (integers) from Python rather than the instance itself. |
| 67 | + |
| 68 | + type(ErrorV), dimension(n) :: instances |
| 69 | + |
| 70 | + integer :: i |
| 71 | + |
| 72 | + do i = 1, n |
| 73 | + instances(i) = error_v_manager_get_instance(inv_instance_indexes(i)) |
| 74 | + end do |
| 75 | + |
| 76 | + ! Do the Fortran call |
| 77 | + res = o_pass_errors(instances, n) |
| 78 | + |
| 79 | + end function pass_errors |
| 80 | + |
| 81 | +end module m_error_v_passing_w |
0 commit comments