C   07/02/79 206141438  MEMBER NAME  LGADCD   (SOURCE)      FORTRAN
      SUBROUTINE LGADCD(J,MM)
C
C     S.YAMADA      07-01-78
C     LAST MODIFICATION  14-06-82  14:35
C---- DUMP THE LEAD GLASS ADC DATA TO LP OR TYPEWRITER/DISPLAY
C
C---- THE ADDRESS PART IS DECODED ACCORDING TO THE INPUT J
C     J=0, NO DECODING
C     J=1,FOR INPUT CODE I.E. CRATE-SLOT-SUBADDRESS
C     J=2,FOR POSITION CODE I.E. IPHI-IZ FOR THE BARREL PART
C                           I.E. TOP/BOTTOM-NUM FOR THE ENDCAP
C
C---- MM IS NO. OF DATA TO BE PRINTED IN A LINE.
C     THIS ARGUMENT IS PREPARED TO USE THE SUBROUTINE BOTH FOR
C     LP AND OTHER DISPLAY DEVICES.
C
      IMPLICIT INTEGER *2 (H)
#include "clgwork1.for"
C
      DIMENSION ICL(8),ISLL(8),NSUBL(8),LGL(8)
      DIMENSION IPHIL(10),IZL(10)
C
      COMMON/ CLGVRN/ NVRSN(20)
      DATA NVCODE/178102023/
      NVRSN(2) = NVCODE
C
      NLNG = LNG-3
      WRITE(6,600) NLNG,HNORD,HNORML,HPOINT
  600 FORMAT('0 /CLGADC/ DUMP,  NO.OF DATA=',I4,'    HNORD,HNORML=',2I6,
     $                    '          POINTER=',4I5)
C
      IF( NLNG.LE.0 ) RETURN
C
      IF(J-1) 1,2,3
    1 WRITE(6,601)
  601 FORMAT(' NONDECODED ADDRESS PART /PULSE HEIGHT')
      GO TO 4
    2 WRITE(6,602)
  602 FORMAT(' DECODED ADDRES, CRATE-SLOT-SUBADDRESS /PULSE HEIGHT')
      GO TO 4
    3 WRITE(6,603)
  603 FORMAT(' DECODED ADDRESS,IPHI-IZ OR TOP/BOT-NUM /PULSE HEIGHT')
C
C---- GET THE NO.OF REPETITION
    4 M = MM
      IF(M.LT.1) M = 1
      IF(M.GT.10) M = 10
      IF(J.GT.0.AND.M.GT.8) M = 8
      N = NLNG/M
      NR = NLNG-M*N
      N1 = N
      IF(NR.GT.0) N1 = N1+1
      NS = 1-M
        DO 10 NN=1,N1
        NS = NS+M
        NE = NS+M-1
        IF(NN.EQ.N1.AND.NR.GT.0) NE = NS+NR-1
C
        IF(J-1) 11,12,13
C
   11   WRITE(6,611) NS,(HLGADC(1,NW),HLGADC(2,NW),NW=NS,NE)
  611   FORMAT(' ',I3,10(I6,1H/,I5))
        GO TO 10
C
C-----  CRATE-SLOT-SUBADDRESS
   12     DO 120 NW=NS,NE
          ID = HLGADC(1,NW)
          IW = ID/48
          NSUB = ID-48*IW
          IC = IW/20
          ISL = IW-20*IC
          INDX = NW-NS+1
          ICL(INDX) = IC
          ISLL(INDX) = ISL
          NSUBL(INDX) = NSUB
          LGL(INDX) = HLGADC(2,NW)
  120     CONTINUE
        WRITE(6,612) NS,(ICL(NW),ISLL(NW),NSUBL(NW),LGL(NW),NW=1,INDX)
  612   FORMAT(' ',I3,8(I3,1H-,I2,1H-,I2,1H/,I5))
        GO TO 10
C----   POSITION   IPHI-IZ OR TOP/BOT-NUM
   13     DO 13  0 NW=NS,NE
          ID = HLGADC(1,NW)
          IF(ID.GE.2688) GO TO 131
          IPHI = ID/32
          IZ = ID-32*IPHI
          GO TO 133
  131     IZ = ID-2687
          IF(IZ.GE.96) GO TO 132
          IPHI = 90
          GO TO 133
  132     IZ = IZ-96
          IPHI = 91
  133     INDX = NW-NS+1
          IPHIL(INDX) = IPHI
          IZL(INDX) = IZ
          LGL(INDX) = HLGADC(2,NW)
  130     CONTINUE
        WRITE(6,613) NS,(IPHIL(NW),IZL(NW),LGL(NW),NW=1,INDX)
  613   FORMAT(' ',I3, 8(I4,1H-,I2,1H/,I5))
   10   CONTINUE
      RETURN
      END
