C   01/11/84            MEMBER NAME  HITDSP   (S)           FORTRAN
C
C-----------------------------------------------------------------------
      SUBROUTINE HITDSP(IKTRAR,LISTLB,MIRROR,LBSYM,TRHIT,TLHT,JNDEX,
     *                  REMEMB,REMB1,IQQ)
C-----------------------------------------------------------------------
C
C    AUTHOR:   J. OLSSON     10/10/79 :  HIT DISPLAY IN EDITING PROGRAM
C
C       MOD:   J. OLSSON     12/10/79 :  CHANGED TO NEW FORMATS FORHIT
C                                        LABEL ARRAY AND MIDOUT
C                                        HRES ARRAY NOT NEEDED ANYMORE
C  LAST MOD:   J. HAGEMANN   09/10/84 :  NEW HITMRK USED
C
C      IKTRAR      :    NUMBER OF TRACKS IN ARRAY HKTRAR   (ALWAYS NE.0)
C      LISTLB = 0  :    DISPLAY ONLY TRACKS IN LIST
C      LISTLB = 1  :    DISPLAY ONLY ANTILIST HITS
C      MIRROR = 0  :    LEFT/RIGHT AMBIGUITY RESOLVED IN DISPLAY
C      MIRROR = 1  :    LEFT/RIGHT AMBIGUITY NOT RESOLVED IN DISPLAY
C      LBSYM  = 0  :    DEFAULT SYMBOL IN DISPLAY  (DSPDTL(6))
C      LBSYM  = 1  :    NON-DEFAULT SYMBOL IN DISPLAY(.NOT.DSPDTL(6))
C      IQQ         :    PRINT VARIABLE FOR DEBUGGING
C
C-----------------------------------------------------------------------
C
      IMPLICIT INTEGER*2 (H)
C
      LOGICAL REMEMB,REMB1,TRHIT,TLHT,TBIT
C
#include "cgraph.for"
#include "cdata.for"
#include "cworkpr.for"
#include "cworkeq.for"
C
      COMMON /CWORK1/ R,FI,R1,FI1,X1,Y1,R2,FI2,X2,Y2,ZET,X3,Y3,X4,Y4
     +               ,KZAMP,HWORK(400),XLTR(200),YLTR(200),XLST(100)
     +               ,YLST(100),HKTRAR(100)
C
      COMMON /CJTRIG/ PI,TWOPI
C
      DIMENSION HELP1(2),HELP2(2)
      EQUIVALENCE (LABL1,HELP1(1)),(LABL2,HELP2(1))
C
C                            MASKS FOR TRACK NO. IN HIT LABEL
      DATA MSKTR1/ZFE/, HELP1/0,0/, HELP2/0,0/
C
C-----------------  C O D E  -------------------------------------------
C
      IPJCA=IDATA(IBLN('JETC'))
      IPJ = 2*IPJCA + 2
      NHITS = (HDATA(IPJ+97)-HDATA(IPJ+1))/4
      NWO = 4*NHITS + 98
      NTRCL1 = HNTCEL(25) - 1
      NTRCL2 = HNTCEL(49) - 1
      NRHIT1 = (HDATA(IPJ+25)-HDATA(IPJ+1))/4
      NRHIT2 = (HDATA(IPJ+49)-HDATA(IPJ+1))/4
      IAMB = 0
C---
      DO 8765  II = 1,200
      XLTR(II) = 0.
8765  YLTR(II) = 0.
      DO 8565  II = 1,100
      XLST(II) = 0.
8565  YLST(II) = 0.
C---
222   NI = IPJ + 95
      IHIT = 0
      HIHIT = -1
      MICKY = 0
      IAMB = IAMB + 1
      IF(IQQ.NE.0) WRITE(6,101) IKTRAR,(HKTRAR(IKT),IKT=1,IKTRAR)
101   FORMAT(' IKTRAR AND ARRAY ',10I5)
      IF(IQQ.NE.0) WRITE(6,102) LISTLB,MIRROR,LBSYM,TRHIT,TLHT,JNDEX
