SUBROUTINE REFTIM(KDATE, KTIME, KRFTIM)

!**** SUBROUTINE REFTIM - TIME IN MINUTES ELAPSED FROM A REFERENCE DATE

!          HEIKKI JARVINEN   ECMWF          15/NOV/1995

!*    PURPOSE
!     -------

!        TIME IN MINUTES ELAPSED FROM A REFERENCE DATE

!**   INTERFACE
!     ---------

!     ***CALL*REFTIM(KDATE, KTIME, KRFTIM)
!     WHERE KDATE  = DATE IN THE FORM YYYYMMDD
!           KTIME  = TIME IN THE FORM HHMMSS
!           KRFTIM = REFERENCE TIME IN MINUTES SINCE 1/1/1970

!        REFTIM IS CALLED BY VARIOUS ROUTINES

!*    METHOD
!     ------

!        NOTE: SECONDS ARE TRUNCATED (NOT ROUNDED) AWAY

!*    EXTERNALS
!     ---------

!        MINDIFF    (ECLIB)

!**   MODIFICATIONS
!     -------------

!     M.Hamrud 980915 Y2K problems            

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

USE YOMLUN   , ONLY :    NULERR

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KDATE 
INTEGER(KIND=JPIM),INTENT(IN)    :: KTIME 
INTEGER(KIND=JPIM),INTENT(OUT)   :: KRFTIM 
INTEGER(KIND=JPIM), PARAMETER :: JPREFYEAR = 19970101

INTEGER(KIND=JPIM) :: IDAY1, IDAY2, IHOUR1, IHOUR2, IMIN1, IMIN2,&
 & IMON1, IMON2, IRET, IYEAR1, IYEAR2  
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"

#include "fcttim.h"
!*
!     ------------------------------------------------------------------

!        1.       REFERENCE TIME
!                 --------------

IF (LHOOK) CALL DR_HOOK('REFTIM',0,ZHOOK_HANDLE)
IYEAR1 = NCCAA(JPREFYEAR)
IMON1  = NMM(JPREFYEAR)
IDAY1  = NDD(JPREFYEAR)
IHOUR1 = 0
IMIN1  = 0
IYEAR2 = NCCAA(KDATE)
IMON2  = NMM(KDATE)
IDAY2  = NDD(KDATE)
IHOUR2 = KTIME/10000         ! HOURS
IMIN2  = MOD(KTIME/100, 100) ! MINUTES

CALL MINDIFF(IYEAR1,IMON1,IDAY1,IHOUR1,IMIN1,&
 & IYEAR2,IMON2,IDAY2,IHOUR2,IMIN2,KRFTIM,IRET)  
IF(IRET /= 0) THEN
  WRITE(NULERR,*)'REFTIM**',IYEAR1,IMON1,IDAY1,IHOUR1,IMIN1,&
   & IYEAR2,IMON2,IDAY2,IHOUR2,IMIN2,KRFTIM,IRET  
  CALL ABOR1('REFTIM:ERROR IN MINDIFF')
ENDIF
IF (LHOOK) CALL DR_HOOK('REFTIM',1,ZHOOK_HANDLE)

END SUBROUTINE REFTIM

