C   04/07/79 202081534  MEMBER NAME  MUFFLM   (JADEMUS)     FORTRAN
C LAST CHANGE 15.40 08/02/82 HUGH MCCANN  ---- WARNING RE NEW NTPH.
C      CHANGE 10.51 04/07/79 JOHN ALLISON.
      SUBROUTINE MUFFLM(NTRKS,HC,NHITS,NWHIT,IMUR,HMUR,NWMUR,HTC,NTPH)
C
      IMPLICIT INTEGER*2 (H)
C
      DIMENSION HC(1),IMUR(1),HMUR(1),HTC(1)
C
C-----------------------------------------------------------------------
C
C NTRKS IS NUMBER OF TRACKS.
C HC CONTAINS MUON HIT COORDINATES.
C NHITS IS THE NUMBER OF MUON HITS.
C NWHIT IS THE NUMBER OF WORDS PER HIT IN HC.
C IMUR,HMUR IS MU-RESULTS 'MUR2' BANK 1.
C NWMUR IS NUMBER OF WORDS PER INNER DETECTOR TRACK IN 'MUR2' BANK 1.
C HTC IS HIT-TRACK CORRELLATION ARRAY.
C NTPH IS NUMBER OF TRACKS PER HIT ALLOCATED IN HTC.
C
C-----------------------------------------------------------------------
C
C SORTS OUT RESULTS OF TRACKING FOR SUMMARY RESULTS IN MUR2 BANK 1.
C
C-----------------------------------------------------------------------
C LOOK THROUGH HIT ASSOCIATION ARRAY HTC. ------------------------------
C-----------------------------------------------------------------------
C
      IP=0
      J=0
      DO 2000 IHIT=1,NHITS
      DO 3000 JENTRY=2,NTPH
      JTRK=HTC(J+JENTRY)
      IF(JTRK.EQ.0)GO TO 3002
C
C AMBIGUITY FOUND. FILL AMBIGUITY TABLES FOR TRACK KTRK.
      DO 4000 KENTRY=1,NTPH
      KTRK=HTC(J+KENTRY)
      IF(KTRK.EQ.0)GO TO 4001
      KTRK=IABS(KTRK)
C
      DO 5000 LENTRY=1,NTPH
      IF(LENTRY.EQ.KENTRY)GO TO 5000
      LTRK=HTC(J+LENTRY)
      IF(LTRK.EQ.0)GO TO 5001
      LTRK=IABS(LTRK)
      IPMU2=2*NWMUR*(KTRK-1)
      ILAYER=HC(IP+2)/10
      IF(ILAYER.GT.1)GO TO 5002
      K=HMUR(IPMU2+13)+1
      HMUR(IPMU2+13)=K
CCCCCCCC  N.B. LIMIT=3 , OLD VALUE OF NTPH. DO NOT INCREASE TO 4.
      IF(K.GT.3)GO TO 5000
      HMUR(IPMU2+K+13)=LTRK
      GO TO 5000
 5002 CONTINUE
      K=HMUR(IPMU2+17)+1
      HMUR(IPMU2+17)=K
CCCCCCCC  N.B. LIMIT=3 , OLD VALUE OF NTPH. DO NOT INCREASE TO 4.
      IF(K.GT.3)GO TO 5000
      HMUR(IPMU2+K+17)=LTRK
 5000 CONTINUE
 5001 CONTINUE
C
 4000 CONTINUE
 4001 CONTINUE
C
 3000 CONTINUE
 3002 CONTINUE
      J=J+NTPH
      IP=IP+NWHIT
 2000 CONTINUE
C
C-----------------------------------------------------------------------
C END OF MAIN LOOP OVER HTC. -------------------------------------------
C-----------------------------------------------------------------------
C
 99   CONTINUE
      RETURN
      END
