!+ Subgroutine to calculate transmittances using an ESFT.
!
! Method:
!	The ESFT and the true transmittances are supplied to the
!	routine which calculates the fitted transmittances and the
!	realtive error in the fit.
!
! 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.
!
!- ---------------------------------------------------------------------
      SUBROUTINE CALC_FIT(N_DATA, N_TERM
     &   , A, K, U, TRANS
     &   , TRANS_FIT, RELATIVE_ERROR
     &   )
!
!
      IMPLICIT NONE
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/prec_machine.ucf'
      INCLUDE 'incl/precision.pcf'
      INCLUDE 'incl/precision_esft.tcf'
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/dimensions_pp.ucf'
!
!     DUMMY ARGUMENTS.
      INTEGER 	!, INTENT(IN)
     &     N_DATA                          
!             NUMBER OF DATA POINTS
     &   , N_TERM                          
!             NUMBER OF TERMS
      REAL*8 	!, INTENT(IN)
     &     TRANS(NPD_AMOUNT+1)         
!             TRANSMISSION
     &   , U(NPD_AMOUNT+1)             
!             AMOUNTS OF ABSORBER
     &   , K(NPD_ESFT_TERM)                  
!             ESFT EXPONENTS
     &   , A(NPD_ESFT_TERM)                  
!             ESFT WEIGHTS
      REAL*8 	!, INTENT(OUT)
     &     TRANS_FIT(NPD_AMOUNT+1)     
!             FITTED TRANSMISSION
     &   , RELATIVE_ERROR(NPD_AMOUNT+1)
!             RELATIVE ERROR
!
!     LOCAL VARIABLES.
      INTEGER
     &     I                               
!             LOOP VARIABLE
     &   , J                               
!             LOOP VARIABLE
!
!
!     CALCULATE THE FIT FOR EACH DATA POINT.
      DO I=1, N_DATA
         TRANS_FIT(I)=0.0D+00
         DO J=1, N_TERM
            TRANS_FIT(I)=TRANS_FIT(I)+A(J)*EXP(-K(J)*U(I))
         ENDDO
!        CALCULATE THE RELATIVE ERROR IN THE FIT. PUT -1 TO FLAG
!        CASES WHERE TRANS(I)=0.0D+00
         IF (TRANS(I).GT.TOL_TEST) THEN
            RELATIVE_ERROR(I)=ABS(TRANS_FIT(I)/TRANS(I)-1.0D+00)
         ELSE
            RELATIVE_ERROR(I)=-1.0D+00
         ENDIF
      ENDDO
!
!
      RETURN
      END
