      SUBROUTINE fndlim(ix, iy, is, qmodel)
c		fwj haberl april 1988
      INCLUDE 'xplot.inc'
      INTEGER*4 ix, iy, is, imin, imax, i1
      REAL*4 rmax, rmin
      LOGICAL*4 qmodel
 
      IF (symbol(is).LT.0) RETURN
      IF (.NOT.qslimx(ix)) THEN
         i1 = nbine(is) - nbins(is) + 1
         CALL deflim(i1, datax(nbins(is)), imin, imax)
         imin = nbins(is) + imin - 1
         imax = nbins(is) + imax - 1
         rmax = amax1(errlx(imax), errux(imax))
         rmin = amin1(errlx(imin), errux(imin))
         IF (limitx(1,ix).EQ.limitx(2,ix)) THEN
            limitx(1, ix) = rmin
            limitx(2, ix) = rmax
         ELSE
            IF (rmin.LT.limitx(1,ix)) THEN
               limitx(1, ix) = rmin
            ENDIF
            IF (rmax.GT.limitx(2,ix)) THEN
               limitx(2, ix) = rmax
            ENDIF
         ENDIF
      ENDIF
      IF (.NOT.qslimy(iy)) THEN
         i1 = nbine(is) - nbins(is) + 1
         CALL deflim(i1, datay(nbins(is)), imin, imax)
         imin = nbins(is) + imin - 1
         imax = nbins(is) + imax - 1
         IF (limity(1,iy).EQ.limity(2,iy)) THEN
            limity(1, iy) = errly(imin)
            limity(2, iy) = erruy(imax)
            IF (qmodel) THEN
               CALL deflim(i1, modely(nbins(is)), imin, imax)
               imin = nbins(is) + imin - 1
               imax = nbins(is) + imax - 1
               limity(1, iy) = amin1(modely(imin), limity(1,iy))
               limity(2, iy) = amax1(modely(imax), limity(2,iy))
            ENDIF
         ELSE
            IF (errly(imin).LT.limity(1,iy)) THEN
               limity(1, iy) = errly(imin)
            ENDIF
            IF (erruy(imax).GT.limity(2,iy)) THEN
               limity(2, iy) = erruy(imax)
            ENDIF
            IF (qmodel) THEN
               CALL deflim(i1, modely(nbins(is)), imin, imax)
               imin = nbins(is) + imin - 1
               imax = nbins(is) + imax - 1
               IF (modely(imin).LT.limity(1,iy)) THEN
                  limity(1, iy) = modely(imin)
               ENDIF
               IF (modely(imax).GT.limity(2,iy)) THEN
                  limity(2, iy) = modely(imax)
               ENDIF
            ENDIF
         ENDIF
      ENDIF
 
      RETURN
      END
