| 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::Numbering |
| 31 |
!! |
| 32 |
!! \sa KIM::Numbering, KIM_Numbering |
| 33 |
!! |
| 34 |
!! \since 2.0 |
| 35 |
module kim_numbering_module |
| 36 |
use, intrinsic :: iso_c_binding |
| 37 |
implicit none |
| 38 |
private |
| 39 |
|
| 40 |
public & |
| 41 |
! Derived types |
| 42 |
kim_numbering_type, & |
| 43 |
! Constants |
| 44 |
KIM_NUMBERING_ZERO_BASED, & |
| 45 |
KIM_NUMBERING_ONE_BASED, & |
| 46 |
! Routines |
| 47 |
kim_known, & |
| 48 |
operator(.eq.), & |
| 49 |
operator(.ne.), & |
| 50 |
kim_from_string, & |
| 51 |
kim_to_string, & |
| 52 |
kim_get_number_of_numberings, & |
| 53 |
kim_get_numbering |
| 54 |
|
| 55 |
!> \brief \copybrief KIM::Numbering |
| 56 |
!! |
| 57 |
!! \sa KIM::Numbering, KIM_Numbering |
| 58 |
!! |
| 59 |
!! \since 2.0 |
| 60 |
type, bind(c) :: kim_numbering_type |
| 61 |
integer(c_int) :: numbering_id |
| 62 |
end type kim_numbering_type |
| 63 |
|
| 64 |
!> \brief \copybrief KIM::NUMBERING::zeroBased |
| 65 |
!! |
| 66 |
!! \sa KIM::NUMBERING::zeroBased, KIM_NUMBERING_zeroBased |
| 67 |
!! |
| 68 |
!! \since 2.0 |
| 69 |
type(kim_numbering_type), protected, save, & |
| 70 |
bind(c, name="KIM_NUMBERING_zeroBased") & |
| 71 |
:: KIM_NUMBERING_ZERO_BASED |
| 72 |
|
| 73 |
!> \brief \copybrief KIM::NUMBERING::oneBased |
| 74 |
!! |
| 75 |
!! \sa KIM::NUMBERING::oneBased, KIM_NUMBERING_oneBased |
| 76 |
!! |
| 77 |
!! \since 2.0 |
| 78 |
type(kim_numbering_type), protected, save, & |
| 79 |
bind(c, name="KIM_NUMBERING_oneBased") & |
| 80 |
:: KIM_NUMBERING_ONE_BASED |
| 81 |
|
| 82 |
!> \brief \copybrief KIM::Numbering::Known |
| 83 |
!! |
| 84 |
!! \sa KIM::Numbering::Known, KIM_Numbering_Known |
| 85 |
!! |
| 86 |
!! \since 2.0 |
| 87 |
interface kim_known |
| 88 |
module procedure kim_numbering_known |
| 89 |
end interface kim_known |
| 90 |
|
| 91 |
!> \brief \copybrief KIM::Numbering::operator==() |
| 92 |
!! |
| 93 |
!! \sa KIM::Numbering::operator==(), KIM_Numbering_Equal |
| 94 |
!! |
| 95 |
!! \since 2.0 |
| 96 |
interface operator(.eq.) |
| 97 |
module procedure kim_numbering_equal |
| 98 |
end interface operator(.eq.) |
| 99 |
|
| 100 |
!> \brief \copybrief KIM::Numbering::operator!=() |
| 101 |
!! |
| 102 |
!! \sa KIM::Numbering::operator!=(), KIM_Numbering_NotEqual |
| 103 |
!! |
| 104 |
!! \since 2.0 |
| 105 |
interface operator(.ne.) |
| 106 |
module procedure kim_numbering_not_equal |
| 107 |
end interface operator(.ne.) |
| 108 |
|
| 109 |
!> \brief \copybrief KIM::Numbering::Numbering(std::string const &) |
| 110 |
!! |
| 111 |
!! \sa KIM::Numbering::Numbering(std::string const &), |
| 112 |
!! KIM_Numbering_FromString |
| 113 |
!! |
| 114 |
!! \since 2.0 |
| 115 |
interface kim_from_string |
| 116 |
module procedure kim_numbering_from_string |
| 117 |
end interface kim_from_string |
| 118 |
|
| 119 |
!> \brief \copybrief KIM::Numbering::ToString |
| 120 |
!! |
| 121 |
!! \sa KIM::Numbering::ToString, KIM_Numbering_ToString |
| 122 |
!! |
| 123 |
!! \since 2.0 |
| 124 |
interface kim_to_string |
| 125 |
module procedure kim_numbering_to_string |
| 126 |
end interface kim_to_string |
| 127 |
|
| 128 |
contains |
| 129 |
!> \brief \copybrief KIM::Numbering::Known |
| 130 |
!! |
| 131 |
!! \sa KIM::Numbering::Known, KIM_Numbering_Known |
| 132 |
!! |
| 133 |
!! \since 2.0 |
| 134 |
logical recursive function kim_numbering_known(numbering) |
| 135 |
implicit none |
| 136 |
interface |
| 137 |
integer(c_int) recursive function known(numbering) & |
| 138 |
bind(c, name="KIM_Numbering_Known") |
| 139 |
use, intrinsic :: iso_c_binding |
| 140 |
import kim_numbering_type |
| 141 |
implicit none |
| 142 |
type(kim_numbering_type), intent(in), value :: numbering |
| 143 |
end function known |
| 144 |
end interface |
| 145 |
type(kim_numbering_type), intent(in) :: numbering |
| 146 |
|
| 147 |
kim_numbering_known = (known(numbering) /= 0) |
| 148 |
end function kim_numbering_known |
| 149 |
|
| 150 |
!> \brief \copybrief KIM::Numbering::operator==() |
| 151 |
!! |
| 152 |
!! \sa KIM::Numbering::operator==(), KIM_Numbering_Equal |
| 153 |
!! |
| 154 |
!! \since 2.0 |
| 155 |
logical recursive function kim_numbering_equal(lhs, rhs) |
| 156 |
implicit none |
| 157 |
type(kim_numbering_type), intent(in) :: lhs |
| 158 |
type(kim_numbering_type), intent(in) :: rhs |
| 159 |
|
| 160 |
kim_numbering_equal = (lhs%numbering_id == rhs%numbering_id) |
| 161 |
end function kim_numbering_equal |
| 162 |
|
| 163 |
!> \brief \copybrief KIM::Numbering::operator!=() |
| 164 |
!! |
| 165 |
!! \sa KIM::Numbering::operator!=(), KIM_Numbering_NotEqual |
| 166 |
!! |
| 167 |
!! \since 2.0 |
| 168 |
logical recursive function kim_numbering_not_equal(lhs, rhs) |
| 169 |
implicit none |
| 170 |
type(kim_numbering_type), intent(in) :: lhs |
| 171 |
type(kim_numbering_type), intent(in) :: rhs |
| 172 |
|
| 173 |
kim_numbering_not_equal = .not. (lhs == rhs) |
| 174 |
end function kim_numbering_not_equal |
| 175 |
|
| 176 |
!> \brief \copybrief KIM::Numbering::Numbering(std::string const &) |
| 177 |
!! |
| 178 |
!! \sa KIM::Numbering::Numbering(std::string const &), |
| 179 |
!! KIM_Numbering_FromString |
| 180 |
!! |
| 181 |
!! \since 2.0 |
| 182 |
recursive subroutine kim_numbering_from_string(string, numbering) |
| 183 |
implicit none |
| 184 |
interface |
| 185 |
type(kim_numbering_type) recursive function from_string(string) & |
| 186 |
bind(c, name="KIM_Numbering_FromString") |
| 187 |
use, intrinsic :: iso_c_binding |
| 188 |
import kim_numbering_type |
| 189 |
implicit none |
| 190 |
character(c_char), intent(in) :: string(*) |
| 191 |
end function from_string |
| 192 |
end interface |
| 193 |
character(len=*, kind=c_char), intent(in) :: string |
| 194 |
type(kim_numbering_type), intent(out) :: numbering |
| 195 |
|
| 196 |
numbering = from_string(trim(string)//c_null_char) |
| 197 |
end subroutine kim_numbering_from_string |
| 198 |
|
| 199 |
!> \brief \copybrief KIM::Numbering::ToString |
| 200 |
!! |
| 201 |
!! \sa KIM::Numbering::ToString, KIM_Numbering_ToString |
| 202 |
!! |
| 203 |
!! \since 2.0 |
| 204 |
recursive subroutine kim_numbering_to_string(numbering, string) |
| 205 |
use kim_convert_string_module, only: kim_convert_c_char_ptr_to_string |
| 206 |
implicit none |
| 207 |
interface |
| 208 |
type(c_ptr) recursive function get_string(numbering) & |
| 209 |
bind(c, name="KIM_Numbering_ToString") |
| 210 |
use, intrinsic :: iso_c_binding |
| 211 |
import kim_numbering_type |
| 212 |
implicit none |
| 213 |
type(kim_numbering_type), intent(in), value :: numbering |
| 214 |
end function get_string |
| 215 |
end interface |
| 216 |
type(kim_numbering_type), intent(in) :: numbering |
| 217 |
character(len=*, kind=c_char), intent(out) :: string |
| 218 |
|
| 219 |
type(c_ptr) :: p |
| 220 |
|
| 221 |
p = get_string(numbering) |
| 222 |
call kim_convert_c_char_ptr_to_string(p, string) |
| 223 |
end subroutine kim_numbering_to_string |
| 224 |
|
| 225 |
!> \brief \copybrief KIM::NUMBERING::GetNumberOfNumberings |
| 226 |
!! |
| 227 |
!! \sa KIM::NUMBERING::GetNumberOfNumberings, |
| 228 |
!! KIM_NUMBERING_GetNumberOfNumberings |
| 229 |
!! |
| 230 |
!! \since 2.0 |
| 231 |
recursive subroutine kim_get_number_of_numberings(number_of_numberings) |
| 232 |
implicit none |
| 233 |
interface |
| 234 |
recursive subroutine get_number_of_numberings(number_of_numberings) & |
| 235 |
bind(c, name="KIM_NUMBERING_GetNumberOfNumberings") |
| 236 |
use, intrinsic :: iso_c_binding |
| 237 |
implicit none |
| 238 |
integer(c_int), intent(out) :: number_of_numberings |
| 239 |
end subroutine get_number_of_numberings |
| 240 |
end interface |
| 241 |
integer(c_int), intent(out) :: number_of_numberings |
| 242 |
|
| 243 |
call get_number_of_numberings(number_of_numberings) |
| 244 |
end subroutine kim_get_number_of_numberings |
| 245 |
|
| 246 |
!> \brief \copybrief KIM::NUMBERING::GetNumbering |
| 247 |
!! |
| 248 |
!! \sa KIM::NUMBERING::GetNumbering, KIM_NUMBERING_GetNumbering |
| 249 |
!! |
| 250 |
!! \since 2.0 |
| 251 |
recursive subroutine kim_get_numbering(index, numbering, ierr) |
| 252 |
implicit none |
| 253 |
interface |
| 254 |
integer(c_int) recursive function get_numbering(index, numbering) & |
| 255 |
bind(c, name="KIM_NUMBERING_GetNumbering") |
| 256 |
use, intrinsic :: iso_c_binding |
| 257 |
import kim_numbering_type |
| 258 |
implicit none |
| 259 |
integer(c_int), intent(in), value :: index |
| 260 |
type(kim_numbering_type), intent(out) :: numbering |
| 261 |
end function get_numbering |
| 262 |
end interface |
| 263 |
integer(c_int), intent(in) :: index |
| 264 |
type(kim_numbering_type), intent(out) :: numbering |
| 265 |
integer(c_int), intent(out) :: ierr |
| 266 |
|
| 267 |
ierr = get_numbering(index - 1, numbering) |
| 268 |
end subroutine kim_get_numbering |
| 269 |
end module kim_numbering_module |