SUBROUTINE CHKOBTIM(LDSLOT,KACTIM)

!**** *CHKOBTIM* - Controls if an observation time slot is available.
!                  (3D/4D VAR)

!     Purpose.
!     --------
!     Controls time slot.

!**   Interface.
!     ----------
!        *CALL* *CNT4AD

!        Explicit arguments :
!        --------------------
!        LDSLOT : .T. IF A TIME SLOT IS TO BE USED

!        Implicit arguments :
!        --------------------
!        None

!     Method.
!     -------
!        See documentation

!     Externals.
!     ----------

!     Reference.
!     ----------
!        ECMWF Research Department documentation of the IFS

!     Author.
!     -------
!        Jean-Noel Thepaut *ECMWF*

!     Modifications.
!     --------------
!        Original : 92-07-20
!        Modified : 98-01-21 F.Veerse Remove RSTATI which is exclusively
!                                     dedicated to the radiation scheme
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        G. Desroziers 04-06-18 LDSLOT actually INTENT(INOUT)
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

USE YOMDIMO  , ONLY : NOBTOTG
USE YOMCT0   , ONLY : LOBS
USE YOMCT3   , ONLY : NSTEP
USE YOMDYN   , ONLY : TSTEP
USE YOMECTAB , ONLY : NTSLOTNO, NTSLOTNOS, NTSLOTNOE, NTSLVSTST
USE YOMVAR   , ONLY : NITER4D
USE YOMLUN   , ONLY : NULOUT

IMPLICIT NONE

LOGICAL           ,INTENT(INOUT) :: LDSLOT 
INTEGER(KIND=JPIM),INTENT(INOUT) :: KACTIM 
LOGICAL :: LLFIRST

REAL(KIND=JPRB) :: ZSTATI
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "obsprep.intfb.h"

!      -----------------------------------------------------------

!*       0.    Check if OBS run
!              ----------------

IF (LHOOK) CALL DR_HOOK('CHKOBTIM',0,ZHOOK_HANDLE)

!*       1.    Check if timeslot(s) to be used with this timestep
!              --------------------------------------------------

IF(LOBS)THEN
  ZSTATI = REAL(NINT(NSTEP*TSTEP),JPRB)
  LLFIRST  = .TRUE.

  DO WHILE(NTSLVSTST(KACTIM) == NSTEP ) 
    NTSLOTNO  = KACTIM
    IF(LLFIRST) THEN
      LLFIRST  = .FALSE.
      NTSLOTNOS = KACTIM
    ENDIF
    NTSLOTNOE = KACTIM
    KACTIM    = KACTIM + 1
    IF (NITER4D == 0 ) THEN
      WRITE(UNIT=NULOUT,FMT='('' CHKOBTIM;'','' TIME SLOT NO. : '',I3 &
       & ,'' TO BE USED WITH TIME STEP (NSTEP) : '',I3 &
       & ,'' ; MODEL TIME (SINCE START) : '',F6.0)')&
       & NTSLOTNO,NSTEP,ZSTATI  
    ENDIF
    CALL OBSPREP('V')
    IF(NOBTOTG > 0) THEN
      LDSLOT=.TRUE.
    ENDIF
  ENDDO
ENDIF

!     ------------------------------------------------------------------

IF (LHOOK) CALL DR_HOOK('CHKOBTIM',1,ZHOOK_HANDLE)
END SUBROUTINE CHKOBTIM
