C   01/11/84 608051143  MEMBER NAME  ZTRGVW   (S)           FORTRAN
C
C-----------------------------------------------------------------------
      SUBROUTINE ZTRGVW
C-----------------------------------------------------------------------
C
C  AUTHOR:    J. OLSSON     20/09/83  :  SHOW Z FOR FADC INFO IN ZTRG
C
C       MOD:  J. OLSSON     27/09/83  :
C       MOD:  J.H.  C.B.     1/11/84  :  ROTNK CHANGE UPDATE
C  LAST MOD:  J.O.           4/08/86  :  EXTENSION FOR ZTRG:2
C
C     SHOW POSITION OF Z FOR FADC INFORMATION IN ZTRG BANK
C
C-----------------------------------------------------------------------
C
      IMPLICIT INTEGER*2 (H)
C
      LOGICAL DSPDTM,VTXCHR
C
#include "cgeo1.for"
#include "cjdrch.for"
#include "cgraph.for"
#include "cdata.for"
#include "chsym.for"
C
      COMMON / CJCELL / NCELL(3),
     +                  NWIRES(3)
      COMMON / CWORK1 / HWORK(100)
      COMMON / CGRAP2 / BCMD,DSPDTM(30)
      COMMON / CHEADR / HEAD(108)
C
      DIMENSION  HELP(2),HZBAD(8),HZSTOR(16)
C
      EQUIVALENCE  (HELP(1),IZWORD)
C
      DATA  HELP / 0,0 /
      DATA  RZ   / 10.0 /
      DATA MASKZ/Z3F/,MSKSUB/Z3/,MSKSLO/Z7C/,MSKCRA/Z380/
C
C-----------------------------------------------------------------------
C---
C--  LOCATE ZTRG BANK
C---
      IPZTRG = IDATA(IBLN('ZTRG'))
      IF(IPZTRG.GT.0) GO TO 6241
      WRITE(6,6242)
6242  FORMAT(' >>>>>  NO  ZTRG  BANK .....')
      GO TO 9999
6241  LEZTRG = IDATA(IPZTRG)
      IF(LEZTRG.GT.1) GO TO 6245
      WRITE(6,6243)
6243  FORMAT(' >>>>>  ZTRG  BANK WITH LENGTH 0 OR 1 ....')
      GO TO 9999
C
6245  ZFACTO = 2.*ZMAX/63.
      IF(ACMD.NE.0.) ZFACTO = ACMD
C
C OLD OR NEW DATA ?
C
      IPZTRG = 2 * IPZTRG
      HBDSCR = HDATA(IPZTRG + 1)
      IF(HBDSCR.GT.1) GO TO 5000
C
C   OLD DATA
C
      CALL ERASE
      CALL TWINDO(0,4095,0,4095)
      XMINRE = XMIN
      XMAXRE = XMAX
      YMINRE = YMIN
      YMAXRE = YMAX
      XMIN=-1800.
      XMAX= 1500.
      YMIN=-1300.
      YMAX = YMIN + XMAX - XMIN
      CALL DWINDO(XMIN,XMAX,YMIN,YMAX)
C
C  DRAW DETECTOR:
C
C--   FIRST DRAW BOX
      CALL DRAMOV(ZTKM,RITNK,ZTKM,ROTNK+DROTNK,0)
      CALL DRAWA(ZTKP,ROTNK+DROTNK)
      CALL DRAWA(ZTKP,RITNK)
      CALL DRAWA(ZTKM,RITNK)
C--   DRAW NOW BEAM PIPE
      CALL DRAMOV(ZENDMI,RPIP,ZENDPL,RPIP,0)
C--                               MARK THE BEAM AND AXIS DIRECTION
      CALL MOVEA(-40.,  0.)
      CALL DRAWA( 40.,  0.)
      CALL MOVEA(  0.,-40.)
      CALL DRAWA(  0., 40.)
      CALL MOVEA(   0.,   0.)
      SIGN=1.
      CALL DRAWA((SIGN* 80.),   0.)
      CALL DRAWA((SIGN* 80.),  20.)
      CALL DRAWA((SIGN*100.),   0.)
      CALL DRAWA((SIGN* 80.), -20.)
      CALL DRAWA((SIGN* 80.),   0.)
