CC  WINDOW.FOR - Illustrates windows and coordinate systems using the
CC               following functions:
CC               setviewport   setvieworg    setcliprgn
CC               setwindow     rectangle     rectangle_w
CC               ellipse       ellipse_w     clearscreen
CC
CC  Although not all illustrated here, functions ending in _w
CC  are similar to rectangle_w and ellipse_w.

      INCLUDE  'FGRAPH.FI'
      INCLUDE  'FGRAPH.FD'

      INTEGER*2              dummy, xhalf, yhalf, xquar, yquar
      DOUBLE PRECISION       x_upleft, y_upleft, x_botrght, y_botrght
      RECORD / xycoord /     xy
      RECORD / videoconfig / vc

C
C     Find graphics mode.
C
      IF( setvideomode( $MAXRESMODE ) .EQ. 0 ) 
     +   STOP 'Error:  cannot set graphics mode'
      CALL getvideoconfig( vc )

      xhalf = vc.numxpixels / 2
      yhalf = vc.numypixels / 2
      xquar = xhalf / 2
      yquar = yhalf / 2

C
C     First window - integer physical coordinates
C
      CALL setviewport( 0, 0, xhalf - 1, yhalf - 1 )
      dummy = setcolor( 2 )
      dummy = rectangle( $GBORDER, 0, 0, xhalf - 1, yhalf - 1 )
      dummy = setcolor( 1 )
      dummy = ellipse( $GFILLINTERIOR, xquar / 4, yquar / 4,
     +                 xhalf - (xquar / 4), yhalf - (yquar / 4) )
      READ (*,*)
      CALL clearscreen( $GVIEWPORT )
      dummy = rectangle( $GBORDER, 0, 0, xhalf - 1, yhalf - 1 )

C
C     Second window - integer world coordinates with clip region
C
      CALL setcliprgn( xhalf, 0, vc.numxpixels, yhalf )
      CALL setvieworg( xhalf + xquar - 1, yquar - 1, xy )
      dummy = setcolor( 3 )
      dummy = rectangle( $GBORDER, -xquar + 1, -yquar + 1, xquar,
     +                   yquar )
      dummy = setcolor( 2 )
      dummy = ellipse( $GFILLINTERIOR, (-xquar * 3) / 4,
     +                 (-yquar * 3) / 4, (xquar * 3) / 4,
     +                 (yquar * 3) / 4 )
      READ (*,*)
      CALL clearscreen( $GVIEWPORT )
      dummy = rectangle( $GBORDER, -xquar + 1, -yquar + 1, xquar,
     +                   yquar )

C
C     Third window
C
      CALL setviewport( xhalf, yhalf, vc.numxpixels - 1,
     +                  vc.numypixels - 1 )
      dummy = setwindow( .FALSE., -4.0, -5.0, 4.0, 5.0 )
      dummy = setcolor( 4 )
      dummy = rectangle_w( $GBORDER, -4.0, -5.0, 4.0, 5.0 )
      dummy = setcolor( 3 )
      dummy = ellipse_w( $GFILLINTERIOR, -3.0, -3.5, 3.0, 3.5 )
      READ (*,*)
      CALL clearscreen( $GVIEWPORT )
      dummy = rectangle_w( $GBORDER, -4.0, -5.0, 4.0, 5.0 )

C
C     Fourth window
C
      CALL setviewport( 0, yhalf, xhalf - 1, vc.numypixels - 1 )
      dummy = setwindow( .FALSE., -4.0, -5.0, 4.0, 5.0 )
      x_upleft  = -4.0
      y_upleft  = -5.0
      x_botrght =  4.0
      y_botrght =  5.0
      dummy = setcolor( 5 )
      dummy = rectangle_w( $GBORDER, x_upleft, y_upleft,
     +                     x_botrght, y_botrght )
      x_upleft  = -3.0
      y_upleft  = -3.5
      x_botrght =  3.0
      y_botrght =  3.5
      dummy = setcolor( 4 )
      dummy = ellipse_w( $GFILLINTERIOR, x_upleft, y_upleft,
     +                   x_botrght, y_botrght )

      READ (*,*)
      dummy = setvideomode( $DEFAULTMODE )
      END
