kim-api  2.2.1+v2.2.1.GNU.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--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_numbering_type, &
46  ! Constants
49  ! Routines
50  kim_known, &
51  operator(.eq.), &
52  operator(.ne.), &
53  kim_from_string, &
54  kim_to_string, &
57 
63  type, bind(c) :: kim_numbering_type
64  integer(c_int) :: numbering_id
65  end type kim_numbering_type
66 
72  type(kim_numbering_type), protected, save, &
73  bind(c, name="KIM_NUMBERING_zeroBased") &
75 
81  type(kim_numbering_type), protected, save, &
82  bind(c, name="KIM_NUMBERING_oneBased") &
84 
90  interface kim_known
91  module procedure kim_numbering_known
92  end interface kim_known
93 
99  interface operator(.eq.)
100  module procedure kim_numbering_equal
101  end interface operator(.eq.)
102 
108  interface operator(.ne.)
109  module procedure kim_numbering_not_equal
110  end interface operator(.ne.)
111 
118  interface kim_from_string
119  module procedure kim_numbering_from_string
120  end interface kim_from_string
121 
127  interface kim_to_string
128  module procedure kim_numbering_to_string
129  end interface kim_to_string
130 
131 contains
137  logical recursive function kim_numbering_known(numbering)
138  implicit none
139  interface
140  integer(c_int) recursive function known(numbering) &
141  bind(c, name="KIM_Numbering_Known")
142  use, intrinsic :: iso_c_binding
143  import kim_numbering_type
144  implicit none
145  type(kim_numbering_type), intent(in), value :: numbering
146  end function known
147  end interface
148  type(kim_numbering_type), intent(in) :: numbering
149 
150  kim_numbering_known = (known(numbering) /= 0)
151  end function kim_numbering_known
152 
158  logical recursive function kim_numbering_equal(lhs, rhs)
159  implicit none
160  type(kim_numbering_type), intent(in) :: lhs
161  type(kim_numbering_type), intent(in) :: rhs
162 
163  kim_numbering_equal = (lhs%numbering_id == rhs%numbering_id)
164  end function kim_numbering_equal
165 
171  logical recursive function kim_numbering_not_equal(lhs, rhs)
172  implicit none
173  type(kim_numbering_type), intent(in) :: lhs
174  type(kim_numbering_type), intent(in) :: rhs
175 
176  kim_numbering_not_equal = .not. (lhs == rhs)
177  end function kim_numbering_not_equal
178 
185  recursive subroutine kim_numbering_from_string(string, numbering)
186  implicit none
187  interface
188  type(kim_numbering_type) recursive function from_string(string) &
189  bind(c, name="KIM_Numbering_FromString")
190  use, intrinsic :: iso_c_binding
191  import kim_numbering_type
192  implicit none
193  character(c_char), intent(in) :: string(*)
194  end function from_string
195  end interface
196  character(len=*, kind=c_char), intent(in) :: string
197  type(kim_numbering_type), intent(out) :: numbering
198 
199  numbering = from_string(trim(string)//c_null_char)
200  end subroutine kim_numbering_from_string
201 
207  recursive subroutine kim_numbering_to_string(numbering, string)
208  use kim_convert_string_module, only: kim_convert_c_char_ptr_to_string
209  implicit none
210  interface
211  type(c_ptr) recursive function get_string(numbering) &
212  bind(c, name="KIM_Numbering_ToString")
213  use, intrinsic :: iso_c_binding
214  import kim_numbering_type
215  implicit none
216  type(kim_numbering_type), intent(in), value :: numbering
217  end function get_string
218  end interface
219  type(kim_numbering_type), intent(in) :: numbering
220  character(len=*, kind=c_char), intent(out) :: string
221 
222  type(c_ptr) :: p
223 
224  p = get_string(numbering)
225  call kim_convert_c_char_ptr_to_string(p, string)
226  end subroutine kim_numbering_to_string
227 
234  recursive subroutine kim_get_number_of_numberings(number_of_numberings)
235  implicit none
236  interface
237  recursive subroutine get_number_of_numberings(number_of_numberings) &
238  bind(c, name="KIM_NUMBERING_GetNumberOfNumberings")
239  use, intrinsic :: iso_c_binding
240  implicit none
241  integer(c_int), intent(out) :: number_of_numberings
242  end subroutine get_number_of_numberings
243  end interface
244  integer(c_int), intent(out) :: number_of_numberings
245 
246  call get_number_of_numberings(number_of_numberings)
247  end subroutine kim_get_number_of_numberings
248 
254  recursive subroutine kim_get_numbering(index, numbering, ierr)
255  implicit none
256  interface
257  integer(c_int) recursive function get_numbering(index, numbering) &
258  bind(c, name="KIM_NUMBERING_GetNumbering")
259  use, intrinsic :: iso_c_binding
260  import kim_numbering_type
261  implicit none
262  integer(c_int), intent(in), value :: index
263  type(kim_numbering_type), intent(out) :: numbering
264  end function get_numbering
265  end interface
266  integer(c_int), intent(in) :: index
267  type(kim_numbering_type), intent(out) :: numbering
268  integer(c_int), intent(out) :: ierr
269 
270  ierr = get_numbering(index - 1, numbering)
271  end subroutine kim_get_numbering
272 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.