!+ Subroutine to write a fromatted ESFT fit.
!
! 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.
!
!- ---------------------------------------------------------------------
      SUBROUTINE WRITE_FIT(L_CONTINUUM
     &   , I_BAND, I_INDEX
     &   , P_FIT, T_FIT
     &   , N_POINTS, AMOUNT, TRANSMITTANCE, TRANS_CALC
     &   , N_TERM, K_ESFT, W_ESFT, I_SCALE
     &   , I_SCALE_FUNCTION, SCALE_VECTOR)
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES
      INCLUDE 'incl/def_pp_io.icf'
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/file_type.pcf'
      INCLUDE 'incl/scale_fnc.pcf'
!
!     DUMMY VARIABLES
      INTEGER	!, INTENT(IN)
     &     I_BAND
!             NUMBER OF BAND
     &   , I_INDEX
!             INDEX NUMBER OF ABSORBER
     &   , N_POINTS
!             NUMBER OF DATA POINTS
     &   , N_TERM
!             NUMBER OF TERMS
     &   , I_SCALE
!             TYPE OF SCALING USED.
     &   , I_SCALE_FUNCTION
!             TYPE OF SCALING FUNCTION USED.
      LOGICAL	!, INTENT(IN)
     &     L_CONTINUUM
!             CONTINUUM FLAG
      REAL*8	!, INTENT(IN)
     &     P_FIT
!             PRESSURE OF FIT
     &   , T_FIT
!             TEMPERATURE OF FIT
     &   , AMOUNT(NPD_AMOUNT)
!             AMOUNTS OF ABSORBER
     &   , TRANSMITTANCE(NPD_AMOUNT)
!             ACTUAL TRANSMITTANCES
     &   , TRANS_CALC(NPD_AMOUNT)
!             CALCULATED TRANSMITTANCES
     &   , K_ESFT(NPD_ESFT_TERM)
!             ESFT EXPONENTS
     &   , W_ESFT(NPD_ESFT_TERM)
!             ESFT WEIGHTS
     &   , SCALE_VECTOR(NPD_SCALE_VARIABLE, NPD_ESFT_TERM)
!             SCALING PARAMETERS
!     LOCAL VARIABLES.
      INTEGER
     &     I
!             LOOP VARIABLE
     &   , L
!             LOOP VARIABLE
!
      INCLUDE 'incl/scale_fnc.dcf'
!
!
!     OUTPUT DATA FOR THIS BAND.
      IF (L_CONTINUUM) THEN
         WRITE(IU_ESFT_OUT, '(A13, I5, //A)') '*FILE TYPE = '
     &      , IT_FILE_CONT_FIT
     &      , 'FITTED CONTINUUM TRANSMISSIONS AND EXTINCTION.'
         WRITE(IU_ESFT_OUT, '(6X, A8, I5, A21, I5)')
     &      'IN BAND ', I_BAND, ': FOR CONTINUUM TYPE ', I_INDEX
      ELSE
         WRITE(IU_ESFT_OUT, '(A13, I5, //A)') '*FILE TYPE = '
     &      , IT_FILE_LINE_FIT
     &      , 'FITTED GAS TRANSMISSIONS AND ESFT TERMS.'
         WRITE(IU_ESFT_OUT, '(6X, A8, I5, A21, I5)')
     &      'IN BAND ', I_BAND, ': FOR ABSORBER INDEX ', I_INDEX
      ENDIF
      WRITE(IU_ESFT_OUT, '(6X, A12, 1PE10.3, A21, 1PE10.3, A3)')
     &  'AT PRESSURE ', P_FIT, ' Pa, AND TEMPERATURE ',T_FIT, ' K.'
      WRITE(IU_ESFT_OUT, '(/)')
      WRITE(IU_ESFT_OUT, '(5X, A18, 7X, A20, 5X, A20, 5X)' )
     &     'AMOUNT OF ABSORBER', 'ACTUAL TRANSMITTANCE'
     &   , 'FITTED TRANSMITTANCE'
      IF (L_CONTINUUM) THEN
         WRITE(IU_ESFT_OUT, '(9X, A11)') '(kg.mol)/m5'
      ELSE
         WRITE(IU_ESFT_OUT, '(9X, A5)') 'kg/m2'
      ENDIF
      DO I=1, N_POINTS
           WRITE(IU_ESFT_OUT, '(3(9X, 1PE16.9))' )
     &          AMOUNT(I), TRANSMITTANCE(I), TRANS_CALC(I)
      ENDDO
      WRITE(IU_ESFT_OUT, '(/)')
!
      WRITE(IU_ESFT_OUT, '(5X, A18, I5, A20, I5, A21, I5)')
     &   'NUMBER OF TERMS = ', N_TERM, ': TYPE OF SCALING = '
     &   , I_SCALE, ': SCALING FUNCTION = ', I_SCALE_FUNCTION
      WRITE(IU_ESFT_OUT, '(4X, A8, 12X, A6, 14X, A18)')
     &   'EXPONENT', 'WEIGHT', 'SCALING PARAMETERS'
      IF (L_CONTINUUM) THEN
         WRITE(IU_ESFT_OUT, '(5X, A11)') 'm5/(kg.mol)'
      ELSE
         WRITE(IU_ESFT_OUT, '(5X, A5)') 'm2/kg'
      ENDIF
      DO I=1, N_TERM
         WRITE(IU_ESFT_OUT, '(2(3X, 1PE16.9), (T39, 2(3X, 1PE16.9)))')
     &      K_ESFT(I), W_ESFT(I)
     &      , (SCALE_VECTOR(L, I), L=1
     &      , N_SCALE_VARIABLE(I_SCALE_FUNCTION))
      ENDDO
!
      WRITE(IU_ESFT_OUT, '(/)')
!
!
      RETURN
      END
