!
! fmsclocks.F90
!
! $Id$
!
! A Fortran77 style wrapper around the FMS clocks module
! which provides subroutines that can be easily called from C/C++

!! from mpp_parameter.F90:
!--- predefined clock granularities, but you can use any integer
!--- using CLOCK_LOOP and above may distort coarser-grain measurements
!integer, parameter :: CLOCK_COMPONENT=1      !component level, e.g model, exchange
!integer, parameter :: CLOCK_SUBCOMPONENT=11  !top level within a model component, e.g dynamics, physics
!integer, parameter :: CLOCK_MODULE_DRIVER=21 !module driver level, e.g adriver that calls multiple 
!                                             !related physics routines
!integer, parameter :: CLOCK_MODULE=31        !module level, e.g main subroutine of a physics module
!integer, parameter :: CLOCK_ROUTINE=41       !level of individual subroutine or function
!integer, parameter :: CLOCK_LOOP=51          !loops or blocks within a routine
!integer, parameter :: CLOCK_INFRA=61         !infrastructure level, e.g halo update

function fmsclock_id(name)
  use fms_mod, only : mpp_clock_id, clock_flag_default, CLOCK_SUBCOMPONENT
  implicit none
  integer                       :: fmsclock_id
  character(len=*),  intent(in) :: name
  fmsclock_id = mpp_clock_id(name, flags=clock_flag_default, grain=CLOCK_SUBCOMPONENT)
end function fmsclock_id

subroutine fmsclock_begin(id)
  use fms_mod, only : mpp_clock_begin
  implicit none
  integer, intent(in) :: id
  call mpp_clock_begin(id)
end subroutine fmsclock_begin

subroutine fmsclock_end(id)
  use fms_mod, only : mpp_clock_end
  implicit none
  integer, intent(in) :: id
  call mpp_clock_end(id)
end subroutine fmsclock_end
