kim-api  2.3.1-git+v2.3.0-git-2-g378406f9.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 ! KIM-API: An API for interatomic models
3 ! Copyright (c) 2013--2022, Regents of the University of Minnesota.
4 ! All rights reserved.
5 !
6 ! Contributors:
7 ! Ryan S. Elliott
8 !
9 ! SPDX-License-Identifier: LGPL-2.1-or-later
10 !
11 ! This library is free software; you can redistribute it and/or
12 ! modify it under the terms of the GNU Lesser General Public
13 ! License as published by the Free Software Foundation; either
14 ! version 2.1 of the License, or (at your option) any later version.
15 !
16 ! This library is distributed in the hope that it will be useful,
17 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ! Lesser General Public License for more details.
20 !
21 ! You should have received a copy of the GNU Lesser General Public License
22 ! along with this library; if not, write to the Free Software Foundation,
23 ! Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 !
25 
26 !
27 ! Release: This file is part of the kim-api.git repository.
28 !
29 
36  use, intrinsic :: iso_c_binding
37  implicit none
38  private
39 
40  public &
41  ! Derived types
42  kim_charge_unit_type, &
43  ! Constants
48  ! Routines
49  kim_known, &
50  operator(.eq.), &
51  operator(.ne.), &
52  kim_from_string, &
53  kim_to_string, &
56 
62  type, bind(c) :: kim_charge_unit_type
68  integer(c_int) charge_unit_id
69  end type kim_charge_unit_type
70 
76  type(kim_charge_unit_type), protected, save, &
77  bind(c, name="KIM_CHARGE_UNIT_unused") &
79 
85  type(kim_charge_unit_type), protected, save, &
86  bind(c, name="KIM_CHARGE_UNIT_c") &
88 
94  type(kim_charge_unit_type), protected, save, &
95  bind(c, name="KIM_CHARGE_UNIT_e") &
97 
103  type(kim_charge_unit_type), protected, save, &
104  bind(c, name="KIM_CHARGE_UNIT_statC") &
106 
112  interface kim_known
113  module procedure kim_charge_unit_known
114  end interface kim_known
115 
121  interface operator(.eq.)
122  module procedure kim_charge_unit_equal
123  end interface operator(.eq.)
124 
130  interface operator(.ne.)
131  module procedure kim_charge_unit_not_equal
132  end interface operator(.ne.)
133 
140  interface kim_from_string
141  module procedure kim_charge_unit_from_string
142  end interface kim_from_string
143 
149  interface kim_to_string
150  module procedure kim_charge_unit_to_string
151  end interface kim_to_string
152 
153 contains
159  logical recursive function kim_charge_unit_known(charge_unit)
160  implicit none
161  interface
162  integer(c_int) recursive function known(charge_unit) &
163  bind(c, name="KIM_ChargeUnit_Known")
164  use, intrinsic :: iso_c_binding
165  import kim_charge_unit_type
166  implicit none
167  type(kim_charge_unit_type), intent(in), value :: charge_unit
168  end function known
169  end interface
170  type(kim_charge_unit_type), intent(in) :: charge_unit
171 
172  kim_charge_unit_known = (known(charge_unit) /= 0)
173  end function kim_charge_unit_known
174 
180  logical recursive function kim_charge_unit_equal(lhs, rhs)
181  implicit none
182  type(kim_charge_unit_type), intent(in) :: lhs
183  type(kim_charge_unit_type), intent(in) :: rhs
184 
185  kim_charge_unit_equal &
186  = (lhs%charge_unit_id == rhs%charge_unit_id)
187  end function kim_charge_unit_equal
188 
194  logical recursive function kim_charge_unit_not_equal(lhs, rhs)
195  implicit none
196  type(kim_charge_unit_type), intent(in) :: lhs
197  type(kim_charge_unit_type), intent(in) :: rhs
198 
199  kim_charge_unit_not_equal = .not. (lhs == rhs)
200  end function kim_charge_unit_not_equal
201 
208  recursive subroutine kim_charge_unit_from_string(string, charge_unit)
209  implicit none
210  interface
211  type(kim_charge_unit_type) recursive function from_string(string) &
212  bind(c, name="KIM_ChargeUnit_FromString")
213  use, intrinsic :: iso_c_binding
214  import kim_charge_unit_type
215  implicit none
216  character(c_char), intent(in) :: string(*)
217  end function from_string
218  end interface
219  character(len=*, kind=c_char), intent(in) :: string
220  type(kim_charge_unit_type), intent(out) :: charge_unit
221 
222  charge_unit = from_string(trim(string)//c_null_char)
223  end subroutine kim_charge_unit_from_string
224 
230  recursive subroutine kim_charge_unit_to_string(charge_unit, string)
231  use kim_convert_string_module, only: kim_convert_c_char_ptr_to_string
232  implicit none
233  interface
234  type(c_ptr) recursive function get_string(charge_unit) &
235  bind(c, name="KIM_ChargeUnit_ToString")
236  use, intrinsic :: iso_c_binding
237  import kim_charge_unit_type
238  implicit none
239  type(kim_charge_unit_type), intent(in), value :: charge_unit
240  end function get_string
241  end interface
242  type(kim_charge_unit_type), intent(in) :: charge_unit
243  character(len=*, kind=c_char), intent(out) :: string
244 
245  type(c_ptr) :: p
246 
247  p = get_string(charge_unit)
248  call kim_convert_c_char_ptr_to_string(p, string)
249  end subroutine kim_charge_unit_to_string
250 
257  recursive subroutine kim_get_number_of_charge_units(number_of_charge_units)
258  implicit none
259  interface
260  recursive subroutine get_number_of_charge_units(number_of_charge_units) &
261  bind(c, name="KIM_CHARGE_UNIT_GetNumberOfChargeUnits")
262  use, intrinsic :: iso_c_binding
263  implicit none
264  integer(c_int), intent(out) :: number_of_charge_units
265  end subroutine get_number_of_charge_units
266  end interface
267  integer(c_int), intent(out) :: number_of_charge_units
268 
269  call get_number_of_charge_units(number_of_charge_units)
270  end subroutine kim_get_number_of_charge_units
271 
277  recursive subroutine kim_get_charge_unit(index, charge_unit, ierr)
278  implicit none
279  interface
280  integer(c_int) recursive function get_charge_unit(index, charge_unit) &
281  bind(c, name="KIM_CHARGE_UNIT_GetChargeUnit")
282  use, intrinsic :: iso_c_binding
283  import kim_charge_unit_type
284  implicit none
285  integer(c_int), intent(in), value :: index
286  type(kim_charge_unit_type), intent(out) :: charge_unit
287  end function get_charge_unit
288  end interface
289  integer(c_int), intent(in) :: index
290  type(kim_charge_unit_type), intent(out) :: charge_unit
291  integer(c_int), intent(out) :: ierr
292 
293  ierr = get_charge_unit(index - 1, charge_unit)
294  end subroutine kim_get_charge_unit
295 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