C
C     ..................................................................
C
C        SUBROUTINE DFRAT
C
C        PURPOSE
C           DFRAT IS USED FOR HANDLING OF DATA AND FUNDAMENTAL FUNCTIONS
C           WITH RATIONAL APPROXIMATION. IT IS A SUBSTANTIAL PART OF
C           RATIONAL APPROXIMATION AND HAS NO MEANING INDEPENDENTLY
C
C        USAGE
C           CALL DFRAT(I,N,M,P,DATI,WGT,IER)
C
C        DESCRIPTION OF PARAMETERS
C           I     - SUBSCRIPT OF CURRENT DATA POINT
C           N     - NUMBER OF ALL DATA POINTS
C           M     - NUMBER OF FUNDAMENTAL FUNCTIONS USED
C           P     - ARRAY OF DIMENSION M+1 AT LEAST, WHICH CONTAINS
C                   ON RETURN THE VALUES OF THE M FUNDAMENTAL
C                   FUNCTIONS, FOLLOWED BY CURRENT FUNCTION VALUE
C                   P MUST BE OF DOUBLE PRECISION
C           DATI  - ARRAY CONTAINING GIVEN N ARGUMENTS, FOLLOWED
C                   BY N FUNCTION VALUES AND FINALLY BY 1 RESPECTIVELY
C                   N WEIGHT VALUES
C                   DATI MUST BE OF DOUBLE PRECISION
C           WGT   - RESULTANT WEIGHT FACTOR USED FOR I-TH TERM
C                   WGT MUST BE OF DOUBLE PRECISION
C           IER   - RESULTANT ERROR PARAMETER, COMBINED WITH INPUT
C                   VALUES FOR CONTROL
C                   IER(2) MEANS DIMENSION OF NUMERATOR
C                   IER(3) MEANS DIMENSION OF DENOMINATOR
C                   IER(1) IS USED AS RESULTANT ERROR PARAMETER,
C                   IER(1) = 0 IN CASE OF NO ERRORS
C                   IER(1) = 1 OTHERWISE (ZERO DENOMINATOR)
C
C        REMARKS
C           VECTOR IER IS USED FOR COMMUNICATION BETWEEN DARAT AND DFRAT
C
C        SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C           DCNP
C
C        METHOD
C           CF. MATHEMATICAL DESCRIPTION OF SUBROUTINE ARAT
C
C     ..................................................................
C
      SUBROUTINE DFRAT(I,N,M,P,DATI,WGT,IER)
C
C
C        DIMENSIONED DUMMY VARIABLES
      DIMENSION P(1),DATI(1),IER(1)
      DOUBLE PRECISION P,DATI,WGT,T,F,FNUM,FDEN
C
C        INITIALIZATION
      IP=IER(2)
      IQ=IER(3)
      IQM1=IQ-1
      IPQ=IP+IQ
C
C        LOOK UP ARGUMENT, FUNCTION VALUE AND WEIGHT
C        LOOK UP NUMERATOR AND DENOMINATOR
      T=DATI(I)
      J=I+N
      F=DATI(J)
      FNUM=P(J)
      J=J+N
      WGT=1.D0
      IF(DATI(2*N+1))2,2,1
    1 WGT=DATI(J)
    2 FDEN=P(J)
C
C        CALCULATE FUNCTION VALUE USED
      F=F*FDEN-FNUM
C
C        CHECK FOR ZERO DENOMINATOR
      IF(FDEN)4,3,4
C
C        ERROR RETURN IN CASE OF ZERO DENOMINATOR
    3 IER(1)=1
      RETURN
C
C        CALCULATE WEIGHT FACTORS USED
    4 WGT=WGT/(FDEN*FDEN)
      FNUM=-FNUM/FDEN
C
C        CALCULATE FUNDAMENTAL FUNCTIONS
      J=IQM1
      IF(IP-IQ)6,6,5
    5 J=IP-1
    6 CALL DCNP(P(IQ),T,J)
C
C        STORE VALUES OF DENOMINATOR FUNDAMENTAL FUNCTIONS
    7 IF(IQM1)10,10,8
    8 DO 9 II=1,IQM1
      J=II+IQ
    9 P(II)=P(J)*FNUM
C
C        STORE FUNCTION VALUE
   10 P(IPQ)=F
C
C        NORMAL RETURN
      IER(1)=0
      RETURN
      END
