kim-api  2.2.1+v2.2.1.GNU.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--2020, 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.2.1 package.
31 !
32 
39  use, intrinsic :: iso_c_binding
40  implicit none
41  private
42 
43  public &
44  ! Derived types
45  kim_collection_type, &
46  ! Constants
51  ! Routines
52  kim_known, &
53  operator(.eq.), &
54  operator(.ne.), &
55  kim_from_string, &
56  kim_to_string, &
59 
65  type, bind(c) :: kim_collection_type
71  integer(c_int) collection_id
72  end type kim_collection_type
73 
79  type(kim_collection_type), protected, save, &
80  bind(c, name="KIM_COLLECTION_system") &
82 
88  type(kim_collection_type), protected, save, &
89  bind(c, name="KIM_COLLECTION_user") &
91 
98  type(kim_collection_type), protected, save, &
99  bind(c, name="KIM_COLLECTION_environmentVariable") &
101 
108  type(kim_collection_type), protected, save, &
109  bind(c, name="KIM_COLLECTION_currentWorkingDirectory") &
111 
117  interface kim_known
118  module procedure kim_collection_known
119  end interface kim_known
120 
126  interface operator(.eq.)
127  module procedure kim_collection_equal
128  end interface operator(.eq.)
129 
135  interface operator(.ne.)
136  module procedure kim_collection_not_equal
137  end interface operator(.ne.)
138 
145  interface kim_from_string
146  module procedure kim_collection_from_string
147  end interface kim_from_string
148 
154  interface kim_to_string
155  module procedure kim_collection_to_string
156  end interface kim_to_string
157 
158 contains
164  logical recursive function kim_collection_known(collection)
165  implicit none
166  interface
167  integer(c_int) recursive function known(collection) &
168  bind(c, name="KIM_Collection_Known")
169  use, intrinsic :: iso_c_binding
170  import kim_collection_type
171  implicit none
172  type(kim_collection_type), intent(in), value :: collection
173  end function known
174  end interface
175  type(kim_collection_type), intent(in) :: collection
176 
177  kim_collection_known = (known(collection) /= 0)
178  end function kim_collection_known
179 
185  logical recursive function kim_collection_equal(lhs, rhs)
186  implicit none
187  type(kim_collection_type), intent(in) :: lhs
188  type(kim_collection_type), intent(in) :: rhs
189 
190  kim_collection_equal &
191  = (lhs%collection_id == rhs%collection_id)
192  end function kim_collection_equal
193 
199  logical recursive function kim_collection_not_equal(lhs, rhs)
200  implicit none
201  type(kim_collection_type), intent(in) :: lhs
202  type(kim_collection_type), intent(in) :: rhs
203 
204  kim_collection_not_equal = .not. (lhs == rhs)
205  end function kim_collection_not_equal
206 
213  recursive subroutine kim_collection_from_string(string, collection)
214  implicit none
215  interface
216  type(kim_collection_type) recursive function from_string(string) &
217  bind(c, name="KIM_Collection_FromString")
218  use, intrinsic :: iso_c_binding
219  import kim_collection_type
220  implicit none
221  character(c_char), intent(in) :: string(*)
222  end function from_string
223  end interface
224  character(len=*, kind=c_char), intent(in) :: string
225  type(kim_collection_type), intent(out) :: collection
226 
227  collection = from_string(trim(string)//c_null_char)
228  end subroutine kim_collection_from_string
229 
235  recursive subroutine kim_collection_to_string(collection, string)
236  use kim_convert_string_module, only: kim_convert_c_char_ptr_to_string
237  implicit none
238  interface
239  type(c_ptr) recursive function get_string(collection) &
240  bind(c, name="KIM_Collection_ToString")
241  use, intrinsic :: iso_c_binding
242  import kim_collection_type
243  implicit none
244  type(kim_collection_type), intent(in), value :: collection
245  end function get_string
246  end interface
247  type(kim_collection_type), intent(in) :: collection
248  character(len=*, kind=c_char), intent(out) :: string
249 
250  type(c_ptr) :: p
251 
252  p = get_string(collection)
253  call kim_convert_c_char_ptr_to_string(p, string)
254  end subroutine kim_collection_to_string
255 
262  recursive subroutine kim_get_number_of_collections(number_of_collections)
263  implicit none
264  interface
265  recursive subroutine get_number_of_collections(number_of_collections) &
266  bind(c, name="KIM_COLLECTION_GetNumberOfCollections")
267  use, intrinsic :: iso_c_binding
268  implicit none
269  integer(c_int), intent(out) :: number_of_collections
270  end subroutine get_number_of_collections
271  end interface
272  integer(c_int), intent(out) :: number_of_collections
273 
274  call get_number_of_collections(number_of_collections)
275  end subroutine kim_get_number_of_collections
276 
282  recursive subroutine kim_get_collection(index, collection, ierr)
283  implicit none
284  interface
285  integer(c_int) recursive function get_collection(index, collection) &
286  bind(c, name="KIM_COLLECTION_GetCollection")
287  use, intrinsic :: iso_c_binding
288  import kim_collection_type
289  implicit none
290  integer(c_int), intent(in), value :: index
291  type(kim_collection_type), intent(out) :: collection
292  end function get_collection
293  end interface
294  integer(c_int), intent(in) :: index
295  type(kim_collection_type), intent(out) :: collection
296  integer(c_int), intent(out) :: ierr
297 
298  ierr = get_collection(index - 1, collection)
299  end subroutine kim_get_collection
300 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.