      SUBROUTINE KENDL1(DATA1,DATA2,N,TAU,Z,PROB)
      DIMENSION DATA1(N),DATA2(N)
      N1=0
      N2=0
      IS=0
      DO 12 J=1,N-1
        DO 11 K=J+1,N
          A1=DATA1(J)-DATA1(K)
          A2=DATA2(J)-DATA2(K)
          AA=A1*A2
          IF(AA.NE.0.)THEN
            N1=N1+1
            N2=N2+1
            IF(AA.GT.0.)THEN
              IS=IS+1
            ELSE
              IS=IS-1
            ENDIF
          ELSE
            IF(A1.NE.0.)N1=N1+1
            IF(A2.NE.0.)N2=N2+1
          ENDIF
11      CONTINUE
12    CONTINUE
      TAU=FLOAT(IS)/SQRT(FLOAT(N1)*FLOAT(N2))
      VAR=(4.*N+10.)/(9.*N*(N-1.))
      Z=TAU/SQRT(VAR)
      PROB=ERFCC(ABS(Z)/1.4142136)
      RETURN
      END
      SUBROUTINE KENDL2(TAB,I,J,IP,JP,TAU,Z,PROB)
      DIMENSION TAB(IP,JP)
      EN1=0.
      EN2=0.
      S=0.
      NN=I*J
      POINTS=TAB(I,J)
      DO 12 K=0,NN-2
        KI=K/J
        KJ=K-J*KI
        POINTS=POINTS+TAB(KI+1,KJ+1)
        DO 11 L=K+1,NN-1
          LI=L/J
          LJ=L-J*LI
          M1=LI-KI
          M2=LJ-KJ
          MM=M1*M2
          PAIRS=TAB(KI+1,KJ+1)*TAB(LI+1,LJ+1)
          IF(MM.NE.0)THEN
            EN1=EN1+PAIRS
            EN2=EN2+PAIRS
            IF(MM.GT.0)THEN
              S=S+PAIRS
            ELSE
              S=S-PAIRS
            ENDIF
          ELSE
            IF(M1.NE.0)EN1=EN1+PAIRS
            IF(M2.NE.0)EN2=EN2+PAIRS
          ENDIF
11      CONTINUE
12    CONTINUE
      TAU=S/SQRT(EN1*EN2)
      VAR=(4.*POINTS+10.)/(9.*POINTS*(POINTS-1.))
      Z=TAU/SQRT(VAR)
      PROB=ERFCC(ABS(Z)/1.4142136)
      RETURN
      END
      SUBROUTINE KSONE(DATA,N,FUNC,D,PROB)
      DIMENSION DATA(N)
      CALL SORT(N,DATA)
      EN=N
      D=0.
      FO=0.
      DO 11 J=1,N
        FN=J/EN
        FF=FUNC(DATA(J))
        DT=AMAX1(ABS(FO-FF),ABS(FN-FF))
        IF(DT.GT.D)D=DT
        FO=FN
11    CONTINUE
      PROB=PROBKS(SQRT(EN)*D)
      RETURN
      END
      SUBROUTINE KSTWO(DATA1,N1,DATA2,N2,D,PROB)
      DIMENSION DATA1(N1),DATA2(N2)
      CALL SORT(N1,DATA1)
      CALL SORT(N2,DATA2)
      EN1=N1
      EN2=N2
      J1=1
      J2=1
      FO1=0.
      FO2=0.
      D=0.
1     IF(J1.LE.N1.AND.J2.LE.N2)THEN
        IF(DATA1(J1).LT.DATA2(J2))THEN
          FN1=J1/EN1
          DT=AMAX1(ABS(FN1-FO2),ABS(FO1-FO2))
          IF(DT.GT.D)D=DT
          FO1=FN1
          J1=J1+1
        ELSE
          FN2=J2/EN2
          DT=AMAX1(ABS(FN2-FO1),ABS(FO2-FO1))
          IF(DT.GT.D)D=DT
          FO2=FN2
          J2=J2+1
        ENDIF
      GO TO 1
      ENDIF
      PROB=PROBKS(SQRT(EN1*EN2/(EN1+EN2))*D)
      RETURN
      END
