      SUBROUTINE ROT3 (A, THETA)
      DIMENSION A(3,3), THETA(3)
      DATA PIHALF/1.5707963267949/
C     --------------------
      IF (ABS(A(1,1)) .GT. ABS(A(2,1))) GO TO 10
      IF (A(2,1) .NE. 0.0) GO TO 11
C
C     CASE WHEN A(1,1) = A(2,1) = 0
C
      THETA(3) = 0.0
      THETA(2) = SIGN(PIHALF,A(3,1))
      U = A(2,2)
      V = A(1,2)
      IF (A(3,1) .GT. 0.0) V = -V
      THETA(1) = ATAN2(V,U)
      RETURN
C
C     COMPUTATION OF R = SQRT(A(1,1)**2 + A(2,1)**2)
C
   10 T = A(2,1)/A(1,1)
      R = ABS(A(1,1))*SQRT(1.0 + T*T)
      GO TO 20
   11 T = A(1,1)/A(2,1)
      R = ABS(A(2,1))*SQRT(1.0 + T*T)
C
C     EVALUATION OF THE ANGLES
C
   20 THETA(3) = ATAN2(A(2,1),A(1,1))
      THETA(2) = ATAN2(A(3,1),R)
      U = DBLE(A(1,1))*DBLE(A(2,2)) - DBLE(A(1,2))*DBLE(A(2,1))
      IF (ABS(THETA(2)) .GT. 0.8) GO TO 21
      U = U/R
      V = A(3,2)/COS(THETA(2))
      GO TO 22
   21 V = DBLE(A(1,1))*DBLE(A(1,2)) + DBLE(A(2,1))*DBLE(A(2,2))
      V = -V/SIN(THETA(2))
   22 THETA(1) = ATAN2(V,U)
      RETURN
      END
