| 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::ChargeUnit |
| 31 |
!! |
| 32 |
!! \sa KIM::ChargeUnit, KIM_ChargeUnit |
| 33 |
!! |
| 34 |
!! \since 2.0 |
| 35 |
module kim_charge_unit_module |
| 36 |
use, intrinsic :: iso_c_binding |
| 37 |
implicit none |
| 38 |
private |
| 39 |
|
| 40 |
public & |
| 41 |
! Derived types |
| 42 |
kim_charge_unit_type, & |
| 43 |
! Constants |
| 44 |
KIM_CHARGE_UNIT_UNUSED, & |
| 45 |
KIM_CHARGE_UNIT_C, & |
| 46 |
KIM_CHARGE_UNIT_E, & |
| 47 |
KIM_CHARGE_UNIT_STATC, & |
| 48 |
! Routines |
| 49 |
kim_known, & |
| 50 |
operator(.eq.), & |
| 51 |
operator(.ne.), & |
| 52 |
kim_from_string, & |
| 53 |
kim_to_string, & |
| 54 |
kim_get_number_of_charge_units, & |
| 55 |
kim_get_charge_unit |
| 56 |
|
| 57 |
!> \brief \copybrief KIM::ChargeUnit |
| 58 |
!! |
| 59 |
!! \sa KIM::ChargeUnit, KIM_ChargeUnit |
| 60 |
!! |
| 61 |
!! \since 2.0 |
| 62 |
type, bind(c) :: kim_charge_unit_type |
| 63 |
!> \brief \copybrief KIM::ChargeUnit::chargeUnitID |
| 64 |
!! |
| 65 |
!! \sa KIM::ChargeUnit::chargeUnitID, KIM_ChargeUnit::chargeUnitID |
| 66 |
!! |
| 67 |
!! \since 2.0 |
| 68 |
integer(c_int) charge_unit_id |
| 69 |
end type kim_charge_unit_type |
| 70 |
|
| 71 |
!> \brief \copybrief KIM::CHARGE_UNIT::unused |
| 72 |
!! |
| 73 |
!! \sa KIM::CHARGE_UNIT::unused, KIM_CHARGE_UNIT_unused |
| 74 |
!! |
| 75 |
!! \since 2.0 |
| 76 |
type(kim_charge_unit_type), protected, save, & |
| 77 |
bind(c, name="KIM_CHARGE_UNIT_unused") & |
| 78 |
:: KIM_CHARGE_UNIT_UNUSED |
| 79 |
|
| 80 |
!> \brief \copybrief KIM::CHARGE_UNIT::C |
| 81 |
!! |
| 82 |
!! \sa KIM::CHARGE_UNIT::C, KIM_CHARGE_UNIT_C |
| 83 |
!! |
| 84 |
!! \since 2.0 |
| 85 |
type(kim_charge_unit_type), protected, save, & |
| 86 |
bind(c, name="KIM_CHARGE_UNIT_c") & |
| 87 |
:: KIM_CHARGE_UNIT_C |
| 88 |
|
| 89 |
!> \brief \copybrief KIM::CHARGE_UNIT::e |
| 90 |
!! |
| 91 |
!! \sa KIM::CHARGE_UNIT::e, KIM_CHARGE_UNIT_e |
| 92 |
!! |
| 93 |
!! \since 2.0 |
| 94 |
type(kim_charge_unit_type), protected, save, & |
| 95 |
bind(c, name="KIM_CHARGE_UNIT_e") & |
| 96 |
:: KIM_CHARGE_UNIT_E |
| 97 |
|
| 98 |
!> \brief \copybrief KIM::CHARGE_UNIT::statC |
| 99 |
!! |
| 100 |
!! \sa KIM::CHARGE_UNIT::statC, KIM_CHARGE_UNIT_statC |
| 101 |
!! |
| 102 |
!! \since 2.0 |
| 103 |
type(kim_charge_unit_type), protected, save, & |
| 104 |
bind(c, name="KIM_CHARGE_UNIT_statC") & |
| 105 |
:: KIM_CHARGE_UNIT_STATC |
| 106 |
|
| 107 |
!> \brief \copybrief KIM::ChargeUnit::Known |
| 108 |
!! |
| 109 |
!! \sa KIM::ChargeUnit::Known, KIM_ChargeUnit_Known |
| 110 |
!! |
| 111 |
!! \since 2.0 |
| 112 |
interface kim_known |
| 113 |
module procedure kim_charge_unit_known |
| 114 |
end interface kim_known |
| 115 |
|
| 116 |
!> \brief \copybrief KIM::ChargeUnit::operator==() |
| 117 |
!! |
| 118 |
!! \sa KIM::ChargeUnit::operator==(), KIM_ChargeUnit_Equal |
| 119 |
!! |
| 120 |
!! \since 2.0 |
| 121 |
interface operator(.eq.) |
| 122 |
module procedure kim_charge_unit_equal |
| 123 |
end interface operator(.eq.) |
| 124 |
|
| 125 |
!> \brief \copybrief KIM::ChargeUnit::operator!=() |
| 126 |
!! |
| 127 |
!! \sa KIM::ChargeUnit::operator!=(), KIM_ChargeUnit_NotEqual |
| 128 |
!! |
| 129 |
!! \since 2.0 |
| 130 |
interface operator(.ne.) |
| 131 |
module procedure kim_charge_unit_not_equal |
| 132 |
end interface operator(.ne.) |
| 133 |
|
| 134 |
!> \brief \copybrief KIM::ChargeUnit::ChargeUnit(std::string const &) |
| 135 |
!! |
| 136 |
!! \sa KIM::ChargeUnit::ChargeUnit(std::string const &), |
| 137 |
!! KIM_ChargeUnit_FromString |
| 138 |
!! |
| 139 |
!! \since 2.0 |
| 140 |
interface kim_from_string |
| 141 |
module procedure kim_charge_unit_from_string |
| 142 |
end interface kim_from_string |
| 143 |
|
| 144 |
!> \brief \copybrief KIM::ChargeUnit::ToString |
| 145 |
!! |
| 146 |
!! \sa KIM::ChargeUnit::ToString, KIM_ChargeUnit_ToString |
| 147 |
!! |
| 148 |
!! \since 2.0 |
| 149 |
interface kim_to_string |
| 150 |
module procedure kim_charge_unit_to_string |
| 151 |
end interface kim_to_string |
| 152 |
|
| 153 |
contains |
| 154 |
!> \brief \copybrief KIM::ChargeUnit::Known |
| 155 |
!! |
| 156 |
!! \sa KIM::ChargeUnit::Known, KIM_ChargeUnit_Known |
| 157 |
!! |
| 158 |
!! \since 2.0 |
| 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 |
|
| 175 |
!> \brief \copybrief KIM::ChargeUnit::operator==() |
| 176 |
!! |
| 177 |
!! \sa KIM::ChargeUnit::operator==(), KIM_ChargeUnit_Equal |
| 178 |
!! |
| 179 |
!! \since 2.0 |
| 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 |
|
| 189 |
!> \brief \copybrief KIM::ChargeUnit::operator!=() |
| 190 |
!! |
| 191 |
!! \sa KIM::ChargeUnit::operator!=(), KIM_ChargeUnit_NotEqual |
| 192 |
!! |
| 193 |
!! \since 2.0 |
| 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 |
|
| 202 |
!> \brief \copybrief KIM::ChargeUnit::ChargeUnit(std::string const &) |
| 203 |
!! |
| 204 |
!! \sa KIM::ChargeUnit::ChargeUnit(std::string const &), |
| 205 |
!! KIM_ChargeUnit_FromString |
| 206 |
!! |
| 207 |
!! \since 2.0 |
| 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 |
|
| 225 |
!> \brief \copybrief KIM::ChargeUnit::ToString |
| 226 |
!! |
| 227 |
!! \sa KIM::ChargeUnit::ToString, KIM_ChargeUnit_ToString |
| 228 |
!! |
| 229 |
!! \since 2.0 |
| 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 |
|
| 251 |
!> \brief \copybrief KIM::CHARGE_UNIT::GetNumberOfChargeUnits |
| 252 |
!! |
| 253 |
!! \sa KIM::CHARGE_UNIT::GetNumberOfChargeUnits, |
| 254 |
!! KIM_CHARGE_UNIT_GetNumberOfChargeUnits |
| 255 |
!! |
| 256 |
!! \since 2.0 |
| 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 |
|
| 272 |
!> \brief \copybrief KIM::CHARGE_UNIT::GetChargeUnit |
| 273 |
!! |
| 274 |
!! \sa KIM::CHARGE_UNIT::GetChargeUnit, KIM_CHARGE_UNIT_GetChargeUnit |
| 275 |
!! |
| 276 |
!! \since 2.0 |
| 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 |