!     Gathering molecules to the computational cell
!     MSE 6270, Leonid Zhigilei
!     It is necessary to gather particles back to the
!     computational cell from time to time for systems
!     with active diffusion.  We have to avoid the
!     situation when the particle diffuses farther than
!     the size of the computational cell.
      SUBROUTINE Gather ()
      INCLUDE 'common.h'
      the_loop: DO I=1,NAN
        I3=I+I+I
        IF(LIDX.EQ.1) THEN
          DX=X(I3-2)-XCENTR
          IF(DX.GT.XLHALF) X(I3-2)=X(I3-2)-XL
          IF(DX.LT.-XLHALF) X(I3-2)=X(I3-2)+XL
        ENDIF
        IF(LIDZ.EQ.1) THEN
          DZ=X(I3)-ZCENTR
          IF(DZ.GT.ZLHALF) X(I3)=X(I3)-ZL
          IF(DZ.LT.-ZLHALF) X(I3)=X(I3)+ZL
        ENDIF
        IF(LIDY.EQ.1) THEN
          DY=X(I3-1)-YCENTR
          IF(DY.GT.YLHALF) X(I3-1)=X(I3-1)-YL
          IF(DY.LT.-YLHALF) X(I3-1)=X(I3-1)+YL
        ENDIF
      END DO the_loop
      RETURN
      END

