C   25/06/78 C9032101   MEMBER NAME  GGSORT   (GAMTSTS)     FORTRAN
      SUBROUTINE GGSORT
C
C     H.WRIEDT    17-11-78
C     LAST MODIFICATION  21.03.79  18:00
C
C     ORIGINALLY WRITTEN AS 'LGSORT' BY S.YAMADA
C     AS TO BE FOUND ON YAMLGSRC.S
C
C---- REARRANGE THE SIMULATED LEAD GLASS ADC DATA IN ORDER.
C---- SORT FOLLOWING THE ALGORITHM 201 OF CACM,SEE P.66 DESY R-INFO
C
C
      IMPLICIT INTEGER*4 (G), INTEGER*2 (H)
      COMMON /CWORK/ IWORK1(42),LNG,HPOINT(4),GGADC(192)
C***  COMMON /CGGADC/ LNG,HPOINT(4),GGADC(192)
      DIMENSION HGGADC(2,192)
      EQUIVALENCE (GGADC(1),HGGADC(1,1))
      COMMON/ CGGVRN/ NVRSN(20)
      DATA NVCODE/178111717/
      NVRSN(16) = NVCODE
C
      NLNG = LNG-2
      IF(NLNG.LE.1) RETURN
C
C           ADDRESS SORT
      M = NLNG
   10 M = M/2
      IF(M.EQ.0) RETURN
      K = NLNG-M
        DO 50 J=1,K
        I = J
   20   IF(I.LT.1) GO TO 50
    1   IF(GGADC(I+M).GE.GGADC(I)) GO TO 50
C----   REPLACING
    3   IW = GGADC(I)
        GGADC(I) = GGADC(I+M)
        GGADC(I+M) = IW
        I = I-M
        GO TO 20
   50   CONTINUE
      GO TO 10
      END
