!+ Subroutine to split groups of transmission data into sets.
!
! Method:
!	Groups are divided into sets which contain transmissions for
!	one gas in one band at one set of temperatures and pressures.
!
! 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 SPLIT_GROUP(IERR
     &   , LENGTH_GROUP, LIST_GROUP
     &   , BAND_GROUP, P_GROUP, T_GROUP, U_CASE, RANGE_CASE, BAND_TRANS
     &   , N_BAND_ABSORB, INDEX_ABSORB, TYPE_ABSORB, INDEX_WATER
     &   , AMOUNT_N2
     &   , N_SET, LENGTH_SET
     &   , INDEX_SET, U_SET, TRANS_SET
     &   , L_CONTINUUM, N_BAND_CONTINUUM, INDEX_CONTINUUM
     &   , MEAN_CONTINUUM, N_SET_CONTINUUM, LENGTH_SET_CONTINUUM
     &   , INDEX_SET_CONTINUUM
     &   , U_SET_CONTINUUM, DENSITY_BROAD, TRANS_SET_CONTINUUM
     &   )
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/lowtran_parameters.ecf'
      INCLUDE 'incl/continuum.pcf'
      INCLUDE 'incl/gas_list.pcf'
      INCLUDE 'incl/gas_list.ncf'
      INCLUDE 'incl/physical_constants_1.ccf'
      INCLUDE 'incl/physical_constants_pp.ccf'
      INCLUDE 'incl/error.pcf'
!
!     DUMMY ARGUMENTS
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
      INTEGER	!, INTENT(IN)
     &     LENGTH_GROUP
!             LENGTH OF GROUP
     &   , LIST_GROUP(NPD_AMOUNT)
!             ELEMENTS OF GROUPS
     &   , BAND_GROUP
!             BANDS FOR EACH GROUP
     &   , N_BAND_ABSORB(NPD_BAND)
!             NUMBER OF ABSORBERS IN BANDS
     &   , INDEX_ABSORB(NPD_SPECIES, NPD_BAND)
!             INDICES OF ABSORBERS IN BANDS
     &   , TYPE_ABSORB(NPD_SPECIES)
!             TYPE NUMBERS OF GASES
     &   , N_BAND_CONTINUUM(NPD_BAND)
!             NUMBER OF CONTINUA IN BANDS
     &   , INDEX_CONTINUUM(NPD_BAND, NPD_CONTINUUM)
!             TYPES OF CONTINUA
     &   , INDEX_WATER
!             POSITION OF WATER DATA
      INTEGER	!, INTENT(OUT)
     &     N_SET
!             NUMBER OF SETS
     &   , N_SET_CONTINUUM
!             NUMBER OF CONTINUUM SETS
     &   , LENGTH_SET(NPD_SET_GROUP)
!             LENGTHS OF THE SETS
     &   , INDEX_SET(NPD_SET_GROUP)
!             INDEX NUMBERS OF SETS
     &   , LENGTH_SET_CONTINUUM(NPD_SET_GROUP)
!             LENGTHS OF THE SETS
     &   , INDEX_SET_CONTINUUM(NPD_SET_GROUP)
!             INDEX NUMBERS OF SETS
      LOGICAL	!, INTENT(IN)
     &     L_CONTINUUM
!             CONTINUUM INCLUSION FLAG
      REAL*8	!, INTENT(IN)
     &     P_GROUP
!             PRESSURES OF GROUPS
     &   , T_GROUP
!             TEMPERATURES OF GROUPS
     &   , U_CASE(NPD_CASE, NPD_SPECIES)
!             AMOUNTS OF ABSORBERS
     &   , RANGE_CASE(NPD_CASE)
!             RANGES FOR EACH CASE
     &   , AMOUNT_N2(NPD_CASE)
!             AMOUNTS OF NITROGEN
     &   , BAND_TRANS(NPD_CASE, NPD_SPECIES)
!             BAND TRANSMISSIONS
     &   , MEAN_CONTINUUM(NPD_CASE, NPD_CONTINUUM)
!             CONTINUUM TRANSMISSIONS
      REAL*8	!, INTENT(OUT)
     &     U_SET(NPD_AMOUNT, NPD_SET_GROUP)
!             AMOUNTS IN SETS
     &   , TRANS_SET(NPD_AMOUNT, NPD_SET_GROUP)
!             TRANSMISSIONS IN SETS
     &   , U_SET_CONTINUUM(NPD_AMOUNT, NPD_SET_GROUP)
!             CONTINUUM AMOUNTS IN SETS
     &   , DENSITY_BROAD(NPD_AMOUNT, NPD_SET_GROUP)
!             DENSITY OF BROADENING SPECIES
     &   , TRANS_SET_CONTINUUM(NPD_AMOUNT, NPD_SET_GROUP)
!             CONTINUUM TRANSMISSIONS
!
!     LOCAL VARIABLES.
      INTEGER
     &     J
!             LOOP VARIABLE
     &   , K
!             LOOP VARIABLE
     &   , KK
