monotonic_scaled Function

private function monotonic_scaled(units_per_second) result(t)

Shared body of monotonic_ms and monotonic_us.

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(in) :: units_per_second

Return Value integer(kind=int64)


Called by

proc~~monotonic_scaled~~CalledByGraph proc~monotonic_scaled monotonic_scaled proc~monotonic_ms monotonic_ms proc~monotonic_ms->proc~monotonic_scaled proc~monotonic_us monotonic_us proc~monotonic_us->proc~monotonic_scaled

Variables

Type Visibility Attributes Name Initial
integer(kind=int64), private :: count
integer(kind=int64), private :: rate

Source Code

   function monotonic_scaled(units_per_second) result(t)
      !! Shared body of `monotonic_ms` and `monotonic_us`.
      integer(int64), intent(in) :: units_per_second
      integer(int64) :: t

      integer(int64) :: count, rate

      call system_clock(count, rate)

      ! F2018 16.9.180: a processor with no clock reports a zero count rate.
      if (rate <= 0_int64) then
         t = PIC_CLOCK_NO_CLOCK
         return
      end if

      ! Split rather than `count*units_per_second/rate`: with a nanosecond
      ! tick the product overflows int64 after a few seconds of uptime. The
      ! quotient and remainder together lose nothing.
      t = (count/rate)*units_per_second + (mod(count, rate)*units_per_second)/rate
   end function monotonic_scaled