!WRF:DRIVER_LAYER:UTIL
!


MODULE module_timing 20

   INTEGER :: count_int1 , count_rate_int1 , count_max_int1
   INTEGER :: count_int2 , count_rate_int2 , count_max_int2
   REAL    :: elapsed_seconds , elapsed_seconds_total = 0
   REAL    :: cpu_1 , cpu_2 , cpu_seconds , cpu_seconds_total = 0

CONTAINS


   SUBROUTINE init_module_timing 3
   END SUBROUTINE init_module_timing

END MODULE module_timing


   SUBROUTINE start_timing 6,1
      USE module_timing

      IMPLICIT NONE

      CALL SYSTEM_CLOCK ( count_int1 , count_rate_int1 , count_max_int1 )
!     CALL CPU_TIME ( cpu_1 )

   END SUBROUTINE start_timing



   SUBROUTINE end_timing ( string ) 5,1
      USE module_timing
   
      IMPLICIT NONE

      CHARACTER *(*) :: string

      CALL SYSTEM_CLOCK ( count_int2 , count_rate_int2 , count_max_int2 )
!     CALL CPU_TIME ( cpu_2 )

      IF ( count_int2 < count_int1 ) THEN
         count_int2 = count_int2 + count_max_int2
      ENDIF

      count_int2 = count_int2 - count_int1
      elapsed_seconds = REAL(count_int2) / REAL(count_rate_int2)
      elapsed_seconds_total = elapsed_seconds_total + elapsed_seconds
!      PRINT '(A,A,A,F10.5,A)' ,'Timing for ',TRIM(string),': ',elapsed_seconds,' elapsed seconds.'
      WRITE(6,'(A,A,A,F10.5,A)') 'Timing for ',TRIM(string),': ',elapsed_seconds,' elapsed seconds.'
      WRITE(0,'(A,A,A,F10.5,A)') 'Timing for ',TRIM(string),': ',elapsed_seconds,' elapsed seconds.'

!     cpu_seconds = cpu_2 - cpu_1
!     cpu_seconds_total = cpu_seconds_total + cpu_seconds
!     PRINT '(A,A,A,F10.5,A)' ,'Timing for ',TRIM(string),': ',cpu_seconds,' cpu seconds.'

   END SUBROUTINE end_timing