kim-api  2.1.4-git+v2.1.3-git-1-g7847914a.GNU
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
kim_numbering_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.git repository.
31 !
32 
33 
40  use, intrinsic :: iso_c_binding
41  implicit none
42  private
43 
44  public &
45  ! Derived types
46  kim_numbering_type, &
47 
48  ! Constants
51 
52  ! Routines
53  kim_known, &
54  operator (.eq.), &
55  operator (.ne.), &
56  kim_from_string, &
57  kim_to_string, &
60 
61 
67  type, bind(c) :: kim_numbering_type
68  integer(c_int) :: numbering_id
69  end type kim_numbering_type
70 
76  type(kim_numbering_type), protected, save, &
77  bind(c, name="KIM_NUMBERING_zeroBased") &
79 
85  type(kim_numbering_type), protected, save, &
86  bind(c, name="KIM_NUMBERING_oneBased") &
88 
94  interface kim_known
95  module procedure kim_numbering_known
96  end interface kim_known
97 
103  interface operator (.eq.)
104  module procedure kim_numbering_equal
105  end interface operator (.eq.)
106 
112  interface operator (.ne.)
113  module procedure kim_numbering_not_equal
114  end interface operator (.ne.)
115 
122  interface kim_from_string
123  module procedure kim_numbering_from_string
124  end interface kim_from_string
125 
131  interface kim_to_string
132  module procedure kim_numbering_to_string
133  end interface kim_to_string
134 
135 contains
141  logical recursive function kim_numbering_known(numbering)
142  implicit none
143  interface
144  integer(c_int) recursive function known(numbering) &
145  bind(c, name="KIM_Numbering_Known")
146  use, intrinsic :: iso_c_binding
147  import kim_numbering_type
148  implicit none
149  type(kim_numbering_type), intent(in), value :: numbering
150  end function known
151  end interface
152  type(kim_numbering_type), intent(in) :: numbering
153 
154  kim_numbering_known = (known(numbering) /= 0)
155  end function kim_numbering_known
156 
162  logical recursive function kim_numbering_equal(lhs, rhs)
163  implicit none
164  type(kim_numbering_type), intent(in) :: lhs
165  type(kim_numbering_type), intent(in) :: rhs
166 
167  kim_numbering_equal &
168  = (lhs%numbering_id .eq. rhs%numbering_id)
169  end function kim_numbering_equal
170 
176  logical recursive function kim_numbering_not_equal(lhs, rhs)
177  implicit none
178  type(kim_numbering_type), intent(in) :: lhs
179  type(kim_numbering_type), intent(in) :: rhs
180 
181  kim_numbering_not_equal = .not. (lhs .eq. rhs)
182  end function kim_numbering_not_equal
183 
190  recursive subroutine kim_numbering_from_string(string, numbering)
191  implicit none
192  interface
193  type(kim_numbering_type) recursive function from_string(string) &
194  bind(c, name="KIM_Numbering_FromString")
195  use, intrinsic :: iso_c_binding
196  import kim_numbering_type
197  implicit none
198  character(c_char), intent(in) :: string(*)
199  end function from_string
200  end interface
201  character(len=*, kind=c_char), intent(in) :: string
202  type(kim_numbering_type), intent(out) :: numbering
203 
204  numbering = from_string(trim(string)//c_null_char)
205  end subroutine kim_numbering_from_string
206 
212  recursive subroutine kim_numbering_to_string(numbering, string)
213  use kim_convert_string_module, only : kim_convert_c_char_ptr_to_string
214  implicit none
215  interface
216  type(c_ptr) recursive function get_string(numbering) &
217  bind(c, name="KIM_Numbering_ToString")
218  use, intrinsic :: iso_c_binding
219  import kim_numbering_type
220  implicit none
221  type(kim_numbering_type), intent(in), value :: numbering
222  end function get_string
223  end interface
224  type(kim_numbering_type), intent(in) :: numbering
225  character(len=*, kind=c_char), intent(out) :: string
226 
227  type(c_ptr) :: p
228 
229  p = get_string(numbering)
230  call kim_convert_c_char_ptr_to_string(p, string)
231  end subroutine kim_numbering_to_string
232 
239  recursive subroutine kim_get_number_of_numberings(number_of_numberings)
240  implicit none
241  interface
242  recursive subroutine get_number_of_numberings(number_of_numberings) &
243  bind(c, name="KIM_NUMBERING_GetNumberOfNumberings")
244  use, intrinsic :: iso_c_binding
245  implicit none
246  integer(c_int), intent(out) :: number_of_numberings
247  end subroutine get_number_of_numberings
248  end interface
249  integer(c_int), intent(out) :: number_of_numberings
250 
251  call get_number_of_numberings(number_of_numberings)
252  end subroutine kim_get_number_of_numberings
253 
259  recursive subroutine kim_get_numbering(index, numbering, ierr)
260  implicit none
261  interface
262  integer(c_int) recursive function get_numbering(index, numbering) &
263  bind(c, name="KIM_NUMBERING_GetNumbering")
264  use, intrinsic :: iso_c_binding
265  import kim_numbering_type
266  implicit none
267  integer(c_int), intent(in), value :: index
268  type(kim_numbering_type), intent(out) :: numbering
269  end function get_numbering
270  end interface
271  integer(c_int), intent(in) :: index
272  type(kim_numbering_type), intent(out) :: numbering
273  integer(c_int), intent(out) :: ierr
274 
275  ierr = get_numbering(index-1, numbering)
276  end subroutine kim_get_numbering
277 end module kim_numbering_module
type(kim_numbering_type), save, public, protected kim_numbering_one_based
An Extensible Enumeration for the Numbering's supported by the KIM API.
type(kim_numbering_type), save, public, protected kim_numbering_zero_based
recursive subroutine, public kim_get_number_of_numberings(number_of_numberings)
Get the number of standard Numbering's defined by the KIM API.
recursive subroutine, public kim_get_numbering(index, numbering, ierr)
Get the identity of each defined standard Numbering.