      subroutine kolm2_as2(n1,n2,dat1,dat2,del,q)
c bernd berg, apr 30, 2001. asymptotic two-sided kolmogorov test for 
c                 two data sets. see kolm2_as.f for further comments.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      dimension dat1(n1),dat2(n2)
c
      femp1=zero
      femp2=zero
      del=zero
      i1=1
      i2=1
1     continue
      if(dat1(i1).lt.dat2(i2)) then
        femp1=(one*i1)/n1
        i1=i1+1
      else if(dat1(i1).eq.dat2(i2)) then
        femp1=(one*i1)/n1
        femp2=(one*i2)/n2
        i1=i1+1
        i2=i2+1  
      else
        femp2=(one*i2)/n2
        i2=i2+1  
      end if
      del=max(del,abs(femp1-femp2))
      if(i1.le.n1.and.i2.le.n2) go to 1
c
c effective number of data n1*n2/(n1+n2).
      sqn=sqrt(n1*((n2*one)/((n1+n2)*one))) ! allow large n1,n2.
      a=-two*(sqn*del+(12*del)/100+(11*del)/(100*sqn))**2
      sign_two=two
      q=zero
      cut=zero
      do j=1,100
        add=sign_two*exp(a*j**2)
        q=q+add
        if(abs(add).le.cut) return
        sign_two=-sign_two
        cut=abs(add)/1000
      end do
c
      write(6,'(" kolm2_as2: no convergence.")')
      stop " kolm2_as2: no convergence."
      end
