C   12/12/78 C9073001   MEMBER NAME  LGSRTH   (SOURCE)      FORTRAN
      SUBROUTINE LGSRTH( IB, ND )
C
C     S.YAMADA    12-12-78     16:40    COPIED FROM (LGSOURCE)
C     LAST MODIFICATION  09-03-79  15:45
C
C---- PULSE HEIGHT SORT OF LEAD GLASS DATA
C---- SORT ACCORDING TO THE ALGORITHM 201 OF CACM,SEE P.66 DESY R-INFO
C
C---- THIS IS A SUBPROGRAM TO SORT LG-DATA OF DIFFERENT DETECTOR PART
C     SEPARATELY.
C---- IB=BASE INDEX,  ND=NO. OF DATA TO BE SORTED.
C
      IMPLICIT INTEGER *2 (H)
#include "clgwork1.for"
      DIMENSION LGADC(2000)
      EQUIVALENCE (LGADC(1),HLGADC(1,1))
C
      COMMON/ CLGVRN/ NVRSN(20)
      DATA NVCODE/178102015/
      NVRSN(17) = NVCODE
C
      IF( ND.LE.1) RETURN
      M = ND
   10 M = M/2
      IF(M.EQ.0) RETURN
      K = ND-M
        DO 50 J=1,K
        I = J+IB
   20   IF(I.LE.IB) GO TO 50
        IF( HLGADC(2,I+M).LE.HLGADC(2,I) ) GO TO 50
C----   REPLACING
    3   IW = LGADC(I)
        LGADC(I) = LGADC(I+M)
        LGADC(I+M) = IW
        I = I-M
        GO TO 20
   50   CONTINUE
      GO TO 10
      END
