!+ Function to calculate second derivative of residual.
!
! Method:
!	Straightforward.
!
! Current Owner of Code: J. M. Edwards
!
! History:
!	 Version 	   Date	  		Comment
!   
!	 1.0		   12-04-95		First Version under RCS
!						(J. M. Edwards)
!
! Description of Code:
!   FORTRAN 77 with extensions listed in documentation. 
!
!- ---------------------------------------------------------------------
      FUNCTION D2_RMS_RESIDUAL(N_DATA, U, TRANS, W_EXP, K_EXP)
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_pp.ucf'
!
!     DUMMY ARGUMENTS
      INTEGER	!, INTENT(IN)
     &     N_DATA
!             NUMBER OF DATA POINTS
      REAL*8	!, INTENT(OUT)
     &     D2_RMS_RESIDUAL
!             2ND DERIVATIVE OF RESIDUAL
      REAL*8	!, INTENT(IN)
     &     U(NPD_AMOUNT+1)
!             AMOUNTS
     &   , TRANS(NPD_AMOUNT+1)
!             TRANSMISSIONS
     &   , W_EXP
!             WEIGHT OF EXPONENTIAL
     &   , K_EXP
!             EXPONENT
!
!     LOCAL ARGUMENTS
      INTEGER
     &     I
!             LOOP VARIABLE
      REAL*8
     &     X
!             EXPONENTIAL TERM
!
!
      D2_RMS_RESIDUAL=0.0D+00
      DO I=1, N_DATA
         X=EXP(-K_EXP*U(I))
         D2_RMS_RESIDUAL=D2_RMS_RESIDUAL
     &      +2.0D+00*X*U(I)*U(I)*W_EXP*(2.0D+00*W_EXP*X-TRANS(I))
      ENDDO
!
!
      RETURN
      END
