--- rotdef.orig	2011-12-09 15:05:52.000000000 +0100
+++ rotdef.f	2021-01-23 18:56:41.083585740 +0100
@@ -14,7 +14,7 @@
   REAL(8)              :: pos(3,ndif)
   REAL(8),INTENT(OUT) :: rotij(3,3,ndif),tauij(3,ndif)
   CHARACTER*67    ERRMSG
-  REAL(8)   x(3),x1(3),toler,toler2,one
+  REAL(8)   x(3),x1(3),toler,toler2,one,oldx1(3)
   INTEGER   i,i1,j,k,l,m,index,index1,jatom,ncount
   DATA TOLER/1.D-7/,ONE/1.D0/
 !
@@ -96,6 +96,7 @@
            x1(1:3)=MOD(ABS(X(1:3)-POS(1:3,INDEX))+toler,one)-toler
 !           WRITE(*,*) 'JATOM,INDEX,I',JATOM,INDEX,I                   
 !           WRITE(*,*) ABS(X1(1:3)),toler
+           oldx1(1:3)=x1(1:3)
            IF(MAXVAL(ABS(X1)).LT.TOLER2) THEN        
               NCOUNT=NCOUNT+1                                             
               TAUIJ(1:3,INDEX)=TAU(1:3,I)
@@ -111,6 +112,7 @@
                  ROTIJ(1:3,1:3,INDEX)=IZ(1:3,1:3,I) 
                  GOTO 30                                                     
               END IF
+              x1(1:3)=oldx1(1:3)
            endif
            if(lattic(1:1).eq.'F'.or.lattic(1:3).eq.'CXY') then
               x1(1:2)=mod(x1(1:2)+0.5d0+toler,one)-toler
@@ -120,7 +122,7 @@
                  ROTIJ(1:3,1:3,INDEX)=IZ(1:3,1:3,I) 
                  GOTO 30                                                     
               END IF
-              x1(1:2)=mod(x1(1:2)+0.5d0,one)
+              x1(1:3)=oldx1(1:3)
            endif
            if(lattic(1:1).eq.'F'.or.lattic(1:3).eq.'CXZ') then
               x1(1)=mod(x1(1)+0.5d0+toler,one)-toler
@@ -131,8 +133,7 @@
                  ROTIJ(1:3,1:3,INDEX)=IZ(1:3,1:3,I) 
                  GOTO 30                                                     
               END IF
-              x1(1)=mod(x1(1)+0.5d0,one)
-              x1(3)=mod(x1(3)+0.5d0,one)
+              x1(1:3)=oldx1(1:3)
            endif
            if(lattic(1:1).eq.'F'.or.lattic(1:3).eq.'CYZ') then
               x1(2:3)=mod(x1(2:3)+0.5d0+toler,one)-toler
@@ -142,6 +143,7 @@
                  ROTIJ(1:3,1:3,INDEX)=IZ(1:3,1:3,I) 
                  GOTO 30                                                     
               END IF
+              x1(1:3)=oldx1(1:3)
            end if
         ENDDO
         !
