PROGRAM TEST_DATES
USE PARKIND1  ,ONLY : JPIM     ,JPRB , JPRD
USE YOMCST   , ONLY : RDAY
USE RTIME2DATE_MOD 
IMPLICIT NONE

#include "fcttim.h"
#include "updcal.intfb.h"

REAL(KIND=JPRB) :: ZT

INTEGER(KIND=JPIM) :: JY,JM,JD,JSEC
INTEGER(KIND=JPIM) :: JYREF,JMREF,JDREF,JSECREF
INTEGER(KIND=JPIM) :: JDATE

RDAY=86400._JPRB

WRITE(*,*) 'TEST_DATES'

WRITE(*,*) '1st test- find date 0 of RTIME'

TOP : DO JY=1900,2100
  DO JM=1,12
    DO JD=1,31
      DO JSEC=0,86400,3600
        ZT=RTIME(JY,JM,JD,JSEC)
        IF (ZT == 0 ) THEN
          JYREF=JY
          JMREF=JM
          JDREF=JD
          JSECREF=JSEC
          WRITE(*,*) JYREF,JMREF,JDREF,JSECREF/3600,ZT
          WRITE(*,*) NYYYYR,NMMR,NDDR,NSECR/3600
          EXIT TOP
        ENDIF
      ENDDO
    ENDDO
  ENDDO
ENDDO TOP

WRITE(*,*) "2nd test UPDCAL"
CALL UPDCAL(1,1,1600,200000,JD,JM,JY)
WRITE(*,*) 'date -u -d "1600-01-01 + 200000 days" +"%Y%m%d" : 21470801: ',NCONSTRUCT_DATEY(JY,JM,JD)
CALL UPDCAL(1,8,2147,-200000,JD,JM,JY)
WRITE(*,*) 'date -u -d "21470801 -200000 days" +"%Y%m%d": 16000101: ',NCONSTRUCT_DATEY(JY,JM,JD)

WRITE(*,*) "3rd Test RTIME2DATE"
CALL RTIME2DATE(RTIME(NYYYYR,NMMR,NDDR,NSECR),JDATE,JSEC)
WRITE(*,*) '1: ', NYYYYR,NMMR,NDDR,NSECR,JDATE,JSEC
CALL RTIME2DATE(RTIME(1832,2,3,6*3600+5*60),JDATE,JSEC)
WRITE(*,*) '2: 18320203 ',6*3600+5*60, JDATE,JSEC
CALL RTIME2DATE(RTIME(2432,8,31,1*3600+50*60),JDATE,JSEC)
WRITE(*,*) '2: 24320831 ',1*3600+50*60, JDATE,JSEC


END PROGRAM TEST_DATES