C--   DRAW WIRES OF INNER DETECTOR
      X1 = -ZMAX + ZOFFS
      X2 = ZMAX + ZOFFS
         DO 7 J = 1,3
         RADD = RINCR(J)
         R = FSENSW(J) - 2.*RADD
         NWE = NWIRES(J)
         IF(J.EQ.3) GO TO 9
           DO 8 K = 1,NWE,2
           R = R + 2.*RADD
           CALL DRAMOV(X1,R,X2,R,14)
    8      CONTINUE
         GO TO 7
    9    R = R + 2.*RADD
           DO 10 K = 1,2
           R = R + (K-1)*RADD*(NWE-1)
           CALL DRAMOV(X1,R,X2,R,14)
   10      CONTINUE
    7    CONTINUE
C
C
      HPOINT = 2*( IPZTRG + 1 )
      HZLENG = 2*( LEZTRG - 1 )
      IF( HZLENG.LE.256) GO TO 6251
      WRITE(6,6244)
6244  FORMAT(' >>>>> ZTRG BANK WITH > 256 HALF WORDS ....')
      GO TO 999
6251  CONTINUE
C
C  LOOP OVER THE RAW DATA AND DECODE
C
C    BIT 15:    > NMAX (=4)
C    BIT 14-11: CHANNEL (WIRE NR., 0-15)
C    BIT 10:    FIFO OVERFLOW
C    BIT 9-8:   HIT COUNTER, NRHIT - 1    (I.E. 0 MEANS 1 HIT)
C    BIT 7:     UNDERFLOW
C    BIT 6:     OVERFLOW
C    BIT 5-0:   Z VALUE, CODED
C
      IOLDWD = -1
      KANOLD = 99999
C
      DO 1130  I = 1,8
1130  HZBAD(I) = 0
C
      DO 1198 IHIT = 1,HZLENG
        HELP(2) = HDATA(HPOINT+IHIT)
C
C  768 = #300, BITS 8 AND 9. ACCEPT ONLY DATA WITH ONE HIT
C
        IF(LAND(IZWORD,768).EQ.0) GO TO 1201
C       WRITE(6,1202) IHIT
1202    FORMAT(' >>>>> WORD NR ',I3,' HAS MORE THAN 1 HIT..')
        HZBAD(1) = HZBAD(1) + 1
        GO TO 1200
C
C  TEST ON BIT NR 15, INDICATOR FOR > NMAX
C
1201    IF(.NOT.TBIT(IZWORD,16)) GO TO 1203
C       WRITE(6,1204) IHIT
1204    FORMAT(' >>>>> WORD NR ',I3,' HAS HIGH COUNT BIT SET..')
        HZBAD(2) = HZBAD(2) + 1
        GO TO 1200
C
C  CHANNEL NR, BITS 14-11
C  Z VALUE, BITS 5-0
C
1203    KANAL = LAND( SHFTR(IZWORD,11),15)
        IZWERT = LAND( IZWORD,63 )
        IF(LAND(IZWORD,64).EQ.0) GO TO 1205
C       WRITE(6,1206) IHIT
1206    FORMAT(' >>>>> WORD NR ',I3,' OVERFLOW FLAG SET..')
        HZBAD(3) = HZBAD(3) + 1
        GO TO 1200
1205    IF(LAND(IZWORD,128).EQ.0) GO TO 1207
C       WRITE(6,1208) IHIT
1208    FORMAT(' >>>>> WORD NR ',I3,' UNDERFLOW FLAG SET..')
        HZBAD(4) = HZBAD(4) + 1
        GO TO 1200
1207    IF(LAND(IZWORD,1024).EQ.0) GO TO 1209
C       WRITE(6,1210) IHIT
1210    FORMAT(' >>>>> WORD NR ',I3,' FIFO OVERFLOW FLAG SET..')
        HZBAD(5) = HZBAD(5) + 1
        GO TO 1200
1209    IF(KANAL.LT.KANOLD) GO TO 1211
C       WRITE(6,1212) IHIT
1212    FORMAT(' >>>>> WORD NR ',I3,' WITH NONDECREASING CHANNEL NR ')
        HZBAD(6) = HZBAD(6) + 1
        GO TO 1200
1211    IF(IOLDWD.NE.IZWORD) GO TO 1213
C       WRITE(6,1214) IHIT
1214    FORMAT(' >>>>> WORD NR ',I3,' WITH DATA IDENTICAL TO PREVIOUS')
        HZBAD(7) = HZBAD(7) + 1
        GO TO 1200
