      SUBROUTINE RPAIR(NNATM,CIN,COUT,IAINI,IAFIN,OMEGAD,NGROUP,IGROUP)
C         ROTATION IS PERFORMED ABOUT THE VECTOR FROM IAINI TO IAFIN.
C           ONLY FOR ATOMS IN IGROUP
C     CIN IS OLD COORDINATE  AND  COUT IS NEW COORDINATE.
C     UNIT OF OMEGAD IS DEGREE.
C      *** THIS ROUTINE IS ADAPTED FROM NAARBR IN THIS LISTING ****
      IMPLICIT REAL (A-H,O-Z)
      CHARACTER*80 DUMMY
C?      LOGICAL MODATA, REDRAW
      LOGICAL DEBUG, DEBUGL, DEBUGN, DEBUGO, DEBUGP, DEBUGI
      COMMON /DEBCOM/ DEBUG, DEBUGL, DEBUGN, DEBUGO, DEBUGP, DEBUGI
C?      COMMON /EDIT/ MODATA, REDRAW
      DIMENSION  IGROUP(*),CIN(3,*),COUT(3,*)
      IF (DEBUG) THEN
         WRITE( DUMMY,100)  IAINI,IAFIN,  OMEGAD
  100 FORMAT(' RPAIR: IAINI=',I4,', IAFIN=',I4,', OMEGA=',F8.3)
         CALL DEBUGR( DUMMY(1:50) )
      ENDIF
      XORIGI=CIN(1,IAFIN)
      YORIGI=CIN(2,IAFIN)
      ZORIGI=CIN(3,IAFIN)
      DX=XORIGI-CIN(1,IAINI)
      DY=YORIGI-CIN(2,IAINI)
      DZ=ZORIGI-CIN(3,IAINI)
      DS=1./ SQRT(DX*DX+DY*DY+DZ*DZ)
      U=DX*DS
      V=DY*DS
      W=DZ*DS
      OMEGA= 0.01745329252D0*OMEGAD
      C= COS(OMEGA)
      C1=1.0D0-C
      S= SIN(OMEGA)
      ROT11=U*U*C1+C
      ROT22=V*V*C1+C
      ROT33=W*W*C1+C
      UVC1=U*V*C1
      ROT21=UVC1+W*S
      ROT12=UVC1-W*S
      VWC1=V*W*C1
      ROT32=VWC1+U*S
      ROT23=VWC1-U*S
      WUC1=W*U*C1
      ROT13=WUC1+V*S
      ROT31=WUC1-V*S
      IF (NGROUP .EQ. 0) THEN
         CALL ROTSUM(ROT11,ROT12,ROT13,ROT21,ROT22,ROT23,
     .            ROT31,ROT32,ROT33 )
         NLIMIT = NNATM
      ELSE
         DO 5 IA=1,NNATM
         DO 5 J=1,3
         COUT(J,IA)=CIN(J,IA)
    5    CONTINUE
C?         MODATA=.TRUE.
         NLIMIT = NGROUP
      ENDIF
C
      DO 10 IB=1,NLIMIT
         IA = IB
         IF (NGROUP.GT.0) IA=IGROUP(IB)
         COXOLD=CIN(1,IA)-XORIGI
         COYOLD=CIN(2,IA)-YORIGI
         COZOLD=CIN(3,IA)-ZORIGI
         COUT(1,IA)=ROT11*COXOLD+ROT12*COYOLD+ROT13*COZOLD+XORIGI
         COUT(2,IA)=ROT21*COXOLD+ROT22*COYOLD+ROT23*COZOLD+YORIGI
   10    COUT(3,IA)=ROT31*COXOLD+ROT32*COYOLD+ROT33*COZOLD+ZORIGI
C?      REDRAW = .TRUE.
      RETURN
      END
