      subroutine kolm2_as(n,fxct,del,q) ! bernd berg, apr 21, 2001.
c asymptotic two-sided kolmogorov test in the form of
c m.a. stephens, j. royal stat. soc. b 32 (1970) 115.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      dimension fxct(n)
c
      del=zero
      do i=1,n
        femp=(one*(i-1))/n
        del=max(del,fxct(i)-femp)
        femp=(one*i)/n
        del=max(del,femp-fxct(i))
      enddo
c
      sqn=sqrt(n*one)
      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
      enddo
c
      write(6,'(" kolm2_as: no convergence.")')
      stop " kolm2_as: no convergence."
      end
