!+ Subroutine to write out avaerged transmissions.
!
! Method:
!	A summary of the transmissions is written to the .sum file
!	whilst the actual transmissiond go to the .dat file.
!
! 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 WRITE_TRANS(TYPE_ABSORB_SET
     &   , TRANS_TYPE
     &   , I_SET, LENGTH_SET, BAND_SET, INDEX_SET, P_SET, T_SET
     &   , U_SET, TRANS_SET
     &   , WAVE_LENGTH_SHORT_SET, WAVE_LENGTH_LONG_SET
     &   , N_PER_TRANS_RECORD, I_FIRST_RECORD
     &   )
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/def_pp_io.icf'
      INCLUDE 'incl/gas_list.pcf'
      INCLUDE 'incl/gas_list.ncf'
      INCLUDE 'incl/file_type.pcf'
!
!     DUMMY ARGUMENTS.
      CHARACTER	!, INTENT(IN)
     &     TRANS_TYPE*4
!             TYPE OF TRANSMITTANCE
      INTEGER	!, INTENT(IN)
     &     TYPE_ABSORB_SET
!             TYPE OF ABSORBER
     &   , BAND_SET
!             BAND OF SET
     &   , LENGTH_SET
!             LENGTH OF THE SET
     &   , INDEX_SET
!             INDEX OF SET
     &   , I_SET
!             ORDINAL OF SET
      INTEGER	!, INTENT(IN)
     &     N_PER_TRANS_RECORD
!             NUMBER OF VALUES IN TRANS RECORD
      INTEGER	!, INTENT(INOUT)
     &     I_FIRST_RECORD
!             FIRST RECORD OF CURRENT SET
      REAL*8	!, INTENT(IN)
     &     P_SET
!             PRESSURE
     &   , T_SET
!             TEMPERATURE
     &   , U_SET(NPD_AMOUNT)
!             AMOUNTS OF GAS
     &   , TRANS_SET(NPD_AMOUNT)
!             TRANSMITTANCES
     &   , WAVE_LENGTH_SHORT_SET
!             SHORTER WAVELENGTH
     &   , WAVE_LENGTH_LONG_SET
!             LONGER WAVELENGTH
!
!     LOCAL VARIABLES
      INTEGER
     &     I
!             LOOP VARIABLE
     &   , J
!             LOOP VARIABLE
     &   , N_RECORD
!             NUMBER OF RECORDS TO BE WRITTEN
     &   , N_EXCESS
!             NUMBER OF EXCESS DATA VALUES
!
!     SET NAMES OF GASES.
      INCLUDE 'incl/gas_names.dcf'
!
!
      WRITE(IU_TRANSMISSION_SUMMARY, '(A13, I5, //)') '*FILE TYPE = '
     &   , IT_FILE_LINE_TRANS_SUMMARY
      WRITE(IU_TRANSMISSION_SUMMARY, '(A10, I5, 3X, A14, I6)')
     &   'DATA SET: ', I_SET, 'FIRST RECORD: ', I_FIRST_RECORD
      WRITE(IU_TRANSMISSION_SUMMARY, '(A4, 1X, A/)')
     &   TRANS_TYPE, 'TRANSMITTANCE AGAINST AMOUNT OF ABSORBER:'
      WRITE(IU_TRANSMISSION_SUMMARY, '(A4, 1X, A20, 2X, A5, 1X, I5
     &   , 2X, A7, I5)') 'GAS:'
     &   , NAME_ABSORB(TYPE_ABSORB_SET), 'TYPE:', TYPE_ABSORB_SET
     &   , 'INDEX: ',INDEX_SET
      WRITE(IU_TRANSMISSION_SUMMARY
     &   , '(A13, 1X, 1PE10.3, 1X, A2, 2X, A17, 1X, 1PE10.3, 1X, A2)')
     &   'AT PRESSURE =', P_SET, 'Pa', 'AND TEMPERATURE =', T_SET, 'K.'
      WRITE(IU_TRANSMISSION_SUMMARY
     &   , '(A8, I5, A1, 3X, 1PE10.3, A4, 2X, 1PE10.3, A2, /)')
     &   'IN BAND ', BAND_SET, ':'
     &   , WAVE_LENGTH_SHORT_SET, 'm TO'
     &   , WAVE_LENGTH_LONG_SET, 'm.'
      WRITE(IU_TRANSMISSION_SUMMARY, '(I5, 1X, A)' ) LENGTH_SET
     &   , 'POINTS OF DATA.'
      WRITE(IU_TRANSMISSION_SUMMARY, '(6X)')
!
!     WRITE THE ACTUAL DATA VALUES.
      N_RECORD=LENGTH_SET/N_PER_TRANS_RECORD
      DO I=1, N_RECORD
         WRITE(IU_TRANSMISSION, REC=I_FIRST_RECORD+(I-1))
     &      (U_SET(J), TRANS_SET(J)
     &      , J=N_PER_TRANS_RECORD*(I-1)+1, N_PER_TRANS_RECORD*I)
      ENDDO
!     CHECK WHETHER ANY EXCESS REMAINS TO BE WRITTEN.
      N_EXCESS=LENGTH_SET-N_RECORD*N_PER_TRANS_RECORD
      IF (N_EXCESS.GT.0) THEN
         WRITE(IU_TRANSMISSION, REC=I_FIRST_RECORD+N_RECORD)
     &      (U_SET(J), TRANS_SET(J)
     &      , J=LENGTH_SET-N_EXCESS+1, LENGTH_SET)
         N_RECORD=N_RECORD+1
      ENDIF
      I_FIRST_RECORD=I_FIRST_RECORD+N_RECORD
!
!
      RETURN
      END
