SUBROUTINE CNT41S
USE PARKIND1  ,ONLY : JPIM     ,JPRB,JPRD


USE YOMLUN1S , ONLY : NULOUT   ,NULFOR
USE YOMCT01S , ONLY : NSTART   ,NSTOP
USE YOMDYN1S , ONLY : NSTEP    ,TSTEP    ,TDT
USE YOMLOG1S,  ONLY : IDBGS1,LREADDAY
USE OMP_LIB
#ifdef DOC

!**** *CNT41S*  - Controls integration job at level 4

!     Purpose.
!     --------
!              Controls integration at level 4

!**   Interface.
!     ----------
!        *CALL* *CNT41S

!        Explicit arguments :
!        --------------------
!        None

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

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

!     Externals.
!     ----------
!        Called by CNT31S.

!     Reference.
!     ----------
!        ECMWF Research Department documentation 
!        of the one-column surface model

!     Author.
!     -------
!        Jean-Francois Mahfouf and Pedro Viterbo  *ECMWF*

!     Modifications.
!     --------------
!        Original : 95-03-21

#endif
!     ------------------------------------------------------------------

IMPLICIT NONE

#include "dattim.intfb.h"
#include "updtim1s.intfb.h"
#include "dtforc.intfb.h"
#include "stepo1s.intfb.h"

INTEGER (KIND=JPIM) :: ZYYYYMMDD,ZHHMM
REAL (KIND=JPRB) :: ZJUL
REAL (KIND=JPRD) :: ZTT0,ZTT1,ZTT2

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


!*       1.    MAIN TIME LOOP.
!              ---------------
ZTT1 = OMP_GET_WTIME()
ZTT0 = ZTT1 
DO NSTEP=NSTART,NSTOP


!*       1.1   CURRENT VALUE OF TIME STEP LENGTH.
!              ----------------------------------
  IF ( IDBGS1 > 0 ) THEN
    CALL DATTIM(ZJUL,ZYYYYMMDD,ZHHMM)
    WRITE(NULOUT,'(a5,i10,a6,i9,a1,i4)') 'STEP=',NSTEP,' DATE=',ZYYYYMMDD, ' ',ZHHMM
  ENDIF
  

  TDT=TSTEP


!*       1.2   RESET OF TIME DEPENDENT CONSTANTS.
!              ----------------------------------

  CALL UPDTIM1S(NSTEP,TDT,TSTEP)

!*       1.3    TIME INTERPOLATION OF THE FORCING.
!               ----------------------------------
  
  IF ( ZHHMM .EQ. 0 .AND. LREADDAY) THEN
    CALL SUFCDF  !! Testing for slot read of forcing ! 
  ENDIF 
  
  CALL DTFORC


!*       1.4   COMPUTATION OF THE ENTIRE TIME STEP.
!              ------------------------------------

  CALL STEPO1S
  
  IF ( IDBGS1 > 0 ) THEN
    ZTT2 = OMP_GET_WTIME()
    WRITE(NULOUT,'(a5,i10,a5,f8.3,a7,f8.3)') 'STEP=',NSTEP,' WALsec: ',ZTT2-ZTT1
    ZTT1 = OMP_GET_WTIME()
  ENDIF

ENDDO
IF ( IDBGS1 > 0 ) THEN
  ZTT2 = OMP_GET_WTIME()
  WRITE(NULOUT,'(a27,f8.3)') 'CNT41S: Time step loop in: ',ZTT2-ZTT0
ENDIF

!*       2.    CLOSE FILES.
!              ------------

!*       2.1   CLOSE ATMOSPHERIC FORCING INPUT FILE.
!              -------------------------------------

CLOSE(NULFOR)

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

RETURN

END SUBROUTINE CNT41S
