!+ Subroutine to calculate self-broadened extinction coefficients.
!
! Method:
!       For each of the supplied wavelengths, the self-broadened
!       extinction coefficient is calculated by using a splined
!       fit. This routine is based on Clough's continuum.
!
! 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 CONTINUUM_SELF_TRANS(IERR
     &   , N_WAVENUMBER, WAVENUMBER
     &   , P, PARTIAL_P, T, AMOUNT_WATER
     &   , N_TABLE_SELF_260, WAVENUMBER_TABLE_SELF_260
     &   , C_H2O_SELF_260_SI, D2_C_H2O_SELF_260_SI
     &   , N_TABLE_SELF_296, WAVENUMBER_TABLE_SELF_296
     &   , C_H2O_SELF_296_SI, D2_C_H2O_SELF_296_SI
     &   , TRANSMISSION_CONTINUUM, DENSITY_BROAD
     &   )
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/ckd1_table_size.ecf'
      INCLUDE 'incl/ckd1_parm.ecf'
      INCLUDE 'incl/gas_list.pcf'
      INCLUDE 'incl/gas_list.ncf'
      INCLUDE 'incl/gas_molar_weight.ccf'
      INCLUDE 'incl/continuum.pcf'
      INCLUDE 'incl/physical_constants_1.ccf'
      INCLUDE 'incl/physical_constants_pp.ccf'
      INCLUDE 'incl/error.pcf'
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
      INTEGER	!, INTENT(IN)
     &     N_WAVENUMBER
!             NUMBER OF WAVENUMBERS
      INTEGER	!, INTENT(IN)
     &     N_TABLE_SELF_260
!             SIZE OF TABLE FOR SELF AT 260K
     &   , N_TABLE_SELF_296
!             SIZE OF TABLE FOR SELF AT 296K
      REAL*8	!, INTENT(IN)
     &     WAVENUMBER(NPD_WAVENUMBER_TRANS)
!             ARRAY OF WAVENUMBERS
     &   , P
!             PRESSURE
     &   , PARTIAL_P
!             PARTIAL PRESSURE OF WATER
     &   , T
!             TEMPERATURE
     &   , AMOUNT_WATER
!             AMOUNT OF WATER VAPOUR
      REAL*8	!, INTENT(IN)
     &     WAVENUMBER_TABLE_SELF_260(NPD_TABLE_SELF_260)
!             WAVENUMBERS OF ENTRIES IN TABLE
     &   , C_H2O_SELF_260_SI(NPD_TABLE_SELF_260)
!             SI VALUES OF COEFFICIENTS IN TABLE
     &   , D2_C_H2O_SELF_260_SI(NPD_TABLE_SELF_260)
!             2ND DERIVATIVES OF COEFFICIENTS
     &   , WAVENUMBER_TABLE_SELF_296(NPD_TABLE_SELF_296)
!             WAVENUMBERS OF ENTRIES IN TABLE
     &   , C_H2O_SELF_296_SI(NPD_TABLE_SELF_296)
!             SI VALUES OF COEFFICIENTS IN TABLE
     &   , D2_C_H2O_SELF_296_SI(NPD_TABLE_SELF_296)
!             2ND DERIVATIVES OF COEFFICIENTS
      REAL*8	!, INTENT(OUT)
     &     TRANSMISSION_CONTINUUM(NPD_WAVENUMBER_TRANS)
!             TRANSMISSION OF SELF-BROADENED CONTINUUM
     &   , DENSITY_BROAD
!             DENSITY OF BROADENING SPECIES
!
!     LOCAL VARIABLES.
      INTEGER
     &     I
!             LOOP VARIABLE
      REAL*8
     &     MOLAR_DENSITY_TOTAL
!             TOTAL MOLAR DENSITY
     &   , DENSITY_SCALING
!             SCALING FACTOR FOR DENSITY
     &   , C_SELF_296
!             COEFFICIENT FOR SELF-BROADENED CONTINUUM AT 296 K
     &   , C_SELF_260
!             COEFFICIENT FOR SELF-BROADENED CONTINUUM AT 260 K
     &   , C_SELF
!             COEFFICIENT FOR SELF-BROADENED CONTINUUM AT T
     &   , D_WAVENUMBER_2
