
CD-Section: Sort the Laue Reflection List
C A routine is available to sort the Laue Reflection List in a number of
C ways. In actual fact an internal index list is generated through which
C the spots in the 'sorted' list are accessed though the actual generated
C spot data remains in situ.
CD-end

C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**********************
C**     LRL_SORT     **
C**********************
C
CD-Routine: Sort Reflections List - LRL_SORT
C This routine sorts the Laue Reflection List in a number of
C ways. In actual fact an internal index list is generated through which
C the spots in the 'sorted' list are accessed; the actual generated
C spot data remains in situ. Spots may be sorted by index, detector
C position, lambda or resolution.
CD-end
CD-Fortran:
      SUBROUTINE LRL_SORT (ISOR)
CD-end
      INCLUDE 'implicit_none.finc'
C
C Purpose: Sort a Laue Reflection List in a number of different orders
C
C Author:  John W. Campbell, July 1993
C
C Arguments:
C
      INTEGER ISOR
CD-Parameters:
C ISOR    i (R)   Sort order flag
C                      = 1,  sort on k, k, l
C                      = 2,  sort on nodal h, k, l
C                      = 3,  sort on XFD (stored x-coordinate)
C                      = 4,  sort on YFD (stored y-coordinate)
C                      = 5,  sort on lambda
C                      = 6,  sort on dmin_thr2
CD-end
C====== GLOBALS:
C
      INCLUDE 'lrl_data.finc'
C
C====== FUNCTION TYPES:
C
      EXTERNAL LRL_BDAT
C
C====== LOCALS:
C

C
C-------------------------------------------------------------------------------
C
      IF (ISOR.LE.0.OR.ISOR.GT.6) THEN
         ISORT = 0
         RETURN
      END IF
      ISORT = ISOR
      IF (ISORT.EQ.1) THEN
         CALL INDXIV (HKL, NUM_SPOTS, INDX)
      ELSE IF (ISORT.EQ.2) THEN
         CALL INDXIV (NOD_HKL, NUM_SPOTS, INDX)
      ELSE IF (ISORT.EQ.3) THEN
         CALL INDXRV (XF_D, NUM_SPOTS, INDX)
      ELSE IF (ISORT.EQ.4) THEN
         CALL INDXRV (YF_D, NUM_SPOTS, INDX)
      ELSE IF (ISORT.EQ.5) THEN
         CALL INDXRV (LAMBDAS, NUM_SPOTS, INDX)
      ELSE IF (ISORT.EQ.6) THEN
         CALL INDXRV (DMIN_THR2, NUM_SPOTS, INDX)
      ELSE
         ISORT = 0
      END IF
      RETURN
      END
