      PROGRAM koch
*     improved output 8/9/95 by computing aspect ratio
*     generate triadic Koch curve using recursion
      IMPLICIT NONE
      REAL*8 x1, x2, y1, y2
      INTEGER IR_, n, k
      LOGICAL TBkeyinput
      DATA k/0/
      CALL GWopen(IR_, 0)
      CALL initial(x1,y1,x2,y2,n)
*     draw Koch curve for different number of iterations
      DO WHILE(k .NE. ICHAR('s'))
         k = 0
         CALL draw(x1,y1,x2,y2,n)
         DO WHILE(.NOT. TBkeyinput())
         ENDDO
         CALL TBgetkey(k)
         n = n + 1                          ! number of stages of generation
         CALL GWclear(IR_, -1)
      END DO
      CALL GWquit(IR_)
      END
C
      SUBROUTINE initial(x1,y1,x2,y2,n)
      IMPLICIT NONE
      REAL*8 x1, y1, x2, y2
      REAL xwin, ywin
      INTEGER IR_, n
      n = 0                                 ! number of iterations
      x1 = 1                                ! coordinates at left end of line
      y1 = 5                                ! arbitrary units
      x2 = 10                               ! coordinates at right end of line
      y2 = 5
      CALL compute_aspect_ratio(8.0,xwin,ywin)
      CALL GWindow(IR_, 0.0, 0.0, xwin, ywin)
      CALL GWsetpen(IR_, 16, -1, -1, -1)
      END
