
      INCLUDE 'FGRAPH.FI'

      SUBROUTINE RealToString (r, digits, wid, TheString)
      REAL r, tempr
      CHARACTER * 80 TheString, Result
      INTEGER  exponent, digits, wid, num, position, behind, before
      INTEGER delta, i,j, y, strLen, location
      LOGICAL sign

      location = 1
      CALL InitStr(TheString)
      tempr = r * 1.000001
      sign = .FALSE.
      strLen = ABS(REAL(digits)) + 2    !!!  min. 2 characters sign, digit
      IF (digits .NE. 0) strLen = strLen + 1
      IF (digits .LT. 0) strLen = strLen + 4
      IF (tempr .LT. 0)  sign = .TRUE.
      tempr = ABS(tempr)


      !!!  normalize downward, less than 10
      exponent = 0
      DO WHILE (tempr .GE. 10.0)
       tempr=tempr/ 10.0
        exponent = exponent + 1
      END DO
      IF (digits .GE. 0) THEN
        before = exponent
      ELSE
        before = 0
      END IF
      behind = ABS(digits)

      !!!  scientific notation
      IF (digits .LT. 0 .AND. tempr .NE. 0.0) THEN
        DO WHILE (tempr .LT. 1.0 )  !!!  normalize upward, greater than 1
         tempr=tempr* 10.0
          exponent = exponent - 1
        END DO
        IF (tempr .GE. 10.0) THEN  !!!  normalize downward to less than 10
         tempr=tempr/ 10.0
          exponent = exponent + 1
        END IF
      END IF
      !!!  sign
      IF (sign) THEN
        Result(1:1) = '-'
        location = location + 1
      END IF

      !!!  Write digits before the decimal-point
      y = AINT(tempr)
      Result(location:location) = CHAR(y+48)
      location = location + 1
      tempr= tempr - REAL(y)
      DO WHILE (before .GT. 0)
        tempr = tempr * 10.0
        y = AINT(tempr)
        Result(location:location) =  CHAR(y+48)
        location = location + 1
        tempr = tempr - y
        before = before - 1
      END DO
      IF (behind .NE. 0) THEN
        Result(location:location) = '.'
        location = location + 1
      END IF

      !!!  write digits after the decimal-point
      DO WHILE (behind .GT. 0)
        tempr = tempr * 10.0
        y = AINT(tempr)
        Result(location:location) = CHAR(y + 48)
        location = location + 1
        t = REAL(y)
        tempr = tempr - REAL(y)
        behind = behind - 1
      END DO

      !!!  scientific notation: write exponent
      IF (digits .LT. 0) THEN
        Result(location:location) =  'E'
        location = location + 1
        IF (exponent .GE. 0) THEN
          Result(location:location) =  '+'
        ELSE
          Result(location:location) =  '-'
        END IF
        location = location + 1
        num = ABS(exponent)
        IF (num .GE. 10) THEN
          explen = 2
        ELSE
          explen = 1
        END IF
        position = location + explen - 1    !!!  start on the right

         DO WHILE (num .NE. 0)
           i = MOD(num, 10)
           Result(position:position) = CHAR(i+48)
           position = position - 1
           num = num / 10
         END DO
         DO WHILE (position .GE. location)
           Result(position:position) = ' '
           position = position - 1
         END DO
         location = location + explen
       END IF

    !!!  leading blanks
       location = location - 1
       IF (wid .GT. location) THEN
         delta = wid - location
       ELSE
         delta = 0
       END IF
       DO i = 1, location
            j = i+delta
            TheString(j:j) = Result(i:i)
       END DO
      END !SUBROUTINE


      SUBROUTINE BarWorld (xx1, yy1, h, w, gc, gh)
      REAL xx1, yy1, h, w
      INCLUDE 'GRAFTYPE.FOR'
      INTEGER gc, gh
      RECORD /WorldRect/ Barrect

      CALL setfillstyleXX(gh, gc)

      Barrect.left = ConvertX1(xx1)
      Barrect.bottom = ConvertY1(yy1)
      Barrect.right = ConvertX1(xx1 + w)
      Barrect.top = ConvertY1(yy1 + h)
      CALL BarXX(Barrect.left, Barrect.bottom,
     +           Barrect.right, Barrect.top)

      END !SUBROUTINE



      SUBROUTINE BarXX (x1, y1, x2, y2)
      REAL x1,y1,x2,y2, vxAbs, vyAbs
      INTEGER x1int, y1int, x2int, y2int, dummy, vx, vy, vh, vl
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /PlotVals/ vxAbs, vyAbs
      COMMON /ViewVals/ vx, vy, vh, vl
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF

      INCLUDE 'FGRAPH.FD'

      IF (CRTGraphOnF) THEN
          x1int = NINT(x1)
          x2int = NINT(x2)
          y1int = vh - NINT(y1)
          y2int = vh - NINT(y2)
	  dummy = rectangle($GBORDER, x1int, y1int, x2int, y2int)
	  IF (y1int .NE. y2int )
     +    dummy =  rectangle( $GFILLINTERIOR, x1int,y1int,x2int,y2int)
      END IF
      IF (PlotterOnF) THEN
        CALL PBar(vxAbs + x1, vyAbs + y1, vxAbs + x2, vyAbs + y2)
        CALL PRectangle(vxAbs + x1, vyAbs + y1, vxAbs + x2, vyAbs + y2)
      END IF
      END !SUBROUTINE



      SUBROUTINE BlackAndWhite(BWFlag)
      INCLUDE 'FGRAPH.FD'
      RECORD /videoconfig/ VC
      LOGICAL BWFlag

      BWFlag = .FALSE.
      CALL getvideoconfig(VC)
      IF (VC.numcolors .LE. 2) BWFlag= .TRUE.
      END !SUBROUTINE



      INTEGER FUNCTION CheckBit (i, Bit)
      INTEGER i, Bit
      INTEGER CheckBitResult
      INTEGER BitMask(0:8)
      COMMON BitMask

      IF ((i .AND. BitMask(Bit)) .EQ. BitMask(Bit)) THEN
         checkBitResult =  1
      ELSE
         checkBitResult  =  0
      END IF
      CheckBit = checkBitResult

      END !FUNCTION



      REAL FUNCTION ClampReal (r, l, h)
      REAL r, l, h
      IF (r .LT. l) THEN
         ClampReal = l
      ELSE
        IF (r .GT. h) THEN
          ClampReal = h
        ELSE
          ClampReal = r
        END IF
      END IF
      END !FUNCTION





      SUBROUTINE ClearViewportXX()
      INCLUDE 'FGRAPH.FD'
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF

      IF (CRTGraphOnF) CALL clearscreen($GVIEWPORT)
      END !SUBROUTINE




      SUBROUTINE ClipOff()
      LOGICAL clipFlag
      INTEGER TubeOn
      COMMON /MiscOnOff/ clipFlag,TubeOn
      clipFlag = .FALSE.
      END !SUBROUTINE



      SUBROUTINE ClipOn()
      LOGICAL clipFlag
      INTEGER TubeOn
      COMMON /MiscOnOff/ clipFlag,TubeOn
      clipFlag = .TRUE.
      END !SUBROUTINE



      SUBROUTINE CloseGraphics()
      INCLUDE 'FGRAPH.FD'
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      INTEGER  dummy

      IF (CRTGraphOnF)  THEN
       dummy =  setvideomode( $DEFAULTMODE )
       CALL unregisterfonts()
      END IF
      IF (PlotterOnF) call SelectPen(0)
      END !SUBROUTINE




      SUBROUTINE Combine( outstr, s)
      CHARACTER * (*) outstr, s
      INTEGER LenO, LenS, i
      LenO = LEN_TRIM(outstr) + 2
      LenS = LEN_TRIM(s)

      DO i = 1, Lens
        outstr(LenO:LenO) = s(i:i)
        LenO = LenO + 1
      END DO
      END !SUBROUTINE


      SUBROUTINE Catenate( outstr, s)
      CHARACTER * (*) outstr, s
      INTEGER LenO, LenS, i
      LenO = LEN_TRIM(outstr) + 1
      LenS = LEN_TRIM(s)

      DO i = 1, Lens
        outstr(LenO:LenO) = s(i:i)
        LenO = LenO + 1
      END DO
      END !SUBROUTINE



      FUNCTION ConvertX1 (xx1)
      REAL xx1, temp
      REAL wx, wy, wh, wl, tx, ty
      INTEGER  vx, vy, vh, vl
      COMMON /WorldVals/ wx, wy, wh, wl, tx, ty
      COMMON /ViewVals/ vx, vy, vh, vl

      temp = (xx1 - wx) * tx + vx
      ConvertX1 = ClampReal(temp, 0.0, 1000.0)
      END !FUNCTION



      FUNCTION ConvertX2 (xx1)
      REAL xx1, temp
      REAL wx, wy, wh, wl, tx, ty
      COMMON /WorldVals/ wx, wy, wh, wl, tx, ty

      temp = xx1 * tx
      ConvertX2 = ClampReal(temp, -1000.0, 1000.0)
      END !FUNCTION





      FUNCTION ConvertY1 (yy1)
      REAL yy1, temp
      REAL wx, wy, wh, wl, tx, ty
      INTEGER  vx, vy, vh, vl
      COMMON /WorldVals/ wx, wy, wh, wl, tx, ty
      COMMON /ViewVals/ vx, vy, vh, vl

      temp = (yy1 - wy) * ty + vy
      ConvertY1 = ClampReal(temp, 0.0, 1000.0)
      END !FUNCTION



      FUNCTION ConvertY2 (yy1)
      REAL yy1,  temp
      REAL wx, wy, wh, wl, tx, ty
      COMMON /WorldVals/ wx, wy, wh, wl, tx, ty

      temp = yy1 * ty
      ConvertY2 = ClampReal(temp, -1000.0, 1000.0)
      END !FUNCTION



      SUBROUTINE CRTGraphOff
      LOGICAL CRTGraphOnF, PlotterOnF
      LOGICAL clipFlag
      INTEGER TubeOn
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      COMMON /MiscOnOff/ clipFlag,TubeOn
      CRTGraphOnF = .FALSE.
      TubeOn = 2
      END !SUBROUTINE


      SUBROUTINE CRTGraphOn
      LOGICAL CRTGraphOnF, PlotterOn, ClipFlag
      INTEGER TubeOn
      COMMON /OnOff/ CRTGraphOnF, PlotterOn
      COMMON /MiscOnOff/ ClipFlag, TubeOn
      CRTGraphOnF = .TRUE.
      TubeOn = 1
      END !SUBROUTINE


      SUBROUTINE ColorFillpoly (numdat, polyVector, fillstyle,
     +                    fillcolor, outline)
      INCLUDE 'STDHDR.FOR'
      INCLUDE 'GRAFTYPE.FOR'
      INCLUDE 'FGRAPH.FD'
      INTEGER polyvector(0:maxv)
      INTEGER numdat, fillstyle, fillcolor, outline
      INTEGER gp, i, j, ii,  edge
      INTEGER xmin, xmax, ymin, ymax
      INTEGER startptX, startptY, endptX, endptY
      INTEGER  vx, vy, vh, vl
      COMMON /ViewVals/ vx, vy, vh, vl

      CALL SelectColor (15)
      CALL MoveToXX(REAL(polyVector(0)),REAL(polyVector(1)))
      CALL SetLineStyleXX(0, 1)
      DO i = 1, numdat - 1
        ii = 2 * i
        CALL LineToXX(REAL(polyVector(ii)) , REAL(polyVector(ii+1)))
      END DO
      CALL PolyMinMax(polyVector, numdat, xmin, ymin, xmax, ymax)
      CALL SetFillStyleXX(fillstyle, fillcolor)
      CALL SelectColor (fillcolor)

      edge = 0
      i = ymin

      DO WHILE (i .LE. ymax)
        startptx = 0
        startpty = 0
        endptx = 0
        endpty = 0
        edge = 0
        j = xmin - 1
        DO WHILE (j .LE. xmax + 1)
          gp  =  getpixel(j,vh-i)
          IF (gp .EQ. 15) THEN
            IF (edge .EQ. 0) THEN
              edge = 1
              startptx = j
              startpty = i
            ELSE
              endptx = j
              endpty = i
              IF (endptx - startptx .GE. 2) THEN
                CALL MoveToXX(startptx + 1.0, REAL(startpty))
                CALL LineToXX(endptx - 1.0, REAL(endpty))
                j = xmax + 2
              ELSE
               startptx = endptx
               startpty = endpty
              END IF
            END IF !!!  edge .NE. 0
          END IF  !!! /* pixel = 15
          j = j + 1
        END DO  !!! while j
        i = i + 1
       END DO !!! while i

      CALL SelectColor (outline)
      CALL MoveToXX(REAL(polyVector(0)), REAL(polyVector(1)))
      CALL SetLineStyleXX(0, 1)
      DO i = 1, numdat - 1
        ii = 2 * i
        CALL LineToXX(REAL(polyVector(ii)),REAL(polyVector(ii+ 1)))
      END DO


      END !SUBROUTINE


      SUBROUTINE GetColXX(OldCol)
      INCLUDE 'FGRAPH.FD'
      LOGICAL CRTGraphOnF, PlotterOnF
      INTEGER OldCol
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      IF (PlotterOnF)   CALL PGetColor (OldCol)
      IF (CRTGraphOnF)  OldCol= getcolor()
      END !FUNCTION






      SUBROUTINE GetMaxCoords (x, y)
      INTEGER x, y
      INCLUDE 'FGRAPH.FD'
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      RECORD /videoconfig/ VC

      IF (CRTGraphOnF) THEN
        CALL getvideoconfig(VC)
        x = VC.numxpixels-1
        y = VC.numypixels-1
      ELSE
        x = 640
        y = 485
      END IF
      END !SUBROUTINE




      SUBROUTINE GetTextStyleXX (font, dir, Hsize, VSize)
      INTEGER font, dir ,Hsize, VSize
      INTEGER textFont, textdir, Htextsize, Vtextsize
      COMMON /TextAttr/ textFont, textdir, Htextsize, Vtextsize

      font = textFont
      dir = textdir
      Hsize = HtextSize
      VSize = VtextSize
      END !SUBROUTINE



      SUBROUTINE GetViewportOrigin (left, top)
      INTEGER  left, top
      INCLUDE  'GRAFTYPE.FOR'
      RECORD /Rect/ viewp
      COMMON /Viewport/ viewp

      left = viewp.left
      top = viewp.top
      END !SUBROUTINE





      SUBROUTINE linerel( x, y)
      INTEGER x, y
      INCLUDE 'FGRAPH.FD'
      RECORD /xycoord/ position
      INTEGER dummy

      CALL getcurrentposition(position)
      dummy = lineto(position.xcoord+x, position.ycoord+y)
      END


      SUBROUTINE LineRelXX (x, y)
      REAL x, y
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF

      IF (CRTGraphOnF)  CALL linerel( NINT(x), -NINT(y))
      IF (PlotterOnF)   CALL PLineRel(x, y)
      END !SUBROUTINE





      SUBROUTINE LineToXX (x, y)
      REAL x, y
      INTEGER  dummy
      REAL vxAbs, vyAbs
      INTEGER  vx, vy, vh, vl
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /ViewVals/ vx, vy, vh, vl
      COMMON /PlotVals/ vxAbs, vyAbs
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF

      INCLUDE 'FGRAPH.FD'
      IF (CRTGraphOnF)  dummy =  lineto( NINT(x), vh - NINT(y))
      IF (PlotterOnF)   CALL PLineTo(vxAbs + x, vyAbs + y)
      END !SUBROUTINE



      SUBROUTINE lineworldabs (xx1, yy1)
      REAL xx1, yy1

      CALL LineToXX(ConvertX1(xx1), ConvertY1(yy1))
      END !SUBROUTINE



      SUBROUTINE lineworldrel (xx1, yy1)
      REAL xx1, yy1

      CALL LineRelXX(ConvertX2(xx1), ConvertY2(yy1))
      END !SUBROUTINE



      SUBROUTINE moverel( x, y)
      INTEGER x, y
      INCLUDE 'FGRAPH.FD'
      RECORD /xycoord/ position

      CALL getcurrentposition(position)
      CALL moveto(position.xcoord+x, position.ycoord+y, position)
      END


      SUBROUTINE MoveRelXX (x, y)
      REAL x,y
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF

      IF (CRTGraphOnF)  CALL moverel( NINT(x), -NINT(y))
	IF (PlotterOnF)   CALL PMoveRel(x, y)
      END !SUBROUTINE



      SUBROUTINE MoveToXX (x, y)
      INCLUDE 'FGRAPH.FD'
      REAL x, y, vxAbs, vyAbs
      RECORD /xycoord/ position
      INTEGER  vx, vy, vh, vl
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /ViewVals/ vx, vy, vh, vl
      COMMON /PlotVals/ vxAbs, vyAbs
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF

      IF (CRTGraphOnF)   CALL moveto(NINT(x), (vh - NINT(y)),position)
      IF (PlotterOnF)  CALL PMoveTo(vxAbs + x, vyAbs + y)
      END !SUBROUTINE




      SUBROUTINE moveworldabs (xx1, yy1)
      REAL xx1, yy1

      CALL MoveToXX(ConvertX1(xx1), ConvertY1(yy1))
      END !SUBROUTINE



      SUBROUTINE moveworldrel (xx1, yy1)
      REAL xx1, yy1

      CALL MoveRelXX(ConvertX2(xx1), ConvertY2(yy1))
      END !SUBROUTINE


      SUBROUTINE NoCursor()
      INCLUDE 'FGRAPH.FD'
      INTEGER dummy
      dummy = displaycursor($GCURSOROFF)
      END !SUBROUTINE


      SUBROUTINE ShowCursor()
      INCLUDE 'FGRAPH.FD'
      INTEGER dummy
      dummy = displaycursor($GCURSORON)
      END !SUBROUTINE

      SUBROUTINE OneTimeInit (mode, fontpath )
      INCLUDE 'FGRAPH.FD'
      INCLUDE 'GRAFTYPE.FOR'
      INTEGER mode,x,y, dummy
      INTEGER vx, vy, vh, vl, horizdir, vertdir, TubeOn
      CHARACTER * (*) fontpath
      LOGICAL CRTGraphOnF, PlotterOnF, ClipFlag
      COMMON /ViewVals/ vx, vy, vh, vl
      COMMON /TextPos/ horizdir, vertdir
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      COMMON /MiscOnOff/ ClipFlag, TubeOn

      horizdir = 0
      vertdir = 0
      vx = 0
      vy = 0
      vl = 720
      vh = 348

      IF (TubeOn .EQ. 0) CALL CRTGraphOn()
      CALL ClipOn()

      IF (CRTGraphOnF) THEN
        IF (registerfonts(fontpath) .LT. 0 .AND.
     +    registerfonts('*.FON') .LT. 0)
     +    STOP 'Error: incorrect pathname for font files.'
         SELECT CASE (mode)
           CASE (-1)
               IF( setvideomode($MAXRESMODE) .EQ.  0)
     +            STOP 'Error: cannot set graphics mode'
           CASE (1)
               dummy = setvideomode($MRES4COLOR)
           CASE (2)
               dummy = setvideomode($MRESNOCOLOR)
           CASE (3)
               dummy = setvideomode($HRESBW)
           CASE (4)
               dummy = setvideomode($MRES16COLOR)
           CASE (5)
               dummy = setvideomode($HRES16COLOR)
           CASE (6)
               dummy = setvideomode($ERESCOLOR)
           CASE (7)
               dummy = setvideomode($VRES2COLOR)
           CASE (8)
               dummy = setvideomode($VRES16COLOR)
           CASE (9)
               dummy = setvideomode($MRES256COLOR)
           CASE (10)
               dummy =  setvideomode($DEFAULTMODE)
           CASE (11)
               dummy = setvideomode($ERESNOCOLOR)
           CASE (12)
               dummy = setvideomode(8)
           CASE DEFAULT
              dummy = setvideomode(6)
         END SELECT
         CALL GetMaxCoords(x, y)
      END IF
      IF (PlotterOnF) THEN
         CALL DefinePlotterFill
         CALL SetPlotterViewport(1000, 500, 10000, 7500)
         CALL GetMaxCoords(x, y)
         CALL ScalePlotterViewport(0, 0, x, y)
      END IF
      CALL SetGraphViewport(0, 0, x, y)

      CALL SetTextJustifyXX(0, 1)
      CALL SetTextStyleXX(0, 0, 10, 12)
      CALL SelectColor(1)
      END !SUBROUTINE



      SUBROUTINE outgraphstring (S, LengthS)
      CHARACTER *(*) s
      INCLUDE 'FGRAPH.FD'
      INTEGER LengthS, i, x, y
      INTEGER sizex, sizey
      INTEGER horizdir, vertdir
      INTEGER textdir, HtextSize, textFont, VTextSize
      RECORD /xycoord/ position
      COMMON /TextPos/ horizdir, vertdir
      COMMON /TextAttr/ textFont, textdir, HtextSize, VtextSize


      CALL getcurrentposition(position)
      x = position.xcoord
      y = position.ycoord
      sizex = HtextSize
      sizey = VtextSize


      SELECT CASE (horizdir)
	     CASE (0)
                   x = x + 0
	     CASE (1)
		  IF (textdir .EQ. 0) THEN
		   x = x - (sizex-1) * (LengthS / 2)
		  ELSE
		    x = x - sizex /2
		  END IF
	     CASE (2)
		  IF (textdir .EQ. 0) THEN
		     x = x - (sizex-1) * (LengthS)
		  ELSE
		      x = x - sizex
		  END IF
	     CASE DEFAULT
		  IF (textdir .EQ. 0) THEN
		     x = x - sizex * (LengthS / 2)
		  ELSE
		      x = x - sizex/2
		  END IF

             END SELECT

	     SELECT CASE (vertdir)
	       CASE (0)
		   IF (textdir .EQ. 0) THEN
		      y = y - sizey
		   ELSE
		       y = y - sizey * LengthS
		   END IF
	       CASE (1)
		    IF (textdir .EQ. 0) THEN
		      y = y - sizey / 2
		   ELSE
		       y = y - (sizey) * (LengthS / 2)
		   END IF
	      CASE (2)

	      CASE DEFAULT
		   IF (textdir .EQ. 0) THEN
		      y = y - sizey
		   ELSE
		       y = y - sizey * (LengthS / 2)
		   END IF
	      END SELECT

	CALL  moveto(x,y, position)
	IF (textdir .EQ. 0) THEN
	  CALL outgtext(s)
	ELSE
	  DO i = 1, LengthS
	    CALL outgtext(s(i:i))
            y = sizey + y
	    CALL moveto(x, y, position)
	  END DO
	END IF

      END !SUBROUTINE



      SUBROUTINE OutTextPie (x, y, S)
      REAL x, y
      CHARACTER * (*)  S
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      CALL MoveToXX(x, y)
      IF (CRTGraphOnF)   CALL outgraphstring(S, LEN_TRIM(S))
      IF (PlotterOnF)    CALL POutText(S)
      END !SUBROUTINE



      SUBROUTINE OutTextXX (S)
      CHARACTER * 80 S
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      IF (CRTGraphOnF) THEN
	    CALL outgraphstring(S, LEN_TRIM(S))
       END IF
      IF (PlotterOnF)    CALL POutText(S)
      END !SUBROUTINE


      SUBROUTINE OutRealXX (S)
      CHARACTER * 80 S
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      IF (CRTGraphOnF) THEN
	    CALL outgraphstring(S, LEN_TRIM(S))
       END IF
      IF (PlotterOnF)    CALL POutText(S)
      END !SUBROUTINE





      SUBROUTINE PieXX (x, y, stangle, endangle, radius, AspectR)
      REAL x,y,stangle, endangle, radius, AspectR, TwoPi360,AsRad
      REAL vxAbs, vyAbs
      INTEGER x1, x2, x3,x4, y1, y2, y3, y4, dummy
      INCLUDE 'FGRAPH.FD'

      INTEGER  vx, vy, vh, vl
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /PlotVals/ vxAbs, vyAbs
      COMMON /ViewVals/ vx, vy, vh, vl
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF


      PARAMETER ( TwoPi360 = 0.0174532)

      IF (PlotterOnF) AspectR = 1.0
      AsRad = AspectR * radius
      x3 = NINT(x + (radius*cos(twopi360*stangle)))
      y3 = NINT(y + (Asrad*sin(stangle*twoPi360)))
      x4 = NINT(x + (radius*cos(twopi360*endangle)))
      y4 = NINT(y + (Asrad*sin(endangle*twopi360)))
      x1 = NINT(x - radius)
      x2 = NINT(x + radius)
      y1 = NINT(y + Asrad)
      y2 = NINT(y - Asrad)
      IF (CRTGraphOnF) THEN
         dummy =  pie( $GFILLINTERIOR, x1, vh-y1, x2, vh-y2,
     +                 x3, vh-y3, x4, vh-y4)
      END IF
      IF (PlotterOnF)
     +  CALL PShadeWedge(vxAbs + x, vyAbs + y, radius, NINT(stangle),
     +              NINT(endangle-stangle))

      END !SUBROUTINE



      SUBROUTINE PlotterOff()
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      PlotterOnF = .FALSE.
      END !SUBROUTINE



      SUBROUTINE PlotterOn()
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      PlotterOnF = .TRUE.
      END !SUBROUTINE






       SUBROUTINE ColorPolyFillWorldAbs (x, y, fillstyle,
     +        fillcolor, numdat)
       INCLUDE 'stdhdr.for'
       REAL x(0:maxv), y(0:maxv)
       INTEGER fillstyle, fillcolor, numdat
       INTEGER outline, ii
       INTEGER polyvector[ALLOCATABLE](:)
       ALLOCATE(polyVector(0:maxv),STAT=iErr)

       CALL moveworldabs(x(0), y(0))
       DO i = 0, numdat - 1
         ii = 2 * i
         polyVector(ii) = NINT(ConvertX1(x(i)))
         polyVector(ii + 1) = NINT(ConvertY1(y(i)))
       END DO
       CALL GetColXX(outline)
       CALL ColorFillpoly(numdat, polyVector,
     +                    fillstyle, fillcolor, outline)
       DEALLOCATE(polyVector,STAT=iErr)
       END !SUBROUTINE



      SUBROUTINE polyLineWorldAbs (x, y, numdat)
      INCLUDE 'stdhdr.for'
      REAL x(0:maxv), y(0:maxv)
      INTEGER  numdat

      CALL moveworldabs(x(0), y(0))
      DO i = 1, numdat - 1
        CALL lineworldabs(x(i), y(i))
      END DO
      END !SUBROUTINE




      SUBROUTINE polyLineWorldRel (x, y, numdat)
      INCLUDE 'STDHDR.FOR'
      REAL x(0:maxv), y(0:maxv)
      INTEGER  numdat

      CALL moveworldrel(x(0), y(0))
      DO i = 1, numdat - 1
          CALL lineworldRel(x(i), y(i))
      END DO
      END !SUBROUTINE





      SUBROUTINE PolyMinMax (polyVector, numdat, xmin, ymin, xmax, ymax)
      INCLUDE 'STDHDR.FOR'
      INTEGER polyVector(0:maxv)
      INTEGER  numdat, xmin, ymin, xmax, ymax, i, ii

      xmin = polyVector(0)
      xmax = polyVector(0)
      ymin = polyVector(1)
      ymax = polyVector(1)

      DO i = 1, numdat - 1
        ii = 2 * i
        IF (polyVector(ii) .LT. xmin)  xmin = polyVector(ii)
        IF (polyVector(ii) .GT. xmax)  xmax = polyVector(ii)
        IF (polyVector(ii+1) .LT. ymin)  ymin = polyVector(ii+1)
        IF (polyVector(ii+1) .GT. ymax)  ymax = polyVector(ii+1)
      END DO

      END !SUBROUTINE



      SUBROUTINE RectangleXX (x1, y1, x2, y2)
      REAL x1,y1,x2,y2, vxAbs, vyAbs
      INTEGER dummy
      INCLUDE 'FGRAPH.FD'
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /PlotVals/ vxAbs, vyAbs
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF

      IF (CRTGraphOnF) THEN
       dummy = rectangle($GBORDER, NINT(x1), NINT(y1),
     +                   NINT(x2), NINT(y2))
      END IF
      IF (PlotterOnF)
     +  CALL PRectangle(vxAbs+x1, vyAbs+y1, vxAbs+x2, vyAbs+y2)
      END !SUBROUTINE


      SUBROUTINE SelectColor (c)
      INTEGER c,color,dummy
      INCLUDE 'FGRAPH.FD'
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      color = 1
      IF (CRTGraphOnF) THEN
          color = NINT(AdjustCRT(c))
         dummy =  setcolor(c)
      END IF
      IF (PlotterOnF)  CALL SelectPen(c)
      END !SUBROUTINE




      SUBROUTINE SetFillStyleXX (pat, c)
      INTEGER pat, c
      LOGICAL CRTGraphOnF, PlotterOnF
      INTEGER * 1 fillmask(8,10)
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      DATA fillmask /#00, #00, #00, #00, #00, #00, #00, #00,
     +   #FF, #FF, #FF, #FF, #FF, #FF, #FF, #FF,
     +   #00, #FF, #00, #FF, #00, #FF, #00, #FF,
     +   #11, #22, #44, #88, #11, #22, #44, #88,
     +   #0F, #1E, #3C, #78, #F0, #E1, #C3, #87,
     +   #87, #C3, #E1, #F0, #78, #3C, #1E, #0F,
     +   #88, #44, #22, #11, #88, #44, #22, #11,
     +   #81, #42, #24, #18, #18, #24, #42, #81,
     +   #C3, #66, #42, #18, #42, #66, #C3, #81,
     +   #88, #88, #88, #88, #88, #88, #88, #88 /

      CALL SelectColor(c)
      IF (CRTGraphOnF) THEN
        call setlinestyle(#FFFF)
        CALL setfillmask(fillmask(1,pat))
      END IF
      IF (PlotterOnF)  CALL PSetFillStyle(pat, c)
      END !SUBROUTINE



      SUBROUTINE SetGlobalView (c)
      INTEGER c
      INTEGER BackgroundColor
      BackgroundColor = NINT(AdjustCRT(c))
      END !SUBROUTINE




      SUBROUTINE SetGraphViewport (xx1, yy1, xx2, yy2)
      INCLUDE 'FGRAPH.FD'
      INCLUDE 'GRAFTYPE.FOR'

      INTEGER xx1,yy1, xx2, yy2, maxX,maxY
      INTEGER  vx, vy, vh, vl, horizdir, vertdir
      INTEGER PUx1, PUy1, PUx2, PUy2, TubeOn
      REAL x1, y1, x2, y2, vxAbs, vyAbs
      RECORD /Rect/ viewp
      LOGICAL CRTGraphOnF, PlotterOnF, ClipFlag
      COMMON /Viewport/ viewp
      COMMON /ViewVals/ vx, vy, vh, vl
      COMMON /PlotVals/ vxAbs, vyAbs
      COMMON /TextPos/ horizdir, vertdir
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      COMMON /MiscOnOff/ ClipFlag, TubeOn

      IF (CRTGraphOnF) THEN
         CALL setviewport  (xx1, yy1, xx2, yy2)
         IF (ClipFlag) CALL setcliprgn(xx1, yy1, xx2, yy2)
      END IF
      IF (PlotterOnF) THEN
	CALL GetMaxCoords(maxX, maxY)
	CALL GetPlotterViewport(pux1, puy1, pux2, puy2)
	IF (clipFlag) THEN
	  x1 = pux1 + (pux2 - pux1) * REAL(xx1) / REAL(maxX)
	  y1 = puy2 - (puy2 - puy1) * REAL(yy1) / REAL(maxY)
	  x2 = pux1 + (pux2 - pux1) * REAL(xx2) / REAL(maxX)
	  y2 = puy2 - (puy2 - puy1) * REAL(yy2) / REAL(maxY)
          CALL SetClippingWindow(x1,y2,x2,y1)
	END IF
      END IF
      vxAbs = xx1
      vyAbs = maxY - yy2
      vx = 0
      vy = 0
      vh = yy2 - yy1
      vl = xx2 - xx1
      viewp.left = xx1
      viewp.top = yy1
      viewp.right = xx2
      viewp.bottom = yy2
      END !SUBROUTINE



      SUBROUTINE SetLineStyleXX (ls, thick)
      INTEGER ls,  thick
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      INTEGER *2 linemask(0:4)
      DATA linemask/ #FFFF, #5555, #6666, #BDBD,#FF00/

      IF (CRTGraphOnF) THEN
        LineStyle = ls
        CALL setlinestyle(linemask(ls))
      END IF
      IF (PlotterOnF)  CALL PSetLineStyle(ls, thick)
      END !SUBROUTINE



      SUBROUTINE SetTextJustifyXX (h, v)
      INTEGER h, v, horizdir, vertdir
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      COMMON /TextPos/ horizdir, vertdir

      IF (CRTGraphOnF) THEN
         horizdir = h
         vertdir = v
      END IF
      IF (PlotterOnF)  CALL PSetTextJustify(h, v)
      END !SUBROUTINE



      SUBROUTINE SetTextStyleXX (font, dir, Hsize, Vsize)
      INCLUDE 'GRAFTYPE.FOR'
      INCLUDE 'FGRAPH.FD'
      INTEGER font, dir, Hsize, Vsize, textdir, dummy
      INTEGER HtextSize, textFont, VtextSize, psize
      CHARACTER * 30 list, hch, vch, attrib
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF
      COMMON /TextAttr/ textFont, textdir, HtextSize, VtextSize
      CHARACTER* (10) option (NFONTS)/
     +     "t'courier'",    "t'helv'",
     +     "t'tms rmn'",    "t'modern'",
     +     "t'script'",     "t'roman'"/

      textdir = dir
      HtextSize = Hsize
      VtextSize = VSize
      textFont = font
      IF (CRTGraphOnF) THEN
        attrib = '              '
        hch = '              '
        vch = '              '
        list = '                 '
        CALL RealString(REAL(Hsize), 0, 1, hch)
        CALL RealString(REAL(Vsize), 0, 1, Vch)
        attrib = 'h'
        CALL catenate(attrib, hch)
        CALL catenate(attrib, 'w')
        CALL catenate(attrib, vch)
        CALL catenate(attrib, 'b')
        list = option(font+1)
        CALL combine(list, attrib )
        dummy = setfont(list)
      END IF
      IF (PlotterOnF)  THEN
        psize = (Vsize / 11) + 1
        CALL PSetTextStyle(0,0,1)
        CALL PSetTextStyle(font, dir, psize)
      END IF
      END !SUBROUTINE

      SUBROUTINE SetWorldCoordinates (wr)
      INCLUDE 'GRAFTYPE.FOR'
      RECORD /WorldRect/ wr

      REAL wx, wy, wh, wl, tx, ty
      INTEGER  vx, vy, vh, vl
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /WorldVals/ wx, wy, wh, wl, tx, ty
      COMMON /ViewVals/ vx, vy, vh, vl
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF

      wx = wr.left
      wy = wr.bottom
      wh = wr.top - wr.bottom
      wl = wr.right - wr.left

      tx = REAL( vl) / wl
      ty = REAL( vh )/ wh
      END !SUBROUTINE



      SUBROUTINE SetWorldRect (Worldr, a, b, c, d)
      INCLUDE 'GRAFTYPE.FOR'
      RECORD /WorldRect/ Worldr
      REAL a,b,c,d

      Worldr.left = a
      Worldr.bottom = b
      Worldr.right = c
      Worldr.top = d

      END !SUBROUTINE


      SUBROUTINE WorldRectangle (wr)
      INCLUDE 'GRAFTYPE.FOR'
      RECORD /WorldRect/ wr, IntRect
	IntRect.left = ConvertX1(wr.left)
	IntRect.bottom = ConvertY1(wr.bottom)
	IntRect.right = ConvertX1(wr.right) + 1.0
	IntRect.top = ConvertY1(wr.top) - 1.0
	CALL RectangleXX(IntRect.left, IntRect.top,
     +                   IntRect.right, IntRect.bottom)
      END !SUBROUTINE

      FUNCTION AdjustCRT(c)
      INTEGER c
      REAL color
      INCLUDE 'FGRAPH.FD'
      RECORD /videoconfig/ VC
      LOGICAL CRTGraphOnF, PlotterOnF
      COMMON /OnOff/ CRTGraphOnF, PlotterOnF

      IF (CRTGraphOnF) THEN
        CALL getvideoconfig(VC)
        IF (VC.numcolors .EQ. 0) THEN
           IF (c  .GE. 1) then
             color = 1
           ELSE
             color = 0
           END IF
        ELSE
          IF (c .GT.  VC.numcolors-1) THEN
             color = VC.numcolors-1
          ELSE
             color = c
          END IF
        END IF
      END IF
      AdjustCRT = color
      END !FUNCTION


      SUBROUTINE QCKSRT
      !!  Based upon the non-recursive QuickSort algorithm presented in
      !!  Numerical Recipes, William T. Vetterling, Cambridge Press
      !!  1986
      INCLUDE 'GRAFTYPE.FOR'
      PARAMETER (M=7, NStack=1000, FA = 211.0,FC = 1663.0)
      PARAMETER (FM = 7875.0, FMI= 1.0/FM)
      INTEGER i, j, fspntr
      REAL IR
      RECORD /xyerec/ FillStack(0:1000),  A
      REAL IStack[ALLOCATABLE](:)
      COMMON /FSP/ fspntr
      COMMON /FStack/ FillStack

      ALLOCATE(IStack(NStack),STAT=iErr)

      n = fspntr
      JStack = 0
      L = 1
      IR = N
      FX = 0.0
10    IF (IR-L .LT. M) THEN
        DO j = L + 1, IR
	   A = FillStack(j-1)
           DO i = j-1, 1, -1
	      IF ((FillStack(i-1).y .LT. A.y) .OR.
     +      ((FillStack(i-1).x .LE. A.x) .AND.
     +        (FillStack(i-1).y .EQ. A.y))) GO TO 12
		FillStack(i) = FillStack(i-1)
           END DO
           i = 0
12         FillStack(i) = A
        END DO
	IF (JStack .EQ. 0) return
        IR =IStack(JStack)
        L = IStack(Jstack-1)
        JStack = JStack -2
      ELSE
        i = L
        J = IR
        IQ =  L + (IR-L)/2
	A = FillStack(IQ-1)
	FillStack(IQ-1) = FillStack(L-1)
20        continue
21      IF (j .GT. 0) THEN
	  IF ((A.y .LT. FillStack(j-1).y) .OR.
     +      ((A.x .LE. FillStack(j-1).x ) .AND.
     +       (FillStack(j-1).y .EQ. A.y))) THEN
            J = J - 1
           GO TO 21
          END IF
        END IF
        IF (J .LE. i) THEN
	  FillStack(i-1) = A
          GO TO 30
        END IF
	FillStack(i-1) = FillStack(j-1)
        i = i + 1
22      IF (i .le. N) THEN
	IF ((A.y .GT. FillStack(i-1).y) .OR.
     +     ((A.x .GE. FillStack(i-1).x) .AND.
     +       (FillStack(i-1).y .EQ. A.y))) THEN
              i = i + 1
             GO TO 22
          END IF
        END IF
        IF (j .LE. i ) THEN
	  FillStack(j-1) = A
          i = j
         GO TO 30
        END IF
	FillStack(j-1) = FillStack(i-1)
        j = j - 1
        GO TO 20
30      JStack = JStack + 2
        IF (Jstack .GT. NStack) pause 'NStack must be made larger.'
        IF (IR- i .GE. i - L ) THEN
          istack(jstack) = IR
          istack(Jstack-1) = i +1
          IR = i -1
        ELSE
          istack(Jstack)= i - 1
          istack(Jstack-1) = L
          L = i + 1
        END IF
      END IF
      GO TO 10
      DEALLOCATE(IStack, STAT=IErr)
      END

      FUNCTION FSCompare (e1 , e2 )
      INCLUDE 'GRAFTYPE.FOR'
        RECORD /xyerec/ temp1, temp2, e1, e2
        temp1 = e1
        temp2 = e2
        IF ((temp1.y .GT. temp2.y) .OR. ((temp1.y .EQ. temp2.y) .AND.
     +      (temp1.x .GT. temp2.x))) THEN
           FSCompare = 1
        ELSE
          IF ((temp1.y .EQ. temp2.y) .AND.
     +        (temp1.x .EQ. temp2.x)) THEN
            FSCompare = 0
          ELSE
            FSCompare = -1
           END IF
         END IF
      END !FUNCTION



      SUBROUTINE MemDraw (x1, y1, x2, y2, edge, ep)
        INTEGER x1, y1, x2, y2, edge, ep
        INTEGER dx, dy, dxabs, dyabs
        INTEGER i, px, py,sdx, sdy, x, y

      ! Bresenham's algorithm for line drawing
      ! Based upon the line-drawing algorithm
      !   in Graphics Programming in C by Roger T. Stevens

        dx = (x2 - x1)
        dy = (y2 - y1)
        dxabs = ABS(dx)
        dyabs = ABS(dy)
        sdx = SignXX(dx)
        sdy = SignXX(dy)
        CALL MemPlot(x1, y1, edge)
        x = 0
        y = 0
        px = x1
        py = y1
        IF (dxabs .GE. dyabs) THEN
          DO i = 1, dxabs - 1
            y = y + dyabs
            IF (y .GE. dxabs) THEN
              y = y - dxabs
              py = py + sdy
            END IF
            px = px + sdx
            CALL MemPlot(px, py, edge)
          END DO
        ELSE
          DO i = 1, dyabs - 1
            x = x + dxabs
            IF (x .GE. dyabs) THEN
              x = x - dyabs
              px = px + sdx
            END IF
            py = py + sdy
            CALL MemPlot(px, py, edge)
          END DO
        END IF
        ! plot endpoint only IF ep flag set true
        IF (ep .EQ. 1)  CALL MemPlot(x2, y2, edge)
      END !SUBROUTINE

      SUBROUTINE MemPlot (xx, yy, ee)
      INCLUDE 'GRAFTYPE.FOR'
      INCLUDE 'FGRAPH.FD'
      INTEGER xx,yy,ee, fspntr
      RECORD /xyerec/ FillStack(0: 1000)
      COMMON /FStack/ FillStack
      COMMON /FSP/ fspntr

        FillStack(fspntr).x = xx
        FillStack(fspntr).y = yy
        FillStack(fspntr).edge = ee
        fspntr = fspntr + 1
      END !SUBROUTINE

      SUBROUTINE FillPoly (xy, n, fillcolor, outlinecolor)
      INCLUDE 'STDHDR.FOR'
      INCLUDE 'GRAFTYPE.FOR'
        INTEGER n, fillcolor, outlinecolor
        INTEGER i, j
        INTEGER plotit, ep, fspntr
        RECORD /xyrec/ xy(0:maxv)
        RECORD /xyerec/ FillStack(0: 1000)
        INTEGER EdgeTable[ALLOCATABLE](:)
        COMMON /FSP/ fspntr
        COMMON /FStack/ FillStack

        ALLOCATE (EdgeTable(0:1000),STAT=Ierr)

        ! Zero out edge table
        DO i = 0, 1000
          EdgeTable(i) = 0
        END DO
        fspntr = 0


        ! Check and make sure we are dealing  with a closed polygon
        IF ((xy(0).x .NE. xy(n - 1).x) .OR.
     +      (xy(0).y .NE. xy(n - 1).y)) THEN
          xy(n) = xy(0)
          n = n + 1
        END IF
        ! Create pixel list of polygon outline
        ! Plot endpoint IF line meets at in interior vertex
        DO i = 1, n - 1
          IF (i .EQ. (n - 1)) THEN
            IF (INT(SignXX(xy(i - 1).y - xy(i).y)) .NE.
     +            INT(SignXX(xy(0).y - xy(1).y))) THEN
              ep = 1
            ELSE
              ep = 0
            END IF
          ELSE
            IF  (ABS(INT(SignXX(xy(i-1).y - xy(i).y)) -
     +           INT(SignXX(xy(i).y - xy(i+1).y))) .EQ. 2) THEN
               ep = 1
             ELSE
               ep = 0
             END IF
          END IF

          IF (xy(i - 1).Y .NE. xy(i).y) THEN
            CALL MemDraw(xy(i - 1).x, xy(i - 1).y,
     +                   xy(i).x, xy(i).y, i, ep)
          END IF
        END DO
        ! Sort pixel list of polygon outline
        CALL QCKSRT
        plotit = 1

        ! set to fill color
        CALL Selectcolor (fillcolor)

        ! Initialze edge table for first edge
        EdgeTable(FillStack(0).edge) = 1
        DO i = 0, fspntr - 1
          ! check and make sure points are on the same scan line
          IF (FillStack(i).y .EQ. FillStack(i + 1).y) THEN
          ! check and make sure edges are different
            IF (FillStack(i).edge .NE. FillStack(i + 1).edge) THEN
          ! check and make sure edge has not be encountered before
              IF (EdgeTable(FillStack(i + 1).edge) .NE. 1) THEN
          ! IF polygon interior (plotit=1)  draw line between edges
                IF (plotit .EQ. 1) THEN
                  CALL TLine(FillStack(i).x, FillStack(i).y,
     +                 FillStack(i + 1).x, FillStack(i).y)
                  plotit = 0  ! set plotit false
                ELSE
                  plotit = 1  ! set plot it true
                END IF
              END IF
              ! Enter edge into edge table
              EdgeTable(FillStack(i + 1).edge) = 1
            END IF
          ELSE
            ! y values different means scan line transition
            ! reset plotit to 1, and EdgeTable
            plotit = 1
             DO j = 0, 1000
                  EdgeTable(j) = 0
             END DO
            EdgeTable(FillStack(i + 1).edge) = 1
          END IF
        END DO

       ! set to outline color
         CALL Selectcolor (outlinecolor)
        ! draw outline of polygon
        DO i = 1, n - 1
           CALL Tline(xy(i - 1).x, xy(i - 1).y, xy(i).x,xy(i).y)
        END DO
      DEALLOCATE(EdgeTable, STAT=IErr)
      END !SUBROUTINE

      SUBROUTINE PolyFillWorldAbs (x, y, fillstyle,
     +                               fillcolor, numdat)
       INCLUDE 'GRAFTYPE.FOR'
       INCLUDE 'STDHDR.FOR'
       INTEGER outline, fillstyle, fillcolor, numdat
       INTEGER  vx, vy, vh, vl
       COMMON /ViewVals/ vx, vy, vh, vl
       REAL x(0:maxv), y(0:maxv)
       RECORD /xyrec/ polyvector[ALLOCATABLE](:)
       ALLOCATE(polyVector(0:maxv),STAT=iErr)

        DO i = 0, numdat - 1
          PolyVector(i).x = NINT(ConvertX1(x(i)))
          PolyVector(i).y = vh-NINT(ConvertY1(y(i)))
          ! added vh to line above to invert fill 5/18/90
        END DO
        CALL GetColXX(outline)
        CALL SetFillStyleXX(fillstyle, fillcolor)
        CALL FillPoly(PolyVector, numdat, fillcolor, outline)
        DEALLOCATE(polyVector, STAT=iErr)
      END !SUBROUTINE


      FUNCTION SignXX(i)
      INTEGER i, result

       IF (i .GT. 0) THEN
         result = 1
       ELSE
        IF (i .LT. 0) THEN
          result = -1
        ELSE
          result = 0
        END IF
       END IF
       SignXX = REAL(result)
      END !FUNCTION

      SUBROUTINE TLine (x1, y1, x2, y2)
        INCLUDE 'FGRAPH.FD'
        INTEGER x1, y1, x2, y2, dummy
        RECORD /xycoord/ position

          CALL moveto (x1, y1, position)
          dummy =  lineto( x2, y2)
      END !SUBROUTINE



!
! 1/19/90 Changed settextstyleXX for Current Font Attributes
!          allows PlotterOn, CRTGraphOFF

! Enhancement
! 1/23/90 Added Polygon fill routines for monochrome display

! 5/18/90 Change direction of polyfillworldabs routine by subtracting
!         calculated y value from viewport height vh
!