      subroutine kolm1(n,fxct,del1,del2,q1,q2) ! bernd berg, mar 4 2001.
c exact one-sided kolmogorov tests, implementing equation of
c birnbaum and tingey, ann. math. stat. 22 (1951) 592. see also: 
c van der waerden, mathematical statistics, springer 1969.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      dimension fxct(n)
c
      do j=1,2
        del=zero
        if(j.eq.1) then
          do i=1,n
            femp=(one*(i-1))/n
            del=max(del,fxct(i)-femp)
          end do
          del1=del
        else
          do i=1,n
            femp=(one*i)/n
            del=max(del,femp-fxct(i))
          end do
          del2=del
        end if
c
        if(del.lt.em12) then
          q=one
        goto 1
        endif
        delln=log(del)
        xn=one*(n+1)
        ynln=gamma_ln(xn)
        q=zero
        do k=0,n
          xkp1=one*(k+1)
          xnp1mk=one*(n+1-k)
          bln=ynln-gamma_ln(xkp1)-gamma_ln(xnp1mk)
          delplus=del+(one*k)/(one*n)
          x=one-delplus
          if(x.le.zero) go to 1
          qln=bln+delln+(k-1)*log(delplus)+(n-k)*log(x)
          q=q+exp(qln)
        end do
1       continue
        if(j.eq.1) then
          q1=q ! assigns q to result q1.
        else
          q2=q ! assigns q to result q2.
        end if
      end do
c
      return
      end