102   FORMAT(' LISTLB ETC ',10I5)
824   NI = NI + 4
8566  IHIT = IHIT + 1
      HIHIT = HIHIT + 2
      IHIT1 = HIHIT
      IHIT2 = IHIT1+1
      IF(IHIT.GT.NRHIT1) MICKY = NTRCL1
      IF(IHIT.GT.NRHIT2) MICKY = NTRCL2
      IF(IHIT.GT.NHITS) GO TO 2255
      HELP1(2) = HWRK(IHIT1+HPHL0-1)
      HELP2(2) = HWRK(IHIT2+HPHL0-1)
      IF(IHIT.LT.50.AND.IQQ.NE.0) WRITE(6,103) IHIT,MICKY,HELP1(2),HELP200008500
     $(2)
103   FORMAT(' IHIT MICKY LABL1 LABL2 ',2I5,Z16,1X,Z16)
      IKFLAG = 0
      ISGN = 0
      IDL = 0
      MTR = 0
      NZWIR = 30
CHECK NOW IF HIT BELONGS TO TRACK OR NOT
8823  IF(IAMB.EQ.2) GO TO 8822
      ITREL = LAND(LABL1,MSKTR1)
      ITREL = ISHFTR(ITREL,1)
      IF(IHIT.LT.50.AND.IQQ.NE.0) WRITE(6,104) IHIT,ITREL
104   FORMAT(' IHIT ITREL ',2I5)
      IF(ITREL.NE.0) GO TO 8564
      IF(LISTLB.EQ.0) GO TO 824
      GO TO 823
8822  ITREL = LAND(LABL2,MSKTR1)
      ITREL = ISHFTR(ITREL,1)
      IF(ITREL.EQ.0) GO TO 824
8564  ITREL = ITREL + MICKY
      LABZ = LBL(ITREL)
      IF(.NOT.TBIT(LABZ,23)) GO TO 8563
      NZWIR = ICRO(ITREL)
8563  CALL TRELTR(ITREL,MTR,MTR2)
      IF(MTR.LT.0) ISGN = -1
      IF(MTR.GT.0) ISGN = 1
      IF(IHIT.LT.50.AND.IQQ.NE.0) WRITE(6,105) IHIT,ITREL,MTR,NZWIR,ISGN
105   FORMAT(' IHIT ITREL MTR NZWIR SIGN ',5I5)
      MTR = IABS(MTR)
      DO 8255  IKT = 1,IKTRAR
8255  IF(HKTRAR(IKT).EQ.MTR) IKFLAG = 1
      IF(IHIT.LT.50.AND.IQQ.NE.0) WRITE(6,105) IHIT,IKFLAG
106   FORMAT(' IHIT IKFLAG ',2I5)
      IF(IKFLAG.EQ.0.AND.LISTLB.EQ.0) GO TO 824
      IF(IKFLAG.NE.0.AND.LISTLB.EQ.1) GO TO 824
      IF(IKFLAG.EQ.0) ISGN = 0
C823   IF(IKFLAG.EQ.0.AND.ISTANV.GT.3.AND.ISTANV.LT.14) GO TO 824
C  DISPLAY
823   IVVX = 0
      IF(ISTANV.GT.3.AND.ISTANV.LT.14) IVVX = 1
      IF(IVVX.EQ.1.AND.DSPDTL(9)) DSPDTL(10) = .TRUE.
      IF(ISTANV.EQ.14) IVVX = 2
      KZAMP = 0
      CALL FICOOR(IVVX,NI,NWE)
      IF(NWE.LT.-500) GO TO 225
      IF(NWE.GE.NZWIR.AND.NZWIR.GE.0) ISGN = - ISGN
      IF(LBSYM.EQ.1) DSPDTL(6)=.NOT.REMEMB
      IF(ISTANV.LT.4.OR.ISTANV.GT.12) GO TO 7539
C *****************************
C ZX AND ZY DISPLAYS ---------*
C *****************************
      IF(DSPDTL(9)) GO TO 3425
C-- TRUE PROJECTIONS -------
      IF(ISGN.LT.0.AND.MIRROR.EQ.0) GO TO 3421
      YPRO= X1
      IF(LASTVW.GT.7) YPRO = Y1
      IF(TRHIT.AND.MTR.NE.0) CALL TRNUMB(MTR,3,-ZET,YPRO,DM)
      IF(TLHT.AND.ITREL.NE.0) CALL TRNUMB(ITREL,3,-ZET,YPRO,DM)
      IF(.NOT.TRHIT.AND..NOT.TLHT)
     $ CALL HITMRK( JNDEX, ZET, YPRO, 4.0, 0 )
      IF(MIRROR.EQ.0) GO TO 3422
