!+ Subroutine to calculate basic coefficients in two-stream equations.
!
! Method:
!	Depending on the two-stream equations employed, the 
!	appropriate coefficients for the fluxes are calculated.
!
! 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 TWO_COEFF_BASIC(IERR
     &   , N_PROFILE, I_LAYER_FIRST, I_LAYER_LAST
     &   , I_2STREAM
     &   , ASYMMETRY, OMEGA
     &   , SUM, DIFF
     &   )
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_field.ucf'
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/diff_elsasser.ccf'
      INCLUDE 'incl/two_stream_scheme.pcf'
      INCLUDE 'incl/error.pcf'
!
!
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
      INTEGER	!, INTENT(IN)
     &     N_PROFILE
!             NUMBER OF PROFILES
     &   , I_LAYER_FIRST
!             FIRST LAYER TO CONSIDER
     &   , I_LAYER_LAST
!             LAST LAYER TO CONSIDER
     &   , I_2STREAM
!             TWO STREAM SCHEME
!
!     OPTICAL PROPERTIES OF LAYER:
      REAL*8	!, INTENT(IN)
     &     ASYMMETRY(NPD_PROFILE, NPD_LAYER)
!             ASYMMETRY FACTOR
     &   , OMEGA(NPD_PROFILE, NPD_LAYER)
!             ALBEDO OF SINGLE SCATTERING
!
!
!     COEFFICIENTS IN THE TWO-STREAM EQUATIONS:
      REAL*8	!, INTENT(OUT)
     &     SUM(NPD_PROFILE, NPD_LAYER)
!             SUM OF ALPHA_1 AND ALPHA_2
     &   , DIFF(NPD_PROFILE, NPD_LAYER)
!             DIFFERENCE OF ALPHA_1 AND ALPHA_2
!
!     LOCAL VARIABLES.
      INTEGER
     &     I
!             LOOP VARIABLE
     &   , L
!             LOOP VARIABLE
!
      REAL*8
     &     ROOT_3
!             SQUARE ROOT OF 3
!
!
      PARAMETER(
     &     ROOT_3=1.7320508075688772D+00
     &   )
!
!
!
!
      IF (I_2STREAM.EQ.IP_EDDINGTON) THEN
         DO I=I_LAYER_FIRST, I_LAYER_LAST
            DO L=1, N_PROFILE
               SUM(L, I)=1.5D+00*(1.0D+00
     &            -OMEGA(L, I)*ASYMMETRY(L, I))
               DIFF(L, I)=2.0D+00*(1.0D+00-OMEGA(L, I))
            ENDDO
         ENDDO
!
      ELSE IF (I_2STREAM.EQ.IP_ELSASSER) THEN
         DO I=I_LAYER_FIRST, I_LAYER_LAST
            DO L=1, N_PROFILE
               SUM(L, I)=ELSASSER_FACTOR
     &            -1.5D+00*OMEGA(L, I)*ASYMMETRY(L, I)
               DIFF(L, I)=ELSASSER_FACTOR*(1.0D+00-OMEGA(L, I))
            ENDDO
         ENDDO
!
      ELSE IF (I_2STREAM.EQ.IP_DISCRETE_ORD) THEN
         DO I=I_LAYER_FIRST, I_LAYER_LAST
            DO L=1, N_PROFILE
               SUM(L, I)=ROOT_3*(1.0D+00
     &            -OMEGA(L, I)*ASYMMETRY(L, I))
               DIFF(L, I)=ROOT_3*(1.0D+00-OMEGA(L, I))
            ENDDO
         ENDDO
!
      ELSE IF (I_2STREAM.EQ.IP_PIFM85) THEN
         DO I=I_LAYER_FIRST, I_LAYER_LAST
            DO L=1, N_PROFILE
               SUM(L, I)=2.0D+00
     &            -1.5D+00*OMEGA(L, I)*ASYMMETRY(L, I)
               DIFF(L, I)=2.0D+00*(1.0D+00-OMEGA(L, I))
            ENDDO
         ENDDO
