!+ Subroutine to print information at end of iteration.
!
! 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.
!
!- ---------------------------------------------------------------------
      SUBROUTINE M_TERMINATE_SCALE(N_SET, LENGTH_SET
     &   , U_SET, TRANS_SET, WEIGHT_POINT
     &   , N_TERM, W_ESFT, K_ESFT
     &   , I_SCALE_FUNCTION, SCALE_VECTOR, P_ARRAY, T_ARRAY
     &   )
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/scale_fnc.pcf'
      INCLUDE 'incl/def_std_io.icf'
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(IN)
     &     N_SET
!             NUMBER OF SETS OF DATA
     &   , LENGTH_SET(NPD_SET_SCALE)
!             LENGTHS OF SETS
     &   , N_TERM
!             NUMBER OF TERMS OF FIT
     &   , I_SCALE_FUNCTION
!             TYPE OF SCALING FUNCTION USED
      REAL*8	!, INTENT(IN)
     &     U_SET(NPD_AMOUNT, NPD_SET_SCALE)
!             AMOUNTS OF ABSORBERS
     &   , TRANS_SET(NPD_AMOUNT, NPD_SET_SCALE)
!             TRANSMISSIVITIES
     &   , WEIGHT_POINT(NPD_SET_SCALE, NPD_AMOUNT)
!             WEIGHTS FOR TRANSMISSIVITIES
     &   , W_ESFT(NPD_ESFT_TERM)
!             ESFT WIEGHTS
     &   , K_ESFT(NPD_ESFT_TERM)
!             ESFT EXPONENTS
     &   , P_ARRAY(NPD_SET_SCALE)
!             PRESSURE ARRAY
     &   , T_ARRAY(NPD_SET_SCALE)
!             TEMPERATURE ARRAY
      REAL*8	!, INTENT(INOUT)
     &     SCALE_VECTOR(NPD_SCALE_VARIABLE, NPD_ESFT_TERM)
!             SCALING PARAMETERS
!
!     LOCAL VARIABLES.
      INTEGER
     &     K
!             LOOP VARIABLE
      REAL*8
     &     SCALE_VECTOR_TEST(NPD_SCALE_VARIABLE, NPD_ESFT_TERM)
!             TEMPORARY SCALING VARIABLES
     &   , RESIDUAL_TEST
!             VALUE OF RESIDUAL AT POINT
!
!     FUNCTIONS CALLED:
      REAL*8
     &     M_RESIDUAL_TRANS
!             RESIDUAL FUNCTION
      EXTERNAL
     &     M_RESIDUAL_TRANS
!
!
      INCLUDE 'incl/scale_fnc.dcf'
