!+ Subroutine to assign archival entries to sets of transmissions.
!
! Method:
!	The properties of the entry are compared with those of any
!	existing sets, and a new set is created if necessary.
!
! 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 LOCATE_ENTRY(N_SET, LENGTH_SET
     &   , P_SET, T_SET, BAND_SET, INDEX_SET
     &   , P_ENTRY, T_ENTRY, I_SPECIES, I_BAND
     &   , I_SET, I_PLACE
     &   )
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/prec_machine.ucf'
      INCLUDE 'incl/precision_pp.tcf'
!
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(INOUT)
     &     N_SET
!             NUMBER OF SETS
     &   , LENGTH_SET(NPD_SET)
!             LENGTH OF SET
     &   , BAND_SET(NPD_SET)
!             BANDS OF SETS
     &   , INDEX_SET(NPD_SET)
!             INDICES OF SETS
      INTEGER	!, INTENT(IN)
     &     I_SPECIES
!             SPECIES OF INPUT
     &   , I_BAND
!             BAND CONSIDERED
      INTEGER	!, INTENT(OUT)
     &     I_SET
!             SET OF DATA FOR CALCULATION
     &   , I_PLACE
!             PLACE IN SET
      REAL*8	!, INTENT(IN)
     &     P_ENTRY
!             PRESSURE OF ENTRY
     &   , T_ENTRY
!             TEMPERATURE OF ENTRY
      REAL*8	!, INTENT(INOUT)
     &     P_SET(NPD_SET)
!             PRESSURE OF SET
     &   , T_SET(NPD_SET)
!             TEMPERATURE OF SET
!
!     LOCAL VARIABLES.
      INTEGER
     &     I
!             LOOP VARIABLE

!
!
!     IF NO SETS HAVE SO FAR BEEN ASSIGNED 
!     A FIRST ONE MUST BE GENERATED.
      IF (N_SET.EQ.0) THEN
         N_SET=1
         LENGTH_SET(1)=1
         P_SET(1)=P_ENTRY
         T_SET(1)=T_ENTRY
         BAND_SET(1)=I_BAND
         INDEX_SET(1)=I_SPECIES
         I_SET=1
         I_PLACE=1
         RETURN
      ENDIF
!
!     CHECK THE SETS WHICH HAVE BEEN GENERATED SO FAR TO SEE
!     WHETHER THIS ENTRY BELONGS WITH THEM.
      I=0
1     I=I+1
         IF ( (ABS(P_SET(I)/P_ENTRY-1.0D+00).LT.TOL_PRESS_PP).AND.
     &        (ABS(T_SET(I)/T_ENTRY-1.0D+00).LT.TOL_TEMP_PP).AND.
     &        (BAND_SET(I).EQ.I_BAND).AND.
     &        (INDEX_SET(I).EQ.I_SPECIES) ) THEN
            I_SET=I
            LENGTH_SET(I)=LENGTH_SET(I)+1
            I_PLACE=LENGTH_SET(I)
         ELSE IF (I.LT.N_SET) THEN
            GOTO 1
         ELSE
!           A NEW SET MUST BE FORMED
            N_SET=N_SET+1
            LENGTH_SET(N_SET)=1
            P_SET(N_SET)=P_ENTRY
            T_SET(N_SET)=T_ENTRY
            BAND_SET(N_SET)=I_BAND
            INDEX_SET(N_SET)=I_SPECIES
            I_SET=N_SET
            I_PLACE=1
         ENDIF
!
!
      RETURN
      END
