C
C
C     ================================
      SUBROUTINE TURNIP(M1,M2,M3,MOST)
C     ================================
C
C---- TURNIP  -  to convert to unique form of indices with max value of
C            ( l*lpack + k )*lpack+ h
C           using symmetry matrices as read by subroutine symmat.
C
C   21-Apr-1989  
C     changed to exclude reflections with l .eq. 0 .and. h .lt. 0
C     ie for Triclinic space groups, take h .gt. 0 in the hk0 zone
C     Allow indices up to LHPACK by increasing packing number LPACK
C     Andrew Leslie & Phil Evans,  MRC LMB
C
C
C
C
C     .. Parameters ..
      INTEGER LPACK,LHPACK
      PARAMETER (LPACK=1024,LHPACK=LPACK/2)
      INTEGER MPACK
      PARAMETER (MPACK= ((LPACK*LHPACK+LHPACK)*LPACK+LHPACK))
C     ..
C     .. Scalar Arguments ..
      INTEGER M1,M2,M3,MOST
C     ..
C     .. Scalars in Common ..
      INTEGER NISYM
      CHARACTER PGNAME*10
C     ..
C     .. Arrays in Common ..
      INTEGER ISYM
C     ..
C     .. Local Scalars ..
      INTEGER H,IBEST,ITEST,K,L,M,MA,MB
C     ..
C     .. Local Arrays ..
      INTEGER ITABLE(3)
C     ..
C     .. Common blocks ..
      COMMON /SYMM/NISYM,ISYM(9,47)
      COMMON /SYMM1/PGNAME
C     ..
C
C
      MOST = 0
      IBEST = -MPACK
      IF (NISYM.NE.0) THEN
        H = M1
        K = M2
        L = M3
C
C---- Initialize with identity operation only if acceptable
C
        IF (L.NE.0 .OR. H.GE.0) THEN
          IBEST = (LPACK*M3+M2)*LPACK + M1
          MOST = 1
        END IF
C
C
        DO 20 M = 1,NISYM
          MB = 0
C
C
          DO 10 MA = 1,3
            ITABLE(MA) = ISYM(MB+1,M)*H + ISYM(MB+2,M)*K +
     +                   ISYM(MB+3,M)*L
            MB = MB + 3
   10     CONTINUE
C
C---- Test only acceptable indices
C
          IF (ITABLE(3).NE.0 .OR. ITABLE(1).GE.0) THEN
            ITEST = (ITABLE(3)*LPACK+ITABLE(2))*LPACK + ITABLE(1)
            IF (ITEST.GT.IBEST) THEN
              M1 = ITABLE(1)
              M2 = ITABLE(2)
              M3 = ITABLE(3)
              IBEST = ITEST
              MOST = M + 1
            END IF
          END IF
   20   CONTINUE
C
C
        IF (MOST.EQ.0) THEN
                    CALL CCPERR(1,
     +  'TURNIP - no symmetry operation found')
        ELSE
C
        END IF
      END IF
C
C
      END