1213    IBADF = 0
C
C --  DISPLAY Z VALUE
C
1611  JW = 1
      IF(KANAL.GT.7) JW = 2
      KANAL1 = KANAL
      IF(KANAL1.GT.7) KANAL1 = KANAL1 - 8
      RADD = RINCR(JW)
      RVAL = FSENSW(JW)
      RVAL = RVAL + KANAL1*RADD*2.
      ZVAL = IZWERT*ZFACTO - ZMAX
C     WRITE(6,1671) IHIT,JW,KANAL,RADD,RVAL,FSENSW(JW),IZWERT
1671  FORMAT(' IH JW K RD RV FSW IZW ',3I4,3E12.4,I4)
      Z0 = 15.
      NZ = 3
      IF(IBADF.EQ.1) Z0 = 8.
      IF(IBADF.EQ.1) NZ = 6
      CALL PLYGON(NZ,Z0,ZVAL,RVAL,0)
C
      GO TO 1199
 1200 CONTINUE
      HZBAD(8) = HZBAD(8) + 1
      KANAL = LAND( SHFTR(IZWORD,11),15)
      IZWERT = LAND( IZWORD,63 )
      IBADF = 1
      GO TO 1611
1199  IOLDWD = IZWORD
      KANOLD = KANAL
1198  CONTINUE
C
      CALL CHRSIZ(4)
      CALL CSIZE(IX,IXT)
      SIZE = IXT*.8
      DEL = 1.7*SIZE
      XS = ZENDMI
      YS = RPIP + 5.
      CALL MOVEA(XS,YS)
      CALL SEELOC(IXT,IYT)
      XS = IXT
      YS = IYT
      IILIM = 50
      CALL CORE(HWORK,IILIM)
      WRITE(JUSCRN,9010) HZLENG,HZBAD(8)
 9010 FORMAT(' NR OF DATA WORDS:',I4,'   NR OF BAD DATA WORDS:',I4)
      CALL SYSSYM(XS,YS,SIZE,HWORK,IILIM,0.)
      YS = YS - DEL
      IILIM = 78
      CALL CORE(HWORK,IILIM)
      WRITE(JUSCRN,9070) (HZBAD(I),I=1,7)
 9070 FORMAT(' >1HIT:',I3,'  B15:',I3,'  OVFLW:',I3,'  UNFLW:',I3,
     $'  FIFLW:',I3,'  NONDECR.:',I3,'  IDENT.:',I3)
      CALL SYSSYM(XS,YS,SIZE,HWORK,IILIM,0.)
C
C   NOW PRINT DATA BELOW THE DETECTOR DISPLAY
C
      CALL MOVEA(XMIN,-70.)
      CALL SEELOC(IXT,IYT)
      XS = IXT
      YS = IYT
C                    WRITE HEADER
      IILIM = 50
      CALL CORE(HWORK,IILIM)
      WRITE(JUSCRN,9011)
 9011 FORMAT(' DATA  B15 CHANNEL FIFOF HITCN UFLOW OFLOW Z-VALUE')
      CALL SYSSYM(XS,YS,SIZE,HWORK,IILIM,0.)
      IPASSZ = 0
C
      DO 1300 IHIT = 1,HZLENG
        HELP(2) = HDATA(HPOINT+IHIT)
        KANAL = LAND( SHFTR(IZWORD,11),15)
        HITCN = LAND( SHFTR(IZWORD,8),3)
        IBIT15 = 0
        IF(TBIT(IZWORD,16)) IBIT15 = 1
        IZWERT = LAND( IZWORD,63 )
        IOVERF= 0
        IF(LAND(IZWORD,64).NE.0) IOVERF = 1
        IUNDEF= 0
        IF(LAND(IZWORD,128).NE.0) IUNDEF = 1
        IFIFOF= 0
        IF(LAND(IZWORD,1024).NE.0) IFIFOF = 1
9965    YS = YS - DEL
        IF(YS.GT.50.) GO TO 9012
C
C SWITCH COLUMN
C
        IF(IPASSZ.NE.0) GO TO 1301
        XS = XMIN + (XMAX-XMIN)*.5
        YS = -70.
        CALL MOVEA(XS,YS)
        CALL SEELOC(IXT,IYT)
        XS = IXT
        YS = IYT
        CALL MOVEA(XS,YS)
C                    WRITE HEADER
        IILIM = 50
        CALL CORE(HWORK,IILIM)
        WRITE(JUSCRN,9011)
        CALL SYSSYM(XS,YS,SIZE,HWORK,IILIM,0.)
        IPASSZ = 1
        GO TO 9965
