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_data_type_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
46 ! Routines
47 kim_known, &
48 operator(.eq.), &
49 operator(.ne.), &
54
60 type, bind(c) :: kim_data_type_type
66 integer(c_int) :: data_type_id
67 end type kim_data_type_type
68
74 type(kim_data_type_type), protected, save, &
75 bind(c, name="KIM_DATA_TYPE_Integer") &
77
83 type(kim_data_type_type), protected, save, &
84 bind(c, name="KIM_DATA_TYPE_Double") &
86
92 interface kim_known
93 module procedure kim_data_type_known
94 end interface kim_known
95
101 interface operator(.eq.)
102 module procedure kim_data_type_equal
103 end interface operator(.eq.)
104
110 interface operator(.ne.)
111 module procedure kim_data_type_not_equal
112 end interface operator(.ne.)
113
120 module procedure kim_data_type_from_string
121 end interface kim_from_string
122
129 module procedure kim_data_type_to_string
130 end interface kim_to_string
131
132contains
138 logical recursive function kim_data_type_known(data_type)
139 implicit none
140 interface
141 integer(c_int) recursive function known(data_type) &
142 bind(c, name="KIM_DataType_Known")
143 use, intrinsic :: iso_c_binding
144 import kim_data_type_type
145 implicit none
146 type(kim_data_type_type), intent(in), value :: data_type
147 end function known
148 end interface
149 type(kim_data_type_type), intent(in) :: data_type
150
151 kim_data_type_known = (known(data_type) /= 0)
152 end function kim_data_type_known
153
159 logical recursive function kim_data_type_equal(lhs, rhs)
160 implicit none
161 type(kim_data_type_type), intent(in) :: lhs
162 type(kim_data_type_type), intent(in) :: rhs
163
164 kim_data_type_equal &
165 = (lhs%data_type_id == rhs%data_type_id)
166 end function kim_data_type_equal
167
173 logical recursive function kim_data_type_not_equal(lhs, rhs)
174 implicit none
175 type(kim_data_type_type), intent(in) :: lhs
176 type(kim_data_type_type), intent(in) :: rhs
177
178 kim_data_type_not_equal = .not. (lhs == rhs)
179 end function kim_data_type_not_equal
180
186 recursive subroutine kim_data_type_from_string(string, data_type)
187 implicit none
188 interface
189 type(kim_data_type_type) recursive function from_string(string) &
190 bind(c, name="KIM_DataType_FromString")
191 use, intrinsic :: iso_c_binding
192 import kim_data_type_type
193 implicit none
194 character(c_char), intent(in) :: string(*)
195 end function from_string
196 end interface
197 character(len=*, kind=c_char), intent(in) :: string
198 type(kim_data_type_type), intent(out) :: data_type
199
200 data_type = from_string(trim(string)//c_null_char)
201 end subroutine kim_data_type_from_string
202
208 recursive subroutine kim_data_type_to_string(data_type, string)
209 use kim_convert_string_module, only: kim_convert_c_char_ptr_to_string
210 implicit none
211 interface
212 type(c_ptr) recursive function get_string(data_type) &
213 bind(c, name="KIM_DataType_ToString")
214 use, intrinsic :: iso_c_binding
215 import kim_data_type_type
216 implicit none
217 type(kim_data_type_type), intent(in), value :: data_type
218 end function get_string
219 end interface
220 type(kim_data_type_type), intent(in) :: data_type
221 character(len=*, kind=c_char), intent(out) :: string
222
223 type(c_ptr) :: p
224
225 p = get_string(data_type)
226 call kim_convert_c_char_ptr_to_string(p, string)
227 end subroutine kim_data_type_to_string
228
235 recursive subroutine kim_get_number_of_data_types(number_of_data_types)
236 implicit none
237 interface
238 recursive subroutine get_number_of_data_types(number_of_data_types) &
239 bind(c, name="KIM_DATA_TYPE_GetNumberOfDataTypes")
240 use, intrinsic :: iso_c_binding
241 implicit none
242 integer(c_int), intent(out) :: number_of_data_types
243 end subroutine get_number_of_data_types
244 end interface
245 integer(c_int), intent(out) :: number_of_data_types
246
247 call get_number_of_data_types(number_of_data_types)
248 end subroutine kim_get_number_of_data_types
249
255 recursive subroutine kim_get_data_type(index, data_type, ierr)
256 implicit none
257 interface
258 integer(c_int) recursive function get_data_type(index, data_type) &
259 bind(c, name="KIM_DATA_TYPE_GetDataType")
260 use, intrinsic :: iso_c_binding
261 import kim_data_type_type
262 implicit none
263 integer(c_int), intent(in), value :: index
264 type(kim_data_type_type), intent(out) :: data_type
265 end function get_data_type
266 end interface
267 integer(c_int), intent(in) :: index
268 type(kim_data_type_type), intent(out) :: data_type
269 integer(c_int), intent(out) :: ierr
270
271 ierr = get_data_type(index - 1, data_type)
272 end subroutine kim_get_data_type
273end module kim_data_type_module
Create a DataType object corresponding to the provided string. If the string does not match one of th...
Determines if the object is a quantity known to the KIM API.
Converts the object to a string.
An Extensible Enumeration for the DataType's supported by the KIM API.
type(kim_data_type_type), save, bind(C, name="KIM_DATA_TYPE_Double"), public, protected kim_data_type_double
The standard Double data type.
type(kim_data_type_type), save, bind(C, name="KIM_DATA_TYPE_Integer"), public, protected kim_data_type_integer
The standard Integer data type.
recursive subroutine, public kim_get_number_of_data_types(number_of_data_types)
Get the number of standard DataType's defined by the KIM API.
recursive subroutine, public kim_get_data_type(index, data_type, ierr)
Get the identity of each defined standard DataType.
An Extensible Enumeration for the DataType's supported by the KIM API.