      SUBROUTINE SORTXYZ0(XX,Y,NORD)
C
C *** NOTE !!!  THIS IS THE OLD VERSION OF SORTXYZ (WRITTEN IN
C       1987) WHICH HAS NOW BEEN REPLACED WITH A MORE EFFICIENT
C       VERSION.  HOWEVER, IF PROBLEMS ARISE IN USING THE NEW
C       ROUTINE, THIS ONE SHOULD BE USED INSTEAD ***
C
C     SORTS VECTOR OF NUCLEAR COORDINATES - TO CHECK FOR EQUIVALENCE
C     OF TWO ORIENTATIONS - NEEDS Q VECTOR AND ATOMIC MASS VECTOR (ATMAS
C
      IMPLICIT DOUBLE PRECISION (A-H, O-Z)
C MXATMS     : Maximum number of atoms currently allowed
C MAXCNTVS   : Maximum number of connectivites per center
C MAXREDUNCO : Maximum number of redundant coordinates.
C
      INTEGER MXATMS, MAXCNTVS, MAXREDUNCO
      PARAMETER (MXATMS=200, MAXCNTVS = 10, MAXREDUNCO = 3*MXATMS)
C coord.com : begin
C
      DOUBLE PRECISION Q, R, ATMASS
      INTEGER NCON, NR, ISQUASH, IATNUM, IUNIQUE, NEQ, IEQUIV,
     &        NOPTI, NATOMS
      COMMON /COORD/ Q(3*MXATMS), R(MAXREDUNCO), NCON(MAXREDUNCO),
     &     NR(MXATMS),ISQUASH(MAXREDUNCO),IATNUM(MXATMS),
     &     ATMASS(MXATMS),IUNIQUE(MAXREDUNCO),NEQ(MAXREDUNCO),
     &     IEQUIV(MAXREDUNCO,MAXREDUNCO),
     &     NOPTI(MAXREDUNCO), NATOMS

C coord.com : end


      COMMON /TOLERS/ SYMTOL,DEGTOL
      DIMENSION X(3*MXATMS),XX(3*NATOMS),Y(3*NATOMS),NORD(MXATMS*2)
C
      ILINE(J)=1+J/3
C
C
C     SORT ON THE X - IF TWO X'S ARE EQUIVALENT, SORT ON Y AND SO ON.
C
      DO 80 I=1,3*NATOMS
 80      X(I)=XX(I)
C
C     FIRST GIVE DUMMY ATOMS RIDICULOUS SCRATCH COORDINATES - ENSURES
C     THAT THEY WILL WIND UP AT THE BOTTOM OF THE LIST
C
      DO 81 I=1,3*NATOMS-2,3
         IF(DABS(ATMASS(ILINE(I))).LT.1D-3)THEN
            DO 82 J=0,2
 82            X(J+I) = -99995.
         ENDIF
 81   CONTINUE
      JK=1
 429  J=1
      DO 96 I=1,3*NATOMS-2,3
C
C     CONTINUE WITH SORTING.
C
         XDIF=X(I)-X(J)
         YDIF=X(I+1)-X(J+1)
         ZDIF=X(I+2)-X(J+2) 
         AXDIF=ABS(XDIF)
         AYDIF=ABS(YDIF)
         AZDIF=ABS(ZDIF)
         IF(XDIF.GT.SYMTOL)THEN
          J=I
         ELSEIF(AXDIF.LT.SYMTOL)THEN
          IF(YDIF.GT.SYMTOL)THEN
           J=I
          ELSEIF(AYDIF.LT.SYMTOL)THEN
           IF(ZDIF.GT.SYMTOL)J=I
          ENDIF
         ENDIF
 96   CONTINUE
      DO 93 I=0,2
C
C     MASS-WEIGHT SORTED VECTOR - WILL ZERO ELEMENTS CORRESPONDING
C     TO DUMMY ATOMS SO THEY DONT MUCK UP THE SYMMETRY CHECKING.
C
         Y(3*JK-2+I)=X(J+I)*NINT(ATMASS(ILINE(J)))
 93      X(J)=-99999.D0
      NORD(JK)=(J+2)/3
      JK=JK+1
      if(jk.eq.NATOMS+1)go to 999
      go to 429
 999  Continue
      Return
      end
