      SUBROUTINE ROTATE(R,A,B,N,BAD)
C
C ROTATE 3 ELEMENT VECTORS
C
      REAL*4 R(3,N),A(3,N),B(3,3)
C
      DO I = 1,N
       IF ( A(1,I).NE.BAD .AND.
     &      A(2,I).NE.BAD .AND.
     &      A(3,I).NE.BAD ) THEN
        R(1,I) = A(1,I)*B(1,1) + A(2,I)*B(2,1) + A(3,I)*B(3,1)
        R(2,I) = A(1,I)*B(1,2) + A(2,I)*B(2,2) + A(3,I)*B(3,2)
        R(3,I) = A(1,I)*B(1,3) + A(2,I)*B(2,3) + A(3,I)*B(3,3)
       ELSE
        R(1,I) = BAD
        R(2,I) = BAD
        R(3,I) = BAD
       END IF
      END DO
C
      RETURN
      END
