      subroutine df_gnu(iug,n,x) ! bernd berg, nov 10 2000.
c gnuplot for cumulative distribution function (cdf).
c the array x has to be sorted on input (call heasort). 
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      character ci*2
      dimension x(n)
      data icnt /0/
      save icnt,ykey
c
      icnt=icnt+1
      if(icnt.gt.99) stop 'df_gnu: inct=99 exhausted!'
      write(ci,'(i2.2)') icnt
c
c gnuplot script:
      xkey=x(1)+(x(n)-x(1))/eight
      open(iug,file='df'//ci//'.plt',status='unknown',form='formatted')
      write(iug,*) 'set noyzeroaxis'
      write(iug,'(" set key left")')
      write(iug,*) 'plot "df'//ci//'.d" using 1:2 with l lt 1,\\'
      write(iug,*) '     "df'//ci//'.d" using 1:3 with l lt 1'
      write(iug,*) 'pause -1'
      close(iug)
c
      if(icnt.eq.1) ykey=xkey
      ykey=min(xkey,ykey)
      if(icnt.gt.1) then ! create df.plt to plot all histograms
      open(iug,file='df.plt',status='unknown',form='formatted')
      write(iug,*) 'set noyzeroaxis'
      write(iug,'(" set key",1g16.6,",0.95")') ykey
      write(iug,*) 'plot "df01.d" using 1:2 with line 1,\\'
      write(iug,*) '     "df01.d" using 1:3 with line 1,\\'
      do i=2,(icnt-1)
        write(iug,100) i,i
        write(iug,101) i,i
      end do
100   format('      "df',i2.2,'.d" using 1:2 with l lt ',i2,',\\')
101   format('      "df',i2.2,'.d" using 1:3 with l lt ',i2,',\\')
      write(iug,102) icnt,icnt
102   format('      "df',i2.2,'.d" using 1:2 with l lt ',i2,',\\')
      write(iug,103) icnt,icnt
103   format('      "df',i2.2,'.d" using 1:3 with l lt ',i2)
      write(iug,*) 'pause -1'
      close(iug)
      endif
c
      open(iug,file='df'//ci//'.d',status='unknown',form='formatted')
      write(iug,'(3g16.7)') x(1),zero,zero
      do i=1,(n-1)
        f=(one*i)/(one*n)
        fq=min(f,one-f)
        write(iug,'(3g16.7)') x(i),  f,fq
        write(iug,'(3g16.7)') x(i+1),f,fq
      end do
      write(iug,'(3g16.7)') x(n),one,zero
      close(iug)
c
      return
      end
