      SUBROUTINE newset(string, iparse, dset, dset_new)
c       to rearrange data sets
c	fwj haberl   26-SEP-1989 11:35:54
      INCLUDE 'xplot.inc'
      INTEGER*4 dset, dset_new
      CHARACTER*(*) string
      LOGICAL*4 qskip
      INTEGER*4 iparse, ibeg, iend, iflag, idelim, nret
      INTEGER*4 ncom
      PARAMETER (ncom=2)
      CHARACTER*10 subcom(ncom)
      INTEGER*4 icom, iset, is, idat, i1
      DATA subcom/'x', 'y'/
 
      CALL xgtarg(string, iparse, ibeg, iend, qskip, iflag, idelim)
      IF (iflag.LT.0) THEN
         GOTO 999
      ENDIF
      IF (iend.GE.ibeg) THEN
         CALL xmatch(string(ibeg:iend), subcom, ncom, icom)
      ELSE
         GOTO 999
      ENDIF
      iset = dset + 1
      nbins(iset) = nbine(dset) + 1
      IF (icom.EQ.1) THEN
         CALL xgtint(string, iparse, 1, 'data set for x-axis', 1, is,
     &               nret, iflag, idelim)
         IF (is.LT.1 .OR. is.GT.dset) THEN
            WRITE (*, *) ' ERROR: Wrong data set'
            GOTO 999
         ENDIF
         nbine(iset) = nbins(iset) + nbine(is) - nbins(is)
         i1 = nbins(is)
         DO idat = nbins(iset), nbine(iset)
            datax(idat) = datax(i1)
            errlx(idat) = errlx(i1)
            errux(idat) = errux(i1)
            i1 = i1 + 1
         ENDDO
         xlab(iset) = ' '
      ELSEIF (icom.EQ.2) THEN
         CALL xgtint(string, iparse, 1, 'data set for x-axis', 1, is,
     &               nret, iflag, idelim)
         IF (is.LT.1 .OR. is.GT.dset) THEN
            WRITE (*, *) ' ERROR: Wrong data set'
            GOTO 999
         ENDIF
         nbine(iset) = nbins(iset) + nbine(is) - nbins(is)
         i1 = nbins(is)
         DO idat = nbins(iset), nbine(iset)
            datax(idat) = datay(i1)
            errlx(idat) = errly(i1)
            errux(idat) = erruy(i1)
            i1 = i1 + 1
         ENDDO
         xlab(iset) = ' '
      ENDIF
      CALL xgtarg(string, iparse, ibeg, iend, qskip, iflag, idelim)
      IF (iflag.LT.0) THEN
         GOTO 999
      ENDIF
      IF (iend.GE.ibeg) THEN
         CALL xmatch(string(ibeg:iend), subcom, ncom, icom)
      ELSE
         GOTO 999
      ENDIF
      IF (icom.EQ.1) THEN
         CALL xgtint(string, iparse, 1, 'data set for y-axis', 1, is,
     &               nret, iflag, idelim)
         IF (is.LT.1 .OR. is.GT.dset) THEN
            WRITE (*, *) ' ERROR: Wrong data set'
            GOTO 999
         ENDIF
         IF ((nbine(iset)-nbins(iset)).NE.(nbine(is)-nbins(is))) THEN
            WRITE (*, *) ' ERROR: The data sets have different'//
     &                   ' no of data points'
            GOTO 999
         ENDIF
         i1 = nbins(is)
         DO idat = nbins(iset), nbine(iset)
            datay(idat) = datax(i1)
            errly(idat) = errlx(i1)
            erruy(idat) = errux(i1)
            i1 = i1 + 1
         ENDDO
         ylab(iset) = ' '
      ELSEIF (icom.EQ.2) THEN
         CALL xgtint(string, iparse, 1, 'data set for y-axis', 1, is,
     &               nret, iflag, idelim)
         IF (is.LT.1 .OR. is.GT.dset) THEN
            WRITE (*, *) ' ERROR: Wrong data set'
            GOTO 999
         ENDIF
         IF ((nbine(iset)-nbins(iset)).NE.(nbine(is)-nbins(is))) THEN
            WRITE (*, *) ' ERROR: The data sets have different'//
     &                   ' no of data points'
            GOTO 999
         ENDIF
         i1 = nbins(is)
         DO idat = nbins(iset), nbine(iset)
            datay(idat) = datay(i1)
            errly(idat) = errly(i1)
            erruy(idat) = erruy(i1)
            i1 = i1 + 1
         ENDDO
         ylab(iset) = ' '
      ENDIF
      dset_new = 1
      RETURN
 999  CONTINUE
      dset_new = 0
      RETURN
      END
