!+ Subroutine to precondition the tridiagonal matrix.
!
! Method:
!	The reflection coefficient in each layer of modified so
!	that is never becomes too small, thus avoiding 
!	ill-conditioning.
!
! 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 PRECONDITIONER_CLEAR(N_PROFILE, N_LAYER
     &   , A3, B
     &   )
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_field.ucf'
      INCLUDE 'incl/prec_machine.ucf'
!
!     DUMMY VARIABLES.
      INTEGER	!, INTENT(IN)
     &     N_PROFILE
!             NUMBER OF PROFILES
     &   , N_LAYER
!             NUMBER OF LAYERS
      REAL*8	!, INTENT(IN)
     &     A3(NPD_PROFILE, 3, 2*NPD_LAYER+2)
!             TRIDIAGONAL MATRIX
     &   , B(NPD_PROFILE, 2*NPD_LAYER+2)
!             SOURCE TERMS
!
!     LOCAL VARIABLES
      INTEGER
     &     I
!             LOOP VARIABLE
     &   , L
!             LOOP VARIABLE
      REAL*8
     &     PERTURBATION
!             PERTURBATION TO REFLECTION COEFF
!
!
!     THE REFLECTION COEFFICIENT IN EACH LAYER IS PERTURBED TO ENSURE
!     THAT IT MAY NEVER FALL BELOW THE SQUARE ROOT OF THE TOLERANCE OF
!     THE MACHINE, THUS AVOIDING ILL-CONDITIONING. AS A PARTIAL 
!     CORRECTION THE SOURCE TERM IS MODIFIED ON THE ASSUMPTION THAT 
!     THE FLUX EMANATING FROM A LAYER IS EQUAL TO THE CORRESPONDING 
!     SOURCE TERM. THIS SHOULD BE A GOOD APPROXIMATION WHEN THE LAYER 
!     IS OPTICALLY THICK; BUT IT IS LESS CLEAR WHAT ONE SHOULD DO 
!     IN TRANSPARENT LAYERS.
      DO I=1, N_LAYER
         DO L=1, N_PROFILE
            PERTURBATION=TOL_MACHINE/(A3(L, 2, 2*I)+SQRT_TOL_MACHINE)
            A3(L, 2, 2*I)=A3(L, 2, 2*I)+PERTURBATION
            B(L, 2*I)=B(L, 2*I)-PERTURBATION*B(L, 2*I-1)
            A3(L, 2, 2*I+1)=A3(L, 2, 2*I+1)+PERTURBATION
            B(L, 2*I+1)=B(L, 2*I+1)-PERTURBATION*B(L, 2*I+2)
         ENDDO
      ENDDO
!     THE SURFACE CONDITION:
      DO L=1, N_PROFILE
         PERTURBATION=TOL_MACHINE/(A3(L, 2, 2*N_LAYER+2)
     &      +SQRT_TOL_MACHINE)
         A3(L, 2, 2*N_LAYER+2)=A3(l, 2, 2*N_LAYER+2)+PERTURBATION
         B(L, 2*N_LAYER+2)=B(L, 2*N_LAYER+2)
     &      -PERTURBATION*B(L, 2*N_LAYER+1)
      ENDDO
!
!
      RETURN
      END
