kim-api 2.3.0+AppleClang.AppleClang.GNU
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
Loading...
Searching...
No Matches
kim_energy_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-2.3.0 package.
28!
29
36 use, intrinsic :: iso_c_binding
37 implicit none
38 private
39
40 public &
41 ! Derived types
43 ! Constants
51 ! Routines
52 kim_known, &
53 operator(.eq.), &
54 operator(.ne.), &
59
65 type, bind(c) :: kim_energy_unit_type
71 integer(c_int) energy_unit_id
73
79 type(kim_energy_unit_type), protected, save, &
80 bind(c, name="KIM_ENERGY_UNIT_unused") &
82
88 type(kim_energy_unit_type), protected, save, &
89 bind(c, name="KIM_ENERGY_UNIT_amu_A2_per_ps2") &
91
97 type(kim_energy_unit_type), protected, save, &
98 bind(c, name="KIM_ENERGY_UNIT_erg") &
100
106 type(kim_energy_unit_type), protected, save, &
107 bind(c, name="KIM_ENERGY_UNIT_eV") &
109
115 type(kim_energy_unit_type), protected, save, &
116 bind(c, name="KIM_ENERGY_UNIT_Hartree") &
118
124 type(kim_energy_unit_type), protected, save, &
125 bind(c, name="KIM_ENERGY_UNIT_J") &
127
133 type(kim_energy_unit_type), protected, save, &
134 bind(c, name="KIM_ENERGY_UNIT_kcal_mol") &
136
142 interface kim_known
143 module procedure kim_energy_unit_known
144 end interface kim_known
145
151 interface operator(.eq.)
152 module procedure kim_energy_unit_equal
153 end interface operator(.eq.)
154
160 interface operator(.ne.)
161 module procedure kim_energy_unit_not_equal
162 end interface operator(.ne.)
163
171 module procedure kim_energy_unit_from_string
172 end interface kim_from_string
173
180 module procedure kim_energy_unit_to_string
181 end interface kim_to_string
182
183contains
189 logical recursive function kim_energy_unit_known(energy_unit)
190 implicit none
191 interface
192 integer(c_int) recursive function known(energy_unit) &
193 bind(c, name="KIM_EnergyUnit_Known")
194 use, intrinsic :: iso_c_binding
196 implicit none
197 type(kim_energy_unit_type), intent(in), value :: energy_unit
198 end function known
199 end interface
200 type(kim_energy_unit_type), intent(in) :: energy_unit
201
202 kim_energy_unit_known = (known(energy_unit) /= 0)
203 end function kim_energy_unit_known
204
210 logical recursive function kim_energy_unit_equal(lhs, rhs)
211 implicit none
212 type(kim_energy_unit_type), intent(in) :: lhs
213 type(kim_energy_unit_type), intent(in) :: rhs
214
215 kim_energy_unit_equal &
216 = (lhs%energy_unit_id == rhs%energy_unit_id)
217 end function kim_energy_unit_equal
218
224 logical recursive function kim_energy_unit_not_equal(lhs, rhs)
225 implicit none
226 type(kim_energy_unit_type), intent(in) :: lhs
227 type(kim_energy_unit_type), intent(in) :: rhs
228
229 kim_energy_unit_not_equal = .not. (lhs == rhs)
230 end function kim_energy_unit_not_equal
231
238 recursive subroutine kim_energy_unit_from_string(string, energy_unit)
239 implicit none
240 interface
241 type(kim_energy_unit_type) recursive function from_string(string) &
242 bind(c, name="KIM_EnergyUnit_FromString")
243 use, intrinsic :: iso_c_binding
245 implicit none
246 character(c_char), intent(in) :: string(*)
247 end function from_string
248 end interface
249 character(len=*, kind=c_char), intent(in) :: string
250 type(kim_energy_unit_type), intent(out) :: energy_unit
251
252 energy_unit = from_string(trim(string)//c_null_char)
253 end subroutine kim_energy_unit_from_string
254
260 recursive subroutine kim_energy_unit_to_string(energy_unit, string)
261 use kim_convert_string_module, only: kim_convert_c_char_ptr_to_string
262 implicit none
263 interface
264 type(c_ptr) recursive function get_string(energy_unit) &
265 bind(c, name="KIM_EnergyUnit_ToString")
266 use, intrinsic :: iso_c_binding
268 implicit none
269 type(kim_energy_unit_type), intent(in), value :: energy_unit
270 end function get_string
271 end interface
272 type(kim_energy_unit_type), intent(in) :: energy_unit
273 character(len=*, kind=c_char), intent(out) :: string
274
275 type(c_ptr) :: p
276
277 p = get_string(energy_unit)
278 call kim_convert_c_char_ptr_to_string(p, string)
279 end subroutine kim_energy_unit_to_string
280
287 recursive subroutine kim_get_number_of_energy_units(number_of_energy_units)
288 implicit none
289 interface
290 recursive subroutine get_number_of_energy_units(number_of_energy_units) &
291 bind(c, name="KIM_ENERGY_UNIT_GetNumberOfEnergyUnits")
292 use, intrinsic :: iso_c_binding
293 integer(c_int), intent(out) :: number_of_energy_units
294 end subroutine get_number_of_energy_units
295 end interface
296 integer(c_int), intent(out) :: number_of_energy_units
297
298 call get_number_of_energy_units(number_of_energy_units)
299 end subroutine kim_get_number_of_energy_units
300
306 recursive subroutine kim_get_energy_unit(index, energy_unit, ierr)
307 implicit none
308 interface
309 integer(c_int) recursive function get_energy_unit(index, energy_unit) &
310 bind(c, name="KIM_ENERGY_UNIT_GetEnergyUnit")
311 use, intrinsic :: iso_c_binding
313 implicit none
314 integer(c_int), intent(in), value :: index
315 type(kim_energy_unit_type), intent(out) :: energy_unit
316 end function get_energy_unit
317 end interface
318 integer(c_int), intent(in) :: index
319 type(kim_energy_unit_type), intent(out) :: energy_unit
320 integer(c_int), intent(out) :: ierr
321
322 ierr = get_energy_unit(index - 1, energy_unit)
323 end subroutine kim_get_energy_unit
324end module kim_energy_unit_module
Create an EnergyUnit object corresponding to the provided string. If the string does not match one of...
Determines if the object is a quantity known to the KIM API.
An Extensible Enumeration for the EnergyUnit's supported by the KIM API.
type(kim_energy_unit_type), save, bind(C, name="KIM_ENERGY_UNIT_erg"), public, protected kim_energy_unit_erg
The standard erg unit of energy.
type(kim_energy_unit_type), save, bind(C, name="KIM_ENERGY_UNIT_unused"), public, protected kim_energy_unit_unused
Indicates that a EnergyUnit is not used.
type(kim_energy_unit_type), save, bind(C, name="KIM_ENERGY_UNIT_Hartree"), public, protected kim_energy_unit_hartree
The standard Hartree unit of energy.
recursive subroutine, public kim_get_number_of_energy_units(number_of_energy_units)
Get the number of standard EnergyUnit's defined by the KIM API.
recursive subroutine, public kim_get_energy_unit(index, energy_unit, ierr)
Get the identity of each defined standard EnergyUnit.
type(kim_energy_unit_type), save, bind(C, name="KIM_ENERGY_UNIT_J"), public, protected kim_energy_unit_j
The standard Joule unit of energy.
type(kim_energy_unit_type), save, bind(C, name="KIM_ENERGY_UNIT_amu_A2_per_ps2"), public, protected kim_energy_unit_amu_a2_per_ps2
The standard amu*A /ps unit of energy.
type(kim_energy_unit_type), save, bind(C, name="KIM_ENERGY_UNIT_eV"), public, protected kim_energy_unit_ev
The standard electronvolt unit of energy.
type(kim_energy_unit_type), save, bind(C, name="KIM_ENERGY_UNIT_kcal_mol"), public, protected kim_energy_unit_kcal_mol
The standard kilocalorie per mole unit of energy.
An Extensible Enumeration for the EnergyUnit's supported by the KIM API.