      SUBROUTINE RETROG(X,Y,IND)
      CHARACTER*1 CCHAR, DELIM, CHAR29, CHAR27
      COMMON/ OUTPUT/ IPAPER,IPAGE
      COMMON /DEVICE/ ITYPE, ISCRN, KOROFF
      COMMON /RETRM/ CCHAR, DELIM
      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
*
*
C ****   THE FOLLOWING STATEMENT SHOULD BE CHANGED FOR THE
C       SPECIFIC COMMAND CHARACTER USED ON YOUR RETRO-GRAPHICS
C
      DATA CCHAR,DELIM /'!', '*'/             
      DATA IMODE / 102 /
*  IMODE HOLDS THE CURRENT TERMINAL MODE:
*       102 => VT102 (OR TRANSPARENT)
*      4027 => TEKTRONIX 4027 EMULATION
*
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
*     IND = 10  =>  DONE DRAWING PICTURE
*
*     IND = 99  =>  REQUEST TO CHANGE COLOR OF LINE (NOT SUPPORTED)
C
      PIXROW = 14
      CHAR27 = CHAR(27)
      CHAR29 = CHAR(29)
      PIXCOL = 640. / 80.
*
*     WORKSPACE IS 28 LINES OUT OF 33 MAX
*
      PIXEL = 28. * PIXROW * IPAGE / 100.
*
      IF (IND.EQ.0) THEN
C  ALL DONE -- CLEAR TERMINAL AND WE WILL QUIT
         IF ( IMODE .EQ. 4027 ) THEN
            WRITE ( *, *) CCHAR//'WOR 0'
            WRITE ( *, *) CCHAR//'ERA'
            INGRAF = 0
*  return to transparent mode
            WRITE ( *, *) CHAR27//'"0g'
            IMODE = 102
         ENDIF
      ELSEIF (IND.EQ.1) THEN
C  ONE TIME ONLY INITIALIZATION OF TERMINAL  (IF NEEDED)
         IMAXR = 28
         IMAXC = 80
         NCOLOR = 0
         ISCRN = 24
C?         KOROFF = 1
         IF ( IMODE .EQ. 102 ) THEN
*  first enter 4010 mode from transparent then 4027 mode from 4010
            WRITE ( *, *) CHAR29//CHAR27//'"6g'
            IMODE = 4027
         ENDIF
         WRITE ( *, *) CCHAR//'WOR 0'
         WRITE ( *, *) CCHAR//'ERA'
         WRITE ( *, '( 1X, A1, ''WOR '',I2,'' H'')') CCHAR, IMAXR
         WRITE (*,*) CCHAR//'LIN 1'
         WRITE ( *, *) CCHAR//'MON K'
         INGRAF = 1
      ELSEIF (IND.EQ.2 ) THEN
         IXLX = X * PIXEL
         IYLY = Y * PIXEL
         CALL RETCLP( IXLX, IYLY )
         IF ( ABS(IXLAST-IXLX) + ABS(IYLAST-IYLY) .GT. 0 )
     .       WRITE (6, 100) CCHAR,IXLX, IYLY
100      FORMAT (' ',A1,'VEC',I3,',',I3)
         IXLAST = IXLX
         IYLAST = IYLY
      ELSEIF (IND.EQ.3) THEN
C DRAW LINE FROM LAST POINT TO NEW POINT
         IXLX = X * PIXEL
         IYLY = Y * PIXEL
         CALL RETCLP( IXLX, IYLY )
         IF ( ABS(IXLAST-IXLX) + ABS(IYLAST-IYLY) .GT. 0 )
     .      WRITE (6, 101) CCHAR,IXLAST,IYLAST,IXLX,IYLY
101      FORMAT (' ',A1,'VEC',I3,',',I3,',',I3,',',I3)
         IXLAST = IXLX
         IYLAST = IYLY
      ELSEIF (IND.EQ.4) THEN
         WRITE (*,*) CCHAR//'LIN E'
      ELSEIF (IND.EQ.5) THEN
         WRITE (*,*) CCHAR//'LIN 1'
      ELSEIF (IND.EQ.6) THEN
