Debian Codegraph @

fortran/include/kim_collection_module.f90

raw
1 !
2 ! KIM-API: An API for interatomic models
3 ! Copyright (c) 2013--2022, Regents of the University of Minnesota.
4 ! All rights reserved.
5 !
6 ! Contributors:
7 ! Ryan S. Elliott
8 !
9 ! SPDX-License-Identifier: LGPL-2.1-or-later
10 !
11 ! This library is free software; you can redistribute it and/or
12 ! modify it under the terms of the GNU Lesser General Public
13 ! License as published by the Free Software Foundation; either
14 ! version 2.1 of the License, or (at your option) any later version.
15 !
16 ! This library is distributed in the hope that it will be useful,
17 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ! Lesser General Public License for more details.
20 !
21 ! You should have received a copy of the GNU Lesser General Public License
22 ! along with this library; if not, write to the Free Software Foundation,
23 ! Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 !
25
26 !
27 ! Release: This file is part of the kim-api.git repository.
28 !
29
30 !> \brief \copybrief KIM::Collection
31 !!
32 !! \sa KIM::Collection, KIM_Collection
33 !!
34 !! \since 2.1
35 module kim_collection_module
36 use, intrinsic :: iso_c_binding
37 implicit none
38 private
39
40 public &
41 ! Derived types
42 kim_collection_type, &
43 ! Constants
44 KIM_COLLECTION_SYSTEM, &
45 KIM_COLLECTION_USER, &
46 KIM_COLLECTION_ENVIRONMENT_VARIABLE, &
47 KIM_COLLECTION_CURRENT_WORKING_DIRECTORY, &
48 ! Routines
49 kim_known, &
50 operator(.eq.), &
51 operator(.ne.), &
52 kim_from_string, &
53 kim_to_string, &
54 kim_get_number_of_collections, &
55 kim_get_collection
56
57 !> \brief \copybrief KIM::Collection
58 !!
59 !! \sa KIM::Collection, KIM_Collection
60 !!
61 !! \since 2.1
62 type, bind(c) :: kim_collection_type
63 !> \brief \copybrief KIM::Collection::collectionID
64 !!
65 !! \sa KIM::Collection::collectionID, KIM_Collection::collectionID
66 !!
67 !! \since 2.1
68 integer(c_int) collection_id
69 end type kim_collection_type
70
71 !> \brief \copybrief KIM::COLLECTION::system
72 !!
73 !! \sa KIM::COLLECTION::system, KIM_COLLECTION_system
74 !!
75 !! \since 2.1
76 type(kim_collection_type), protected, save, &
77 bind(c, name="KIM_COLLECTION_system") &
78 :: KIM_COLLECTION_SYSTEM
79
80 !> \brief \copybrief KIM::COLLECTION::user
81 !!
82 !! \sa KIM::COLLECTION::user, KIM_COLLECTION_user
83 !!
84 !! \since 2.1
85 type(kim_collection_type), protected, save, &
86 bind(c, name="KIM_COLLECTION_user") &
87 :: KIM_COLLECTION_USER
88
89 !> \brief \copybrief KIM::COLLECTION::environmentVariable
90 !!
91 !! \sa KIM::COLLECTION::environmentVariable,
92 !! KIM_COLLECTION_environmentVariable
93 !!
94 !! \since 2.1
95 type(kim_collection_type), protected, save, &
96 bind(c, name="KIM_COLLECTION_environmentVariable") &
97 :: KIM_COLLECTION_ENVIRONMENT_VARIABLE
98
99 !> \brief \copybrief KIM::COLLECTION::currentWorkingDirectory
100 !!
101 !! \sa KIM::COLLECTION::currentWorkingDirectory,
102 !! KIM_COLLECTION_currentWorkingDirectory
103 !!
104 !! \since 2.1
105 type(kim_collection_type), protected, save, &
106 bind(c, name="KIM_COLLECTION_currentWorkingDirectory") &
107 :: KIM_COLLECTION_CURRENT_WORKING_DIRECTORY
108
109 !> \brief \copybrief KIM::Collection::Known
110 !!
111 !! \sa KIM::Collection::Known, KIM_Collection_Known
112 !!
113 !! \since 2.1
114 interface kim_known
115 module procedure kim_collection_known
116 end interface kim_known
117
118 !> \brief \copybrief KIM::Collection::operator==()
119 !!
120 !! \sa KIM::Collection::operator==(), KIM_Collection_Equal
121 !!
122 !! \since 2.1
123 interface operator(.eq.)
124 module procedure kim_collection_equal
125 end interface operator(.eq.)
126
127 !> \brief \copybrief KIM::Collection::operator!=()
128 !!
129 !! \sa KIM::Collection::operator!=(), KIM_Collection_NotEqual
130 !!
131 !! \since 2.1
132 interface operator(.ne.)
133 module procedure kim_collection_not_equal
134 end interface operator(.ne.)
135
136 !> \brief \copybrief KIM::Collection::Collection(std::string const &)
137 !!
138 !! \sa KIM::Collection::Collection(std::string const &),
139 !! KIM_Collection_FromString
140 !!
141 !! \since 2.1
142 interface kim_from_string
143 module procedure kim_collection_from_string
144 end interface kim_from_string
145
146 !> \brief \copybrief KIM::Collection::ToString
147 !!
148 !! \sa KIM::Collection::ToString, KIM_Collection_ToString
149 !!
150 !! \since 2.1
151 interface kim_to_string
152 module procedure kim_collection_to_string
153 end interface kim_to_string
154
155 contains
156 !> \brief \copybrief KIM::Collection::Known
157 !!
158 !! \sa KIM::Collection::Known, KIM_Collection_Known
159 !!
160 !! \since 2.1
161 logical recursive function kim_collection_known(collection)
162 implicit none
163 interface
164 integer(c_int) recursive function known(collection) &
165 bind(c, name="KIM_Collection_Known")
166 use, intrinsic :: iso_c_binding
167 import kim_collection_type
168 implicit none
169 type(kim_collection_type), intent(in), value :: collection
170 end function known
171 end interface
172 type(kim_collection_type), intent(in) :: collection
173
174 kim_collection_known = (known(collection) /= 0)
175 end function kim_collection_known
176
177 !> \brief \copybrief KIM::Collection::operator==()
178 !!
179 !! \sa KIM::Collection::operator==(), KIM_Collection_Equal
180 !!
181 !! \since 2.1
182 logical recursive function kim_collection_equal(lhs, rhs)
183 implicit none
184 type(kim_collection_type), intent(in) :: lhs
185 type(kim_collection_type), intent(in) :: rhs
186
187 kim_collection_equal &
188 = (lhs%collection_id == rhs%collection_id)
189 end function kim_collection_equal
190
191 !> \brief \copybrief KIM::Collection::operator!=()
192 !!
193 !! \sa KIM::Collection::operator!=(), KIM_Collection_NotEqual
194 !!
195 !! \since 2.1
196 logical recursive function kim_collection_not_equal(lhs, rhs)
197 implicit none
198 type(kim_collection_type), intent(in) :: lhs
199 type(kim_collection_type), intent(in) :: rhs
200
201 kim_collection_not_equal = .not. (lhs == rhs)
202 end function kim_collection_not_equal
203
204 !> \brief \copybrief KIM::Collection::Collection(std::string const &)
205 !!
206 !! \sa KIM::Collection::Collection(std::string const &),
207 !! KIM_Collection_FromString
208 !!
209 !! \since 2.1
210 recursive subroutine kim_collection_from_string(string, collection)
211 implicit none
212 interface
213 type(kim_collection_type) recursive function from_string(string) &
214 bind(c, name="KIM_Collection_FromString")
215 use, intrinsic :: iso_c_binding
216 import kim_collection_type
217 implicit none
218 character(c_char), intent(in) :: string(*)
219 end function from_string
220 end interface
221 character(len=*, kind=c_char), intent(in) :: string
222 type(kim_collection_type), intent(out) :: collection
223
224 collection = from_string(trim(string)//c_null_char)
225 end subroutine kim_collection_from_string
226
227 !> \brief \copybrief KIM::Collection::ToString
228 !!
229 !! \sa KIM::Collection::ToString, KIM_Collection_ToString
230 !!
231 !! \since 2.1
232 recursive subroutine kim_collection_to_string(collection, string)
233 use kim_convert_string_module, only: kim_convert_c_char_ptr_to_string
234 implicit none
235 interface
236 type(c_ptr) recursive function get_string(collection) &
237 bind(c, name="KIM_Collection_ToString")
238 use, intrinsic :: iso_c_binding
239 import kim_collection_type
240 implicit none
241 type(kim_collection_type), intent(in), value :: collection
242 end function get_string
243 end interface
244 type(kim_collection_type), intent(in) :: collection
245 character(len=*, kind=c_char), intent(out) :: string
246
247 type(c_ptr) :: p
248
249 p = get_string(collection)
250 call kim_convert_c_char_ptr_to_string(p, string)
251 end subroutine kim_collection_to_string
252
253 !> \brief \copybrief KIM::COLLECTION::GetNumberOfCollections
254 !!
255 !! \sa KIM::COLLECTION::GetNumberOfCollections,
256 !! KIM_COLLECTION_GetNumberOfCollections
257 !!
258 !! \since 2.1
259 recursive subroutine kim_get_number_of_collections(number_of_collections)
260 implicit none
261 interface
262 recursive subroutine get_number_of_collections(number_of_collections) &
263 bind(c, name="KIM_COLLECTION_GetNumberOfCollections")
264 use, intrinsic :: iso_c_binding
265 implicit none
266 integer(c_int), intent(out) :: number_of_collections
267 end subroutine get_number_of_collections
268 end interface
269 integer(c_int), intent(out) :: number_of_collections
270
271 call get_number_of_collections(number_of_collections)
272 end subroutine kim_get_number_of_collections
273
274 !> \brief \copybrief KIM::COLLECTION::GetCollection
275 !!
276 !! \sa KIM::COLLECTION::GetCollection, KIM_COLLECTION_GetCollection
277 !!
278 !! \since 2.1
279 recursive subroutine kim_get_collection(index, collection, ierr)
280 implicit none
281 interface
282 integer(c_int) recursive function get_collection(index, collection) &
283 bind(c, name="KIM_COLLECTION_GetCollection")
284 use, intrinsic :: iso_c_binding
285 import kim_collection_type
286 implicit none
287 integer(c_int), intent(in), value :: index
288 type(kim_collection_type), intent(out) :: collection
289 end function get_collection
290 end interface
291 integer(c_int), intent(in) :: index
292 type(kim_collection_type), intent(out) :: collection
293 integer(c_int), intent(out) :: ierr
294
295 ierr = get_collection(index - 1, collection)
296 end subroutine kim_get_collection
297 end module kim_collection_module