      SUBROUTINE MPI99(X,Y,IND)
*  FOR AN ZENITY MPI-99 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
*
*
********
      BYTE GRAPH(1050,200),RECORD(1000),BYTE(2),HOLD
      CHARACTER*1 ESC, ASCII, FF, CAR, LF
      CHARACTER*1 CTLZ, NEWZ
      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))
      EQUIVALENCE ( CTLZ, ASCII(26)), (NEWZ, ASCII(24))
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
*
*     IND = 99  =>  CHANGE COLOR (NOT USED HERE)
C
      PIXEL = 576.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 TRMINAL  (IF NEEDED)
         RETURN
      ELSEIF (IND.EQ.2 ) THEN
C     LOCATION OF NEW POINT -- NO LINE TO IT
         IXLX = X * PIXEL
         IYLY = Y * PIXEL
         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 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 = 7
        WRITE ( 11, '(1024A1)' ) CHAR(138), CAR,LF
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
C      **                                                  
      WRITE ( 11, '(1024A1)' ) ESC,'1', CAR,LF
C    **
        DO 20 I=MAXLIN,1,-1
        IF (MAXROW(I).LT.1) GO TO 20
        DO 10 J=1,MAXROW(I)
        RECORD( J) = GRAPH(J,I)
** IBM-PC ALTERATION:  TO USE KERMIT (COLUMBIA UNIVERSITY)
**   FOR FILE TRANSFER TO AN IBM-PC USING PC-DOS FOR LATER
**   OUTPUT OF THE PLOT FILE TO AN EPSON FX-80, THE FILE MUST
**   NOT HAVE ANY CONTROL ^Z (ASCII-26) CHARACTERS.  THIS
**   MAY BE COMMON FOR OTHER MS-DOS SYSTEMS AND THEREFORE
**   FOR PRINTERS CONNECTED TO SUCH COMPUTERS.
** TO AVOID THE PROBLEM, I REPLACE ASCII-26 BY ASCII-24.
** THE BIT PATTERNS ARE:
** BIT  ASCII-26      ASCII-24
** 7      
** 6
** 5
** 4      1             1
** 3      1             1
** 2                    
** 1      1
** 0
**
         IF (RECORD(J) .EQ. ICHAR(CTLZ)) RECORD(J)=ICHAR(NEWZ)
10     CONTINUE  
C      **                                    
        K1 = 0
        K2 = MAXROW(I)
 18     IF ( K2 .GE. 256) THEN
           K2 = K2 - 256
           K1 = K1 + 1
           GOTO 18
        ENDIF
        IF ( K2 .EQ. ICHAR(CTLZ) ) THEN
           K2 = K2 + 1
           MAXROW(I) = MAXROW(I) + 1
        ENDIF
        WRITE(11, '(1024A1)' ) ESC,'*',CHAR(5),CHAR(K2),CHAR(K1),
     .                (RECORD(L),L=1, MAXROW(I) ), CAR,LF
20     CONTINUE                               
C      **                                     
C      ** CLEAN UP                             
C      **                                      
C?        WRITE ( 11, '(1024A1)' ) CHAR(27),'@', CAR,LF
        WRITE ( 11, '(A)' ) FF
        WRITE ( 11, '(1024A1)' ) CHAR(27),'@', CAR,LF
        CLOSE(UNIT=11)                        
C      **           
      ELSEIF( IND.EQ.99) THEN
* REQUEST TO CHANGE COLOR OF LINE
         CONTINUE
      ELSE
C WE HAVE AN ERROR IN IND
      WRITE ( *, '( '' ERROR IN PLOT, IND='', I4)' ) IND
      ENDIF
      RETURN
      END
