      PROGRAM REPORTDAY

C     THIS PROGRAM IS BUGGY.
      
      IMPLICIT NONE
      
      INTEGER STARTYR
      INTEGER YEAR, MONTH, DAY
      INTEGER Y, D, I
      INTEGER TOTALD
      INTEGER DAYSINMONTH(12)
      
      LOGICAL LEAPYR, LEAP
      LOGICAL ISLEAPYR
      
      PARAMETER (STARTYR = 2000)
      
      DATA DAYSINMONTH /31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31/
      
      PRINT *, 'THIS IS A PROGRAM THAT CALCULATES THE NUMBER OF DAYS'
      
      PRINT *,'INPUT THE YEAR'
      READ *, YEAR
      IF (YEAR .LT. STARTYR) THEN
      	PRINT *, 'WRONG YEAR ', YEAR
      	STOP
      ELSE
      	PRINT *, 'YEAR = ', YEAR
      ENDIF
      
      IF (ISLEAPYR(YEAR)) THEN 
      	PRINT *, 'THIS IS A LEAP YEAR'
      ENDIF
      
      CALL READMON(MONTH)
      PRINT *, MONTH
      
      PRINT *,'INPUT THE DAY'
      READ *, DAY
      IF (MONTH .EQ. 1) THEN
      	IF (DAY .LT. 1 .OR. DAY .GT. 31) THEN
      	  PRINT *, 'WRONG MONTH ', MONTH 
      	  STOP
      	ENDIF
      ELSE IF (MONTH .EQ. 2) THEN
      	IF ((DAY .LT. 1) .OR. ((DAY .GT. 29) .AND. LEAPYR) .OR. 
     + (DAY .GT. 28 .AND. (.NOT. LEAPYR))) THEN
      	  PRINT *, 'WRONG DAY ', DAY 
      	  STOP
      	ENDIF
      ENDIF
      PRINT *, 'DAY = ', DAY
      
      TOTALD = 0
      DO 10 Y = 2000, YEAR - 1
      	LEAP = ISLEAPYR(Y)
      	IF (LEAP) THEN
      	  TOTALD = TOTALD + 366
      	ELSE
	  TOTALD = TOTALD + 365
	ENDIF
10    CONTINUE
      PRINT *, 'TOTAL # OF DAYS (AFTER COUNTING YEARS) = ', TOTALD
      
      DO 20 I = 1, MONTH - 1
        TOTALD = TOTALD + DAYSINMONTH(I)
20    CONTINUE
            	
      IF (LEAPYR .AND. MONTH .GT. 2) THEN
        TOTALD = TOTALD + 1
      ENDIF
      
      PRINT *, 'TOTAL # OF DAYS (AFTER COUNTING MONTH) = ', TOTALD
      
      TOTALD = TOTALD + DAY - 1
      PRINT *, 'TOTAL # OF DAYS (AFTER COUNTING DAY) = ', TOTALD
      
      D = MOD(TOTALD + 6, 7)
      PRINT *, 'D = ', D
      
      
      STOP
      END
      
      LOGICAL FUNCTION ISLEAPYR(YEAR)
      INTEGER YEAR
      
      IF (YEAR .GT. 0) THEN 
       ISLEAPYR = (MOD(YEAR, 400) .EQ. 0 .OR. (MOD(YEAR, 4) .EQ. 0 .AND. 
     +    MOD(YEAR, 100) .NE. 0))
      ENDIF
      RETURN
      END
      
      SUBROUTINE READMON(M)
      INTEGER M
      
      PRINT *,'INPUT THE MONTH'
      READ *, M
      IF (M .LT. 0 .OR. M .GT. 12) THEN
      	PRINT *, 'WRONG MONTH ', M 
      	STOP
      ELSE
      	PRINT *, 'MONTH = ', M
      ENDIF
      
      RETURN
      END