C
9012    IILIM = 48
        CALL CORE(HWORK,IILIM)
        WRITE(JUSCRN,9013) IZWORD,IBIT15,KANAL,IFIFOF,HITCN,IUNDEF,
     $  IOVERF,IZWERT
 9013   FORMAT(' ',Z4,3X,I1,4X,I2,5X,I1,5X,I1,5X,I1,5X,I1,4X,I5)
        CALL SYSSYM(XS,YS,SIZE,HWORK,IILIM,0.)
 1300 CONTINUE
 1301 CONTINUE
C
C   DISPLAY Z-COORDINATES FROM SECTOR 7 IN JETC BANK
C
      IPJ = IDATA(IBLN('JETC'))
      IF(IPJ.GT.0) GO TO 2461
      WRITE(6,2462)
2462  FORMAT('  NO JETC BANK...')
      GO TO 999
2461  NWO = (HDATA(2*IPJ+99)-HDATA(2*IPJ+3)+100)/2
      IF(NWO.GT.2) GO TO 2463
      WRITE(6,2464)
2464  FORMAT('  NO DATA IN JETC BANK...')
      GO TO 999
2463  IPJH = 2*IPJ
      NI = IPJH + 101
   93 CONTINUE
C     LOOP OVER WIRES
      NIW = HDATA(NI)
      NIW = SHFTR(NIW,3) + 1
      IF(NIW.GT.1536.OR.NIW.LE.0) GO TO 9191
      INCL = SHFTR(NIW-1,4) + 1
C                     CELLS IN SECTOR 7:   7,31,61,62
      IF(INCL.EQ.7.OR.INCL.EQ.31) GO TO 2354
      IF(INCL.EQ.61.OR.INCL.EQ.62) GO TO 2354
      GO TO 9191
2354  NRING = (NIW-1)/384 + 1
      IF(NRING.GT.3) NRING = 3
      RADD = RINCR(NRING)
      R = FSENSW(NRING) - RADD
      NEW = NIW - (NRING-1)*384
      NCE = SHFTR(NEW-1,4)
      NWE = NEW - NCE*16
      R = R + NWE*RADD
      NI = NI + 1
C  GET Z-COORDINATE
      IA1 = HDATA(NI)
      NI = NI + 1
      IA2 = HDATA(NI)
      IF(IA1+IA2.GT.0) GO TO 1013
      ZET = 0.
      GO TO 1014
1013  ZET = ZAL*.5*(IA2 - IA1)/(IA1+IA2)
1014  NI = NI + 2
C DISPLAY HIT
      CALL MOVEA(ZET-RZ, R)
      CALL DRAWA(ZET+RZ, R)
      CALL MOVEA(ZET,R-RZ)
      CALL DRAWA(ZET,R+RZ)
C
      GO TO 9333
9191  NI = NI + 4
 9333 IF(NI.LE.(IPJH + 2*NWO)) GO TO 93
      GO TO 999
C
C   NEW DATA (1986)
C
5000  CALL ERASE
      CALL TWINDO(0,4095,0,4095)
      XMINRE = XMIN
      XMAXRE = XMAX
      YMINRE = YMIN
      YMAXRE = YMAX
      XMIN=-1800.
      XMAX= 1500.
      YMIN=-1300.
      YMAX = YMIN + XMAX - XMIN
      CALL DWINDO(XMIN,XMAX,YMIN,YMAX)
C
C  DRAW INNER DETECTOR:
C
C                            FIRST DRAW BOX
C
  20  CALL DRAMOV(ZTKM, RITNK,ZTKM, ROTNK,0)
      CALL DRAWA( ZTKP, ROTNK)
      CALL DRAWA( ZTKP, RITNK)
      CALL DRAWA( ZTKM, RITNK)
      CALL DRAMOV(ZTKM,-RITNK,ZTKM,-ROTNK,0)
      CALL DRAWA( ZTKP,-ROTNK)
      CALL DRAWA( ZTKP,-RITNK)
      CALL DRAWA( ZTKM,-RITNK)
C--                                      DRAW NOW BEAM PIPE/VTX-CHAMB
      VTXCHR = .TRUE.
      CALL DRAWBP( 2 , VTXCHR )
      CALL DRAWVC( 2 )
