      SUBROUTINE ERROR (N)
      IMPLICIT NONE
C
      INTEGER N
C
      INCLUDE MATLAB$KOM:SIZEPARMS.INC
      INCLUDE MATLAB$KOM:VSTK.KOM
      INCLUDE MATLAB$KOM:RECU.KOM
      INCLUDE MATLAB$KOM:ALFS.KOM
      INCLUDE MATLAB$KOM:IOP.KOM
      INCLUDE MATLAB$KOM:COM.KOM
C
      INTEGER ERRMSG(8), BLH, BEL, COLOR1, COLOR2, K, LUNIT, I, LB, LT
C
C ***      SET BEL TO CTRL-G IF POSSIBLE
      DATA ERRMSG / 1H/, 1H-, 1H-, 1HE, 1HR, 1HR, 1HO, 1HR /
      DATA BLH / 1H  /, BEL / 1H  /
      DATA COLOR1 / Z'9B33326D' /, COLOR2 / Z'9B30306D' /
C
C
      K = LPT(2)-LPT(1)
      IF (K.LT.1) K = 1
      LUNIT = WTE
C
98    CONTINUE
      WRITE (LUNIT, 100) COLOR1, (BLH, I = 1, K),
     .                   (ERRMSG(I), I = 1, 8), COLOR2, BEL
100   FORMAT (1X, A4, 80A1, A4)
      GO TO ( 1,  2,  3,  4,  5,  6,  7,  8,  9, 10,
     .       11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
     .       21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
     .       31, 32, 33, 34, 35, 36, 37, 38, 39, 40), N
C
1     CONTINUE
      WRITE (LUNIT, 900) 'IMPROPER MULTIPLE ASSIGNMENT'
900   FORMAT (1X, A)
      GO TO 99
C
2     CONTINUE
      WRITE (LUNIT, 900) 'IMPROPER FACTOR'
      GO TO 99
C
3     CONTINUE
      WRITE (LUNIT, 900) 'EXPECT RIGHT PARENTHESIS'
      GO TO 99
C
4     CONTINUE
      DO 94 I = 1, 4
        K = IDS(I,PT+1)
        BUF(I) = ALFA(K+1)
94    CONTINUE
      WRITE (LUNIT, 104) (BUF(I), I = 1, 4)
104   FORMAT (' UNDEFINED VARIABLE: ', 4A1)
      GO TO 99
C
5     CONTINUE
      WRITE (LUNIT, 900) 'COLUMN LENGTHS DO NOT MATCH'
      GO TO 99
C
6     CONTINUE
      WRITE (LUNIT, 900) 'ROW LENGTHS DO NOT MATCH'
      GO TO 99
C
7     CONTINUE
      WRITE (LUNIT, 900) 'TEXT TOO LONG'
      GO TO 99
C
8     CONTINUE
      WRITE (LUNIT, 900) 'INCOMPATIBLE FOR ADDITION'
      GO TO 99
C
9     CONTINUE
      WRITE (LUNIT, 900) 'INCOMPATIBLE FOR SUBTRACTION'
      GO TO 99
C
10    CONTINUE
      WRITE (LUNIT, 900) 'INCOMPATIBLE FOR MULTIPLICATION'
       GO TO 99
C
11    CONTINUE
      WRITE (LUNIT, 900) 'INCOMPATIBLE FOR RIGHT DIVISION'
      GO TO 99
C
12    CONTINUE
      WRITE (LUNIT, 900) 'INCOMPATIBLE FOR LEFT DIVISION'
      GO TO 99
C
13    CONTINUE
      WRITE (LUNIT, 900) 'IMPROPER ASSIGNMENT TO PERMANENT VARIABLE'
      GO TO 99
C
14    CONTINUE
      WRITE (LUNIT, 900) 'EYE-DENTITY UNDEFINED BY CONTEXT'
      GO TO 99
C
15    CONTINUE
      WRITE (LUNIT, 900) 'IMPROPER ASSIGNMENT TO SUBMATRIX'
      GO TO 99
