35 integer,
parameter :: CLOCK_TICK = 1
57 procedure :: clock_is_equal
58 generic ::
operator(.eq.) => clock_is_equal
59 procedure :: clock_is_different
60 generic ::
operator(/=) => clock_is_different
61 procedure :: clock_is_earlier
62 generic ::
operator(.lt.) => clock_is_earlier
63 procedure :: clock_is_later
64 generic ::
operator(.gt.) => clock_is_later
65 procedure :: clock_is_equal_or_earlier
66 generic ::
operator(.le.) => clock_is_equal_or_earlier
67 procedure :: clock_is_equal_or_later
68 generic ::
operator(.ge.) => clock_is_equal_or_later
69 procedure :: clock_copy
70 generic ::
assignment(=) => clock_copy
71 procedure :: clock_add_tick
72 generic ::
operator(+) => clock_add_tick
73 procedure :: clock_subtract_tick
74 generic ::
operator(-) => clock_subtract_tick
89 type(clock_t) function clock_init(time_step, initial_tick) result(this)
90 float,
optional,
intent(in) :: time_step
91 integer,
optional,
intent(in) :: initial_tick
97 if (this%time_step <=
m_zero)
then
100 this%time_ = this%tick*this%time_step
108 class(clock_t),
intent(in) :: this
109 character(len=65) :: clock_string
113 write(clock_string,
'(A7,F16.6,A,I8.8,A)') &
125 class(
clock_t),
intent(in) :: this
129 message(1) = this%print_str()
130 call messages_info(1)
140 logical :: commensurable
141 integer :: this_granularity, new_granularity
145 if (this%time_step > m_zero .and. new%time_step > m_zero)
then
146 if (this%time_step >= new%time_step)
then
147 commensurable = ceiling(this%time_step/new%time_step) ==
floor(this%time_step/new%time_step)
148 this_granularity = ceiling(this%time_step/new%time_step)
151 commensurable = ceiling(new%time_step/this%time_step) ==
floor(new%time_step/this%time_step)
153 new_granularity = ceiling(new%time_step/this%time_step)
156 if (.not. commensurable)
then
157 message(1) =
'Cannot set clock new time, as it is not commensurable with clock time-step.'
158 call messages_fatal(1)
161 this%tick = (new%tick * new_granularity) / this_granularity
162 this%time_ = this%tick*this%time_step
164 this%time_ = new%time_
172 class(
clock_t),
intent(in) :: clock_in
173 class(
clock_t),
intent(inout) :: this
177 this%tick = clock_in%tick
178 this%time_step = clock_in%time_step
179 this%time_ = clock_in%time_
187 integer,
intent(in) :: tick
192 new_clock%tick = new_clock%tick + tick
193 new_clock%time_ = new_clock%tick*new_clock%time_step
201 integer,
intent(in) :: tick
206 new_clock%tick = new_clock%tick - tick
207 new_clock%time_ = new_clock%tick*new_clock%time_step
214 class(
clock_t),
intent(in) :: this
225 class(
clock_t),
intent(in) :: this
237 class(
clock_t),
intent(in) :: this
248 class(
clock_t),
intent(inout) :: this
260 class(
clock_t),
intent(in) :: clock_a, clock_b
268 is_earlier = clock_a%time_ < clock_b%time_
275 logical function clock_is_later(clock_a, clock_b)
result(is_later)
276 class(
clock_t),
intent(in) :: clock_a, clock_b
284 is_later = clock_a%time_ > clock_b%time_
292 class(
clock_t),
intent(in) :: clock_a, clock_b
303 class(
clock_t),
intent(in) :: clock_a, clock_b
313 logical function clock_is_equal(clock_a, clock_b)
result(are_equal)
314 class(
clock_t),
intent(in) :: clock_a, clock_b
319 if (abs(clock_b%time_) <= m_epsilon)
then
322 are_equal = clock_a%time_ == m_zero
323 else if (abs(clock_a%time_) <= m_epsilon)
then
326 are_equal = clock_b%time_ == m_zero
337 class(
clock_t),
intent(in) :: clock_a, clock_b
348 class(
clock_t),
intent(in) :: this
349 character(len=*),
intent(in) :: filename
350 type(namespace_t),
intent(in) :: namespace
352 integer :: restart_file_unit
356 call io_mkdir(
"restart", namespace, parents=.
true.)
357 restart_file_unit = io_open(
"restart/"//filename, namespace, form=
"unformatted", action=
'write')
358 write(restart_file_unit) this%tick, this%time_step
359 call io_close(restart_file_unit)
366 class(
clock_t),
intent(inout) :: this
367 character(len=*),
intent(in) :: filename
368 type(namespace_t),
intent(in) :: namespace
370 integer :: restart_file_unit
374 restart_file_unit = io_open(
"restart/"//filename, namespace, form=
"unformatted", action=
'read', die=.false.)
375 if (restart_file_unit > 0)
then
376 read(restart_file_unit) this%tick, this%time_step
377 call io_close(restart_file_unit)
379 this =
clock_t(this%time_step, this%tick)
double floor(double __x) __attribute__((__nothrow__
type(clock_t) function clock_init(time_step, initial_tick)
Initialize the clock with a given label and associated physical time step. The internal clock counter...
real(8) function clock_get_dt(this)
type(clock_t) function clock_add_tick(clock, tick)
logical function clock_is_equal_or_later(clock_a, clock_b)
subroutine clock_restart_write(this, filename, namespace)
integer function clock_get_tick(this)
subroutine clock_print(this)
subroutine clock_set_time(this, new)
real(8) function clock_time(this)
type(clock_t) function clock_subtract_tick(clock, tick)
logical function clock_is_later(clock_a, clock_b)
logical function clock_is_equal_or_earlier(clock_a, clock_b)
real(8), parameter time_relative_tolerance
character(len=65) function clock_print_str(this)
logical function clock_is_equal(clock_a, clock_b)
subroutine clock_reset(this)
subroutine clock_copy(this, clock_in)
logical function clock_is_earlier(clock_a, clock_b)
logical function clock_restart_read(this, filename, namespace)
logical function clock_is_different(clock_a, clock_b)
real(8), parameter, public m_zero
subroutine, public push_sub(sub_name)
subroutine, public pop_sub(sub_name)