      Subroutine Termv(Ival,Iflag)
c
      Dimension Ivals(20)
      Byte Char1,Char2
      Equivalence (I,Char1),(J,Char2)
c
      Call Ipoke("44,"10040 .OR. Ipeek("44))
c
      Write(7,150) 29,'F',29,'S'
150   Format('+',1A1,$)
      Write(7,175) 27,27
175   Format('+',1A1,'7',1A1,'[c',$)
c
c                Strip off the first part of the return sequence
c
 5    Continue
      I = Ittinr()
      If (Char1 .NE. '?') Go To 5
c
c                Read in each of the terminal characteristics
c
      Nvals = 0
10    Continue
      Nvals = Nvals + 1
      If (Char1 .EQ. 'c') Go To 20
      I = Ittinr()
      J = Ittinr()
      If (Char2 .EQ. ';' .OR. Char2 .EQ. 'c') Then
         Ivals(Nvals) = I-48
         If (Char2 .EQ. 'c') Go To 20
      Else
         Ivals(Nvals) = 10 * (I-48) + J - 48
         I = Ittinr()
      End If
      Go To 10
c
c                      See if we have a match
c
 20   Continue
c
      Iflag = 0
      Do 30 I=1,Nvals
         If (Ival .EQ. Ivals(I)) Iflag = 1
 30   Continue
c
c                      Reset the single character mode
c
      Write(7,150) 29,'T',29,'E',27,'8'
      Return
      End
      Subroutine MATINV(Matrix,Nsize,Ndim)
c
c ***********************************************************************
c *                                                                     *
c *        Subroutine Matinv - To solve a matrix using a Gauss          *
c *        elimination method.  The right hand sides of the             *
c *        simultaneous equations are stored in Matrix(I,Nsize+1)       *
c *        The solution to the matrix are then placed there.  It        *
c *        should be noted that the rest of the matrix is the           *
c *        identity matrix.                                             *
c *                                                                     *
c *        Input data:                                                  *
c *                                                                     *
c *        Matrix  - The matrix containing the coefficients of the      *
c *                  simultaneous equations, with the right hand        *
c *                  side of the equation stored in Matrix(I,Nsize+1)   *
c *        Nsize   - The size of the matrix                             *
c *        Ndim    - The first dimension of the Matrix - MUST match     *
c *                  that used in the dimension statement of the        *
c *                  calling program                                    *
c *                                                                     *
c *        Output data:                                                 *
c *                                                                     *
c *        Matrix  - The solution to the simultaneous equations are     *
c *                  stored in Matrix(I,Nsize+1)                        *
c *                                                                     *
c *        Programmed by Steven C. Fisher, DTNSRDC Code 1522            *
c *                                                                     *
c *                                                                     *
c ***********************************************************************
c
      Dimension Matrix(Ndim,1)
      Double Precision Matrix,Amax,Save
      Ncols = Nsize+1
      Nloop = Nsize-1
      Do 50 I=1,Nloop
c
c          Find the row with the largest I th element magnitude.  Then
c          swap its row with the ith row.
c
         Irow = I
         Amax = 0.0
         Do 10 J=I,Nsize
            If (Amax .GT. Dabs(Matrix(I,J))) Go To 10
            Irow = J
            Amax = Dabs(Matrix(I,J))
10       Continue
c
c          Swap the rows, and normalize the new I th row by its element
c          along the main diagonal (which is the leftmost nonzero
c          element in that row)
c
         Amax = Matrix(Irow,I)
c
         If (Amax .EQ. 0.0) Amax = 1E-20
c
         If (Dabs(Amax) .LT. 1D-20) Amax = Dsign(1D-20,Amax)
c
         Do 20 J=I,Ncols
            Save = Matrix(Irow,J)
            Matrix(Irow,J) = Matrix(I,J)
            Matrix(I,J) = Save/Amax
20       Continue
c
c          Now, subtract the Ith row from the other rows
c
         Iplus1 = I+1
         Do 40 J=Iplus1,Nsize
            Save = Matrix(J,I)
            Do 30 K=I,Ncols
               Matrix(J,K) = Matrix(J,K)-Save*Matrix(I,K)
30          Continue
40       Continue
50    Continue
c
c          The matrix now consists of 1's in the diagonal, and zeros below
c          the diagonal.  Backfit in the answers in to solve the matrix.
c
      If (Matrix(Nsize,Nsize) .EQ. 0.0) Matrix(Nsize,Nsize) = 1D-20
      Matrix(Nsize,Ncols) = Matrix(Nsize,Ncols)/Matrix(Nsize,Nsize)
      Matrix(Nsize,Nsize) = 1.0
c
      Do 70 I=2,Nsize
         J = Nsize-I+1
         Sum = Matrix(J,Ncols)
         Do 60 k = 2,I
            Nplace = Ncols-K+1
            Sum = Sum-Matrix(J,Nplace)*Matrix(Nplace,Ncols)
60       Continue
         Matrix(J,Ncols) = Sum
70    Continue
      Return
      End