!             SQUARE OF DIFFERENCES IN WAVENUMBERS
     &   , RADIATION_TERM
!             TERM FOR STIMULATED EMISSION
     &   , K_SELF
!             EXTINCTION COEFFICIENT FOR SELF
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     SPLINE_EVALUATE
!
!
!
!     CALCULATE THE SCALING FACTORS.
!     THE DATA ARE STORED FOR THE MOLAR DENSITY WHICH APPLIES AT THE
!     REFERENCE CONDITIONS, AND THIS MUST BE SCALED TO THE 
!     ACTUAL DENISTY.
      DENSITY_SCALING=(P/P_REF_CONTIN_DATA)*(T_REF_CONTIN_DATA/T)
      MOLAR_DENSITY_TOTAL=P/(R_GAS*T)
!
      DENSITY_BROAD=PARTIAL_P/(R_GAS*T)
!
      DO I=1, N_WAVENUMBER
!
!        SELF-BROADENED CONTINUUM AT 260 K
         CALL SPLINE_EVALUATE(IERR, N_TABLE_SELF_260
     &      , WAVENUMBER_TABLE_SELF_260, C_H2O_SELF_260_SI
     &      , D2_C_H2O_SELF_260_SI, WAVENUMBER(I)
     &      , C_SELF_260)
!        OUTSIDE THE RANGE OF THE FIT THE COEFFICIENT IS SET TO 0.
         IF (IERR.EQ.I_ERR_RANGE) THEN
            C_SELF_260=0.0D+00
            IERR=I_NORMAL
         ENDIF
!
!        SELF-BROADENED CONTINUUM AT 296K
         CALL SPLINE_EVALUATE(IERR, N_TABLE_SELF_296
     &      , WAVENUMBER_TABLE_SELF_296, C_H2O_SELF_296_SI
     &      , D2_C_H2O_SELF_296_SI, WAVENUMBER(I)
     &      , C_SELF_296)
!        OUTSIDE THE RANGE OF THE FIT THE COEFFICIENT IS SET TO 0.
         IF (IERR.EQ.I_ERR_RANGE) THEN
            C_SELF_296=0.0D+00
            IERR=I_NORMAL
         ENDIF
!
!        INCLUDE THE TEMPERATURE DEPENDENCE OF CLOUGH ET AL.
         C_SELF=C_SELF_296*EXP(((296.0D+00-T)/(296.0D+00-260.0D+00))
     &      *LOG(C_SELF_260/C_SELF_296))
!        MAKE THE FASCODE CORRECTION OF 0.7667 AT 1050 CM-1
         C_SELF=C_SELF*(1.0D+00-FACTOR_SELF*ALPHA2_SELF
     &     /((WAVENUMBER(I)-WAVENUMBER_0_SELF)**2+ALPHA2_SELF))
!        MAKE THE SECONDARY CORRECTION.
         D_WAVENUMBER_2=(WAVENUMBER(I)-WAVENUMBER_0_SELF_2)**2
         C_SELF=C_SELF*(1.0D+00-FACTOR_SELF_2*(ALPHA2_SELF_2
     &      /(ALPHA2_SELF_2+D_WAVENUMBER_2*(1.0D+00
     &      +BETA_0_SELF*D_WAVENUMBER_2))))
!
!        CALCULATE THE RADIATION TERM
         RADIATION_TERM=WAVENUMBER(I)
     &      *TANH(WAVENUMBER(I)*H_PLANCK*C_LIGHT
     &      /(2.0D+00*K_BOLTZMANN*T))
!
!        MULTIPLY BY THE DENSITY SCALING AND DIVIDE BY THE MOLECULAR
!        WEIGHT TO USE AMOUNTS IN KG.M-2
         K_SELF=C_SELF*DENSITY_SCALING*RADIATION_TERM
     &      *(DENSITY_BROAD/MOLAR_DENSITY_TOTAL)
     &      /MOLAR_WEIGHT(IP_H2O)
!
!        THE TRANSMISSIONS ARE MONOCHROMATIC.
         TRANSMISSION_CONTINUUM(I)=EXP(-K_SELF*AMOUNT_WATER)
!
      ENDDO
!
!
!
      RETURN
      END
