      SUBROUTINE CHEBY (A, B, F, G, PHI, EPS, ITNO, MXITER, L, M,
     X                    P, Q, ERROR, IERR, W)
C     ******************************************************************
C     RATIONAL CHEBYCHEV APPROXIMATION OF CONTINUOUS FUNCTIONS
C     ******************************************************************
      DOUBLE PRECISION A, B, F, G, PHI, EPS, ERROR
      DOUBLE PRECISION P(1), Q(1), W(1)
      EXTERNAL F, G, PHI
C     -------------------
      IF (L .LT. 0 .OR. M .LT. 0) GO TO 10
      LP1 = L + 1
      MP1 = M + 1
      LPM = L + M
      N = LPM + 1
      NP1 = N + 1
C     -------------------
      I1 = NP1 + 1
      I2 = I1 + NP1
      I3 = I2 + NP1*NP1
      I4 = I3 + NP1
      I5 = I4 + NP1
      CALL CHEBY1 (A, B, F, G, PHI, EPS, ITNO, MXITER, L, M, P, Q,
     1              ERROR, IERR, LP1, MP1, LPM, N, NP1, W(1),
     2              W(I1), W(I2), W(I3), W(I4), W(I5))
      RETURN
C     ------------------------------------------------------------------
C     ERROR RETURN
C     ------------------------------------------------------------------
   10 IERR = 1
      RETURN
      END
