      SUBROUTINE HPGL(X,Y,IND)
* CLONED FROM HPPLOT DESIGNED FOR TERMINALS WITH HP GRAPHIC LANGUAGE
      INCLUDE 'SIZES'
      LOGICAL ERASE
      LOGICAL ISINIT
      COMMON/ OUTPUT/ IPAPER,IPAGE
      CHARACTER*80  FILEIN, FILOUT, FILPLT, LLEGND
      CHARACTER*1 ASCII, ESC, CTLZ
      COMMON /ASCIIC/ ASCII(0: 255)
      COMMON /LEGEND/  FILEIN, FILOUT, FILPLT, LLEGND
      INTEGER PIXROW, PIXCOL, PIXEL
      COMMON /TERM/ IMAXR, IMAXC, PIXROW, PIXCOL, PIXEL, LCOUNT, INGRAF,
     .              IXL, IXR, IYT, IYB, NCOLOR, MCOLOR( 64 ), ITTRM,
     .              MARGX, MARGY
* VARIABLES IN COMMON TERM:
*  IMAXR = MAX NUMBER OF ROWS
*  IMAXC = MAX NUMBER OF COLUMNS
*  PIXROW = NUMBER OF PIXELS PER ROW
*  PIXCOL = NUMBER OF PIXELS PER COLUMN
*  PIXEL  = LESSER OF PIXROW OR PIXCOL
*  LCOUNT = NUMBER OF LINES CURRENTLY WRITTEN TO DIALOG AREA
*  INGRAF = 0=> HOST TEXT GOES TO MONITOR SPACE\\ 1=> TEXT TO GRAPHICS
*  IXL    = LEFT MOST VALUE OF X
*  IXR    = RIGHT MOST VALUE OF X
*  IYT    = VALUE OF Y AT TOP OF SCREEN
*  IYB    = VALUE OF Y AT BOTTOM OF SCREEN
*  NCOLOR = NUMBER OF COLORS IN MCOLOR MAP
*  MCOLOR = MAP OF COLORS
*  ITTRM  = UNIQUE MODEL NUMBER OF GENERAL TERMINAL TYPE
*  MARGX  = NUMBER OF PIXELS PADDED TO X-COORDINATE
*  MARGY  = NUMBER OF PIXELS PADDED TO Y-COORDINATE
*
*
      EQUIVALENCE (ESC, ASCII(27)), ( CTLZ, ASCII(26))

      DATA ISINIT / .FALSE. /
C
C   CODES FOR IND:
C
C     IND = 0   =>  REMOVE ALL GRAPHICS TO QUIT
C     IND = 1   =>  ANY ONE TIME ONLY INITIALIZATION
C     IND = 2   =>  MOVE GRAPHICS TO POINT (X,Y) -- DO NOT DRAW LINE
C     IND = 3   =>  DRAW LINE FROM LAST POINT TO NEW (X,Y)
C     IND = 4   =>  DRAW DARK LINE
C     IND = 5   =>  DRAW BRIGHT SOLID LINE
C     IND = 6   =>  INITIALIZE & SET-UP FOR NEXT PICTURE
C     IND = 8   =>  TEMPORARY RELEASE FROM GRAPHICS
C     IND = 9   =>  RETURN TO GRAPHICS FROM TEMP RELEASE
C
*     IND = 99  =>  SET NEW COLOR (VALUE IN X)
*
C
      IF (IND.EQ.0) THEN
C  ALL DONE -- CLEAR TERMINAL AND WE WILL QUIT
         WRITE ( *, *) 'PU;SP0;PA16000,11400;AF;     '
         WRITE ( *, *) ESC//'.Z                          '
         WRITE ( *, *) CTLZ
         ISINIT = .FALSE.

      ELSEIF (IND.EQ.1) THEN
C  ONE TIME ONLY INITIALIZATION OF TERMINAL
         ERASE = .FALSE.
         PIXEL = 7900. * IPAPER / 100.
         NCOLOR = 7
         LCOLOR = 1
C??         MARGX = 7900 / 2 - PIXEL * 0.5
C??         MARGY = 7900 / 2 - PIXEL * 0.5
      ELSEIF (IND.EQ.2 ) THEN
* THIS DEVICE CLIPS FOR ME
         IXLX = X * PIXEL
         IYLY = Y * PIXEL
         IF ( ERASE ) RETURN
         WRITE ( *, '('' PU;PA'', I5, '','', I5,'';'')') IXLX, IYLY

      ELSEIF (IND.EQ.3) THEN
C DRAW LINE FROM LAST POINT TO NEW POINT
*   THIS DEVICE CLIPS FOR ME
         IXLX = X * PIXEL
         IYLY = Y * PIXEL
         IF ( ERASE ) RETURN
         WRITE ( *, '('' PD;PA'', I5, '','', I5,'';''))') IXLX, IYLY

      ELSEIF (IND.EQ.4) THEN
* NO ABILITY TO ERASE FIGURE FOR PEN PLOTTER
        ERASE= .TRUE.

      ELSEIF (IND.EQ.5) THEN
* NO ABILITY TO ERASE FIGURE FOR PEN PLOTTER
        ERASE = .FALSE.

      ELSEIF (IND.EQ.6) THEN
C  INITIALIZE FOR DRAWING NEXT PICTURE
         ERASE = .FALSE.
         LCOLOR = 1
         NCOLOR = 7
         IF ( ISINIT ) RETURN
         ISINIT = .TRUE.
         WRITE ( *, '(A)') ' '//ESC//'.YGM5000;0;0;7800;'//
     .     ESC//'.M150;;10;13:'//ESC//'.I080;0;17:'//ESC//'.N0;19:'//
     .     'DF;CS01;SS;PU;SP1;VS64;'

         WRITE ( *, '(A)') ' VA;PU;   '

         PIXEL = 7900. * IPAPER / 100.

      ELSEIF (IND.EQ.8) THEN
C TEMPORARY RELEASE FROM GRPHICS  (USUALLY FOR TEXT)

      ELSEIF (IND.EQ.9) THEN
C RETURN TO GRAPHICS FROM TEMPORARY RELEASE

      ELSEIF (IND.EQ.10) THEN
C DONE DRAWING PICTURE
*  PUT PEN TO HOME
         WRITE ( *, *) 'PU;SP0;PA16000,11400;AF;     '
         WRITE ( *, *) ESC//'.Z                          '
         WRITE ( *, *) CTLZ
         ISINIT = .FALSE.

      ELSEIF ( IND.EQ.99) THEN
* SELECT NEW COLOR, THE VALUE IS IN X
         ERASE = .FALSE.
         ICOLOR = INT( X )
         IF ( ICOLOR .GT. NCOLOR ) THEN
            ICOLOR = NCOLOR
         ELSEIF( ICOLOR .LT. 1 ) THEN
            ICOLOR = 1
         ENDIF
         IF ( ICOLOR .NE. LCOLOR) THEN
           WRITE ( *, '('' PU;SP'',I1,'';'')' ) ICOLOR
           LCOLOR = ICOLOR
         ENDIF
      ELSE
C WE HAVE AN ERROR IN IND
         WRITE ( *, *) ' ERROR IN PLOT, IND=',IND

      ENDIF
      RETURN
      END
