C
C     ..................................................................
C
C        SUBROUTINE DALI
C
C        PURPOSE
C           TO INTERPOLATE FUNCTION VALUE Y FOR A GIVEN ARGUMENT VALUE
C           X USING A GIVEN TABLE (ARG,VAL) OF ARGUMENT AND FUNCTION
C           VALUES.
C
C        USAGE
C           CALL DALI (X,ARG,VAL,Y,NDIM,EPS,IER)
C
C        DESCRIPTION OF PARAMETERS
C           X      - DOUBLE PRECISION ARGUMENT VALUE SPECIFIED BY INPUT.
C           ARG    - DOUBLE PRECISION INPUT VECTOR (DIMENSION NDIM) OF
C                    ARGUMENT VALUES OF THE TABLE (NOT DESTROYED).
C           VAL    - DOUBLE PRECISION INPUT VECTOR (DIMENSION NDIM) OF
C                    FUNCTION VALUES OF THE TABLE (DESTROYED).
C           Y      - RESULTING INTERPOLATED DOUBLE PRECISION FUNCTION
C                    VALUE.
C           NDIM   - AN INPUT VALUE WHICH SPECIFIES THE NUMBER OF
C                    POINTS IN TABLE (ARG,VAL).
C           EPS    - SINGLE PRECISION INPUT CONSTANT WHICH IS USED AS
C                    UPPER BOUND FOR THE ABSOLUTE ERROR.
C                    FOR THE ABSOLUTE ERROR.
C           IER    - A RESULTING ERROR PARAMETER.
C
C        REMARKS
C           (1) TABLE (ARG,VAL) SHOULD REPRESENT A SINGLE-VALUED
C               FUNCTION AND SHOULD BE STORED IN SUCH A WAY, THAT THE
C               DISTANCES ABS(ARG(I)-X) INCREASE WITH INCREASING
C               SUBSCRIPT I. TO GENERATE THIS ORDER IN TABLE (ARG,VAL),
C               SUBROUTINES DATSG, DATSM OR DATSE COULD BE USED IN A
C               PREVIOUS STAGE.
C           (2) NO ACTION BESIDES ERROR MESSAGE IN CASE NDIM LESS
C               THAN 1.
C           (3) INTERPOLATION IS TERMINATED EITHER IF THE DIFFERENCE
C               BETWEEN TWO SUCCESSIVE INTERPOLATED VALUES IS
C               ABSOLUTELY LESS THAN TOLERANCE EPS, OR IF THE ABSOLUTE
C               VALUE OF THIS DIFFERENCE STOPS DIMINISHING, OR AFTER
C               (NDIM-1) STEPS. FURTHER IT IS TERMINATED IF THE
C               PROCEDURE DISCOVERS TWO ARGUMENT VALUES IN VECTOR ARG
C               WHICH ARE IDENTICAL. DEPENDENT ON THESE FOUR CASES,
C               ERROR PARAMETER IER IS CODED IN THE FOLLOWING FORM
C                IER=0 - IT WAS POSSIBLE TO REACH THE REQUIRED
C                        ACCURACY (NO ERROR).
C                IER=1 - IT WAS IMPOSSIBLE TO REACH THE REQUIRED
C                        ACCURACY BECAUSE OF ROUNDING ERRORS.
C                IER=2 - IT WAS IMPOSSIBLE TO CHECK ACCURACY BECAUSE
C                        NDIM IS LESS THAN 3, OR THE REQUIRED ACCURACY
C                        COULD NOT BE REACHED BY MEANS OF THE GIVEN
C                        TABLE. NDIM SHOULD BE INCREASED.
C                IER=3 - THE PROCEDURE DISCOVERED TWO ARGUMENT VALUES
C                        IN VECTOR ARG WHICH ARE IDENTICAL.
C
C        SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C           NONE
C
C        METHOD
C           INTERPOLATION IS DONE BY MEANS OF AITKENS SCHEME OF
C           LAGRANGE INTERPOLATION. ON RETURN Y CONTAINS AN INTERPOLATED
C           FUNCTION VALUE AT POINT X, WHICH IS IN THE SENSE OF REMARK
C           (3) OPTIMAL WITH RESPECT TO GIVEN TABLE. FOR REFERENCE, SEE
C           F.B.HILDEBRAND, INTRODUCTION TO NUMERICAL ANALYSIS,
C           MCGRAW-HILL, NEW YORK/TORONTO/LONDON, 1956, PP.49-50.
C
C     ..................................................................
C
      SUBROUTINE DALI(X,ARG,VAL,Y,NDIM,EPS,IER)
C
C
      DIMENSION ARG(1),VAL(1)
      DOUBLE PRECISION ARG,VAL,X,Y,H
      IER=2
      DELT2=0.
      IF(NDIM-1)9,7,1
C
C     START OF AITKEN-LOOP
    1 DO 6 J=2,NDIM
      DELT1=DELT2
      IEND=J-1
      DO 2 I=1,IEND
      H=ARG(I)-ARG(J)
      IF(H)2,13,2
    2 VAL(J)=(VAL(I)*(X-ARG(J))-VAL(J)*(X-ARG(I)))/H
      DELT2=DABS(VAL(J)-VAL(IEND))
      IF(J-2)6,6,3
    3 IF(DELT2-EPS)10,10,4
    4 IF(J-8)6,5,5
    5 IF(DELT2-DELT1)6,11,11
    6 CONTINUE
C     END OF AITKEN-LOOP
C
    7 J=NDIM
    8 Y=VAL(J)
    9 RETURN
C
C     THERE IS SUFFICIENT ACCURACY WITHIN NDIM-1 ITERATION STEPS
   10 IER=0
      GOTO 8
C
C     TEST VALUE DELT2 STARTS OSCILLATING
   11 IER=1
   12 J=IEND
      GOTO 8
C
C     THERE ARE TWO IDENTICAL ARGUMENT VALUES IN VECTOR ARG
   13 IER=3
      GOTO 12
      END