C  INITIALIZE FOR DRAWING NEXT PICTURE
         IF ( IMODE .EQ. 102 ) THEN
*  first enter 4010 mode from trnasparent then 4027 mode from 4010
            WRITE ( *, *) CHAR29//CHAR27//'"6g'
            IMODE = 4027
         ENDIF
         WRITE ( *, *) CCHAR//'WOR 28 H'
         WRITE ( *, *) CCHAR//'ERA'
         WRITE ( *, *) CCHAR//'GRA 1,28'
         WRITE ( *, *) CCHAR//'MON K'
         INGRAF = 1
      ELSEIF (IND.EQ.8) THEN
C TEMPORARY RELEASE FROM GRAPHICS  (USUALLY FOR TEXT)
         WRITE ( *, *) CCHAR//'MON H K'
         INGRAF = 0
      ELSEIF (IND.EQ.9) THEN
C RETURN TO GRAPHICS FROM TEMPORARY RELEASE
         WRITE ( *, *) CCHAR//'WOR H'
         INGRAF = 1
      ELSEIF (IND.EQ.10) THEN
C DONE DRAWING PICTURE
         WRITE ( *, *) CCHAR//'MON H K'
         WRITE ( *, *) CCHAR//'ERA M'
         INGRAF = 0
      ELSEIF ( IND.EQ.99 ) THEN
* COLOR CHANGE IMPLEMENTED AS SET SOLID LINE ( SAME AS IND=5)
         WRITE (*,*) CCHAR//'LIN 1'
      ELSE
C WE HAVE AN ERROR IN IND
         IF ( INGRAF .NE. 0 ) WRITE ( *, *) CCHAR//'MON H'
         WRITE ( *, *) ' ERROR IN PLOT, IND=',IND
         IF ( INGRAF .NE. 0 ) WRITE ( *, *) CCHAR//'WOR H'
      ENDIF
      RETURN
      END

      SUBROUTINE RETSTR(IROW, ICOL, STRING)
*
*  TO PLACE TEXT SRING IN GRAPHIC AREA
*    THE STRING STARTS AT LOCATION (ROW, COL)
* RESPONSIBILITY FOR WRAPPING, ETC IS UP TO THE USER
*
      CHARACTER*(80) STRING
      CHARACTER*1 CCHAR, DELIM
      COMMON /RETRM/ CCHAR, DELIM
      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
*
*
*  FIRST WE CHECK FOR THE USER USING OUR DELIMITER CHARACTER
      IF ( INDEX( STRING, '"') .GT. 0 ) THEN
*         A MATCH, CHECK THE FIRST ALTERNATE
         IF ( INDEX( STRING, '&') .EQ. 0 ) THEN
            DELIM = '&'
         ELSEIF ( INDEX( STRING, '*') .EQ. 0 ) THEN
            DELIM = '*'
         ELSE
            DELIM = '+'
         ENDIF
      ELSE
         DELIM = '"'
      ENDIF
*
      IF ( ICOL*IROW .EQ. 0 ) THEN
         WRITE ( *, '( 1X, A1, ''STR'',A )' )
     .      CCHAR, DELIM//STRING//DELIM
      ELSE
         WRITE ( *, '( 1X, A1, ''VEC'',I3,'','',I3, A1, ''STR'',A )' )
     .      CCHAR, (ICOL-1)* PIXCOL +1, (IMAXR - IROW) * PIXROW,
     .      CCHAR, DELIM//STRING//DELIM
      ENDIF
      DELIM = '*'
      RETURN
      END

      SUBROUTINE RETCLP( INX, INY )
      IMPLICIT INTEGER ( A - Z )
      DATA XMIN, XMAX, YMIN, YMAX / 0, 640, 0, 480 /
      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
*
*
      IF ( INX .LT. XMIN ) THEN
         INX = XMIN
      ELSEIF ( INX .GT. XMAX ) THEN
         INX = XMAX
      ENDIF
      IF ( INY .LT. YMIN ) THEN
         INY = YMIN
      ELSEIF ( INY .GT. YMAX ) THEN
         INY = YMAX
      ENDIF
*
      RETURN
      END
