      function chi2_df(chi2) ! bernd berg, july 2 1999.
c chi2 cumulative distribution function.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      common /chi2par/ nf
c     data icall/0/
c     save icall
c     icall=icall+1
      a=half*nf
      x=half*chi2
      chi2_df=gamma_p(a,x)
c     write(6,'("icall,a,chi2,df:",i9,3g15.6,/)') icall,a,chi2,chi2_df
c     if(icall.ge.130) stop "chi2_df: icall."
      return
      end