C
16    CONTINUE
      WRITE (LUNIT, 900) 'IMPROPER COMMAND'
      GO TO 99
C
17    CONTINUE
      LB = VSIZE-LSTK(BOT)+1
      LT = ERR+LSTK(BOT)
      WRITE (LUNIT, 117) LB, LT, VSIZE
117   FORMAT (' TOO MUCH MEMORY REQUIRED', /,
     .        '  ', I7, ' VARIABLES,', I7, ' TEMPORARIES,',
     .              I7, ' AVAILABLE.')
      GO TO 99
C
18    CONTINUE
      WRITE (LUNIT, 900) 'TOO MANY NAMES'
      GO TO 99
C
19    CONTINUE
      WRITE (LUNIT, 900) 'MATRIX IS SINGULAR TO WORKING PRECISION'
      GO TO 99
C
20    CONTINUE
      WRITE (LUNIT, 900) 'MATRIX MUST BE SQUARE'
      GO TO 99
C
21    CONTINUE
      WRITE (LUNIT, 900) 'SUBSCRIPT OUT OF RANGE'
      GO TO 99
C
22    CONTINUE
      WRITE (LUNIT, 122) (RSTK(I), I = 1, PT)
122   FORMAT (' RECURSION DIFFICULTIES', 10I4)
      GO TO 99
C
23    CONTINUE
      WRITE (LUNIT, 900) 'ONLY 1, 2 OR INF NORM OF MATRIX'
      GO TO 99
C
24    CONTINUE
      WRITE (LUNIT, 900) 'NO CONVERGENCE'
      GO TO 99
C
25    CONTINUE
      WRITE (LUNIT, 900) 'CAN NOT USE FUNCTION NAME AS VARIABLE'
      GO TO 99
C
26    CONTINUE
      WRITE (LUNIT, 900) 'TOO COMPLICATED (STACK OVERFLOW)'
      GO TO 99
C
27    CONTINUE
      WRITE (LUNIT, 900) 'DIVISION BY ZERO IS A NO-NO'
      GO TO 99
C
28    CONTINUE
      WRITE (LUNIT, 900) 'EMPTY MACRO'
      GO TO 99
C
29    CONTINUE
      WRITE (LUNIT, 900) 'NOT POSITIVE DEFINITE'
      GO TO 99
C
30    CONTINUE
      WRITE (LUNIT, 900) 'IMPROPER EXPONENT'
      GO TO 99
C
31    CONTINUE
      WRITE (LUNIT, 900) 'IMPROPER STRING'
      GO TO 99
C
32    CONTINUE
      WRITE (LUNIT, 900) 'SINGULARITY OF LOG OR ATAN'
      GO TO 99
C
33    CONTINUE
      WRITE (LUNIT, 900) 'TOO MANY COLONS'
      GO TO 99
C
34    CONTINUE
      WRITE (LUNIT, 900) 'IMPROPER FOR CLAUSE'
      GO TO 99
C
35    CONTINUE
      WRITE (LUNIT, 900) 'IMPROPER WHILE OR IF CLAUSE'
      GO TO 99
C
36    CONTINUE
      WRITE (LUNIT, 900) 'ARGUMENT OUT OF RANGE'
      GO TO 99
C
37    CONTINUE
      WRITE (LUNIT, 900) 'IMPROPER MACRO'
      GO TO 99
C
38    CONTINUE
      WRITE (LUNIT, 900) 'IMPROPER FILE NAME'
      GO TO 99
C
39    CONTINUE
      WRITE (LUNIT, 900) 'INCORRECT NUMBER OF ARGUMENTS'
      GO TO 99
C
40    CONTINUE
      WRITE (LUNIT, 900) 'EXPECT STATEMENT TERMINATOR'
      GO TO 99
C
99    CONTINUE
      ERR = N
      IF (LUNIT.EQ.WIO .OR. WIO.EQ.0) RETURN
      LUNIT = WIO
      GO TO 98
C
      END
