kim-api  2.2.1+v2.2.1.GNU.GNU.
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
kim_data_type_module.f90
Go to the documentation of this file.
1 !
2 ! CDDL HEADER START
3 !
4 ! The contents of this file are subject to the terms of the Common Development
5 ! and Distribution License Version 1.0 (the "License").
6 !
7 ! You can obtain a copy of the license at
8 ! http://www.opensource.org/licenses/CDDL-1.0. See the License for the
9 ! specific language governing permissions and limitations under the License.
10 !
11 ! When distributing Covered Code, include this CDDL HEADER in each file and
12 ! include the License file in a prominent location with the name LICENSE.CDDL.
13 ! If applicable, add the following below this CDDL HEADER, with the fields
14 ! enclosed by brackets "[]" replaced with your own identifying information:
15 !
16 ! Portions Copyright (c) [yyyy] [name of copyright owner]. All rights reserved.
17 !
18 ! CDDL HEADER END
19 !
20 
21 !
22 ! Copyright (c) 2016--2020, Regents of the University of Minnesota.
23 ! All rights reserved.
24 !
25 ! Contributors:
26 ! Ryan S. Elliott
27 !
28 
29 !
30 ! Release: This file is part of the kim-api-2.2.1 package.
31 !
32 
39  use, intrinsic :: iso_c_binding
40  implicit none
41  private
42 
43  public &
44  ! Derived types
45  kim_data_type_type, &
46  ! Constants
49  ! Routines
50  kim_known, &
51  operator(.eq.), &
52  operator(.ne.), &
53  kim_from_string, &
54  kim_to_string, &
57 
63  type, bind(c) :: kim_data_type_type
69  integer(c_int) :: data_type_id
70  end type kim_data_type_type
71 
77  type(kim_data_type_type), protected, save, &
78  bind(c, name="KIM_DATA_TYPE_Integer") &
80 
86  type(kim_data_type_type), protected, save, &
87  bind(c, name="KIM_DATA_TYPE_Double") &
89 
95  interface kim_known
96  module procedure kim_data_type_known
97  end interface kim_known
98 
104  interface operator(.eq.)
105  module procedure kim_data_type_equal
106  end interface operator(.eq.)
107 
113  interface operator(.ne.)
114  module procedure kim_data_type_not_equal
115  end interface operator(.ne.)
116 
122  interface kim_from_string
123  module procedure kim_data_type_from_string
124  end interface kim_from_string
125 
131  interface kim_to_string
132  module procedure kim_data_type_to_string
133  end interface kim_to_string
134 
135 contains
141  logical recursive function kim_data_type_known(data_type)
142  implicit none
143  interface
144  integer(c_int) recursive function known(data_type) &
145  bind(c, name="KIM_DataType_Known")
146  use, intrinsic :: iso_c_binding
147  import kim_data_type_type
148  implicit none
149  type(kim_data_type_type), intent(in), value :: data_type
150  end function known
151  end interface
152  type(kim_data_type_type), intent(in) :: data_type
153 
154  kim_data_type_known = (known(data_type) /= 0)
155  end function kim_data_type_known
156 
162  logical recursive function kim_data_type_equal(lhs, rhs)
163  implicit none
164  type(kim_data_type_type), intent(in) :: lhs
165  type(kim_data_type_type), intent(in) :: rhs
166 
167  kim_data_type_equal &
168  = (lhs%data_type_id == rhs%data_type_id)
169  end function kim_data_type_equal
170 
176  logical recursive function kim_data_type_not_equal(lhs, rhs)
177  implicit none
178  type(kim_data_type_type), intent(in) :: lhs
179  type(kim_data_type_type), intent(in) :: rhs
180 
181  kim_data_type_not_equal = .not. (lhs == rhs)
182  end function kim_data_type_not_equal
183 
189  recursive subroutine kim_data_type_from_string(string, data_type)
190  implicit none
191  interface
192  type(kim_data_type_type) recursive function from_string(string) &
193  bind(c, name="KIM_DataType_FromString")
194  use, intrinsic :: iso_c_binding
195  import kim_data_type_type
196  implicit none
197  character(c_char), intent(in) :: string(*)
198  end function from_string
199  end interface
200  character(len=*, kind=c_char), intent(in) :: string
201  type(kim_data_type_type), intent(out) :: data_type
202 
203  data_type = from_string(trim(string)//c_null_char)
204  end subroutine kim_data_type_from_string
205 
211  recursive subroutine kim_data_type_to_string(data_type, string)
212  use kim_convert_string_module, only: kim_convert_c_char_ptr_to_string
213  implicit none
214  interface
215  type(c_ptr) recursive function get_string(data_type) &
216  bind(c, name="KIM_DataType_ToString")
217  use, intrinsic :: iso_c_binding
218  import kim_data_type_type
219  implicit none
220  type(kim_data_type_type), intent(in), value :: data_type
221  end function get_string
222  end interface
223  type(kim_data_type_type), intent(in) :: data_type
224  character(len=*, kind=c_char), intent(out) :: string
225 
226  type(c_ptr) :: p
227 
228  p = get_string(data_type)
229  call kim_convert_c_char_ptr_to_string(p, string)
230  end subroutine kim_data_type_to_string
231 
238  recursive subroutine kim_get_number_of_data_types(number_of_data_types)
239  implicit none
240  interface
241  recursive subroutine get_number_of_data_types(number_of_data_types) &
242  bind(c, name="KIM_DATA_TYPE_GetNumberOfDataTypes")
243  use, intrinsic :: iso_c_binding
244  implicit none
245  integer(c_int), intent(out) :: number_of_data_types
246  end subroutine get_number_of_data_types
247  end interface
248  integer(c_int), intent(out) :: number_of_data_types
249 
250  call get_number_of_data_types(number_of_data_types)
251  end subroutine kim_get_number_of_data_types
252 
258  recursive subroutine kim_get_data_type(index, data_type, ierr)
259  implicit none
260  interface
261  integer(c_int) recursive function get_data_type(index, data_type) &
262  bind(c, name="KIM_DATA_TYPE_GetDataType")
263  use, intrinsic :: iso_c_binding
264  import kim_data_type_type
265  implicit none
266  integer(c_int), intent(in), value :: index
267  type(kim_data_type_type), intent(out) :: data_type
268  end function get_data_type
269  end interface
270  integer(c_int), intent(in) :: index
271  type(kim_data_type_type), intent(out) :: data_type
272  integer(c_int), intent(out) :: ierr
273 
274  ierr = get_data_type(index - 1, data_type)
275  end subroutine kim_get_data_type
276 end module kim_data_type_module
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.
type(kim_data_type_type), save, public, protected kim_data_type_double
type(kim_data_type_type), save, public, protected kim_data_type_integer
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.