*
* $Id: reorsl.F,v 1.1.1.1 1996/01/11 14:14:42 mclareni Exp $
*
* $Log: reorsl.F,v $
* Revision 1.1.1.1  1996/01/11 14:14:42  mclareni
* Cojets
*
*
#include "cojets/pilot.h"
      SUBROUTINE REORSL(LDEC,IFLAG)
C     *****************************
C-- REORDERS DECAY MODE ENTRIES IN SEMILEPTONIC DECAYS, AS READ FROM
C-- TABLE, ACCORDING TO THE CONVENTION:
C-- IF A QUARK/LEPTON DECAYS (NOT THE "ANTI"), THE 1ST DECAY ENTRY MUST
C-- BE A QUARK/LEPTON (NOT THE "ANTI"). (IF AN "ANTI" DECAYS, 1ST ENTRY
C-- MUST BE AN "ANTI").
C-- CREATED: 88/05/03.
#if defined(CERNLIB_SINGLE)
      IMPLICIT REAL (A-H,O-Z)
#endif
#if defined(CERNLIB_DOUBLE)
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
#endif
#include "cojets/itapes.inc"
      DIMENSION LDEC(6)
      LOGICAL COND
C-- REORDER LEPTONS IN SEMILEPTONIC DECAYS
      DO 1 L=1,2
      LDA=ABS(LDEC(L))
1     IF(LDA.GT.16.OR.LDA.LT.11) GO TO 10
      IF(LDEC(3).EQ.0) GO TO 10
C-- IT IS A SL DECAY
      ID=LDEC(6)
      IDABS=ABS(ID)
      IP=ID
      IF(IDABS.GT.100.AND.IDABS.LT.1000) IP=-IP
      IF(IP*LDEC(1).LT.0) THEN
        L1=LDEC(2)
        LDEC(2)=LDEC(1)
        LDEC(1)=L1
      ENDIF
C-- REORDER QUARKS AND DIQUARKS
10    CONTINUE
      NQ=0
      NBAL=0
      NTOT=0
      DO 11 IL=1,5
      IF(LDEC(IL).EQ.0) GO TO 11
      NTOT=NTOT+1
      IF(ABS(LDEC(IL)).GT.6.AND.MOD(LDEC(IL),100).NE.0) GO TO 11
      NQ=NQ+1
      IF((LDEC(IL).GT.0.AND.LDEC(IL).LE.6).OR.
     *(LDEC(IL).LT.0.AND.ABS(LDEC(IL)).GT.6)) THEN
        NBAL=NBAL+1
      ELSE
        NBAL=NBAL-1
      ENDIF
11    CONTINUE
      IF(NQ.EQ.0) RETURN
      NP=NTOT-NQ
      IFLD=MOD(ABS(LDEC(6)),100)
      IF(IFLD.NE.60.AND.NQ.NE.2.AND.NQ.NE.4) GO TO 500
      IF(IFLD.NE.60.AND.NBAL.NE.0) GO TO 500
      IF(IFLD.EQ.60.AND.NQ.NE.1.AND.NQ.NE.3) GO TO 500
      IF(IFLD.EQ.60.AND.ABS(NBAL).NE.1) GO TO 500
      IF(IFLD.EQ.60) RETURN
C-- GO AHEAD WITH REORDERING
C-- 1ST PUT PARTICLES BEFORE QUARK/DIQUARKS
      IF(NP.EQ.0) GO TO 30
      DO 22 LQ=1,NP
      DO 23 IL=LQ,NTOT
      LDC=LDEC(IL)
      COND=ABS(LDC).GE.10.AND.MOD(ABS(LDC),100).NE.0
      IF(COND) THEN
        IF(IL.EQ.LQ) GO TO 22
        LDR=LDEC(LQ)
        LDEC(LQ)=LDEC(IL)
        LDEC(IL)=LDR
        GO TO 22
      ENDIF
23    CONTINUE
22    CONTINUE
C-- 2ND QUARK/DIQUARKS AMONG THEMSELVES
30    ITX=NQ-1
      DO 12 LQ=1,ITX
      ILQ=LQ+NP
      DO 13 IL=ILQ,NTOT
      LDC=LDEC(IL)
      COND=ABS(LDC).LE.6.AND.LDC.GT.0.OR.ABS(LDC).GT.6.AND.LDC.LT.0
      IF((-1)**LQ.GT.0) COND=.NOT.COND
      IF(COND) THEN
        IF(IL.EQ.ILQ) GO TO 12
        LDR=LDEC(ILQ)
        LDEC(ILQ)=LDEC(IL)
        LDEC(IL)=LDR
        GO TO 12
      ENDIF
13    CONTINUE
12    CONTINUE
      RETURN
C-- ABNORMAL EXIT
500   IFLAG=IFLAG+10
      IF(IFLAG.EQ.10) WRITE(ITLIS,501) LDEC(6),(LDEC(IL),IL=1,5)
501   FORMAT(/' $$$BAD QUARK/DIQUARK INPUT IN DECAY TABLE ENTRY'
     */1X,6I10)
      RETURN
      END
