kim-api  2.2.1+v2.2.1.GNU.GNU.
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
kim_time_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  ! Derived types
45  kim_time_unit_type, &
46  ! Constants
52  ! Routines
53  kim_known, &
54  operator(.eq.), &
55  operator(.ne.), &
56  kim_from_string, &
57  kim_to_string, &
60 
66  type, bind(c) :: kim_time_unit_type
72  integer(c_int) time_unit_id
73  end type kim_time_unit_type
74 
80  type(kim_time_unit_type), protected, save, &
81  bind(c, name="KIM_TIME_UNIT_unused") &
83 
89  type(kim_time_unit_type), protected, save, &
90  bind(c, name="KIM_TIME_UNIT_fs") &
92 
98  type(kim_time_unit_type), protected, save, &
99  bind(c, name="KIM_TIME_UNIT_ps") &
101 
107  type(kim_time_unit_type), protected, save, &
108  bind(c, name="KIM_TIME_UNIT_ns") &
110 
116  type(kim_time_unit_type), protected, save, &
117  bind(c, name="KIM_TIME_UNIT_s") &
118  :: kim_time_unit_s
119 
125  interface kim_known
126  module procedure kim_time_unit_known
127  end interface kim_known
128 
134  interface operator(.eq.)
135  module procedure kim_time_unit_equal
136  end interface operator(.eq.)
137 
143  interface operator(.ne.)
144  module procedure kim_time_unit_not_equal
145  end interface operator(.ne.)
146 
152  interface kim_from_string
153  module procedure kim_time_unit_from_string
154  end interface kim_from_string
155 
161  interface kim_to_string
162  module procedure kim_time_unit_to_string
163  end interface kim_to_string
164 
165 contains
171  logical recursive function kim_time_unit_known(time_unit)
172  implicit none
173  interface
174  integer(c_int) recursive function known(time_unit) &
175  bind(c, name="KIM_TimeUnit_Known")
176  use, intrinsic :: iso_c_binding
177  import kim_time_unit_type
178  implicit none
179  type(kim_time_unit_type), intent(in), value :: time_unit
180  end function known
181  end interface
182  type(kim_time_unit_type), intent(in) :: time_unit
183 
184  kim_time_unit_known = (known(time_unit) /= 0)
185  end function kim_time_unit_known
186 
192  logical recursive function kim_time_unit_equal(lhs, rhs)
193  implicit none
194  type(kim_time_unit_type), intent(in) :: lhs
195  type(kim_time_unit_type), intent(in) :: rhs
196 
197  kim_time_unit_equal = (lhs%time_unit_id == rhs%time_unit_id)
198  end function kim_time_unit_equal
199 
205  logical recursive function kim_time_unit_not_equal(lhs, rhs)
206  implicit none
207  type(kim_time_unit_type), intent(in) :: lhs
208  type(kim_time_unit_type), intent(in) :: rhs
209 
210  kim_time_unit_not_equal = .not. (lhs == rhs)
211  end function kim_time_unit_not_equal
212 
218  recursive subroutine kim_time_unit_from_string(string, time_unit)
219  implicit none
220  interface
221  type(kim_time_unit_type) recursive function from_string(string) &
222  bind(c, name="KIM_TimeUnit_FromString")
223  use, intrinsic :: iso_c_binding
224  import kim_time_unit_type
225  implicit none
226  character(c_char), intent(in) :: string(*)
227  end function from_string
228  end interface
229  character(len=*, kind=c_char), intent(in) :: string
230  type(kim_time_unit_type), intent(out) :: time_unit
231 
232  time_unit = from_string(trim(string)//c_null_char)
233  end subroutine kim_time_unit_from_string
234 
240  recursive subroutine kim_time_unit_to_string(time_unit, string)
241  use kim_convert_string_module, only: kim_convert_c_char_ptr_to_string
242  implicit none
243  interface
244  type(c_ptr) recursive function get_string(time_unit) &
245  bind(c, name="KIM_TimeUnit_ToString")
246  use, intrinsic :: iso_c_binding
247  import kim_time_unit_type
248  implicit none
249  type(kim_time_unit_type), intent(in), value :: time_unit
250  end function get_string
251  end interface
252  type(kim_time_unit_type), intent(in) :: time_unit
253  character(len=*, kind=c_char), intent(out) :: string
254 
255  type(c_ptr) :: p
256 
257  p = get_string(time_unit)
258  call kim_convert_c_char_ptr_to_string(p, string)
259  end subroutine kim_time_unit_to_string
260 
267  recursive subroutine kim_get_number_of_time_units(number_of_time_units)
268  implicit none
269  interface
270  recursive subroutine get_number_of_time_units(number_of_time_units) &
271  bind(c, name="KIM_TIME_UNIT_GetNumberOfTimeUnits")
272  use, intrinsic :: iso_c_binding
273  implicit none
274  integer(c_int), intent(out) :: number_of_time_units
275  end subroutine get_number_of_time_units
276  end interface
277  integer(c_int), intent(out) :: number_of_time_units
278 
279  call get_number_of_time_units(number_of_time_units)
280  end subroutine kim_get_number_of_time_units
281 
287  recursive subroutine kim_get_time_unit(index, time_unit, ierr)
288  implicit none
289  interface
290  integer(c_int) recursive function get_time_unit(index, time_unit) &
291  bind(c, name="KIM_TIME_UNIT_GetTimeUnit")
292  use, intrinsic :: iso_c_binding
293  import kim_time_unit_type
294  implicit none
295  integer(c_int), intent(in), value :: index
296  type(kim_time_unit_type), intent(out) :: time_unit
297  end function get_time_unit
298  end interface
299  integer(c_int), intent(in) :: index
300  type(kim_time_unit_type), intent(out) :: time_unit
301  integer(c_int), intent(out) :: ierr
302 
303  ierr = get_time_unit(index - 1, time_unit)
304  end subroutine kim_get_time_unit
305 end module kim_time_unit_module
recursive subroutine, public kim_get_number_of_time_units(number_of_time_units)
Get the number of standard TimeUnit's defined by the KIM API.
type(kim_time_unit_type), save, public, protected kim_time_unit_unused
recursive subroutine, public kim_get_time_unit(index, time_unit, ierr)
Get the identity of each defined standard TimeUnit.
type(kim_time_unit_type), save, public, protected kim_time_unit_s
An Extensible Enumeration for the TimeUnit's supported by the KIM API.
type(kim_time_unit_type), save, public, protected kim_time_unit_ns
type(kim_time_unit_type), save, public, protected kim_time_unit_fs
type(kim_time_unit_type), save, public, protected kim_time_unit_ps