kim-api  2.2.1+v2.2.1.GNU.GNU.
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
kim_length_unit_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  ! Derive types
45  kim_length_unit_type, &
46  ! Constants
53  ! Routines
54  kim_known, &
55  operator(.eq.), &
56  operator(.ne.), &
57  kim_from_string, &
58  kim_to_string, &
61 
67  type, bind(c) :: kim_length_unit_type
73  integer(c_int) length_unit_id
74  end type kim_length_unit_type
75 
81  type(kim_length_unit_type), protected, save, &
82  bind(c, name="KIM_LENGTH_UNIT_unused") &
84 
90  type(kim_length_unit_type), protected, save, &
91  bind(c, name="KIM_LENGTH_UNIT_A") &
93 
99  type(kim_length_unit_type), protected, save, &
100  bind(c, name="KIM_LENGTH_UNIT_Bohr") &
102 
108  type(kim_length_unit_type), protected, save, &
109  bind(c, name="KIM_LENGTH_UNIT_cm") &
111 
117  type(kim_length_unit_type), protected, save, &
118  bind(c, name="KIM_LENGTH_UNIT_m") &
120 
126  type(kim_length_unit_type), protected, save, &
127  bind(c, name="KIM_LENGTH_UNIT_nm") &
129 
135  interface kim_known
136  module procedure kim_length_unit_known
137  end interface kim_known
138 
144  interface operator(.eq.)
145  module procedure kim_length_unit_equal
146  end interface operator(.eq.)
147 
153  interface operator(.ne.)
154  module procedure kim_length_unit_not_equal
155  end interface operator(.ne.)
156 
163  interface kim_from_string
164  module procedure kim_length_unit_from_string
165  end interface kim_from_string
166 
172  interface kim_to_string
173  module procedure kim_length_unit_to_string
174  end interface kim_to_string
175 
176 contains
182  logical recursive function kim_length_unit_known(length_unit)
183  implicit none
184  interface
185  integer(c_int) recursive function known(length_unit) &
186  bind(c, name="KIM_LengthUnit_Known")
187  use, intrinsic :: iso_c_binding
188  import kim_length_unit_type
189  implicit none
190  type(kim_length_unit_type), intent(in), value :: length_unit
191  end function known
192  end interface
193  type(kim_length_unit_type), intent(in) :: length_unit
194 
195  kim_length_unit_known = (known(length_unit) /= 0)
196  end function kim_length_unit_known
197 
203  logical recursive function kim_length_unit_equal(lhs, rhs)
204  implicit none
205  type(kim_length_unit_type), intent(in) :: lhs
206  type(kim_length_unit_type), intent(in) :: rhs
207 
208  kim_length_unit_equal &
209  = (lhs%length_unit_id == rhs%length_unit_id)
210  end function kim_length_unit_equal
211 
217  logical recursive function kim_length_unit_not_equal(lhs, rhs)
218  implicit none
219  type(kim_length_unit_type), intent(in) :: lhs
220  type(kim_length_unit_type), intent(in) :: rhs
221 
222  kim_length_unit_not_equal = .not. (lhs == rhs)
223  end function kim_length_unit_not_equal
224 
231  recursive subroutine kim_length_unit_from_string(string, length_unit)
232  implicit none
233  interface
234  type(kim_length_unit_type) recursive function from_string(string) &
235  bind(c, name="KIM_LengthUnit_FromString")
236  use, intrinsic :: iso_c_binding
237  import kim_length_unit_type
238  implicit none
239  character(c_char), intent(in) :: string(*)
240  end function from_string
241  end interface
242  character(len=*, kind=c_char), intent(in) :: string
243  type(kim_length_unit_type), intent(out) :: length_unit
244 
245  length_unit = from_string(trim(string)//c_null_char)
246  end subroutine kim_length_unit_from_string
247 
253  recursive subroutine kim_length_unit_to_string(length_unit, string)
254  use kim_convert_string_module, only: kim_convert_c_char_ptr_to_string
255  implicit none
256  interface
257  type(c_ptr) recursive function get_string(length_unit) &
258  bind(c, name="KIM_LengthUnit_ToString")
259  use, intrinsic :: iso_c_binding
260  import kim_length_unit_type
261  implicit none
262  type(kim_length_unit_type), intent(in), value :: length_unit
263  end function get_string
264  end interface
265  type(kim_length_unit_type), intent(in) :: length_unit
266  character(len=*, kind=c_char), intent(out) :: string
267 
268  type(c_ptr) :: p
269 
270  p = get_string(length_unit)
271  call kim_convert_c_char_ptr_to_string(p, string)
272  end subroutine kim_length_unit_to_string
273 
280  recursive subroutine kim_get_number_of_length_units(number_of_length_units)
281  implicit none
282  interface
283  recursive subroutine get_number_of_length_units(number_of_length_units) &
284  bind(c, name="KIM_LENGTH_UNIT_GetNumberOfLengthUnits")
285  use, intrinsic :: iso_c_binding
286  integer(c_int), intent(out) :: number_of_length_units
287  end subroutine get_number_of_length_units
288  end interface
289  integer(c_int), intent(out) :: number_of_length_units
290 
291  call get_number_of_length_units(number_of_length_units)
292  end subroutine kim_get_number_of_length_units
293 
299  recursive subroutine kim_get_length_unit(index, length_unit, ierr)
300  implicit none
301  interface
302  integer(c_int) recursive function get_length_unit(index, length_unit) &
303  bind(c, name="KIM_LENGTH_UNIT_GetLengthUnit")
304  use, intrinsic :: iso_c_binding
305  import kim_length_unit_type
306  implicit none
307  integer(c_int), intent(in), value :: index
308  type(kim_length_unit_type), intent(out) :: length_unit
309  end function get_length_unit
310  end interface
311  integer(c_int), intent(in) :: index
312  type(kim_length_unit_type), intent(out) :: length_unit
313  integer(c_int), intent(out) :: ierr
314 
315  ierr = get_length_unit(index - 1, length_unit)
316  end subroutine kim_get_length_unit
317 end module kim_length_unit_module
type(kim_length_unit_type), save, public, protected kim_length_unit_a
type(kim_length_unit_type), save, public, protected kim_length_unit_bohr
type(kim_length_unit_type), save, public, protected kim_length_unit_m
recursive subroutine, public kim_get_number_of_length_units(number_of_length_units)
Get the number of standard LengthUnit's defined by the KIM API.
type(kim_length_unit_type), save, public, protected kim_length_unit_unused
An Extensible Enumeration for the LengthUnit's supported by the KIM API.
type(kim_length_unit_type), save, public, protected kim_length_unit_nm
recursive subroutine, public kim_get_length_unit(index, length_unit, ierr)
Get the identity of each defined standard LengthUnit.
type(kim_length_unit_type), save, public, protected kim_length_unit_cm