!+ Program to calculate transmittances from an 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.
!
!- ---------------------------------------------------------------------
      PROGRAM TRANS_CHECK
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/scale_fnc.pcf'
      INCLUDE 'incl/error.pcf'
!
!     DECLARATION OF VARIABLES.
      CHARACTER
     &     FILE_SPECTRAL*80
      INTEGER
     &     IERR
     &   , I_GAS
     &   , I_BAND
     &   , I
     &   , K
     &   , N_AMOUNT
      REAL*8
     &     U(NPD_AMOUNT)
     &   , U_MIN
     &   , U_MAX
     &   , P
     &   , T
     &   , SCALE
     &   , TRANS(NPD_AMOUNT)
!
      INCLUDE 'dec_spec.finc'
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     IN_SPECTRUM
!
!
      DATA IERR/I_NORMAL/
!
!
!
100   WRITE(IU_USER, '(A)') 'NAME OF SPECTRAL FILE?'
      READ(IU_STDIN, *) FILE_SPECTRAL
      INCLUDE 'read_spec.finc'
      IF (IERR.NE.I_NORMAL) THEN
         IF (IERR.EQ.I_ERR_EXIST) THEN
            GOTO 100
         ELSE
            STOP
         ENDIF
      ENDIF
!
      WRITE(IU_USER, '(/A)') 'ENTER INDEX OF GAS AND BAND.'
      READ(IU_STDIN, *) I_GAS, I_BAND
      WRITE(IU_USER, '(/A)') 'ENTER PRESSURE AND TEMPERATURE.'
      READ(IU_STDIN, *) P, T
      WRITE(IU_USER, '(/A)')
     &   'ENTER NUMBER OF AMOUNTS, MINIMUM AND MAXIMUM'
      READ(IU_STDIN, *) N_AMOUNT, U_MIN, U_MAX
!
      IF (N_AMOUNT.GT.1) THEN
         DO I=1, N_AMOUNT
            U(I)=EXP(LOG(U_MIN)+(DBLE(I-1)/DBLE(N_AMOUNT-1))
     &         *(LOG(U_MAX)-LOG(U_MIN)))
         TRANS(I)=0.0D+00
      ENDDO
      ELSE
         U(1)=U_MIN
      ENDIF
!
      DO K=1, I_BAND_ESFT(I_BAND, I_GAS)
         IF (I_SCALE_FNC(I_BAND, I_GAS).EQ.IP_SCALE_FNC_NULL) THEN
            SCALE=1.0D+00
         ELSE IF (I_SCALE_FNC(I_BAND, I_GAS).EQ.
     &            IP_SCALE_POWER_LAW) THEN
            SCALE=EXP(SCALE_VECTOR(1, K, I_BAND, I_GAS)
     &         *LOG(P/P_REFERENCE(I_GAS, I_BAND))
     &         +SCALE_VECTOR(2, K, I_BAND, I_GAS)
     &         *LOG(T/T_REFERENCE(I_GAS, I_BAND)))
         ELSE IF (I_SCALE_FNC(I_BAND, I_GAS).EQ.
     &            IP_SCALE_POWER_QUAD) THEN
            SCALE=EXP(SCALE_VECTOR(1, K, I_BAND, I_GAS)
     &         *LOG(P/P_REFERENCE(I_GAS, I_BAND)))
     &         *(1.0D+00+SCALE_VECTOR(2, K, I_BAND, I_GAS)
     &         *(T/T_REFERENCE(I_GAS, I_BAND)-1.0D+00)
     &         +SCALE_VECTOR(3, K, I_BAND, I_GAS)
     &         *(T/T_REFERENCE(I_GAS, I_BAND)-1.0D+00)**2)
         ELSE IF (I_SCALE_FNC(I_BAND, I_GAS)
     &      .EQ.IP_SCALE_DOPPLER_QUAD) THEN
            SCALE=EXP(SCALE_VECTOR(1, K, I_BAND, I_GAS)
     &         *LOG((P+SCALE_VECTOR(2, K, I_BAND, I_GAS))
     &         /(P_REFERENCE(I_GAS, I_BAND)
     &         +SCALE_VECTOR(2, K, I_BAND, I_GAS))))
     &         *(1.0D+00+SCALE_VECTOR(3, K, I_BAND, I_GAS)
     &         *(T/T_REFERENCE(I_GAS, I_BAND)-1.0D+00)
     &         +SCALE_VECTOR(4, K, I_BAND, I_GAS)
     &         *(T/T_REFERENCE(I_GAS, I_BAND)-1.0D+00)**2)
         ENDIF
         DO I=1, N_AMOUNT
            TRANS(I)=TRANS(I)+W_ESFT(K, I_BAND, I_GAS)
     &         *EXP(-K_ESFT(K, I_BAND, I_GAS)*SCALE*U(I))
         ENDDO
      ENDDO
!
      WRITE(IU_STDOUT, '(6X, A6, 6X, A13)') 'AMOUNT', 'TRANSMITTANCE'
      DO I=1, N_AMOUNT
         WRITE(IU_STDOUT, '(2(3X, 1PE12.5))')
     &      U(I), TRANS(I)
      ENDDO
!
!
      STOP
      END
