ComIn 0.5.1
ICON Community Interface
Loading...
Searching...
No Matches
comin_callback.F90
Go to the documentation of this file.
1!> @file comin_callback.F90
2!! @brief Routines to handle third party plugin callbacks.
3!
4! @authors 08/2021 :: ICON Community Interface <comin@icon-model.org>
5!
6! SPDX-License-Identifier: BSD-3-Clause
7!
8! See LICENSES for license information.
9! Where software is supplied by third parties, it is indicated in the
10! headers of the routines.
11!
13
14 USE iso_c_binding, ONLY: c_int, c_funptr, c_funloc, c_bool, c_ptr
16
17 IMPLICIT NONE
18
19 PRIVATE
20
25
26#include "comin_global.inc"
27
28 abstract INTERFACE
29 SUBROUTINE comin_callback_routine() BIND(C)
30 END SUBROUTINE comin_callback_routine
31 END INTERFACE
32
33 INTERFACE
34 SUBROUTINE comin_callback_register_f(entry_point_id, comin_callback_fct) BIND(C)
35 IMPORT c_int, c_funptr
36 INTEGER(c_int), VALUE, INTENT(IN) :: entry_point_id
37 TYPE(c_funptr), VALUE, INTENT(IN) :: comin_callback_fct
38 END SUBROUTINE comin_callback_register_f
39
40 SUBROUTINE comin_callback_context_call(entry_point_id, domain_id, lacc) BIND(C)
41 IMPORT c_int, c_bool
42 INTEGER(KIND=C_INT), INTENT(IN), VALUE :: entry_point_id
43 INTEGER(KIND=C_INT), INTENT(IN), VALUE :: domain_id
44 LOGICAL(KIND=C_BOOL), INTENT(IN), VALUE :: lacc
45 END SUBROUTINE comin_callback_context_call
46
47 FUNCTION comin_callback_get_ep_name_c(entry_point_id) &
48 & result(ep_name) &
49 & BIND(C, name="comin_callback_get_ep_name")
50 IMPORT c_int, c_ptr
51 INTEGER(KIND=C_INT), INTENT(IN), VALUE :: entry_point_id
52 TYPE(c_ptr) :: ep_name
53 END FUNCTION comin_callback_get_ep_name_c
54 END INTERFACE
55
56CONTAINS
57
58 !> Routine to register new callbacks during primary constructor.
59 !! @ingroup fortran_interface
60 SUBROUTINE comin_callback_register(entry_point_id, comin_callback_fct)
61 INTEGER, INTENT(IN) :: entry_point_id
62 PROCEDURE(comin_callback_routine) :: comin_callback_fct
63
64 CALL comin_callback_register_f(entry_point_id, c_funloc(comin_callback_fct))
65 END SUBROUTINE comin_callback_register
66
67 !> returns entry point name (character string) corresponding to `iep`.
68 !! @ingroup fortran_interface
69 SUBROUTINE comin_callback_get_ep_name( iep, out_ep_name )
70 INTEGER, INTENT(IN) :: iep !< entry point ID
71 CHARACTER(LEN=:), ALLOCATABLE, INTENT(OUT) :: out_ep_name !< entry point name string
72
73 out_ep_name = convert_c_string(comin_callback_get_ep_name_c(iep))
74 END SUBROUTINE comin_callback_get_ep_name
75
76END MODULE comin_callback
void comin_callback_register_f(int entry_point_ftn, t_comin_callback_function fct_ptr)
const char * comin_callback_get_ep_name(t_comin_entry_point iep)
void comin_callback_register(t_comin_entry_point entry_point, t_comin_callback_function fct_ptr)