Debian Codegraph @

fortran/include/kim_energy_unit_module.f90

raw
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
30 !> \brief \copybrief KIM::EnergyUnit
31 !!
32 !! \sa KIM::EnergyUnit, KIM_EnergyUnit
33 !!
34 !! \since 2.0
35 module kim_energy_unit_module
36 use, intrinsic :: iso_c_binding
37 implicit none
38 private
39
40 public &
41 ! Derived types
42 kim_energy_unit_type, &
43 ! Constants
44 KIM_ENERGY_UNIT_UNUSED, &
45 KIM_ENERGY_UNIT_AMU_A2_PER_PS2, &
46 KIM_ENERGY_UNIT_ERG, &
47 KIM_ENERGY_UNIT_EV, &
48 KIM_ENERGY_UNIT_HARTREE, &
49 KIM_ENERGY_UNIT_J, &
50 KIM_ENERGY_UNIT_KCAL_MOL, &
51 ! Routines
52 kim_known, &
53 operator(.eq.), &
54 operator(.ne.), &
55 kim_from_string, &
56 kim_to_string, &
57 kim_get_number_of_energy_units, &
58 kim_get_energy_unit
59
60 !> \brief \copybrief KIM::EnergyUnit
61 !!
62 !! \sa KIM::EnergyUnit, KIM_EnergyUnit
63 !!
64 !! \since 2.0
65 type, bind(c) :: kim_energy_unit_type
66 !> \brief \copybrief KIM::EnergyUnit::energyUnitID
67 !!
68 !! \sa KIM::EnergyUnit::energyUnitID, KIM_EnergyUnit::energyUnitID
69 !!
70 !! \since 2.0
71 integer(c_int) energy_unit_id
72 end type kim_energy_unit_type
73
74 !> \brief \copybrief KIM::ENERGY_UNIT::unused
75 !!
76 !! \sa KIM::ENERGY_UNIT::unused, KIM_ENERGY_UNIT_unused
77 !!
78 !! \since 2.0
79 type(kim_energy_unit_type), protected, save, &
80 bind(c, name="KIM_ENERGY_UNIT_unused") &
81 :: KIM_ENERGY_UNIT_UNUSED
82
83 !> \brief \copybrief KIM::ENERGY_UNIT::amu_A2_per_ps2
84 !!
85 !! \sa KIM::ENERGY_UNIT::amu_A2_per_ps2, KIM_ENERGY_UNIT_amu_A2_per_ps2
86 !!
87 !! \since 2.0
88 type(kim_energy_unit_type), protected, save, &
89 bind(c, name="KIM_ENERGY_UNIT_amu_A2_per_ps2") &
90 :: KIM_ENERGY_UNIT_AMU_A2_PER_PS2
91
92 !> \brief \copybrief KIM::ENERGY_UNIT::erg
93 !!
94 !! \sa KIM::ENERGY_UNIT::erg, KIM_ENERGY_UNIT_erg
95 !!
96 !! \since 2.0
97 type(kim_energy_unit_type), protected, save, &
98 bind(c, name="KIM_ENERGY_UNIT_erg") &
99 :: KIM_ENERGY_UNIT_ERG
100
101 !> \brief \copybrief KIM::ENERGY_UNIT::eV
102 !!
103 !! \sa KIM::ENERGY_UNIT::eV, KIM_ENERGY_UNIT_eV
104 !!
105 !! \since 2.0
106 type(kim_energy_unit_type), protected, save, &
107 bind(c, name="KIM_ENERGY_UNIT_eV") &
108 :: KIM_ENERGY_UNIT_EV
109
110 !> \brief \copybrief KIM::ENERGY_UNIT::Hartree
111 !!
112 !! \sa KIM::ENERGY_UNIT::Hartree, KIM_ENERGY_UNIT_Hartree
113 !!
114 !! \since 2.0
115 type(kim_energy_unit_type), protected, save, &
116 bind(c, name="KIM_ENERGY_UNIT_Hartree") &
117 :: KIM_ENERGY_UNIT_HARTREE
118
119 !> \brief \copybrief KIM::ENERGY_UNIT::J
120 !!
121 !! \sa KIM::ENERGY_UNIT::J, KIM_ENERGY_UNIT_J
122 !!
123 !! \since 2.0
124 type(kim_energy_unit_type), protected, save, &
125 bind(c, name="KIM_ENERGY_UNIT_J") &
126 :: KIM_ENERGY_UNIT_J
127
128 !> \brief \copybrief KIM::ENERGY_UNIT::kcal_mol
129 !!
130 !! \sa KIM::ENERGY_UNIT::kcal_mol, KIM_ENERGY_UNIT_kcal_mol
131 !!
132 !! \since 2.0
133 type(kim_energy_unit_type), protected, save, &
134 bind(c, name="KIM_ENERGY_UNIT_kcal_mol") &
135 :: KIM_ENERGY_UNIT_KCAL_MOL
136
137 !> \brief \copybrief KIM::EnergyUnit::Known
138 !!
139 !! \sa KIM::EnergyUnit::Known, KIM_EnergyUnit_Known
140 !!
141 !! \since 2.0
142 interface kim_known
143 module procedure kim_energy_unit_known
144 end interface kim_known
145
146 !> \brief \copybrief KIM::EnergyUnit::operator==()
147 !!
148 !! \sa KIM::EnergyUnit::operator==(), KIM_EnergyUnit_Equal
149 !!
150 !! \since 2.0
151 interface operator(.eq.)
152 module procedure kim_energy_unit_equal
153 end interface operator(.eq.)
154
155 !> \brief \copybrief KIM::EnergyUnit::operator!=()
156 !!
157 !! \sa KIM::EnergyUnit::operator!=(), KIM_EnergyUnit_NotEqual
158 !!
159 !! \since 2.0
160 interface operator(.ne.)
161 module procedure kim_energy_unit_not_equal
162 end interface operator(.ne.)
163
164 !> \brief \copybrief KIM::EnergyUnit::EnergyUnit(std::string const &)
165 !!
166 !! \sa KIM::EnergyUnit::EnergyUnit(std::string const &),
167 !! KIM_EnergyUnit_FromString
168 !!
169 !! \since 2.0
170 interface kim_from_string
171 module procedure kim_energy_unit_from_string
172 end interface kim_from_string
173
174 !> \brief \copybrief KIM::EnergyUnit::ToString
175 !!
176 !! \sa KIM::EnergyUnit::ToString, KIM_EnergyUnit_ToString
177 !!
178 !! \since 2.0
179 interface kim_to_string
180 module procedure kim_energy_unit_to_string
181 end interface kim_to_string
182
183 contains
184 !> \brief \copybrief KIM::EnergyUnit::Known
185 !!
186 !! \sa KIM::EnergyUnit::Known, KIM_EnergyUnit_Known
187 !!
188 !! \since 2.0
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
195 import kim_energy_unit_type
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
205 !> \brief \copybrief KIM::EnergyUnit::operator==()
206 !!
207 !! \sa KIM::EnergyUnit::operator==(), KIM_EnergyUnit_Equal
208 !!
209 !! \since 2.0
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
219 !> \brief \copybrief KIM::EnergyUnit::operator!=()
220 !!
221 !! \sa KIM::EnergyUnit::operator!=(), KIM_EnergyUnit_NotEqual
222 !!
223 !! \since 2.0
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
232 !> \brief \copybrief KIM::EnergyUnit::EnergyUnit(std::string const &)
233 !!
234 !! \sa KIM::EnergyUnit::EnergyUnit(std::string const &),
235 !! KIM_EnergyUnit_FromString
236 !!
237 !! \since 2.0
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
244 import kim_energy_unit_type
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
255 !> \brief \copybrief KIM::EnergyUnit::ToString
256 !!
257 !! \sa KIM::EnergyUnit::ToString, KIM_EnergyUnit_ToString
258 !!
259 !! \since 2.0
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
267 import kim_energy_unit_type
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
281 !> \brief \copybrief KIM::ENERGY_UNIT::GetNumberOfEnergyUnits
282 !!
283 !! \sa KIM::ENERGY_UNIT::GetNumberOfEnergyUnits,
284 !! KIM_ENERGY_UNIT_GetNumberOfEnergyUnits
285 !!
286 !! \since 2.0
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
301 !> \brief \copybrief KIM::ENERGY_UNIT::GetEnergyUnit
302 !!
303 !! \sa KIM::ENERGY_UNIT::GetEnergyUnit, KIM_ENERGY_UNIT_GetEnergyUnit
304 !!
305 !! \since 2.0
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
312 import kim_energy_unit_type
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
324 end module kim_energy_unit_module