kim-api  2.3.1-git+v2.3.0-git-2-g378406f9.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 ! KIM-API: An API for interatomic models
3 ! Copyright (c) 2013--2022, Regents of the University of Minnesota.
4 ! All rights reserved.
5 !
6 ! Contributors:
7 ! Ryan S. Elliott
8 !
9 ! SPDX-License-Identifier: LGPL-2.1-or-later
10 !
11 ! This library is free software; you can redistribute it and/or
12 ! modify it under the terms of the GNU Lesser General Public
13 ! License as published by the Free Software Foundation; either
14 ! version 2.1 of the License, or (at your option) any later version.
15 !
16 ! This library is distributed in the hope that it will be useful,
17 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ! Lesser General Public License for more details.
20 !
21 ! You should have received a copy of the GNU Lesser General Public License
22 ! along with this library; if not, write to the Free Software Foundation,
23 ! Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 !
25 
26 !
27 ! Release: This file is part of the kim-api.git repository.
28 !
29 
36  use, intrinsic :: iso_c_binding
37  implicit none
38  private
39 
40  public &
41  ! Derived types
42  kim_time_unit_type, &
43  ! 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_time_unit_type
69  integer(c_int) time_unit_id
70  end type kim_time_unit_type
71 
77  type(kim_time_unit_type), protected, save, &
78  bind(c, name="KIM_TIME_UNIT_unused") &
80 
86  type(kim_time_unit_type), protected, save, &
87  bind(c, name="KIM_TIME_UNIT_fs") &
89 
95  type(kim_time_unit_type), protected, save, &
96  bind(c, name="KIM_TIME_UNIT_ps") &
98 
104  type(kim_time_unit_type), protected, save, &
105  bind(c, name="KIM_TIME_UNIT_ns") &
107 
113  type(kim_time_unit_type), protected, save, &
114  bind(c, name="KIM_TIME_UNIT_s") &
115  :: kim_time_unit_s
116 
122  interface kim_known
123  module procedure kim_time_unit_known
124  end interface kim_known
125 
131  interface operator(.eq.)
132  module procedure kim_time_unit_equal
133  end interface operator(.eq.)
134 
140  interface operator(.ne.)
141  module procedure kim_time_unit_not_equal
142  end interface operator(.ne.)
143 
149  interface kim_from_string
150  module procedure kim_time_unit_from_string
151  end interface kim_from_string
152 
158  interface kim_to_string
159  module procedure kim_time_unit_to_string
160  end interface kim_to_string
161 
162 contains
168  logical recursive function kim_time_unit_known(time_unit)
169  implicit none
170  interface
171  integer(c_int) recursive function known(time_unit) &
172  bind(c, name="KIM_TimeUnit_Known")
173  use, intrinsic :: iso_c_binding
174  import kim_time_unit_type
175  implicit none
176  type(kim_time_unit_type), intent(in), value :: time_unit
177  end function known
178  end interface
179  type(kim_time_unit_type), intent(in) :: time_unit
180 
181  kim_time_unit_known = (known(time_unit) /= 0)
182  end function kim_time_unit_known
183 
189  logical recursive function kim_time_unit_equal(lhs, rhs)
190  implicit none
191  type(kim_time_unit_type), intent(in) :: lhs
192  type(kim_time_unit_type), intent(in) :: rhs
193 
194  kim_time_unit_equal = (lhs%time_unit_id == rhs%time_unit_id)
195  end function kim_time_unit_equal
196 
202  logical recursive function kim_time_unit_not_equal(lhs, rhs)
203  implicit none
204  type(kim_time_unit_type), intent(in) :: lhs
205  type(kim_time_unit_type), intent(in) :: rhs
206 
207  kim_time_unit_not_equal = .not. (lhs == rhs)
208  end function kim_time_unit_not_equal
209 
215  recursive subroutine kim_time_unit_from_string(string, time_unit)
216  implicit none
217  interface
218  type(kim_time_unit_type) recursive function from_string(string) &
219  bind(c, name="KIM_TimeUnit_FromString")
220  use, intrinsic :: iso_c_binding
221  import kim_time_unit_type
222  implicit none
223  character(c_char), intent(in) :: string(*)
224  end function from_string
225  end interface
226  character(len=*, kind=c_char), intent(in) :: string
227  type(kim_time_unit_type), intent(out) :: time_unit
228 
229  time_unit = from_string(trim(string)//c_null_char)
230  end subroutine kim_time_unit_from_string
231 
237  recursive subroutine kim_time_unit_to_string(time_unit, string)
238  use kim_convert_string_module, only: kim_convert_c_char_ptr_to_string
239  implicit none
240  interface
241  type(c_ptr) recursive function get_string(time_unit) &
242  bind(c, name="KIM_TimeUnit_ToString")
243  use, intrinsic :: iso_c_binding
244  import kim_time_unit_type
245  implicit none
246  type(kim_time_unit_type), intent(in), value :: time_unit
247  end function get_string
248  end interface
249  type(kim_time_unit_type), intent(in) :: time_unit
250  character(len=*, kind=c_char), intent(out) :: string
251 
252  type(c_ptr) :: p
253 
254  p = get_string(time_unit)
255  call kim_convert_c_char_ptr_to_string(p, string)
256  end subroutine kim_time_unit_to_string
257 
264  recursive subroutine kim_get_number_of_time_units(number_of_time_units)
265  implicit none
266  interface
267  recursive subroutine get_number_of_time_units(number_of_time_units) &
268  bind(c, name="KIM_TIME_UNIT_GetNumberOfTimeUnits")
269  use, intrinsic :: iso_c_binding
270  implicit none
271  integer(c_int), intent(out) :: number_of_time_units
272  end subroutine get_number_of_time_units
273  end interface
274  integer(c_int), intent(out) :: number_of_time_units
275 
276  call get_number_of_time_units(number_of_time_units)
277  end subroutine kim_get_number_of_time_units
278 
284  recursive subroutine kim_get_time_unit(index, time_unit, ierr)
285  implicit none
286  interface
287  integer(c_int) recursive function get_time_unit(index, time_unit) &
288  bind(c, name="KIM_TIME_UNIT_GetTimeUnit")
289  use, intrinsic :: iso_c_binding
290  import kim_time_unit_type
291  implicit none
292  integer(c_int), intent(in), value :: index
293  type(kim_time_unit_type), intent(out) :: time_unit
294  end function get_time_unit
295  end interface
296  integer(c_int), intent(in) :: index
297  type(kim_time_unit_type), intent(out) :: time_unit
298  integer(c_int), intent(out) :: ierr
299 
300  ierr = get_time_unit(index - 1, time_unit)
301  end subroutine kim_get_time_unit
302 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