      subroutine rotation(xpos,psi1,phi1,theta1)
      implicit double precision (A-H,O-Z)
c subroutine for rotational transformation
c input: xpos reads from cell1
c	 u1 = psi1
c	 u2 = phi1
c	 u3 = theta1
c output: ppos
      parameter (nat=160)
      dimension xpos(nat,3),xpos1(3,nat),a(3,3),ppos(3,nat)
      parameter (trans=0.017453292d0)
c
      do i=1,nat
         do j=1,3
            xpos1(j,i)=xpos(i,j)
         end do
      end do
c
      psi=trans*psi1
      phi=trans*phi1
      theta=trans*theta1
c
      cpsi=dcos(psi)
      spsi=dsin(psi)
      cphi=dcos(phi)
      sphi=dsin(phi)
      ctheta=dcos(theta)
      stheta=dsin(theta)
c
      a(1,1)=cpsi*cphi-ctheta*spsi*sphi
      a(1,2)=cphi*spsi+ctheta*cpsi*sphi
      a(1,3)=sphi*stheta
      a(2,1)=-sphi*cpsi-ctheta*spsi*cphi
      a(2,2)=-sphi*spsi+ctheta*cpsi*cphi
      a(2,3)=cphi*stheta
      a(3,1)=stheta*spsi
      a(3,2)=-stheta*cpsi
      a(3,3)=ctheta
      do i=1,nat
	   do j=1,3
	    ppos(j,i)=0.0d0
	       do k=1,3
		  ppos(j,i)=ppos(j,i)+xpos1(k,i)*a(j,k)
	       end do
	   end do
      end do
      do i=1,nat
	   do j=1,3
	    xpos(i,j)=ppos(j,i)
	   end do
      end do
      return
      end
