#include "fpreproc/library_names.h"
#include "fpreproc/f77_dcomplx.h"
#include "fpreproc/fp_const.h"
*DECK DAI
      REAL*8 FUNCTION DAI (X)
C***BEGIN PROLOGUE  DAI
C***PURPOSE  Evaluate the Airy function.
C***LIBRARY   SLATEC (FNLIB)
C***CATEGORY  C10D
C***TYPE      REAL*8 (AI-S, DAI-D)
C***KEYWORDS  AIRY FUNCTION, FNLIB, SPECIAL FUNCTIONS
C***AUTHOR  Fullerton, W., (LANL)
C***DESCRIPTION
C
C DAI(X) calculates the double precision Airy function for double
C precision argument X.
C
C Series for AIF        on the interval -1.00000E+00 to  1.00000E+00
C                                        with weighted error   8.37E-33
C                                         log weighted error  32.08
C                               significant figures required  30.87
C                                    decimal places required  32.63
C
C Series for AIG        on the interval -1.00000E+00 to  1.00000E+00
C                                        with weighted error   7.47E-34
C                                         log weighted error  33.13
C                               significant figures required  31.50
C                                    decimal places required  33.68
C
C***REFERENCES  (NONE)
C***ROUTINES CALLED  D1MACH, D9AIMP, DAIE, DCSEVL, INITDS, XERMSG
C***REVISION HISTORY  (YYMMDD)
C   770701  DATE WRITTEN
C   890531  Changed all specific intrinsics to generic.  (WRB)
C   890531  REVISION DATE from Version 3.2
C   891214  Prologue converted to Version 4.0 format.  (BAB)
C   900315  CALLs to XERROR changed to CALLs to XERMSG.  (THJ)
C   920618  Removed space from variable names.  (RWC, WRB)
C***END PROLOGUE  DAI
C============
C idecl:  explicitize implicit INTEGER declarations:
      IMPLICIT NONE
      INTEGER naif,naig,initds
C============
      REAL*8 X, AIFCS(13), AIGCS(13), THETA, XM, XMAX, X3SML,
     1  Z, D1MACH, DCSEVL, DAIE, XMAXT
      LOGICAL FIRST
      SAVE AIFCS, AIGCS, NAIF, NAIG, X3SML, XMAX, FIRST
      DATA AIFCS(  1) / -CONST(.37971358496669997496197089469414,-1)/
      DATA AIFCS(  2) / +CONST(.59191888537263638574319728013777,-1)/
      DATA AIFCS(  3) / +CONST(.98629280577279975365603891044060,-3)/
      DATA AIFCS(  4) / +CONST(.68488438190765667554854830182412,-5)/
      DATA AIFCS(  5) / +CONST(.25942025962194713019489279081403,-7)/
      DATA AIFCS(  6) / +CONST(.61766127740813750329445749697236,-10)/
      DATA AIFCS(  7) / +CONST(.10092454172466117901429556224601,-12)/
      DATA AIFCS(  8) / +CONST(.12014792511179938141288033225333,-15)/
      DATA AIFCS(  9) / +CONST(.10882945588716991878525295466666,-18)/
      DATA AIFCS( 10) / +CONST(.77513772196684887039238400000000,-22)/
      DATA AIFCS( 11) / +CONST(.44548112037175638391466666666666,-25)/
      DATA AIFCS( 12) / +CONST(.21092845231692343466666666666666,-28)/
      DATA AIFCS( 13) / +CONST(.83701735910741333333333333333333,-32)/
      DATA AIGCS(  1) / +CONST(.18152365581161273011556209957864,-1)/
      DATA AIGCS(  2) / +CONST(.21572563166010755534030638819968,-1)/
      DATA AIGCS(  3) / +CONST(.25678356987483249659052428090133,-3)/
      DATA AIGCS(  4) / +CONST(.14265214119792403898829496921721,-5)/
      DATA AIGCS(  5) / +CONST(.45721149200180426070434097558191,-8)/
      DATA AIGCS(  6) / +CONST(.95251708435647098607392278840592,-11)/
      DATA AIGCS(  7) / +CONST(.13925634605771399051150420686190,-13)/
      DATA AIGCS(  8) / +CONST(.15070999142762379592306991138666,-16)/
      DATA AIGCS(  9) / +CONST(.12559148312567778822703205333333,-19)/
      DATA AIGCS( 10) / +CONST(.83063073770821340343829333333333,-23)/
      DATA AIGCS( 11) / +CONST(.44657538493718567445333333333333,-26)/
      DATA AIGCS( 12) / +CONST(.19900855034518869333333333333333,-29)/
      DATA AIGCS( 13) / +CONST(.74702885256533333333333333333333,-33)/
      DATA FIRST /.TRUE./
C***FIRST EXECUTABLE STATEMENT  DAI
      IF (FIRST) THEN
         NAIF = INITDS (AIFCS, 13, CONST(0.1,0)*AREAL(D1MACH(3)))
         NAIG = INITDS (AIGCS, 13, CONST(0.1,0)*AREAL(D1MACH(3)))
C
         X3SML = D1MACH(3)**CONST(0.3334,0)
         XMAXT = (-CONST(1.5,0)*LOG(D1MACH(1)))**CONST(0.6667,0)
         XMAX = XMAXT - XMAXT*LOG(XMAXT)/
     *      (CONST(4.0,0)*SQRT(XMAXT)+CONST(1.0,0))
     *      - CONST(0.01,0)
      ENDIF
      FIRST = .FALSE.
C
      IF (X.GE.(-CONST(1.,0))) GO TO 20
      CALL D9AIMP (X, XM, THETA)
      DAI = XM * COS(THETA)
      RETURN
C
 20   IF (X.GT.CONST(1.0,0)) GO TO 30
      Z = CONST(0.0,0)
      IF (ABS(X).GT.X3SML) Z = X**3
      DAI = CONST(0.375,0)+ (DCSEVL (Z, AIFCS, NAIF) - X*(CONST(0.25,0)+
     1  DCSEVL (Z, AIGCS, NAIG)) )
      RETURN
C
 30   IF (X.GT.XMAX) GO TO 40
      DAI = DAIE(X) * EXP(-CONST(2.0,0)*X*SQRT(X)/CONST(3.0,0))
      RETURN
C
 40   DAI = CONST(0.0,0)
      CALL XERMSG ('SLATEC', 'DAI', 'X SO BIG AI UNDERFLOWS', 1, 1)
      RETURN
C
      END
! 22Jun2000 fgtok -s r8_precision.sub "r8con.csh conversion"
! 22Jun2000 fgtok
! 22Jun2000 fgtok
! 22Jun2000 fgtok
