C   24/05/79 002210653  MEMBER NAME  PRALGN   (SOURCE)      FORTRAN
      SUBROUTINE PRALGN(LORN,J,MM)
C
C     S.YAMADA      24-05-79   11:30
C                   09-09-79   03:30 Y.WATANABE
C---- DUMP THE LEAD GLASS ADC BANK('ALGN') TO LP
C
C---- LORN=0  FOR 'ALGL'/0,  LORN=1 FOR 'ALGN'/1
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 "cdata.for"
C
      DIMENSION ICL(8),ISLL(8),NSUBL(8),LGL(8),AL(2),NL(2)
      DIMENSION IPHIL(10),IZL(10)
      DATA AL/4HALGL,4HALGN/
C
C---- GET THE POINTER
      DATA INITP/0/
      IF(INITP.GT.0) GO TO 5
      INITP=1
      NL(1)= IBLN(AL(1))
      NL(2)= IBLN(AL(2))
5     CONTINUE
      LO=LORN+1
      IF(LO.LT.1) LO=1
      IF(LO.GT.2) LO=2
C     CALL CLOC(NPLG,AL(LO),NL(LO))
      NPLG=IDATA(NL(LO))
C
      IF(NPLG.LE.0) GO TO 90
      NNPLG = 2*NPLG
      LNG = IDATA(NPLG)
      N1 = NNPLG+1
      N6 = NNPLG+6
C
      NLNG = LNG-3
      WRITE(6,600) AL(LO),NL(LO),NLNG,(HDATA(NH),NH=N1,N6)
  600 FORMAT('0 DUMP OF ',A4,1H/,I1,2X,'NO.OF DATA=',I4,
     $ 5X,'HNORD,HNORML=',2I6,5X,'POINTER=',4I5)
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
        IS = NNPLG+5+2*NS
        IE = IS+2*M-1
        IF(NN.EQ.N1.AND.NR.GT.0) IE = IS+2*NR-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,(HDATA(NH),NH=IS,IE)
  611   FORMAT(' ',I3,10(I6,1H/,I5))
        GO TO 10
C
C-----  CRATE-SLOT-SUBADDRESS
   12     DO 120 NW=NS,NE
          ID = HDATA(NNPLG+5+2*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) = HDATA(NNPLG+6+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 = HDATA(NNPLG+5+2*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) = HDATA(NNPLG+6+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
   90 WRITE(6,690) AL(LO),NL(LO)
  690 FORMAT('0  (PRALGN)',A4,1H/,I1,'  DOES NOT EXIST.')
      RETURN
      END
