kim-api  2.1.4-git+v2.1.3-git-1-g7847914a.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--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.git repository.
31 !
32 
33 
40  use, intrinsic :: iso_c_binding
41  implicit none
42  private
43 
44  public &
45  ! Derived types
46  kim_time_unit_type, &
47 
48  ! Constants
54 
55  ! Routines
56  kim_known, &
57  operator (.eq.), &
58  operator (.ne.), &
59  kim_from_string, &
60  kim_to_string, &
63 
64 
70  type, bind(c) :: kim_time_unit_type
76  integer(c_int) time_unit_id
77  end type kim_time_unit_type
78 
84  type(kim_time_unit_type), protected, save, &
85  bind(c, name="KIM_TIME_UNIT_unused") &
87 
93  type(kim_time_unit_type), protected, save, &
94  bind(c, name="KIM_TIME_UNIT_fs") &
96 
102  type(kim_time_unit_type), protected, save, &
103  bind(c, name="KIM_TIME_UNIT_ps") &
105 
111  type(kim_time_unit_type), protected, save, &
112  bind(c, name="KIM_TIME_UNIT_ns") &
114 
120  type(kim_time_unit_type), protected, save, &
121  bind(c, name="KIM_TIME_UNIT_s") &
122  :: kim_time_unit_s
123 
129  interface kim_known
130  module procedure kim_time_unit_known
131  end interface kim_known
132 
138  interface operator (.eq.)
139  module procedure kim_time_unit_equal
140  end interface operator (.eq.)
141 
147  interface operator (.ne.)
148  module procedure kim_time_unit_not_equal
149  end interface operator (.ne.)
150 
156  interface kim_from_string
157  module procedure kim_time_unit_from_string
158  end interface kim_from_string
159 
165  interface kim_to_string
166  module procedure kim_time_unit_to_string
167  end interface kim_to_string
168 
169 contains
175  logical recursive function kim_time_unit_known(time_unit)
176  implicit none
177  interface
178  integer(c_int) recursive function known(time_unit) &
179  bind(c, name="KIM_TimeUnit_Known")
180  use, intrinsic :: iso_c_binding
181  import kim_time_unit_type
182  implicit none
183  type(kim_time_unit_type), intent(in), value :: time_unit
184  end function known
185  end interface
186  type(kim_time_unit_type), intent(in) :: time_unit
187 
188  kim_time_unit_known = (known(time_unit) /= 0)
189  end function kim_time_unit_known
190 
196  logical recursive function kim_time_unit_equal(lhs, rhs)
197  implicit none
198  type(kim_time_unit_type), intent(in) :: lhs
199  type(kim_time_unit_type), intent(in) :: rhs
200 
201  kim_time_unit_equal &
202  = (lhs%time_unit_id .eq. rhs%time_unit_id)
203  end function kim_time_unit_equal
204 
210  logical recursive function kim_time_unit_not_equal(lhs, rhs)
211  implicit none
212  type(kim_time_unit_type), intent(in) :: lhs
213  type(kim_time_unit_type), intent(in) :: rhs
214 
215  kim_time_unit_not_equal = .not. (lhs .eq. rhs)
216  end function kim_time_unit_not_equal
217 
223  recursive subroutine kim_time_unit_from_string(string, time_unit)
224  implicit none
225  interface
226  type(kim_time_unit_type) recursive function from_string(string) &
227  bind(c, name="KIM_TimeUnit_FromString")
228  use, intrinsic :: iso_c_binding
229  import kim_time_unit_type
230  implicit none
231  character(c_char), intent(in) :: string(*)
232  end function from_string
233  end interface
234  character(len=*, kind=c_char), intent(in) :: string
235  type(kim_time_unit_type), intent(out) :: time_unit
236 
237  time_unit = from_string(trim(string)//c_null_char)
238  end subroutine kim_time_unit_from_string
239 
245  recursive subroutine kim_time_unit_to_string(time_unit, string)
246  use kim_convert_string_module, only : kim_convert_c_char_ptr_to_string
247  implicit none
248  interface
249  type(c_ptr) recursive function get_string(time_unit) &
250  bind(c, name="KIM_TimeUnit_ToString")
251  use, intrinsic :: iso_c_binding
252  import kim_time_unit_type
253  implicit none
254  type(kim_time_unit_type), intent(in), value :: time_unit
255  end function get_string
256  end interface
257  type(kim_time_unit_type), intent(in) :: time_unit
258  character(len=*, kind=c_char), intent(out) :: string
259 
260  type(c_ptr) :: p
261 
262  p = get_string(time_unit)
263  call kim_convert_c_char_ptr_to_string(p, string)
264  end subroutine kim_time_unit_to_string
265 
272  recursive subroutine kim_get_number_of_time_units(number_of_time_units)
273  implicit none
274  interface
275  recursive subroutine get_number_of_time_units(number_of_time_units) &
276  bind(c, name="KIM_TIME_UNIT_GetNumberOfTimeUnits")
277  use, intrinsic :: iso_c_binding
278  implicit none
279  integer(c_int), intent(out) :: number_of_time_units
280  end subroutine get_number_of_time_units
281  end interface
282  integer(c_int), intent(out) :: number_of_time_units
283 
284  call get_number_of_time_units(number_of_time_units)
285  end subroutine kim_get_number_of_time_units
286 
292  recursive subroutine kim_get_time_unit(index, time_unit, ierr)
293  implicit none
294  interface
295  integer(c_int) recursive function get_time_unit(index, time_unit) &
296  bind(c, name="KIM_TIME_UNIT_GetTimeUnit")
297  use, intrinsic :: iso_c_binding
298  import kim_time_unit_type
299  implicit none
300  integer(c_int), intent(in), value :: index
301  type(kim_time_unit_type), intent(out) :: time_unit
302  end function get_time_unit
303  end interface
304  integer(c_int), intent(in) :: index
305  type(kim_time_unit_type), intent(out) :: time_unit
306  integer(c_int), intent(out) :: ierr
307 
308  ierr = get_time_unit(index-1, time_unit)
309  end subroutine kim_get_time_unit
310 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