      SUBROUTINE distri(string, iparse, dset, dset_new)
c       make data distribution
c	fwj haberl   13-FEB-1989 15:54:44
c	implicit undefined(a-z)
      INCLUDE 'xplot.inc'
      INTEGER*4 iparse, dset, dset_new
      CHARACTER*(*) string
      LOGICAL*4 qnew
      REAL*4 bound(2), xlo, xhi, xde
      INTEGER*4 iset(dset_max), nbound, ntot, is, ib, i, nset, idata
      INTEGER*4 nret, iflag, idelim
      DATA bound/0., 2./, nbound/20/
 
      CALL xgtrl4(string, iparse, 2, 'boundaries', 1, bound, nret,
     &            iflag, idelim)
      CALL xgtint(string, iparse, 1, 'data set', 1, nbound, nret, iflag,
     &            idelim)
      CALL xgtint(string, iparse, dset_max, 'data set', 1, iset, nret,
     &            iflag, idelim)
      IF (nret.GT.0) THEN
         dset_new = 1
         nset = dset + 1
         nbins(nset) = nbine(dset) + 1
         nbine(nset) = nbine(dset) + nbound
         xde = (bound(2)-bound(1))/nbound
         xlo = bound(1)
         DO i = nbins(nset), nbine(nset)
            xhi = xlo + xde
            datax(i) = 0.5*(xhi+xlo)
            errlx(i) = xlo
            errux(i) = xhi
            datay(i) = 0.
            errly(i) = 0.
            erruy(i) = 0.
            xlo = xhi
         ENDDO
      ENDIF
      qnew = .FALSE.
      ntot = 0
      DO is = 1, nret
         IF (iset(is).GT.0 .AND. iset(is).LE.dset) THEN
            qnew = .TRUE.
            DO ib = nbins(iset(is)), nbine(iset(is))
               ntot = ntot + 1
               IF (datay(ib).GT.bound(1) .AND. datay(ib).LE.bound(2))
     &              THEN
                  xlo = bound(1)
                  DO i = nbins(nset), nbine(nset)
                     xhi = xlo + xde
                     IF (datay(ib).GT.xhi) idata = i + 1
                     xlo = xhi
                  ENDDO
                  datay(idata) = datay(idata) + 1
               ENDIF
            ENDDO
         ENDIF
      ENDDO
      IF (qnew) THEN
         IF (ntot.GT.0) THEN
            DO i = nbins(nset), nbine(nset)
               datay(i) = datay(i)/ntot
               errly(i) = datay(i)
               erruy(i) = datay(i)
            ENDDO
         ENDIF
         xlab(nset) = ' '
         ylab(nset) = 'distribution'
      ELSE
         GOTO 999
      ENDIF
      RETURN
 999  CONTINUE
      dset_new = 0
      RETURN
      END
