      SUBROUTINE MPRD31(R,A,B)
C
C PERFORM MATRIX MULTIPLICATION (3X3 BY 3X1)
C
      REAL*4 R(3,1),A(3,3),B(3,1)
C
      R(1,1) = A(1,1)*B(1,1) + A(1,2)*B(2,1) + A(1,3)*B(3,1)
      R(2,1) = A(2,1)*B(1,1) + A(2,2)*B(2,1) + A(2,3)*B(3,1)
      R(3,1) = A(3,1)*B(1,1) + A(3,2)*B(2,1) + A(3,3)*B(3,1)
C
      RETURN
      END
      SUBROUTINE MPRD33(R,A,B)
C
C PERFORM MATRIX MULTIPLICATION (3X3 BY 3X3)
C
      REAL*4 R(3,3),A(3,3),B(3,3)
C
      R(1,1) = A(1,1)*B(1,1) + A(1,2)*B(2,1) + A(1,3)*B(3,1)
      R(1,2) = A(1,1)*B(1,2) + A(1,2)*B(2,2) + A(1,3)*B(3,2)
      R(1,3) = A(1,1)*B(1,3) + A(1,2)*B(2,3) + A(1,3)*B(3,3)
C
      R(2,1) = A(2,1)*B(1,1) + A(2,2)*B(2,1) + A(2,3)*B(3,1)
      R(2,2) = A(2,1)*B(1,2) + A(2,2)*B(2,2) + A(2,3)*B(3,2)
      R(2,3) = A(2,1)*B(1,3) + A(2,2)*B(2,3) + A(2,3)*B(3,3)
C
      R(3,1) = A(3,1)*B(1,1) + A(3,2)*B(2,1) + A(3,3)*B(3,1)
      R(3,2) = A(3,1)*B(1,2) + A(3,2)*B(2,2) + A(3,3)*B(3,2)
      R(3,3) = A(3,1)*B(1,3) + A(3,2)*B(2,3) + A(3,3)*B(3,3)
C
      RETURN
      END
      SUBROUTINE ROT31(R,A,B,N,BAD)
C
C PERFORM MATRIX MULTIPLICATION (3X3 BY 3X1)
C
      REAL*4 R(3,N),A(3,3),B(3,N)
C
      DO I = 1,N
       IF ( B(1,I).NE.BAD .AND.
     &      B(2,I).NE.BAD .AND.
     &      B(3,I).NE.BAD ) THEN
        R(1,I) = A(1,1)*B(1,I) + A(1,2)*B(2,I) + A(1,3)*B(3,I)
        R(2,I) = A(2,1)*B(1,I) + A(2,2)*B(2,I) + A(2,3)*B(3,I)
        R(3,I) = A(3,1)*B(1,I) + A(3,2)*B(2,I) + A(3,3)*B(3,I)
       ELSE
        R(1,I) = BAD
        R(2,I) = BAD
        R(3,I) = BAD
       END IF
      END DO
C
      RETURN
      END
