kim-api  2.2.1+v2.2.1.GNU.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--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_charge_unit_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_charge_unit_type
71  integer(c_int) charge_unit_id
72  end type kim_charge_unit_type
73 
79  type(kim_charge_unit_type), protected, save, &
80  bind(c, name="KIM_CHARGE_UNIT_unused") &
82 
88  type(kim_charge_unit_type), protected, save, &
89  bind(c, name="KIM_CHARGE_UNIT_c") &
91 
97  type(kim_charge_unit_type), protected, save, &
98  bind(c, name="KIM_CHARGE_UNIT_e") &
100 
106  type(kim_charge_unit_type), protected, save, &
107  bind(c, name="KIM_CHARGE_UNIT_statC") &
109 
115  interface kim_known
116  module procedure kim_charge_unit_known
117  end interface kim_known
118 
124  interface operator(.eq.)
125  module procedure kim_charge_unit_equal
126  end interface operator(.eq.)
127 
133  interface operator(.ne.)
134  module procedure kim_charge_unit_not_equal
135  end interface operator(.ne.)
136 
143  interface kim_from_string
144  module procedure kim_charge_unit_from_string
145  end interface kim_from_string
146 
152  interface kim_to_string
153  module procedure kim_charge_unit_to_string
154  end interface kim_to_string
155 
156 contains
162  logical recursive function kim_charge_unit_known(charge_unit)
163  implicit none
164  interface
165  integer(c_int) recursive function known(charge_unit) &
166  bind(c, name="KIM_ChargeUnit_Known")
167  use, intrinsic :: iso_c_binding
168  import kim_charge_unit_type
169  implicit none
170  type(kim_charge_unit_type), intent(in), value :: charge_unit
171  end function known
172  end interface
173  type(kim_charge_unit_type), intent(in) :: charge_unit
174 
175  kim_charge_unit_known = (known(charge_unit) /= 0)
176  end function kim_charge_unit_known
177 
183  logical recursive function kim_charge_unit_equal(lhs, rhs)
184  implicit none
185  type(kim_charge_unit_type), intent(in) :: lhs
186  type(kim_charge_unit_type), intent(in) :: rhs
187 
188  kim_charge_unit_equal &
189  = (lhs%charge_unit_id == rhs%charge_unit_id)
190  end function kim_charge_unit_equal
191 
197  logical recursive function kim_charge_unit_not_equal(lhs, rhs)
198  implicit none
199  type(kim_charge_unit_type), intent(in) :: lhs
200  type(kim_charge_unit_type), intent(in) :: rhs
201 
202  kim_charge_unit_not_equal = .not. (lhs == rhs)
203  end function kim_charge_unit_not_equal
204 
211  recursive subroutine kim_charge_unit_from_string(string, charge_unit)
212  implicit none
213  interface
214  type(kim_charge_unit_type) recursive function from_string(string) &
215  bind(c, name="KIM_ChargeUnit_FromString")
216  use, intrinsic :: iso_c_binding
217  import kim_charge_unit_type
218  implicit none
219  character(c_char), intent(in) :: string(*)
220  end function from_string
221  end interface
222  character(len=*, kind=c_char), intent(in) :: string
223  type(kim_charge_unit_type), intent(out) :: charge_unit
224 
225  charge_unit = from_string(trim(string)//c_null_char)
226  end subroutine kim_charge_unit_from_string
227 
233  recursive subroutine kim_charge_unit_to_string(charge_unit, string)
234  use kim_convert_string_module, only: kim_convert_c_char_ptr_to_string
235  implicit none
236  interface
237  type(c_ptr) recursive function get_string(charge_unit) &
238  bind(c, name="KIM_ChargeUnit_ToString")
239  use, intrinsic :: iso_c_binding
240  import kim_charge_unit_type
241  implicit none
242  type(kim_charge_unit_type), intent(in), value :: charge_unit
243  end function get_string
244  end interface
245  type(kim_charge_unit_type), intent(in) :: charge_unit
246  character(len=*, kind=c_char), intent(out) :: string
247 
248  type(c_ptr) :: p
249 
250  p = get_string(charge_unit)
251  call kim_convert_c_char_ptr_to_string(p, string)
252  end subroutine kim_charge_unit_to_string
253 
260  recursive subroutine kim_get_number_of_charge_units(number_of_charge_units)
261  implicit none
262  interface
263  recursive subroutine get_number_of_charge_units(number_of_charge_units) &
264  bind(c, name="KIM_CHARGE_UNIT_GetNumberOfChargeUnits")
265  use, intrinsic :: iso_c_binding
266  implicit none
267  integer(c_int), intent(out) :: number_of_charge_units
268  end subroutine get_number_of_charge_units
269  end interface
270  integer(c_int), intent(out) :: number_of_charge_units
271 
272  call get_number_of_charge_units(number_of_charge_units)
273  end subroutine kim_get_number_of_charge_units
274 
280  recursive subroutine kim_get_charge_unit(index, charge_unit, ierr)
281  implicit none
282  interface
283  integer(c_int) recursive function get_charge_unit(index, charge_unit) &
284  bind(c, name="KIM_CHARGE_UNIT_GetChargeUnit")
285  use, intrinsic :: iso_c_binding
286  import kim_charge_unit_type
287  implicit none
288  integer(c_int), intent(in), value :: index
289  type(kim_charge_unit_type), intent(out) :: charge_unit
290  end function get_charge_unit
291  end interface
292  integer(c_int), intent(in) :: index
293  type(kim_charge_unit_type), intent(out) :: charge_unit
294  integer(c_int), intent(out) :: ierr
295 
296  ierr = get_charge_unit(index - 1, charge_unit)
297  end subroutine kim_get_charge_unit
298 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