      SUBROUTINE CENDAY(NYY, NMM, NDD, NCEN)
      IMPLICIT NONE
C
C**********************************************************************
C
C   NAME- CENDAY
C
C   LANGUAGE- VS FORTRAN  TYPE- SUBROUTINE      COMPUTER- CRAY J916
C
C   VERSION- 1.0    DATE- 11/16/88   PROGRAMMER- S. SWEETLAND (SMSRC)
C   VERSION- 2.0    DATE- 05/06/96   PROGRAMMER- FRANK TILLEY (SMSRC)
C      CHANGED ALL I*4 VARIABLES TO INT FOR REHOSTING TO THE CRAY.
C   VERSION- 3.0    DATE- 04/02/98   PROGRAMMER- LEAH WILSON (RSTX)
C      MODIFIED TO ACCEPT NYY AS 4-DIGITS OR 2-DIGITS
C   VERSION- 3.1    DATE- 05/16/06   PROGRAMMER- FRANK TILLEY (IMSG)
C      ADDED CHECKING OF MONTH AND DAY VALUES. IF EITHER IS INVALID
C      THE CENTURY DAY IS RETURNED AS ZERO (WR-303).
C
C   FUNCTION- COMPUTES JULIAN DAY SINCE 1/1/1900 OF A GIVEN DAY
C
C   CALLING SEQUENCE PARAMETERS-
C     VARIABLE          TYPE I/O  FUNCTION
C     --------          ---- ---  --------
C     NYY               INT  I    LAST TWO DIGITS OF THE YEAR(00-99)
C     NMM               INT  I    MONTH OF THE YEAR, 1-12
C     NDD               INT  I    DAY OF THE MONTH, 1-31
C     NCEN              INT  O    NUMBER OF DAYS SINCE 0 JAN. 1900
C
      INTEGER   NYY,NMM,NDD,NCEN
C
C   LOCAL PARAMETERS-
C     VARIABLE          TYPE  FUNCTION
C     --------          ----  --------
C     JULDAY            INT   CALCULATED JULIAN DAY OF THIS YEAR
C     LEAPYR            INT   FLAG 1 OR 0 FOR LEAP YEAR
C     NLEAPS            INT   COUNT OF LEAP YEARS SINCE AND
C                             INCLUDING 1900
C     NTAB              INT   12-CELL VECTOR CONTAINING CONSECUTIVE
C                             DAYS' TOTAL AT THE END OF EACH MONTH
C     NYYCEN            INT   CALCULATED VARIABLE FOR NUMBER OF
C                             YEARS SINCE 1900
C
      INTEGER  JULDAY,LEAPYR,NLEAPS,NTAB(12),NYYCEN,IDUM
      DATA NTAB/0,31,59,90,120,151,181,212,243,273,304,334/
C
C   INTRINSIC FUNCTIONS USED- MOD
C
C   COMMENTS-
C
C   MODIFIED NMC.PROD.V77W3LIB.SOURCE(W3FS17)
C
C   RESTRICTIONS: THIS PROCEDURE IS VALID FROM JAN. 1, 1956 THRU
C     FEB. 2056, AND THEN SOME
C
C   NOTES: IF THE INPUT MONTH OR DAY IS INVALID THE CENTURY DAY
C          IS RETURNED AS ZERO.
C   
C**********************************************************************
C
      NCEN = 0
      IF (NMM.LT.1.OR.NMM.GT.12.OR.NDD.LT.1.OR.NDD.GT.31.OR.
     +    NYY.LT.0) THEN
         IF (NYY.LT.0) THEN
            PRINT *,' CENDAY: INVALID YEAR: ',NYY
         END IF
         IF (NMM.LT.1.OR.NMM.GT.12) THEN
            PRINT *,' CENDAY: INVALID MONTH ',NMM
         END IF
         IF (NDD.LT.1.OR.NDD.GT.31) THEN
            PRINT *,' CENDAY: INVALID DAY ',NDD
         END IF
         PRINT *,' CENDAY: CENTURY DAY RETURNED AS ZERO'
         RETURN
      END IF

C   IF YEAR IS INPUT AS 4-DIGITS, KNOCK IT DOWN TO 2-DIGITS FOR
C   THIS SUBROUTINE TO RETURN THE PROPER RESULTS.
C
      IF(NYY.GE.100) THEN         
         IDUM = NYY / 100
         NYY = NYY - IDUM*100
      ENDIF
C
C   SET LEAP YEAR FLAG TO 0 AND TEST TO SEE IF THE ARGUMENT OF
C   THE YEAR PASSED FROM THE SUBROUTINE SELDAY IS A LEAP YEAR
C   NOTE:  THE YEAR 2000 IS A LEAP YEAR
C
      LEAPYR = 0
      IF(MOD(NYY,4) .EQ. 0)LEAPYR = 1
C
C   COUNT THE NUMBER OF LEAP YEARS SO FAR IN THIS CENTURY
      NLEAPS = NYY / 4
C
C  WELCOME TO THE 21ST CENTURY.  WE DON'T ANTICIPATE THAT THE
C  THE BIRDS WILL STILL BE FLYING IN 2056, BUT IF THEY ARE,
C  CHANGE THE 56 TO 86
C
C   SET THE LOCAL VARIABLE NYYCEN EQUAL TO THE ARGUMENT NYY
C   IF THE YEAR IS BETWEEN 0 AND 56 ASSUME IT IT YEAR 2000 OR LATER
C
      NYYCEN = NYY
      IF(NYYCEN .GE. 0 .AND. NYYCEN .LT. 56)THEN
C
C   IF IT IS THE YEAR 2000 OR LATER ADD 25 TO THE COUNT OF LEAP
C   YEARS TO COMPENSATE FOR THE 20TH CENTURY
C
         NLEAPS = NLEAPS + 25
C
C   IF IT IS THE 21ST CENTURY, ADD 100 TO THE YEAR SO THAT WHEN
C   THE YEAR IS MULTIPLIED BY THE NUMBER OF DAYS IN A YEAR (365)
C   THE CENTURY DAY CALCULATION WILL BE CORRECT
C
         NYYCEN = NYY + 100
      ENDIF
C
C   IF IT IS A LEAP YEAR, ADJUST THE LEAP YEAR COUNT
C
      IF(LEAPYR.EQ.1 .AND. NLEAPS.GT.0)NLEAPS = NLEAPS - 1
C
C   IF THE MONTH IS JANUARY OR FEBRUARY, SET THE LEAP YEAR FLAG TO 0
C
      IF(LEAPYR.EQ.1 .AND. NMM.LT.3)LEAPYR = 0
C
C   CALCULATE THE JULIAN DAY BY ADDING THE NUMBER OF DAYS ELAPSED SO
C   FAR THIS YEAR PLUS THE NUMBER OF DAYS IN THIS MONTH PLUS THE
C   LEAP YEAR FLAG
C
      JULDAY = NTAB(NMM) + NDD + LEAPYR
C
C   CALCULATE THE JULIAN DAY OF THIS CENTURY BY MULTIPLYING THE
C   NUMBER OF YEAR TIMES THE NUMBER OF DAYS IN A YEAR (365) AND
C   ADDING TO THE PRODUCT THE JULIAN DAY CALCULATED IN THE PREVIOUS
C   LINE OF CODE AND THE NUMBER OF LEAP YEARS
C
      NCEN = NYYCEN * 365 + JULDAY + NLEAPS
C
      RETURN
      END
