kim-api  2.1.2+v2.1.2.GNU
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
kim_collection_module.f90
Go to the documentation of this file.
1 !
2 ! CDDL HEADER START
3 !
4 ! The contents of this file are subject to the terms of the Common Development
5 ! and Distribution License Version 1.0 (the "License").
6 !
7 ! You can obtain a copy of the license at
8 ! http://www.opensource.org/licenses/CDDL-1.0. See the License for the
9 ! specific language governing permissions and limitations under the License.
10 !
11 ! When distributing Covered Code, include this CDDL HEADER in each file and
12 ! include the License file in a prominent location with the name LICENSE.CDDL.
13 ! If applicable, add the following below this CDDL HEADER, with the fields
14 ! enclosed by brackets "[]" replaced with your own identifying information:
15 !
16 ! Portions Copyright (c) [yyyy] [name of copyright owner]. All rights reserved.
17 !
18 ! CDDL HEADER END
19 !
20 
21 !
22 ! Copyright (c) 2016--2019, Regents of the University of Minnesota.
23 ! All rights reserved.
24 !
25 ! Contributors:
26 ! Ryan S. Elliott
27 !
28 
29 !
30 ! Release: This file is part of the kim-api-2.1.2 package.
31 !
32 
33 
40  use, intrinsic :: iso_c_binding
41  implicit none
42  private
43 
44  public &
45  ! Derived types
46  kim_collection_type, &
47 
48  ! Constants
53 
54  ! Routines
55  kim_known, &
56  operator (.eq.), &
57  operator (.ne.), &
58  kim_from_string, &
59  kim_to_string, &
62 
63 
69  type, bind(c) :: kim_collection_type
75  integer(c_int) collection_id
76  end type kim_collection_type
77 
83  type(kim_collection_type), protected, save, &
84  bind(c, name="KIM_COLLECTION_system") &
86 
92  type(kim_collection_type), protected, save, &
93  bind(c, name="KIM_COLLECTION_user") &
95 
102  type(kim_collection_type), protected, save, &
103  bind(c, name="KIM_COLLECTION_environmentVariable") &
105 
112  type(kim_collection_type), protected, save, &
113  bind(c, name="KIM_COLLECTION_currentWorkingDirectory") &
115 
121  interface kim_known
122  module procedure kim_collection_known
123  end interface kim_known
124 
130  interface operator (.eq.)
131  module procedure kim_collection_equal
132  end interface operator (.eq.)
133 
139  interface operator (.ne.)
140  module procedure kim_collection_not_equal
141  end interface operator (.ne.)
142 
149  interface kim_from_string
150  module procedure kim_collection_from_string
151  end interface kim_from_string
152 
158  interface kim_to_string
159  module procedure kim_collection_to_string
160  end interface kim_to_string
161 
162 contains
168  logical recursive function kim_collection_known(collection)
169  implicit none
170  interface
171  integer(c_int) recursive function known(collection) &
172  bind(c, name="KIM_Collection_Known")
173  use, intrinsic :: iso_c_binding
174  import kim_collection_type
175  implicit none
176  type(kim_collection_type), intent(in), value :: collection
177  end function known
178  end interface
179  type(kim_collection_type), intent(in) :: collection
180 
181  kim_collection_known = (known(collection) /= 0)
182  end function kim_collection_known
183 
189  logical recursive function kim_collection_equal(lhs, rhs)
190  implicit none
191  type(kim_collection_type), intent(in) :: lhs
192  type(kim_collection_type), intent(in) :: rhs
193 
194  kim_collection_equal &
195  = (lhs%collection_id .eq. rhs%collection_id)
196  end function kim_collection_equal
197 
203  logical recursive function kim_collection_not_equal(lhs, rhs)
204  implicit none
205  type(kim_collection_type), intent(in) :: lhs
206  type(kim_collection_type), intent(in) :: rhs
207 
208  kim_collection_not_equal = .not. (lhs .eq. rhs)
209  end function kim_collection_not_equal
210 
217  recursive subroutine kim_collection_from_string(string, collection)
218  implicit none
219  interface
220  type(kim_collection_type) recursive function from_string(string) &
221  bind(c, name="KIM_Collection_FromString")
222  use, intrinsic :: iso_c_binding
223  import kim_collection_type
224  implicit none
225  character(c_char), intent(in) :: string(*)
226  end function from_string
227  end interface
228  character(len=*, kind=c_char), intent(in) :: string
229  type(kim_collection_type), intent(out) :: collection
230 
231  collection = from_string(trim(string)//c_null_char)
232  end subroutine kim_collection_from_string
233 
239  recursive subroutine kim_collection_to_string(collection, string)
240  use kim_convert_string_module, only : kim_convert_c_char_ptr_to_string
241  implicit none
242  interface
243  type(c_ptr) recursive function get_string(collection) &
244  bind(c, name="KIM_Collection_ToString")
245  use, intrinsic :: iso_c_binding
246  import kim_collection_type
247  implicit none
248  type(kim_collection_type), intent(in), value :: collection
249  end function get_string
250  end interface
251  type(kim_collection_type), intent(in) :: collection
252  character(len=*, kind=c_char), intent(out) :: string
253 
254  type(c_ptr) :: p
255 
256  p = get_string(collection)
257  call kim_convert_c_char_ptr_to_string(p, string)
258  end subroutine kim_collection_to_string
259 
266  recursive subroutine kim_get_number_of_collections(number_of_collections)
267  implicit none
268  interface
269  recursive subroutine get_number_of_collections(number_of_collections) &
270  bind(c, name="KIM_COLLECTION_GetNumberOfCollections")
271  use, intrinsic :: iso_c_binding
272  implicit none
273  integer(c_int), intent(out) :: number_of_collections
274  end subroutine get_number_of_collections
275  end interface
276  integer(c_int), intent(out) :: number_of_collections
277 
278  call get_number_of_collections(number_of_collections)
279  end subroutine kim_get_number_of_collections
280 
286  recursive subroutine kim_get_collection(index, collection, ierr)
287  implicit none
288  interface
289  integer(c_int) recursive function get_collection(index, collection) &
290  bind(c, name="KIM_COLLECTION_GetCollection")
291  use, intrinsic :: iso_c_binding
292  import kim_collection_type
293  implicit none
294  integer(c_int), intent(in), value :: index
295  type(kim_collection_type), intent(out) :: collection
296  end function get_collection
297  end interface
298  integer(c_int), intent(in) :: index
299  type(kim_collection_type), intent(out) :: collection
300  integer(c_int), intent(out) :: ierr
301 
302  ierr = get_collection(index-1, collection)
303  end subroutine kim_get_collection
304 end module kim_collection_module
type(kim_collection_type), save, public, protected kim_collection_user
type(kim_collection_type), save, public, protected kim_collection_environment_variable
recursive subroutine, public kim_get_number_of_collections(number_of_collections)
Get the number of standard Collection's defined by the KIM API.
type(kim_collection_type), save, public, protected kim_collection_system
recursive subroutine, public kim_get_collection(index, collection, ierr)
Get the identity of each defined standard Collection.
type(kim_collection_type), save, public, protected kim_collection_current_working_directory
An Extensible Enumeration for the Collection's supported by the KIM API.