!
!
!
!     DISPLAY RMS RESIDUAL ERRORS FOR DIFFERENT CHOICES OF SCALING
!     PARAMETERS.
      WRITE(IU_STDOUT, '(/A)') 'FINAL SCALING CALCULATED:'
      WRITE(IU_MONITOR, '(/A)') 'FINAL SCALING CALCULATED:'
      IF (I_SCALE_FUNCTION.EQ.IP_SCALE_POWER_LAW) THEN
         WRITE(IU_STDOUT, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF PRESSURE = '
     &      , (SCALE_VECTOR(1, K), K=1, N_TERM)
         WRITE(IU_STDOUT, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF TEMPERATURE = '
     &      , (SCALE_VECTOR(2, K), K=1, N_TERM)
         WRITE(IU_MONITOR, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF PRESSURE = '
     &      , (SCALE_VECTOR(1, K), K=1, N_TERM)
         WRITE(IU_MONITOR, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF TEMPERATURE = '
     &      , (SCALE_VECTOR(2, K), K=1, N_TERM)
      ENDIF
      RESIDUAL_TEST=M_RESIDUAL_TRANS(N_SET, LENGTH_SET
     &   , U_SET, TRANS_SET, WEIGHT_POINT
     &   , N_TERM, W_ESFT, K_ESFT
     &   , I_SCALE_FUNCTION, SCALE_VECTOR, P_ARRAY, T_ARRAY)
      RESIDUAL_TEST=SQRT(RESIDUAL_TEST)
      WRITE(IU_STDOUT, '(6X, A, 1PE12.5)') 'R.M.S. RESIDUAL ERROR IN'
     &   //' TRANSMISSION = ', RESIDUAL_TEST
      WRITE(IU_MONITOR, '(6X, A, 1PE12.5)') 'R.M.S. RESIDUAL ERROR IN'
     &   //' TRANSMISSION = ', RESIDUAL_TEST
!
      WRITE(IU_STDOUT, '(/A)') 'PRESSURE SCALING ALONE:'
      WRITE(IU_MONITOR, '(/A)') 'PRESSURE SCALING ALONE:'
      IF (I_SCALE_FUNCTION.EQ.IP_SCALE_POWER_LAW) THEN
         DO K=1, N_TERM
            SCALE_VECTOR_TEST(1, K)=SCALE_VECTOR(1, K)
            SCALE_VECTOR_TEST(2, K)=0.0D+00
         ENDDO
         WRITE(IU_STDOUT, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF PRESSURE = '
     &      , (SCALE_VECTOR_TEST(1, K), K=1, N_TERM)
         WRITE(IU_MONITOR, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF PRESSURE = '
     &      , (SCALE_VECTOR_TEST(1, K), K=1, N_TERM)
         WRITE(IU_STDOUT, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF TEMPERATURE = '
     &      , (SCALE_VECTOR_TEST(2, K), K=1, N_TERM)
         WRITE(IU_MONITOR, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF TEMPERATURE = '
     &      , (SCALE_VECTOR_TEST(2, K), K=1, N_TERM)
      ENDIF
      RESIDUAL_TEST=M_RESIDUAL_TRANS(N_SET, LENGTH_SET
     &   , U_SET, TRANS_SET, WEIGHT_POINT
     &   , N_TERM, W_ESFT, K_ESFT
     &   , I_SCALE_FUNCTION, SCALE_VECTOR_TEST, P_ARRAY, T_ARRAY)
      RESIDUAL_TEST=SQRT(RESIDUAL_TEST)
      WRITE(IU_STDOUT, '(6X, A, 1PE12.5)') 'R.M.S. RESIDUAL ERROR IN'
     &   //' TRANSMISSION = ', RESIDUAL_TEST
      WRITE(IU_MONITOR, '(6X, A, 1PE12.5)') 'R.M.S. RESIDUAL ERROR IN'
     &   //' TRANSMISSION = ', RESIDUAL_TEST
!
      WRITE(IU_STDOUT, '(/A)') 'TEMPERATURE SCALING ALONE:'
      WRITE(IU_MONITOR, '(/A)') 'TEMPERATURE SCALING ALONE:'
      IF (I_SCALE_FUNCTION.EQ.IP_SCALE_POWER_LAW) THEN
         DO K=1, N_TERM
            SCALE_VECTOR_TEST(1, K)=0.0D+00
            SCALE_VECTOR_TEST(2, K)=SCALE_VECTOR(2, K)
         ENDDO
         WRITE(IU_STDOUT, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF PRESSURE = '
     &      , (SCALE_VECTOR_TEST(1, K), K=1, N_TERM)
         WRITE(IU_MONITOR, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF PRESSURE = '
     &      , (SCALE_VECTOR_TEST(1, K), K=1, N_TERM)
         WRITE(IU_STDOUT, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF TEMPERATURE = '
     &      , (SCALE_VECTOR_TEST(2, K), K=1, N_TERM)
         WRITE(IU_MONITOR, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF TEMPERATURE = '
     &      , (SCALE_VECTOR_TEST(2, K), K=1, N_TERM)
      ENDIF
      RESIDUAL_TEST=M_RESIDUAL_TRANS(N_SET, LENGTH_SET
     &   , U_SET, TRANS_SET, WEIGHT_POINT
     &   , N_TERM, W_ESFT, K_ESFT
     &   , I_SCALE_FUNCTION, SCALE_VECTOR_TEST, P_ARRAY, T_ARRAY)
      RESIDUAL_TEST=SQRT(RESIDUAL_TEST)
      WRITE(IU_STDOUT, '(6X, A, 1PE12.5)') 'R.M.S. RESIDUAL ERROR IN'
     &   //' TRANSMISSION = ', RESIDUAL_TEST
      WRITE(IU_MONITOR, '(6X, A, 1PE12.5)') 'R.M.S. RESIDUAL ERROR IN'
     &   //' TRANSMISSION = ', RESIDUAL_TEST
!
      WRITE(IU_STDOUT, '(/A)') 'NO SCALING AT ALL:'
      WRITE(IU_MONITOR, '(/A)') 'NO SCALING AT ALL:'
      IF (I_SCALE_FUNCTION.EQ.IP_SCALE_POWER_LAW) THEN
         DO K=1, N_TERM
            SCALE_VECTOR_TEST(1, K)=0.0D+00
            SCALE_VECTOR_TEST(2, K)=0.0D+00
         ENDDO
         WRITE(IU_STDOUT, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF PRESSURE = '
     &      , (SCALE_VECTOR_TEST(1, K), K=1, N_TERM)
         WRITE(IU_MONITOR, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF PRESSURE = '
     &      , (SCALE_VECTOR_TEST(1, K), K=1, N_TERM)
         WRITE(IU_STDOUT, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF TEMPERATURE = '
     &      , (SCALE_VECTOR_TEST(2, K), K=1, N_TERM)
         WRITE(IU_MONITOR, '(6X, A, /, (4(4X, 1PE10.3)))')
     &        'EXPONENTS OF TEMPERATURE = '
     &      , (SCALE_VECTOR_TEST(2, K), K=1, N_TERM)
      ENDIF
      RESIDUAL_TEST=M_RESIDUAL_TRANS(N_SET, LENGTH_SET
     &   , U_SET, TRANS_SET, WEIGHT_POINT
     &   , N_TERM, W_ESFT, K_ESFT
     &   , I_SCALE_FUNCTION, SCALE_VECTOR_TEST, P_ARRAY, T_ARRAY)
      RESIDUAL_TEST=SQRT(RESIDUAL_TEST)
      WRITE(IU_STDOUT, '(6X, A, 1PE12.5)') 'R.M.S. RESIDUAL ERROR IN'
     &   //' TRANSMISSION = ', RESIDUAL_TEST
      WRITE(IU_MONITOR, '(6X, A, 1PE12.5)') 'R.M.S. RESIDUAL ERROR IN'
     &   //' TRANSMISSION = ', RESIDUAL_TEST
!
!
      RETURN
      END
