C     .TITLE MORT4
C
C  13 DEC 72 - ADD DATE OF PAYMENT, IF AVAILABLE
C  17 OCT 72 - PAUL HENDERSON (UPDATED FROM AN EARLIER VERSION)
C
C  WATRAN PROGRAM TO PRODUCE AN AMORTIZATION TABLE FROM INFORMATION
C  ENTERED FROM THE KEYBOARD AT RUN TIME.  OUTPUT IS ON .DAT +6.
C  PERIODIC PAYMENTS ARE READ IN FROM .DAT +5.
C
      DIMENSION DATE (14)
      REAL NUMBER,NP,JBYP,NYEARS
101   WRITE (4,11)
      READ(4,15) DEBT
      WRITE(4,12)
      READ(4,15) ANNINT
      WRITE(4,14)
      READ(4,15) PPERYR
      JBYP=ANNINT/PPERYR/100.
      RATE=JBYP
      I=0
      TOTINT=0.
      TOTPAY=0.
      DEBTI=DEBT
      WRITE (6,23) IFIX(PPERYR),ANNINT
      WRITE (6,4)
      WRITE(6,5)I,DEBT
1     READ (5,15,END=2) PAY,DATE
      TOTPAY=TOTPAY+PAY
      PAYINT=RATE*DEBT
      TOTINT=TOTINT+PAYINT
      PPRINC=PAY-PAYINT
      DEBTJ=DEBT
      DEBT=DEBT-PPRINC
      I=I+1
      IF(DEBT)2,2,102
102   WRITE(6,6)I,PAY,PAYINT,PPRINC,DEBT,DATE
      IF ((I-(I/12)*12).EQ.0) WRITE (6,21)
      IF ((I-(I/48)*48).NE.0) GO TO 1
      WRITE (6,22)
      WRITE (6,4)
      GO TO 1
2     WRITE (6,8) TOTINT
      WRITE (6,9) TOTPAY
      WRITE (6,22)
      GO TO 101
4     FORMAT(7H PERIOD,8H PAYMENT,9H INTEREST,11H  PRINCIPAL,
     *9H     DEBT/)
5     FORMAT(I5,28XF12.2)
6     FORMAT(I5,F8.2,F9.2,F11.2,F12.2,14A5)
8     FORMAT(/18H  TOTAL INTEREST $,F8.2)
9     FORMAT(/18H   AMOUNT REPAID $,F8.2)
11    FORMAT(28H WHAT IS THE AMOUNT BORROWED)
12    FORMAT(39H WHAT IS THE RATE OF INTEREST PER ANNUM)
14    FORMAT(27H HOW MANY PAYMENTS PER YEAR)
15    FORMAT(F10.2,T11,14A5)
21    FORMAT (1H )
22    FORMAT (1H1)
  23  FORMAT (5XI3,' PAYMENTS PER YEAR @',F6.2,'% PER ANNUM'/)
      END
