      subroutine fit_ggnu(iuo,iud,ndat,nfit,x,y,sigy,a)
c bernd berg, october 1, 2002.
c prepares data files data.d and gfit.d for gnuplot with gfit.plt.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      parameter(nplot=200,mmax=20)
      dimension x(ndat),y(ndat),sigy(ndat),a(nfit),dyda(mmax)
      if(nfit.gt.mmax) stop "fit_ggnu: mmax too small."
c
      write(iuo,'(/," fit_ggnu: data for gfit.plt and gaudif.plt.")')
      write(iuo,'(" on data.d: used (x,y,ey) and fit (f,y-f).",/)')
      open(iud,file='data.d',form='formatted',status='unknown')
      do i=1,ndat
        call subg(x(i),a,yy,dyda,nfit)
        write(iud,'(5g14.6)') x(i),y(i),sigy(i),yy,(y(i)-yy)
      end do
      close(iud)
c
      open(iud,file='gfit.d',form='formatted',status='unknown')
      delx=(x(ndat)-x(1))/nplot
      do i=0,nplot
        xx=x(1)+i*delx
        call subg(xx,a,yy,dyda,nfit)
        write(iud,'(2g16.7)') xx,yy
      end do
      close(iud)
c
      open(iud,file='gaudif.d',form='formatted',status='unknown')
      qm=zero
      do i=1,ndat
        call subg(x(i),a,yy,dyda,nfit)
        call gaudif(y(i),sigy(i),yy,zero,q)
        write(iud,'(5g14.6)') x(i),y(i),sigy(i),yy,q
        qm=qm+q
      end do
      close(iud)
      write(iuo,*) "average of the gaussian difference tests:",qm/ndat
      return
      end
