      module timer

      contains
      real  function elapsed_time ()
      integer :: clock_count,clock_rate,clock_max
      integer ,  save:: last_count 
      logical ,  save:: system_clock_not_yet_called=.TRUE. 
      call system_clock (count=clock_count,count_rate=clock_rate,count_m&
     &ax=clock_max)
      if (system_clock_not_yet_called) then 
          system_clock_not_yet_called = .FALSE.
         elapsed_time = 0.0
        else if (clock_count .gt. last_count) then
            elapsed_time = real (clock_count-last_count)/real (clock_rat&
     &e)
          else
            elapsed_time = real (clock_max-last_count+clock_count)/real &
     &(clock_rate)
      endif
      last_count = clock_count
      return
      end function

      end module