C--                               MARK THE BEAM AND AXIS DIRECTION
      CALL MOVEA(-40.,  0.)
      CALL DRAWA( 40.,  0.)
      CALL MOVEA(  0.,-40.)
      CALL DRAWA(  0., 40.)
      CALL MOVEA(   0.,   0.)
      SIGN=1.
      CALL DRAWA((SIGN* 80.),   0.)
      CALL DRAWA((SIGN* 80.),  20.)
      CALL DRAWA((SIGN*100.),   0.)
      CALL DRAWA((SIGN* 80.), -20.)
      CALL DRAWA((SIGN* 80.),   0.)
C--                               DRAW WIRES OF INNER DETECTOR
      X1 = -ZMAX + ZOFFS
      X2 = ZMAX + ZOFFS
         DO 107 J = 1,3
         RADD = RINCR(J)
         R = FSENSW(J) - 2.*RADD
         NWE = NWIRES(J)
         IF(J.EQ.3) GO TO 109
           DO 108 K = 1,NWE,2
           R = R + 2.*RADD
           CALL DRAMOV(X1,R,X2,R,14)
           CALL DRAMOV(X1,-R,X2,-R,14)
  108      CONTINUE
         GO TO 107
  109    R = R + 2.*RADD
           DO 110 K = 1,2
           R = R + (K-1)*RADD*(NWE-1)
           CALL DRAMOV(X1,R,X2,R,14)
           CALL DRAMOV(X1,-R,X2,-R,14)
 110      CONTINUE
  107    CONTINUE
C
      HZLENG = HDATA(IPZTRG+3)
      IPZTRG = IPZTRG + 3
C
C  LOOP OVER THE DATA, DECODE AND DISPLAY
C
C
C    BIT 15:    ADRESS BIT, IF ON ADRESS WORD
C
C  DATA WORD FORMAT:
C
C    BIT 5-0:   Z VALUE, CODED
C    BIT   6:   OVERFLOW INDICATOR
C    BIT   7:   LOWER LEVEL INDICATOR
C    BIT   8:   UPPER LEVEL INDICATOR
C    BIT   9:   FIFO OUTPUT READY, MEANING NOT CLEAR, IGNORE...
C
C  ADRESS WORD FORMAT:
C
C    BIT 0-1:   SUBADRESS (0-3)
C    BIT 2-6:   CARD, SLOT ADRESS (0-19)
C    BIT 7-9:   CRATE ADRESS  (0-2)
C
      NZHIT = 0
C
      DO 1500 IHIT = 1,HZLENG
C
        HELP(2) = HDATA(IPZTRG+IHIT)
C
        IF(HELP(2).LT.0) GO TO 2500
C
C DATA WORD, STORE Z-VALUE IN ARRAY FOR LATER DISPLAY WHEN WIRE KNOWN
C
        NZHIT = NZHIT + 1
        IF(NZHIT.LE.16) GO TO 2001
        WRITE(6,1499)
1499  FORMAT('  ERROR**   MORE THAN 16 HITS ON WIRE ')
        GO TO 1500
2001    HZSTOR(NZHIT) = LAND(MASKZ,IZWORD)
        GO TO 1500
C
C ADRESS WORD, DECODE AND DISPLAY IF HITS HAD BEEN FOUND
C
2500  IF(NZHIT.LE.0) GO TO 1500
C
C NOTE THAT FOR BANK DESCRIPTOR 2, MANY EMPTY WIRES OCCUR, DUE TO
C LOGICAL ERROR IN INTERFACE.
C
      ISUBA = LAND(MSKSUB,IZWORD)
      ISLOZ = LAND(MSKSLO,IZWORD)
      ISLOZ = SHFTR(ISLOZ,2)
      ICRAZ = LAND(MSKCRA,IZWORD)
      ICRAZ = SHFTR(ICRAZ,7)
C
      NWIRE = IWCARD(ICRAZ,ISLOZ,ISUBA)
      IF(NWIRE.LT.0) GO TO 2600
      NIW = NWIRE + 1
C
C THERE ARE NZHIT HITS ON WIRE NWIRE, DISPLAY
C
      NRING = (NIW-1)/384 + 1
      IF(NRING.GT.3) NRING = 3
      RADD = RINCR(NRING)
      NCL = NCELL(NRING)
      R = FSENSW(NRING) - RADD
      NEW = NIW - (NRING-1)*384
      NCE = SHFTR(NEW-1,4)
      NWE = NEW - NCE*16
      R = R + NWE*RADD
C                         POSITIVE OR NEGATIVE R ?, ASSUMING ZY-VIEW
      IF(NIW.GE.193.AND.NIW.LE.384) R = -R
      IF(NIW.GE.577.AND.NIW.LE.768) R = -R