3421  YPRO = X2
      IF(LASTVW.GT.7) YPRO = Y2
      IF(TRHIT.AND.MTR.NE.0) CALL TRNUMB(MTR,3,-ZET,YPRO,DM)
      IF(TLHT.AND.ITREL.NE.0) CALL TRNUMB(ITREL,3,-ZET,YPRO,DM)
      IF(.NOT.TRHIT.AND..NOT.TLHT)
     $ CALL HITMRK( JNDEX, ZET, YPRO, 4.0, 0 )
3422  IF(MTR.EQ.0.OR.IKFLAG.EQ.0) GO TO 805
3427  XLST(MTR) = - ZET
      YLST(MTR) = YPRO
      GO TO 805
C-- WRAPPED PROJECTIONS ---------
3425  IF(ISGN.LT.0.AND.MIRROR.EQ.0) GO TO 3426
      YPRO = R1
      IF(TRHIT.AND.MTR.NE.0) CALL TRNUMB(MTR,3,-ZET,YPRO,DM)
      IF(TLHT.AND.ITREL.NE.0) CALL TRNUMB(ITREL,3,-ZET,YPRO,DM)
      IF(.NOT.TRHIT.AND..NOT.TLHT)
     $ CALL HITMRK( JNDEX, ZET, YPRO, 4.0, 0 )
      IF(MTR.EQ.0) GO TO 3426
      IF(MIRROR.EQ.0) GO TO 3422
3426  YPRO = R2
      IF(TRHIT.AND.MTR.NE.0) CALL TRNUMB(MTR,3,-ZET,YPRO,DM)
      IF(TLHT.AND.ITREL.NE.0) CALL TRNUMB(ITREL,3,-ZET,YPRO,DM)
      IF(.NOT.TRHIT.AND..NOT.TLHT)
     $ CALL HITMRK( JNDEX, ZET, YPRO, 4.0, 0 )
      GO TO 3422
C *****************************
C        RFI DISPLAYS  -------*
C *****************************
7539  IF(MTR.EQ.0.OR.IKFLAG.EQ.0) GO TO 1001
      IF(ISGN.LT.0.AND.MIRROR.EQ.0) GO TO 804
      IF(IKFLAG.EQ.0) GO TO 1001
      XLST(MTR) = X1
      YLST(MTR) = Y1
      XLTR(ITREL) = X1
      YLTR(ITREL) = Y1
      IF(TRHIT) CALL TRNUMB(MTR,3,X1,Y1,DM)
      IF(TLHT) CALL TRNUMB(ITREL,3,X1,Y1,DM)
1001  IF(.NOT.TRHIT.AND..NOT.TLHT)
     $ CALL HITMRK( ISTANV, -X1, Y1, 4.0, 0 )
      IF(ISGN.GT.0.AND.MIRROR.EQ.0) GO TO 805
804   IF(MTR.EQ.0.OR.IKFLAG.EQ.0) GO TO 1011
      XLST(MTR) = X2
      YLST(MTR) = Y2
      XLTR(ITREL) = X2
      YLTR(ITREL) = Y2
      IF(TRHIT) CALL TRNUMB(MTR,3,X2,Y2,DM)
      IF(TLHT) CALL TRNUMB(ITREL,3,X2,Y2,DM)
1011  IF(.NOT.TRHIT.AND..NOT.TLHT)
     $ CALL HITMRK( ISTANV, -X2, Y2, 4.0, 0 )
  805 DSPDTL(6) = REMEMB
      DSPDTL(10) = REMB1
      IF(NI.LE.(IPJ+NWO)) GO TO 8566
C-- WRITE TRACK NUMBER AT POSITION OF LAST HIT
2255  IF(LISTLB.EQ.1) GO TO 225
      IF(IAMB.EQ.1) GO TO 222
      IF(TRHIT) GO TO 8056
      DO 2344  II = 1,NTR
      IF(ABS(XLST(II)).LT..1.AND.ABS(YLST(II)).LT..1) GO TO 2344
      CALL TRNUMB(II,0,XLST(II),YLST(II),DM)
2344  CONTINUE
C** WRITE OUT TRACK ELEMENT NUMBERS ON SCREEN
8056  IF(TLHT) GO TO 225
      DO 5876  II = 1,HNTR
      IF(ABS(XLTR(II)).LT..1.AND.ABS(YLTR(II)).LT..1) GO TO 5876
      CALL TRNUMB(II,1,XLTR(II),YLTR(II),DM)
5876  CONTINUE
225   RETURN
      END
