C         SUBROUTINE TO ROTATE ABOUT PRINCIPAL AXES
C
          SUBROUTINE ROTATE(RO,PI,YA,MODULE)
          DIMENSION SAVE(3,3),AM(3,3)
          COMMON/ACCUM/RAC(3,3,15)
          DATA RD/.017145/
5         IF(RO.NE.0.)GO TO 1
          IF(PI.NE.0.)GO TO 2
          IF(YA.NE.0.)GO TO 3
          GO TO 99
C
C         ROLL MATRIX
C
1         AM(1,1)=1.
          AM(2,1)=0.
          AM(3,1)=0.
          AM(1,2)=0.
          AM(2,2)=COS(RO*RD)
          AM(3,2)=SIN(RO*RD)
          AM(1,3)=0.
          AM(2,3)=-AM(3,2)
          AM(3,3)=AM(2,2)
          GO TO 10
C
C         PITCH MATRIX
C
2         AM(1,1)=COS(PI*RD)
          AM(2,1)=0.
          AM(1,3)=SIN(PI*RD)
          AM(1,2)=0.
          AM(2,2)=1.
          AM(3,2)=0.
          AM(3,1)=-AM(1,3)
          AM(2,3)=0.
          AM(3,3)=AM(1,1)
          GO TO 10
C
C         YAW MATRIX
C
3         AM(1,1)=COS(YA*RD)
          AM(2,1)=SIN(YA*RD)
          AM(3,1)=0.
          AM(1,2)=-AM(2,1)
          AM(2,2)=AM(1,1)
          AM(3,2)=0.
          AM(1,3)=0.
          AM(2,3)=0.
          AM(3,3)=1.
C
C         SAVE RAC
C
10        DO 68 K=1,3
          DO 68 I=1,3
68        SAVE(I,K)=RAC(I,K,MODULE)
C
C         FORM NEW RAC
          DO 69 K=1,3
          DO 69 I=1,3
          SUM=0.
          DO 67 J=1,3
67        SUM=SAVE(I,J)*AM(J,K)+SUM
69        RAC(I,K,MODULE)=SUM
99        RETURN
          END
