      subroutine qdf_gnu1(iug,cf,n,x,xmin,xmax) ! bernd berg oct 25 2006.
c gnuplot for the peaked cumulative distribution function (qcdf).
c the array x has to be sorted on input. 
c plotting range restricted to xmin,xmax. cf used for file name.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
c     character*(*) cf
      character cf*2,ci*2
      dimension x(n)
      data icnt /0/
      save icnt
c
      icnt=icnt+1
      if(icnt.gt.99) stop 'df_gnu: inct=99 exhausted!'
      write(ci,'(i2.2)') icnt
c
c gnuplot script:
      open(iug,file=cf//"_qdf"//ci//".plt",
     &  status='unknown',form='formatted')
      write(iug,*) 'set noyzeroaxis'
      write(iug,*) 'set yrange [0:0.525]'
      write(iug,*) 'plot "'//cf//'_qdf'//ci//'.d" using 1:3 with line 1'
      write(iug,*) 'pause -1'
      close(iug)
c
      if(icnt.gt.1) then ! create qdf.plt to plot all histograms
      open(iug,file=cf//"_qdf.plt",status='unknown',form='formatted')
      write(iug,*) 'set noyzeroaxis'
      write(iug,'(" set xrange [",g16.7,":",g16.7,"]")') xmin,xmax
      write(iug,*) 'set yrange [0:0.525]'
      write(iug,*) 'plot "'//cf//'_qdf01.d" using 1:3 with line 1,\\'
      do i=2,(icnt-1)
        write(iug,101) cf,i,i
      end do
101   format(2x,'"',a2,'_qdf',i2.2,'.d" using 1:3 with line ',i2,',\\')
      write(iug,103) cf,icnt,icnt
103   format(2x,'"',a2,'_qdf',i2.2,'.d" using 1:3 with line ',i2)
      write(iug,*) 'pause -1'
      close(iug)
      endif
c
      open(iug,file=cf//"_qdf"//ci//".d",
     &   status='unknown',form='formatted')
      write(iug,'(3g16.7)') x(1),zero,zero
      do i=1,(n-1)
        f=(i*one)/(n*one)
        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
