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)
C     USED IN LGANAL PART OF PROGRAMS
C        NO CUTS ON MAX FIRIED #CHANNELS (I.E. DIMENSION=2880)
C        CHANGE SIZE OF THE CLUSTER BANK TO 16.. 13/6/80
C        CHANGED BY Y.WATANABE ON 23/09/79. 00:30
      COMMON /CWORK/ LNG,HNORD,HNORML,HPOINT(4),HLGADC(2,2880),
     1               LGCL(3),LNGCL,NPNT(4),IDENT(2),NCLST,NCLBEC(3),
     2               ETOT(4),NNEUT,EGAM(4),IFLAG(5),NWPCL,
     3               MAPCL(81),  CLPRP(1280)
      INTEGER *2 HMAPCL(2,81)
      DIMENSION ICLSPR(16,80),CLSPRP(16,80), CLMPRP(1361)
      EQUIVALENCE (HMAPCL(1,1),MAPCL(1)), (CLMPRP(1),MAPCL(1))
      EQUIVALENCE (ICLSPR(1,1),CLPRP(1)),  (CLSPRP(1,1),CLPRP(1))
C
      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
