      SUBROUTINE YMD2YD(Y,M,D,YD)
C
C     GIVEN A YEAR, MONTH, AND DAY (AND FRACTION OF DAY) IN THE
C     GREGORIAN CALENDAR, THIS ROUTINE RETURNS THE DATE EXPRESSED
C     IN THE FORM YYYYDDD.DD.
C
C     B. KNAPP, 1988-11-14, 2001-04-24 (i*4)
C
C
C     RCS DATA
C     
C     $Header$
C     
C     $Log$
C
C
      IMPLICIT  NONE
C
C     INPUT:
      INTEGER*4 Y,M
      REAL*8 D
C
C     OUTPUT:
      REAL*8 YD
C
C     LOCAL:
      REAL*8 YD0, JD, DOY
      INTEGER*4 MDAYS(13,2),YY,MM
      DATA MDAYS  
     &   /  0, 31, 59, 90,120,151,181,212,243,273,304,334,365,
     &      0, 31, 60, 91,121,152,182,213,244,274,305,335,366/
      SAVE MDAYS
C
C     EXTERNAL FUNCTIONS, SUBROUTINES
      EXTERNAL YD2JD, JD2YD
C
      IF (D.LT.1.0D0 .AND. M.EQ.1) THEN
         YY = Y-1
         MM = 13
      ELSE
         YY = Y
         MM = M
      ENDIF
C
      IF ((MOD(YY,4).EQ.0) .AND.
     &    (MOD(YY,100).NE.0).OR.(MOD(YY,400).EQ.0)) THEN
         DOY = MDAYS(MM,2)+D
      ELSE
         DOY = MDAYS(MM,1)+D
      ENDIF
      YD0 = (1000*ABS(YY))+DOY
C
C     NOW CONVERT TO JD AND BACK, TO HANDLE ABNORMAL CASES WHERE
C     D IS GREATER THAN THE NUMBER OF DAYS IN THE MONTH M
      CALL YD2JD( YD0, JD )
      CALL JD2YD( JD, YD )
C
      IF (YY.LT.0) YD=-YD
C
      RETURN
      END
