kim-api  2.1.2+v2.1.2.GNU
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
kim_charge_unit_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_charge_unit_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_charge_unit_type
75  integer(c_int) charge_unit_id
76  end type kim_charge_unit_type
77 
83  type(kim_charge_unit_type), protected, save, &
84  bind(c, name="KIM_CHARGE_UNIT_unused") &
86 
92  type(kim_charge_unit_type), protected, save, &
93  bind(c, name="KIM_CHARGE_UNIT_c") &
95 
101  type(kim_charge_unit_type), protected, save, &
102  bind(c, name="KIM_CHARGE_UNIT_e") &
104 
110  type(kim_charge_unit_type), protected, save, &
111  bind(c, name="KIM_CHARGE_UNIT_statC") &
113 
119  interface kim_known
120  module procedure kim_charge_unit_known
121  end interface kim_known
122 
128  interface operator (.eq.)
129  module procedure kim_charge_unit_equal
130  end interface operator (.eq.)
131 
137  interface operator (.ne.)
138  module procedure kim_charge_unit_not_equal
139  end interface operator (.ne.)
140 
147  interface kim_from_string
148  module procedure kim_charge_unit_from_string
149  end interface kim_from_string
150 
156  interface kim_to_string
157  module procedure kim_charge_unit_to_string
158  end interface kim_to_string
159 
160 contains
166  logical recursive function kim_charge_unit_known(charge_unit)
167  implicit none
168  interface
169  integer(c_int) recursive function known(charge_unit) &
170  bind(c, name="KIM_ChargeUnit_Known")
171  use, intrinsic :: iso_c_binding
172  import kim_charge_unit_type
173  implicit none
174  type(kim_charge_unit_type), intent(in), value :: charge_unit
175  end function known
176  end interface
177  type(kim_charge_unit_type), intent(in) :: charge_unit
178 
179  kim_charge_unit_known = (known(charge_unit) /= 0)
180  end function kim_charge_unit_known
181 
187  logical recursive function kim_charge_unit_equal(lhs, rhs)
188  implicit none
189  type(kim_charge_unit_type), intent(in) :: lhs
190  type(kim_charge_unit_type), intent(in) :: rhs
191 
192  kim_charge_unit_equal &
193  = (lhs%charge_unit_id .eq. rhs%charge_unit_id)
194  end function kim_charge_unit_equal
195 
201  logical recursive function kim_charge_unit_not_equal(lhs, rhs)
202  implicit none
203  type(kim_charge_unit_type), intent(in) :: lhs
204  type(kim_charge_unit_type), intent(in) :: rhs
205 
206  kim_charge_unit_not_equal = .not. (lhs .eq. rhs)
207  end function kim_charge_unit_not_equal
208 
215  recursive subroutine kim_charge_unit_from_string(string, charge_unit)
216  implicit none
217  interface
218  type(kim_charge_unit_type) recursive function from_string(string) &
219  bind(c, name="KIM_ChargeUnit_FromString")
220  use, intrinsic :: iso_c_binding
221  import kim_charge_unit_type
222  implicit none
223  character(c_char), intent(in) :: string(*)
224  end function from_string
225  end interface
226  character(len=*, kind=c_char), intent(in) :: string
227  type(kim_charge_unit_type), intent(out) :: charge_unit
228 
229  charge_unit = from_string(trim(string)//c_null_char)
230  end subroutine kim_charge_unit_from_string
231 
237  recursive subroutine kim_charge_unit_to_string(charge_unit, string)
238  use kim_convert_string_module, only : kim_convert_c_char_ptr_to_string
239  implicit none
240  interface
241  type(c_ptr) recursive function get_string(charge_unit) &
242  bind(c, name="KIM_ChargeUnit_ToString")
243  use, intrinsic :: iso_c_binding
244  import kim_charge_unit_type
245  implicit none
246  type(kim_charge_unit_type), intent(in), value :: charge_unit
247  end function get_string
248  end interface
249  type(kim_charge_unit_type), intent(in) :: charge_unit
250  character(len=*, kind=c_char), intent(out) :: string
251 
252  type(c_ptr) :: p
253 
254  p = get_string(charge_unit)
255  call kim_convert_c_char_ptr_to_string(p, string)
256  end subroutine kim_charge_unit_to_string
257 
264  recursive subroutine kim_get_number_of_charge_units(number_of_charge_units)
265  implicit none
266  interface
267  recursive subroutine get_number_of_charge_units(number_of_charge_units) &
268  bind(c, name="KIM_CHARGE_UNIT_GetNumberOfChargeUnits")
269  use, intrinsic :: iso_c_binding
270  implicit none
271  integer(c_int), intent(out) :: number_of_charge_units
272  end subroutine get_number_of_charge_units
273  end interface
274  integer(c_int), intent(out) :: number_of_charge_units
275 
276  call get_number_of_charge_units(number_of_charge_units)
277  end subroutine kim_get_number_of_charge_units
278 
284  recursive subroutine kim_get_charge_unit(index, charge_unit, ierr)
285  implicit none
286  interface
287  integer(c_int) recursive function get_charge_unit(index, charge_unit) &
288  bind(c, name="KIM_CHARGE_UNIT_GetChargeUnit")
289  use, intrinsic :: iso_c_binding
290  import kim_charge_unit_type
291  implicit none
292  integer(c_int), intent(in), value :: index
293  type(kim_charge_unit_type), intent(out) :: charge_unit
294  end function get_charge_unit
295  end interface
296  integer(c_int), intent(in) :: index
297  type(kim_charge_unit_type), intent(out) :: charge_unit
298  integer(c_int), intent(out) :: ierr
299 
300  ierr = get_charge_unit(index-1, charge_unit)
301  end subroutine kim_get_charge_unit
302 end module kim_charge_unit_module
type(kim_charge_unit_type), save, public, protected kim_charge_unit_c
type(kim_charge_unit_type), save, public, protected kim_charge_unit_e
recursive subroutine, public kim_get_charge_unit(index, charge_unit, ierr)
Get the identity of each defined standard ChargeUnit.
recursive subroutine, public kim_get_number_of_charge_units(number_of_charge_units)
Get the number of standard ChargeUnit's defined by the KIM API.
An Extensible Enumeration for the ChargeUnit's supported by the KIM API.
type(kim_charge_unit_type), save, public, protected kim_charge_unit_unused
type(kim_charge_unit_type), save, public, protected kim_charge_unit_statc