        SUBROUTINE YPHAFN(X,A,Y,DERIV,NA)
*
*  Module number: 14.4.3
*
*  Module name: YPHAFN
*
*  Keyphrase:
*  ----------
*       Compute pha fit function value
*  Description:
*  ------------
C
C ROUTINE TO EVALUTE THE DERIVATIVES OF FUNCTION FOR LEAST-SQUARES SEARCH
C       WITH FORM OF A GAUSSIAN AND A QUADRATIC POLYNOMIAL.
C       Y = A(1)*EXP(-Z/2) + A(4)+A(5)*X+A(6)*X*X
C       WHERE Z = (X-A(2))/A(3)
C
C
*
*  FORTRAN name: YPHAfn.for
*
*  Keywords of accessed files and tables:
*  --------------------------------------
*       none
*
*  Subroutines Called:
*  -------------------
*       none
*
*  History:
*  --------
*  Version      Date        Author          Description
*     1       DEC 88       D. Lindler   Designed and coded
*-------------------------------------------------------------------------------
C INPUT PARAMETERS
C
C       X - X VALUE
C       A - ARRAY OF PARAMETERS
C
C OUTPUT PARAMETERS
C
C       DERIV - DERIVATIVES OF FUNCTION
C
        INTEGER NA
        DOUBLE PRECISION X,A(NA),Y,DERIV(*)
        INTEGER I
        DOUBLE PRECISION TEMP,Z,Z2
C-----------------------------------------------------------------------
        DO 1 I=1,3
1               DERIV(I)=0.0
C
C LINEAR BASELINE
C
        Y = 0.0
        IF (NA .GT. 3)THEN
                Y = Y+A(4)
                DERIV(4)=1.0
        ENDIF
        IF (NA .GT. 4) THEN
                Y = Y+A(5)*X
                DERIV(5)=X
        ENDIF
        IF (NA .GT. 5) THEN
                Y = Y+A(6)*X*X
                DERIV(6)=X*X
        ENDIF
C
C GAUSSIAN
C
        IF(A(3).GT.1.0E-10)THEN
                Z = (X - A(2))/A(3)
                Z2=Z**2
                IF(Z2.LT.50.0)THEN
                        TEMP=EXP(-Z2/2.0)
                        Y = Y + A(1)*TEMP
                        DERIV(1) = TEMP
                        DERIV(2) = A(1)*DERIV(1)*Z/A(3)
                        DERIV(3) = DERIV(2)*Z
                ENDIF
        ENDIF
        RETURN
        END