C
      DO 2510  I = 1,NZHIT
C     ZVAL = HZSTOR(I)*ZFACTO - ZMAX
      ZVAL = ZMAX - HZSTOR(I)*ZFACTO
      Z0 = 15.
      NZ = 3
      CALL PLYGON(NZ,Z0,ZVAL,R,0)
2510  CONTINUE
C
2600  NZHIT = 0
C
1500  CONTINUE
C
C   DISPLAY NORMAL ZY-VIEW OF INNER DETECTOR HITS
C
      IPJ = IDATA(IBLN('JETC'))
      IF(IPJ.GT.0) GO TO 2761
      WRITE(6,2462)
      GO TO 999
C
2761  NWO = (HDATA(2*IPJ+99)-HDATA(2*IPJ+3)+100)/2
      IF(NWO.GT.2) GO TO 2763
      WRITE(6,2464)
      GO TO 999
C
2763  IPJH = 2*IPJ
      NI = IPJH + 101
 2793 CONTINUE
C     LOOP OVER WIRES
      NIW = HDATA(NI)
      NIW = SHFTR(NIW,3) + 1
      IF(NIW.GT.1536.OR.NIW.LE.0) GO TO 2791
      INCL = SHFTR(NIW-1,4) + 1
      NRING = (NIW-1)/384 + 1
      IF(NRING.GT.3) NRING = 3
      RADD = RINCR(NRING)
      R = FSENSW(NRING) - RADD
      NEW = NIW - (NRING-1)*384
      NCE = SHFTR(NEW-1,4)
      NWE = NEW - NCE*16
      R = R + NWE*RADD
      IF(NIW.GE.193.AND.NIW.LE.384) R = -R
      IF(NIW.GE.577.AND.NIW.LE.768) R = -R
      IF(NIW.GE.1153.AND.NIW.LE.1536) R = -R
      NI = NI + 1
C  GET Z-COORDINATE
      IA1 = HDATA(NI)
      NI = NI + 1
      IA2 = HDATA(NI)
      IF(IA1+IA2.GT.0) GO TO 2713
      ZET = 0.
      GO TO 2714
2713  ZET = ZAL*.5*(IA2 - IA1)/(IA1+IA2)
2714  NI = NI + 2
C DISPLAY HIT
      CALL MOVEA(ZET-RZ, R)
      CALL DRAWA(ZET+RZ, R)
      CALL MOVEA(ZET,R-RZ)
      CALL DRAWA(ZET,R+RZ)
C
      GO TO 2733
2791  NI = NI + 4
 2733 IF(NI.LE.(IPJH + 2*NWO)) GO TO 2793
C***
C***                    WRITE CAPTION
C***
999   INDES = -4
      CALL CAPMRK(INDES,IESUM)
      CALL TWINDO(0,4095,0,4095)
      XMIN = XMINRE
      XMAX = XMAXRE
      YMIN = YMINRE
      YMAX = YMAXRE
      CALL SETSCL(LASTVW)
9999  RETURN
      END
      FUNCTION IWCARD(IC,ISLOT,ISUBA)
C
C RETURNS WIRE NUMBER CORRESPONDING TO CRATE,SLOT AND SUBADRESS IN
C  Z-TRIGGER HARDWARE
C
      IMPLICIT INTEGER*2 (H)
C
      DIMENSION HOFSET(48)
C
      DATA HOFSET /  48,  56, 432, 440,  64,  72, 448, 456,  80,  88,
     $              464, 472,  96, 104, 480, 488, 112, 120, 496, 504,
     $              128, 136, 512, 520,
     $              240, 248, 624, 632, 256, 264, 640, 648, 272, 280,
     $              656, 664, 288, 296, 672, 680, 304, 312, 688, 696,
     $              320, 328, 704, 712/
C
C  TEST INPUT VALUES
C
      NN = IC*20 + ISLOT + 1
      IF(NN.GE.1.AND.NN.LE.48.AND.ISUBA.GE.0.AND.ISUBA.LE.3) GO TO 1
      WRITE(6,1000) IC,ISLOT,ISUBA
1000  FORMAT(' WICARD ERROR: CRATE,SLOT,SUBADR. ',3I8)
      IWCARD = -100
      GO TO 999
C
C CORRESPONDING WIRE NUMBER, FOR CORRECT INPUT DATA
C
1     IWCARD = HOFSET(NN) + ISUBA * 2
999   CONTINUE
      RETURN
      END
