      SUBROUTINE LA50(X,Y,IND)
*  FOR AN DEC LA50 GRAPHIC PRINTER
      COMMON/OUTPUT/ IPAPER,IPAGE
      CHARACTER*80 FILEIN,FILOUT,FILPLT, LLEGND
      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
*
*
********
      CHARACTER*1024 RECORD
      BYTE GRAPH(1050,200),BYTE(2),HOLD
      CHARACTER*1 ESC, ASCII, FF, CAR, LF
      INTEGER*2 IX1,IY1,IX2,IY2,MAXROW,MAXLIN, NBITPC
      COMMON /BITMAP/ IX1,IY1,IX2,IY2,GRAPH,MAXROW(200),MAXLIN
      COMMON /ASCIIC/ ASCII(0: 255)
      EQUIVALENCE (ESC, ASCII(27)), (FF, ASCII(12)), (CAR, ASCII(13))
      EQUIVALENCE (LF, ASCII(10))
C      **                                                  
*********
        COMMON /BITDEN/ NBITPC
C      **
*********
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 = 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 =10   =>  DONE DRAWING PICTURE
C     IND =99   =>  CHANGE COLOR TO VALUE IN X
C
      PIXEL = 500.0 * IPAPER / 100
      IF (IND.EQ.O) THEN
C  ALL DONE -- CLEAR TERMINAL AND WE WILL QUIT
      ELSEIF (IND.EQ.1) THEN
C  ONE TIME ONLY INITIALIZATION OF TERMINAL  (IF NEEDED)
         NBITPC = 6
         RETURN
      ELSEIF (IND.EQ.2 ) THEN
C     LOCATION OF NEW POINT -- NO LINE TO IT
         IXLX = X * PIXEL * 2
         IYLY = (1.0 - Y) * PIXEL
         IXLAST = IXLX
         IYLAST = IYLY
      ELSEIF (IND.EQ.3) THEN
C DRAW LINE FROM LAST POINT TO NEW POINT
         IXLX = X * PIXEL * 2
         IYLY = (1.0 - Y) * PIXEL
         CALL BITLIN(IXLAST,IYLAST,IXLX,IYLY)
         IXLAST = IXLX
         IYLAST = IYLY
      ELSEIF (IND.EQ.6) THEN
C  INITIALIZE FOR DRAWING NEXT PICTURE
         CALL BMCLR
*
      OPEN( UNIT=11, FILE=FILPLT, ACCESS='SEQUENTIAL',
     +      STATUS='NEW', RECL=1024)
      REWIND 11
C      **                               
        NBITPC = 6
C      **
         RETURN
      ELSEIF (IND.EQ.8) THEN
C TEMPORARY RELEASE FROM GRPHICS  (USUALLY FOR TEXT)
         RETURN
      ELSEIF (IND.EQ.9) THEN
C RETURN TO GRAPHICS FROM TEMPORARY RELEASE
         RETURN
      ELSEIF (IND.EQ.10) THEN
C DONE DRAWING PICTURE
*
*   NOEW WE OUTPUT FILE OF GRAPHICS
*
*  LA50 FORMAT:   '$'  IS GRAPHICS CARRIAGE RETURN (NO LINEFEED)
*                 '-'  IS GRAPHICS LINE FEED
*                 ALL GRAPHICS ARE 6-PIN ENCODING OFSET BY ICHAR("?")
*                 '!'  IS GRAPHIC REPEAT SYMBOL USE IS:
*                       !###S  :  ### IS BCD (IE PRINTABLE REPETITION)
*                                  S  IS GRAPHIC SYMBOL TO REPEAT
*
C      **                                                  
        WRITE ( 11, '(A)' ) ESC//'Pq'
C
        IQUEST = ICHAR('?')
        DO 20 I= 1, MAXLIN
           ILAST = GRAPH(1, I) + IQUEST
           RECORD(1:) = CHAR(ILAST)
           IREC = 1
           ICOUNT = 0
           DO 10 J= 2, MAXROW(I)+1
              ITEMP = GRAPH( J, I) + IQUEST
              IF ( ITEMP .EQ. ILAST) THEN
                 ICOUNT = ICOUNT + 1
              ELSE
                 IF ( ICOUNT .EQ. 0) THEN
                    WRITE ( RECORD(IREC:),'(A)') CHAR(ILAST)
                    IREC = IREC + 1
                 ELSEIF ( ICOUNT .EQ. 1) THEN
                    WRITE ( RECORD(IREC:), '(A)') 
     .                    CHAR(ILAST)//CHAR(ILAST)

                    IREC = IREC + 2
                 ELSEIF ( ICOUNT .LT. 9 ) THEN
                    WRITE ( RECORD(IREC:),'(''!'',I1,A1)') 
     .                                    ICOUNT+1,CHAR(ILAST)
                    IREC = IREC + 3
                 ELSEIF ( ICOUNT .LT. 99 ) THEN
                    WRITE ( RECORD(IREC:),'(''!'',I2,A1)') 
     .                                    ICOUNT+1,CHAR(ILAST)
                    IREC = IREC + 4
                 ELSEIF ( ICOUNT .LT. 999 ) THEN
                    WRITE ( RECORD(IREC:),'(''!'',I3,A1)') 
     .                                    ICOUNT+1,CHAR(ILAST)
                    IREC = IREC + 5
                 ELSE
                    WRITE ( RECORD(IREC:),'(''!'',I4,A1)') 
     .                                    ICOUNT+1,CHAR(ILAST)
                    IREC = IREC + 6
                 ENDIF
                 ICOUNT = 0
                 ILAST = ITEMP
                 IF ( IREC .GT. 900 ) THEN
                    WRITE ( 11, '( A)') RECORD(1:IREC)
                    IREC = 0
                 ENDIF
              ENDIF
10         CONTINUE  
C      **                                    
         IF ( IREC .GT. 1 ) THEN
            WRITE(11, '( A)' ) RECORD(1:IREC)//'$'//'-'
         ELSE
            WRITE(11, '( A)' ) '$'//'-'
         ENDIF
20     CONTINUE                               
C      **                                     
C      ** CLEAN UP                             
C      **                                      
        WRITE ( 11, '(A)' ) ESC//'\\'//FF
        CLOSE(UNIT=11)                        
C      **           
      ELSEIF (IND.EQ.99) THEN
C  REQUEST CHANGE COLOR
*  NOT SUPPORTED HERE
         CONTINUE
      ELSE
C WE HAVE AN ERROR IN IND
      WRITE ( *, '( '' ERROR IN PLOT, IND='', I4)' ) IND
      ENDIF
      RETURN
      END