!
      ELSE IF (I_2STREAM.EQ.IP_2S_TEST) THEN
         DO I=I_LAYER_FIRST, I_LAYER_LAST
            DO L=1, N_PROFILE
               SUM(L, I)=1.5D+00
     &            -1.5D+00*OMEGA(L, I)*ASYMMETRY(L, I)
               DIFF(L, I)=1.5D+00*(1.0D+00-OMEGA(L, I))
            ENDDO
         ENDDO
!
      ELSE IF (I_2STREAM.EQ.IP_HEMI_MEAN) THEN
         DO I=I_LAYER_FIRST, I_LAYER_LAST
            DO L=1, N_PROFILE
               SUM(L, I)=2.0D+00
     &            *(1.0D+00-OMEGA(L, I)*ASYMMETRY(L, I))
               DIFF(L, I)=2.0D+00*(1.0D+00-OMEGA(L, I))
            ENDDO
         ENDDO
!
      ELSE IF (I_2STREAM.EQ.IP_PIFM80) THEN
         DO I=I_LAYER_FIRST, I_LAYER_LAST
            DO L=1, N_PROFILE
               SUM(L, I)=2.0D+00
     &            -1.5D+00*OMEGA(L, I)*ASYMMETRY(L, I)
     &            -0.5D+00*OMEGA(L, I)
               DIFF(L, I)=2.0D+00*(1.0D+00-OMEGA(L, I))
            ENDDO
         ENDDO
!
      ELSE IF (I_2STREAM.EQ.IP_IFM) THEN
         WRITE(IU_ERR, '(/A)')
     &      '*** ERROR: THE IMPROVED FLUX METHOD HAS '
     &      //'NOT BEEN IMPLEMENTED.'
         IERR=I_ERR_FATAL
         RETURN
!
      ELSE IF (I_2STREAM.EQ.IP_ZDK_FLUX) THEN
         WRITE(IU_ERR, '(/A)')
     &      '*** ERROR: ZDUNKOWSKI''S FLUX METHOD HAS '
     &      //'NOT BEEN IMPLEMENTED.'
         IERR=I_ERR_FATAL
         RETURN
!
      ELSE IF (I_2STREAM.EQ.IP_KRSCHG_FLUX) THEN
         WRITE(IU_ERR, '(/A)')
     &      '*** ERROR: KERSCHGEN''S FLUX METHOD HAS '
     &      //'NOT BEEN IMPLEMENTED.'
         IERR=I_ERR_FATAL
         RETURN
!
      ELSE IF (I_2STREAM.EQ.IP_COAKLEY_CHYLEK_1) THEN
         WRITE(IU_ERR, '(/A)')
     &      '*** ERROR: COAKLEY-CHYLEK''S FIRST METHOD HAS '
     &      //'NOT BEEN IMPLEMENTED.'
         IERR=I_ERR_FATAL
         RETURN
!
      ELSE IF (I_2STREAM.EQ.IP_COAKLEY_CHYLEK_2) THEN
         WRITE(IU_ERR, '(/A)')
     &      '*** ERROR: COAKLEY-CHYLEK''S SECOND METHOD HAS '
     &      //'NOT BEEN IMPLEMENTED.'
         IERR=I_ERR_FATAL
         RETURN
!
      ELSE IF (I_2STREAM.EQ.IP_MEADOR_WEAVER) THEN
         WRITE(IU_ERR, '(/A)')
     &      '*** ERROR: MEADOR & WEAVER''S METHOD HAS '
     &      //'NOT BEEN IMPLEMENTED.'
         IERR=I_ERR_FATAL
         RETURN
!
      ELSE
         WRITE(IU_ERR, '(/A)')
     &      '*** ERROR: AN ILLEGAL PARAMETER HAS BEEN SUPPLIED '
     &      //'TO DEFINE THE 2-STREAM SCHEME.'
         IERR=I_ERR_FATAL
         RETURN
!
      ENDIF
!
!
!
      RETURN
      END
