C*TDATE  -- name of month and day of week
C+
      SUBROUTINE TDATE (Y,M,D,JD,MNAME,DNAME)
      INTEGER Y, M, D
      INTEGER JD
      CHARACTER*3 MNAME, DNAME
C
C Input: date (y/m/d) in Y,M,D   (may be 'unnormalized')
C Output: 'normalized' date in Y/M/D, julian day
C number at 12 hrs UT (JD), name of month (MNAME),
C day of week (DNAME)
C
C History:
C  1978 Mar  8 - TJP.
C  1987 Nov 12 - convert to Fortran-77 standard (TJP).
C-----------------------------------------------------------------------
      INTEGER     NYRM1, IC, LEAP, NDAYS, J, ML
      CHARACTER*3 MLIST(12)
      INTEGER     MLENG(12)
      CHARACTER*3 DLIST(7)
      DATA MLIST/'Jan','Feb','Mar','Apr','May','Jun',
     1           'Jul','Aug','Sep','Oct','Nov','Dec'/
      DATA MLENG/31,28,31,30,31,30,31,31,30,31,30,31/
      DATA DLIST/'Mon','Tue','Wed','Thu','Fri','Sat','Sun'/
C
C JD number at 12 hrs UT on Jan 0 of year Y (Gregorian calendar).
C
      IF (M.GE.1 .AND. M.LE.12) GOTO 1
           Y = Y + (M-1)/12
           M = MOD(M-1,12)+1
           IF (M.LT.0) Y = Y-1
           IF (M.LT.0) M = M+12
    1 NYRM1 = Y-1
      IC = NYRM1/100
      JD = 1721425 + 365*NYRM1 + NYRM1/4 - IC + IC/4
C
C Day number; is it a leap year?
C
      NDAYS = D
      IF (M.EQ.1) GOTO 20
      DO 10 J = 2,M
          NDAYS = NDAYS+MLENG(J-1)
   10 CONTINUE
   20 LEAP = 0
      IF((MOD(Y,4).EQ.0.AND.MOD(Y,100).NE.0).OR.(MOD(Y,400).EQ.0))
     1          LEAP = 1
      IF(M.GT.2) NDAYS = NDAYS+LEAP
C
C Return JD and DNAME.
C
      JD = JD+NDAYS
      DNAME = DLIST(1+MOD(JD,7))
C
C Convert back to M/D.
C
      DO 30 J=1,12
          ML = MLENG(J)
          IF(J.EQ.2) ML = ML+LEAP
          IF(NDAYS.LE.ML) GOTO 40
          NDAYS = NDAYS-ML
   30 CONTINUE
      Y = Y+1
      M = 1
      D = NDAYS
      GOTO 1
C
   40 M = J
      D = NDAYS
      MNAME = MLIST(J)
      RETURN
C
      END
