ComIn 0.5.1
ICON Community Interface
Loading...
Searching...
No Matches
comin_var_request.F90
Go to the documentation of this file.
1!> @file comin_variable.F90
2!! @brief Functions to modify and retrieve Variable definition
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!!
12
14
15 use, INTRINSIC :: iso_c_binding, only: c_bool, c_ptr, c_f_pointer
18
19 IMPLICIT NONE
20
21 PRIVATE
22
23 ! Public procedures, intention: called by host
31
32 ! Public procedures, intention: called by plugin
33 PUBLIC :: comin_var_request_add
34
35 ! Public procedures, intention: for internal use
37
38 ! Direct forwards to C++ implementation.
39 INTERFACE
40
41 !> Create a new request list iterator, at the begin of the list.
42 FUNCTION comin_request_list_iterator_begin() RESULT(ptr) BIND(C)
43 IMPORT c_ptr
44 TYPE(c_ptr) :: ptr ! New iterator.
46
47 !> Compare the request list iterator with the end of the list.
48 FUNCTION comin_request_list_iterator_is_end(it) RESULT(is_end) BIND(C)
49 IMPORT c_ptr, c_bool
50 TYPE(c_ptr), VALUE, INTENT(IN) :: it !< Iterator.
51 LOGICAL(c_bool) :: is_end ! .TRUE. if at end of list.
53
54 !> Advance the iterator to the next element, returning the current one.
55 FUNCTION comin_request_list_iterator_next(it) RESULT(item) BIND(C)
56 IMPORT c_ptr
57 TYPE(c_ptr), VALUE, INTENT(IN) :: it !< Iterator.
58 TYPE(c_ptr) :: item ! Pointer to the current item.
60
61 !> Delete the request list iterator.
63 IMPORT c_ptr
64 TYPE(c_ptr), INTENT(INOUT) :: it !< Iterator.
66
67 END INTERFACE
68
69 ! Underlying functions to be wrapped.
70 INTERFACE
71
72 SUBROUTINE comin_var_request_add_c(var_descriptor, lmodexclusive) &
73 & BIND(C, name="comin_var_request_add")
74 IMPORT t_comin_var_descriptor_c, c_bool
75 TYPE (t_comin_var_descriptor_c), VALUE, INTENT(IN) :: var_descriptor
76 LOGICAL(C_BOOL), VALUE, INTENT(IN) :: lmodexclusive
77 END SUBROUTINE comin_var_request_add_c
78
79 FUNCTION comin_var_request_get_metadata_c(request) RESULT(ptr) &
80 & bind(c, name='comin_var_request_get_metadata')
81 IMPORT c_ptr
82 TYPE(c_ptr), VALUE, INTENT(IN) :: request
83 TYPE(c_ptr) :: ptr
84 END FUNCTION comin_var_request_get_metadata_c
85
86 FUNCTION comin_var_request_get_descriptor_c(request) RESULT(ptr) &
87 & bind(c, name='comin_var_request_get_descriptor')
88 IMPORT c_ptr
89 TYPE(c_ptr), VALUE, INTENT(IN) :: request
90 TYPE(c_ptr) :: ptr
91 END FUNCTION comin_var_request_get_descriptor_c
92
93 !> Return the request item for the given C descriptor.
94 FUNCTION comin_var_request_find_c(var_descriptor) RESULT(ptr) &
95 & bind(c, name='comin_var_request_find')
96 IMPORT c_ptr, t_comin_var_descriptor_c
97 TYPE(t_comin_var_descriptor_c), INTENT(IN) :: var_descriptor !< C variable descriptor.
98 TYPE(c_ptr) :: ptr ! Pointer to the request item or a disassociated pointer if no request exists.
99 END FUNCTION comin_var_request_find_c
100
101 END INTERFACE
102
103CONTAINS
104
105 !> By calling this subroutine inside the primary constructor, 3rd
106 !! party plugins may request the creation of additional variables.
107 !! @ingroup fortran_interface
108 !!
109 !! Note: The lmodexclusive argument provides the information if this
110 !! variable is exclusive to the calling plugin.
111 !!
112 !! Note: If a 3rd party plugin requests the creation of a variable
113 !! through this subroutine, it is still not guaranteed that
114 !! this variable is actually created! It might be skipped
115 !! due to inconsistencies, it could be a duplicate
116 !! etc. Therefore, 3rd party plugins still have to evaluate
117 !! the return code of `comin_var_request_add`.
118 !!
119 SUBROUTINE comin_var_request_add(var_descriptor, lmodexclusive)
120 TYPE (t_comin_var_descriptor), INTENT(IN) :: var_descriptor
121 LOGICAL, INTENT(IN) :: lmodexclusive
122
123 CALL comin_var_request_add_c( &
124 & t_comin_var_descriptor_c(var_descriptor), LOGICAL(lmodexclusive, c_bool))
125 END SUBROUTINE comin_var_request_add
126
127 !> Get the metadata associated with the given request.
128 FUNCTION comin_var_request_get_metadata(req) RESULT(metadata)
129 TYPE(c_ptr), VALUE, INTENT(IN) :: req !< Request pointer.
130 TYPE(t_comin_var_metadata) :: metadata !< Associated metadata.
131
132 metadata%comin_metadata_c = comin_var_request_get_metadata_c(req)
134
135 !> Get the descriptor associated with the given request.
136 FUNCTION comin_var_request_get_descriptor(req) RESULT(descr)
137 TYPE(c_ptr), VALUE, INTENT(IN) :: req !< Request pointer.
138 TYPE(t_comin_var_descriptor) :: descr !< Variable descriptor.
139
140 TYPE(t_comin_var_descriptor_c), POINTER :: descr_c
141
142 CALL c_f_pointer(comin_var_request_get_descriptor_c(req), descr_c)
143 descr = t_comin_var_descriptor(descr_c)
144 END FUNCTION
145
146 !> Find the request associated with the given descriptor.
147 FUNCTION comin_var_request_find(var_descriptor) RESULT(req)
148 TYPE(t_comin_var_descriptor), INTENT(IN) :: var_descriptor !< Variable descriptor.
149 TYPE(c_ptr) :: req !< Pointer to the request or not associated.
150
152 END FUNCTION comin_var_request_find
153
154END MODULE comin_var_request
comin::keyval::Map * comin_var_request_get_metadata(t_comin_request_item *req)
void comin_var_request_add(t_comin_var_descriptor var_desc, bool lmodexclusive)
t_comin_request_item * comin_var_request_find(const t_comin_var_descriptor *var_desc)
t_comin_var_descriptor * comin_var_request_get_descriptor(t_comin_request_item *req)
Create a new request list iterator, at the begin of the list.
Compare the request list iterator with the end of the list.
Advance the iterator to the next element, returning the current one.
Return the request item for the given C descriptor.