      SUBROUTINE SCHMIT(U,N,NDIM)
      implicit double precision (A-H,O-Z)
      include 'SIZES'
      include 'MOP6FILE'
      dimension U(NDIM,NDIM)
      save ZERO, SMALL, ONE
      data ZERO,SMALL,ONE/0.0,0.01,1.0/
      II=0
      do 110 K=1,N
         K1=K-1
C
C     NORMALIZE KTH COLUMN VECTOR
C
         DOT = ZERO
         do 10 I=1,N
   10    DOT=DOT+U(I,K)*U(I,K)
         if (DOT.EQ.ZERO) go to 100
         SCALE=ONE/SQRT(DOT)
         do 20 I=1,N
   20    U(I,K)=SCALE*U(I,K)
   30    if (K1.EQ.0) go to 110
         NPASS=0
C
C     PROJECT OUT K-1 PREVIOUS ORTHONORMAL VECTORS FROM KTH VECTOR
C
   40    NPASS=NPASS+1
         do 70 J=1,K1
            DOT=ZERO
            do 50 I=1,N
   50       DOT=DOT+U(I,J)*U(I,K)
            do 60 I=1,N
   60       U(I,K)=U(I,K)-DOT*U(I,J)
   70    continue
C
C     SECOND NORMALIZATION (AFTER PROJECTION)
C     IF KTH VECTOR IS SMALL BUT NOT ZERO THEN NORMALIZE
C     AND PROJECT AGAIN TO CONTROL ROUND-OFF ERRORS.
C
         DOT=ZERO
         do 80 I=1,N
   80    DOT=DOT+U(I,K)*U(I,K)
         if (DOT.EQ.ZERO) go to 100
         if (DOT.LT.SMALL.AND.NPASS.GT.2) go to 100
         SCALE=ONE/SQRT(DOT)
         do 90 I=1,N
   90    U(I,K)=SCALE*U(I,K)
         if (DOT.LT.SMALL) go to 40
         go to 110
C
C     REPLACE LINEARLY DEPENDENT KTH VECTOR BY A UNIT VECTOR.
C
  100    II=II+1
C     if (II.GT.N) stop
         U(II,K)=ONE
         go to 30
  110 continue
      return
      end