!             TEMPORARY VARIABLE
     &   , I_CASE
!             CASE NUMBER
     &   , I_GAS
!             NUMBER OF GAS
     &   , I_INDEX
!             INDEX NUMBER FOR CONTINUUM
!
      INCLUDE 'incl/gas_molar_weight.ccf'
!
!
!     WORK THROUGH THE GROUPS AND ASSEMBLE THE SETS.
      N_SET=0
      N_SET_CONTINUUM=0
!
!     GASEOUS DATA.
      DO J=1, N_BAND_ABSORB(BAND_GROUP)
         N_SET=N_SET+1
!
!        TEST FOR ARRAY BOUND VIOLATION.
         IF (N_SET.GT.NPD_SET_GROUP) THEN
            WRITE(IU_STDOUT, '(/A)')
     &         '*** ERROR: THERE ARE TOO MANY SETS OF '
     &         //'TRANSMITTANCES IN THIS GROUP.'
            WRITE(IU_STDOUT, '(A)')
     &         'INCREASE NPD_SET_GROUP AND RECOMPILE.'
            IERR=I_ERR_FATAL
            RETURN
         ENDIF
!
         INDEX_SET(N_SET)=INDEX_ABSORB(J, BAND_GROUP)
         I_GAS=INDEX_SET(N_SET)
         LENGTH_SET(N_SET)=LENGTH_GROUP
         DO K=1, LENGTH_GROUP
            I_CASE=LIST_GROUP(K)
            U_SET(K, N_SET)=U_CASE(I_CASE, I_GAS)
            TRANS_SET(K, N_SET)=BAND_TRANS(I_CASE, I_GAS)
         ENDDO
      ENDDO
!
!     CONTINUUM DATA.
      IF (L_CONTINUUM) THEN
         DO J=1, N_BAND_CONTINUUM(BAND_GROUP)
            N_SET_CONTINUUM=N_SET_CONTINUUM+1
            I_INDEX=INDEX_CONTINUUM(BAND_GROUP, J)
!
!           TEST FOR ARRAY BOUND VIOLATION.
            IF (N_SET_CONTINUUM.GT.NPD_SET_GROUP) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: THERE ARE TOO MANY SETS OF '
     &            //'TRANSMITTANCES IN THIS GROUP.'
               WRITE(IU_ERR, '(A)')
     &            'INCREASE NPD_SET_GROUP AND RECOMPILE.'
               IERR=I_ERR_FATAL
               RETURN
            ENDIF
!
            INDEX_SET_CONTINUUM(N_SET_CONTINUUM)=I_INDEX
            LENGTH_SET_CONTINUUM(N_SET_CONTINUUM)=0
            DO K=1, LENGTH_GROUP
               I_CASE=LIST_GROUP(K)
               IF (MEAN_CONTINUUM(I_CASE, INDEX_SET_CONTINUUM
     &            (N_SET_CONTINUUM)).GT.0) THEN
                  LENGTH_SET_CONTINUUM(N_SET_CONTINUUM)=1+
     &               LENGTH_SET_CONTINUUM(N_SET_CONTINUUM)
                  KK=LENGTH_SET_CONTINUUM(N_SET_CONTINUUM)
                  TRANS_SET_CONTINUUM(KK, N_SET_CONTINUUM)
     &               =MEAN_CONTINUUM(I_CASE, INDEX_SET_CONTINUUM
     &               (N_SET_CONTINUUM))
                  IF (I_INDEX.EQ.IP_SELF_CONTINUUM) THEN
                     U_SET_CONTINUUM(KK, N_SET_CONTINUUM)
     &                  =U_CASE(I_CASE, INDEX_WATER)
                     DENSITY_BROAD(KK, N_SET_CONTINUUM)
     &                  =U_CASE(I_CASE, INDEX_WATER)
     &                  /(RANGE_CASE(I_CASE)*MOLAR_WEIGHT(IP_H2O))
                  ELSE IF (I_INDEX.EQ.IP_FRN_CONTINUUM) THEN
                     U_SET_CONTINUUM(KK, N_SET_CONTINUUM)
     &                  =U_CASE(I_CASE, INDEX_WATER)
                     DENSITY_BROAD(KK, N_SET_CONTINUUM)
     &                  =P_GROUP/(R_GAS*T_GROUP)
     &                  -U_CASE(I_CASE, INDEX_WATER)
     &                  /(RANGE_CASE(I_CASE)*MOLAR_WEIGHT(IP_H2O))
                  ELSE IF (I_INDEX.EQ.IP_N2_CONTINUUM) THEN
                     U_SET_CONTINUUM(KK, N_SET_CONTINUUM)
     &                  =AMOUNT_N2(I_CASE)
                     DENSITY_BROAD(KK, N_SET_CONTINUUM)
     &                  =P_GROUP/(R_GAS*T_GROUP)
                  ENDIF
               ENDIF
            ENDDO
         ENDDO
      ENDIF
!
!
      RETURN
      END
