      FUNCTION  MJDAY (MONTH,DAY,YEAR)
C
C**********************************************************************
C
C   NAME- MJDAY
C
C   LANGUAGE- FORTRAN 77     TYPE- FUNCTION        COMPUTER- CRAY    
C
C   VERSION- 1.0    DATE- 12/29/88   PROGRAMMER- KARL W. COX (SMSRC)
C   VERSION- 2.0    DATE- 07/19/94   PROGRAMMER- FRANK TILLEY (SMSRC)
C          ATOVS-12 EXPLICITLY DECLARED I*4 FUNCTION "MJDAY".
C   VERSION- 3.0    DATE- 05/13/96   PROGRAMMER- ALEX POZDNYAK (FDC) 
C       FOR REHOSTING TO THE CRAY, CHANGED ALL I*4 DECLARATIONS TO
C       INTEGER.
C
C   FUNCTION- RETURNS THE NUMBER OF WHOLE DAYS SINCE 00Z ON
C        NOV. 16, 1858 (I.E., JULIAN DAY 2400000).  THE PURPOSE IS TO
C        OBTAIN A SMALLER NUMBER TO BE USED IN COMPUTATIONS TO AVOID
C        POSSIBLE PRECISION PROBLEMS.
C
C   CALLING SEQUENCE PARAMETERS-
C     VARIABLE   TYPE  I/O  DESCRIPTION
C     --------   ----  ---  -----------
C     MONTH      INT    I   NUMBER OF MONTH (1 - 12).
C     DAY        INT    I   DAY OF MONTH.
C     YEAR       INT    I   YEAR:  POSITIVE VALUES ARE AD,
C                           NEGATIVE VALUES ARE BC.  IF YEAR = 0,
C                           1 BC IS ASSUMED.
C
C   LOCAL PARAMETERS-
C     VARIABLE   TYPE  DESCRIPTION
C     --------   ----  -----------
C     JULYR      INT   NUMBER OF YEARS SINCE BEGINNING OF JULIAN
C                      CALENDAR.
C     DOFYR      INT   NUMBER OF THE DAY FROM THE BEGINNING OF
C                      THE YEAR.
C     NCENTS     INT   NUMBER OF CENTURIES AD.
C     JULDAY     INT   JULIAN DAY NUMBER.
C     GREG       INT   PARAMETER TO CHECK RELATION OF DATE TO
C                      GREGORIAN CALENDAR REFORM.
C
C   SUBPROGRAMS CALLED- NONE
C
C   FUNCTIONS USED- MOD, NINT, REAL
C
C   EXIT STATES- NONE
C
C**********************************************************************
      INTEGER   MJDAY,MONTH,DAY,YEAR
      INTEGER   JULYR,DOFYR,NCENTS,JULDAY
C
      INTEGER   GREG
      PARAMETER (GREG=15+31*(10+12*1582))
C
      IF (YEAR .LT. 0) YEAR = YEAR + 1
      JULYR = YEAR + 4712
C
C  FIRST CALCULATE THE NUMBER OF DAYS SINCE JAN 1, 4713 BC BY THE
C  JULIAN CALENDAR.
C
      IF(MONTH .LT. 3) THEN
            DOFYR = NINT(30.6*REAL(MONTH - 1)) + DAY
        ELSE IF(MOD(JULYR,4) .EQ. 0) THEN
            DOFYR = NINT(30.6*REAL(MONTH) - 31.8) + DAY
        ELSE
            DOFYR = NINT(30.6*REAL(MONTH) - 32.8) + DAY
        ENDIF
      JULDAY = 365*JULYR + (JULYR - 1)/4 + DOFYR
C
C  IF DATE IS AFTER OCT 15,1582, MAKE ADJUSTMENTS FOR GREGORIAN REFORM.
C  THE JULIAN AND GREGORIAN CALENDARS AGREE ON JAN 1, 300 AD, BUT
C  DIVERGE BY THREE DAYS EVERY FOUR CENTURIES FROM THAT POINT ON.
C
      IF (DAY+31*(MONTH+12*YEAR) .GE. GREG) THEN
        IF(MONTH .GE. 3) THEN
            NCENTS = YEAR/100
          ELSE
            NCENTS = (YEAR - 1)/100
          ENDIF
        JULDAY = JULDAY - (NCENTS - NCENTS/4 - 2)
      ENDIF
C
C  COMPUTE MODIFIED JULIAN DAY
C
      MJDAY = JULDAY - 2400001
C
      RETURN
      END
