!+ Subroutine to calculate the value of a scaling. 
!
! Method:
!	By iteration, a scaling factor is found to fit an ESFT term
!	at one point.
!
! 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 FIND_SCALING_POINT(IERR
     &   , N_TERM, A, K, AMOUNT, TRANS
     &   , SCALING
     &   )
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/prec_machine.ucf'
      INCLUDE 'incl/precision.pcf'
      INCLUDE 'incl/iter_scale.acf'
      INCLUDE 'incl/tol_scale.tcf'
      INCLUDE 'incl/error.pcf'
!
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(IN)
     &     IERR
!             ERROR FLAG
     &   , N_TERM
!             NUMBER OF ESFT TERMS
      REAL*8	!, INTENT(IN)
     &     A(NPD_ESFT_TERM)
!             ESFT WEIGHTS
     &   , K(NPD_ESFT_TERM)
!             ESFT EXPONENTS
     &   , AMOUNT
!             AMOUNT OF ABSORBER
     &   , TRANS
!             TRANSMISSION
      REAL*8	!, INTENT(OUT)
     &     SCALING
!             SCALING FACTOR
!
!
!     LOCAL VARIABLES
      INTEGER
     &     I
!             LOOP VARIABLE
     &   , ITERATION
!             ITERATION
      REAL*8
     &     SUM
!             SUM OF ESFT TERMS
     &   , K_BAR
!             GREY EXPONENT
     &   , TRANS_EST
!             ESTIMATED TRANSMISSION
!
!
!
      IF (TRANS.GT.(1.0D+00-TOL_TRANSMISSION)) THEN
!
!        DEAL WITH EXCEPTIONAL CASES.
         K_BAR=0.0D+00
         DO I=1, N_TERM
            K_BAR=K_BAR+A(I)*K(I)
         ENDDO
         K_BAR=K_BAR*AMOUNT
         IF (K_BAR.GT.TOL_MACHINE) THEN
            SCALING=(1.0D+00-TRANS)/K_BAR
         ELSE
            SCALING=1.0D+00
         ENDIF
!
      ELSE
!
!        SET THE SCALING FACTOR TO 1 AND ITERATE.
         SCALING=1.0D+00
         ITERATION=0
1        IF (ITERATION.LE.NP_MAX_ITERATION_SCALE-1) THEN
            ITERATION=ITERATION+1
            SUM=0.0D+00
            DO I=1, N_TERM
               SUM=SUM+A(I)*EXP(-K(I)*AMOUNT*SCALING)
            ENDDO
            IF ( ABS(SUM-TRANS).LT.TOL_TRANSMISSION) RETURN
            SCALING=SCALING*(LOG(TRANS)-TOL_MACHINE)
     &         /(LOG(SUM)-TOL_MACHINE)
            GOTO 1
         ELSE
!           IF THE ITERATION HAS NOT CONVERGED WE TRY 
!           NEWTON-RAPHSON ITERATION.
!
            ITERATION=0
2           IF (ITERATION.LE.NP_MAX_ITERATION_SCALE-1) THEN
               ITERATION=ITERATION+1
               TRANS_EST=0.0D+00
               SUM=0.0D+00
               DO I=1, N_TERM
                  TRANS_EST=TRANS_EST+A(I)
     &               *EXP(-K(I)*AMOUNT*SCALING)
                  SUM=SUM+A(I)*K(I)*EXP(-K(I)*AMOUNT*SCALING)
               ENDDO
               IF ( ABS(TRANS_EST-TRANS).LT.TOL_TRANSMISSION) RETURN
               SCALING=SCALING-(TRANS-TRANS_EST)/(AMOUNT*SUM)
               GOTO 2
            ELSE
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: TOO MANY ITERATIONS ARE REQUIRED '
     &            //'TO FIND THE SCALING.'
               IERR=I_ABORT_CALCULATION
               RETURN
            ENDIF
!
         ENDIF
!
      ENDIF
!
!
      RETURN
      END
