kim-api  2.1.2+v2.1.2.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--2019, 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.1.2 package.
31 !
32 
33 
40  use, intrinsic :: iso_c_binding
41  implicit none
42  private
43 
44  public &
45  ! Derived types
46  kim_data_type_type, &
47 
48  ! Constants
51 
52  ! Routines
53  kim_known, &
54  operator (.eq.), &
55  operator (.ne.), &
56  kim_from_string, &
57  kim_to_string, &
60 
61 
67  type, bind(c) :: kim_data_type_type
73  integer(c_int) :: data_type_id
74  end type kim_data_type_type
75 
81  type(kim_data_type_type), protected, save, &
82  bind(c, name="KIM_DATA_TYPE_Integer") &
84 
90  type(kim_data_type_type), protected, save, &
91  bind(c, name="KIM_DATA_TYPE_Double") &
93 
99  interface kim_known
100  module procedure kim_data_type_known
101  end interface kim_known
102 
108  interface operator (.eq.)
109  module procedure kim_data_type_equal
110  end interface operator (.eq.)
111 
117  interface operator (.ne.)
118  module procedure kim_data_type_not_equal
119  end interface operator (.ne.)
120 
126  interface kim_from_string
127  module procedure kim_data_type_from_string
128  end interface kim_from_string
129 
135  interface kim_to_string
136  module procedure kim_data_type_to_string
137  end interface kim_to_string
138 
139 contains
145  logical recursive function kim_data_type_known(data_type)
146  implicit none
147  interface
148  integer(c_int) recursive function known(data_type) &
149  bind(c, name="KIM_DataType_Known")
150  use, intrinsic :: iso_c_binding
151  import kim_data_type_type
152  implicit none
153  type(kim_data_type_type), intent(in), value :: data_type
154  end function known
155  end interface
156  type(kim_data_type_type), intent(in) :: data_type
157 
158  kim_data_type_known = (known(data_type) /= 0)
159  end function kim_data_type_known
160 
166  logical recursive function kim_data_type_equal(lhs, rhs)
167  implicit none
168  type(kim_data_type_type), intent(in) :: lhs
169  type(kim_data_type_type), intent(in) :: rhs
170 
171  kim_data_type_equal &
172  = (lhs%data_type_id .eq. rhs%data_type_id)
173  end function kim_data_type_equal
174 
180  logical recursive function kim_data_type_not_equal(lhs, rhs)
181  implicit none
182  type(kim_data_type_type), intent(in) :: lhs
183  type(kim_data_type_type), intent(in) :: rhs
184 
185  kim_data_type_not_equal = .not. (lhs .eq. rhs)
186  end function kim_data_type_not_equal
187 
193  recursive subroutine kim_data_type_from_string(string, data_type)
194  implicit none
195  interface
196  type(kim_data_type_type) recursive function from_string(string) &
197  bind(c, name="KIM_DataType_FromString")
198  use, intrinsic :: iso_c_binding
199  import kim_data_type_type
200  implicit none
201  character(c_char), intent(in) :: string(*)
202  end function from_string
203  end interface
204  character(len=*, kind=c_char), intent(in) :: string
205  type(kim_data_type_type), intent(out) :: data_type
206 
207  data_type = from_string(trim(string)//c_null_char)
208  end subroutine kim_data_type_from_string
209 
215  recursive subroutine kim_data_type_to_string(data_type, string)
216  use kim_convert_string_module, only : kim_convert_c_char_ptr_to_string
217  implicit none
218  interface
219  type(c_ptr) recursive function get_string(data_type) &
220  bind(c, name="KIM_DataType_ToString")
221  use, intrinsic :: iso_c_binding
222  import kim_data_type_type
223  implicit none
224  type(kim_data_type_type), intent(in), value :: data_type
225  end function get_string
226  end interface
227  type(kim_data_type_type), intent(in) :: data_type
228  character(len=*, kind=c_char), intent(out) :: string
229 
230  type(c_ptr) :: p
231 
232  p = get_string(data_type)
233  call kim_convert_c_char_ptr_to_string(p, string)
234  end subroutine kim_data_type_to_string
235 
242  recursive subroutine kim_get_number_of_data_types(number_of_data_types)
243  implicit none
244  interface
245  recursive subroutine get_number_of_data_types(number_of_data_types) &
246  bind(c, name="KIM_DATA_TYPE_GetNumberOfDataTypes")
247  use, intrinsic :: iso_c_binding
248  implicit none
249  integer(c_int), intent(out) :: number_of_data_types
250  end subroutine get_number_of_data_types
251  end interface
252  integer(c_int), intent(out) :: number_of_data_types
253 
254  call get_number_of_data_types(number_of_data_types)
255  end subroutine kim_get_number_of_data_types
256 
262  recursive subroutine kim_get_data_type(index, data_type, ierr)
263  implicit none
264  interface
265  integer(c_int) recursive function get_data_type(index, data_type) &
266  bind(c, name="KIM_DATA_TYPE_GetDataType")
267  use, intrinsic :: iso_c_binding
268  import kim_data_type_type
269  implicit none
270  integer(c_int), intent(in), value :: index
271  type(kim_data_type_type), intent(out) :: data_type
272  end function get_data_type
273  end interface
274  integer(c_int), intent(in) :: index
275  type(kim_data_type_type), intent(out) :: data_type
276  integer(c_int), intent(out) :: ierr
277 
278  ierr = get_data_type(index-1, data_type)
279  end subroutine kim_get_data_type
280 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.