! copyright (c) 2008 Swedish Defence Research Agency (FOI)
! may not be copied or distributed without written permission from FOI



C	to compute certain Airy-function values, using the gil et al. 
C	routine aiz
C       note 1: the SLATEC routines daie,daide would be faster 
C               for real arguments, hence the "ccc commented" statements
C	note 2: the two pertinent functions are computed "separately", 
C	        it would be more efficient to lift out certain "common" 
C	        computations

C	Sven Ivansson  2006



	SUBROUTINE AIRY2E (Z, ALN, AIE,AIDE)
C	upon exit: 
C	  Ai(z)  = dexp(-aln) * aie
C	  Ai'(z) = dexp(-aln) * aide

	IMPLICIT NONE

	COMPLEX*32 Z

	REAL*16 ALN
	COMPLEX*32 AIE,AIDE

	INTEGER IERR
	REAL*16 X, DAIE,DAIDE, REZ,IMZ, REUT,IMUT
	COMPLEX*32 ZNOW, CZET,CSCALE, QCMPLX

	ZNOW = Z

ccc	IF (AIMAG(ZNOW).EQ.0.0Q0) THEN

ccc	  X = REAL(ZNOW)
ccc	  IF (X.GT.0.0Q0) THEN
ccc	    ALN = (2.0Q0/3.0Q0) * X * SQRT(X)
ccc	  ELSE
ccc	    ALN = 0.0Q0
ccc	  END IF
ccc	  AIE = DAIE(X)
ccc	  AIDE = DAIDE(X)

ccc	ELSE

	  REZ = REAL(ZNOW)
	  IMZ = AIMAG(ZNOW)

	  CZET = (2.0Q0/3.0Q0) * ZNOW*SQRT(ZNOW)
	  CSCALE = EXP ( -QCMPLX(0.0Q0,AIMAG(CZET)) )
	  ALN = REAL(CZET)

	  CALL AIZ ( 1,2, REZ,IMZ, REUT,IMUT, IERR )
	  AIE = QCMPLX(REUT,IMUT)
	  IF (IERR.NE.0) THEN
	    WRITE(*,*) '%%% aiz 1, ierr=',IERR
	    WRITE(*,*) 'znow=',ZNOW
	    STOP 567
	  END IF
	  AIE = CSCALE * AIE
	  CALL AIZ ( 2,2, REZ,IMZ, REUT,IMUT, IERR )
	  AIDE = QCMPLX(REUT,IMUT)
	  IF (IERR.NE.0) THEN
	    WRITE(*,*) '%%% aiz 2, ierr=',IERR
	    WRITE(*,*) 'znow=',ZNOW
	    STOP 567
	  END IF
	  AIDE = CSCALE * AIDE

ccc	END IF

	RETURN
	END
