      SUBROUTINE TOPINT(CLDTMP,TEMP,TAUIR,TROPRS,ILEVEL,TAUHRS)
      IMPLICIT NONE
C**********************************************************************
C
C   NAME- TOPINT
C
C   LANGUAGE- FORTRAN   TYPE- SUBROUTINE     COMPUTER- CRAY
C
C   VERSION- 1.0    DATE- 03/17/94   PROGRAMMER- SISONG ZHOU
C   VERSION- 1.1    DATE- 04/14/95   PROGRAMMER- TIM GARDNER  (HSTX)
C   VERSION- 1.2    DATE- 06/03/96   PROGRAMMER- LEAH CASEY (HSTX)
C   VERSION- 3.0    DATE- 11/14/97   PROGRAMMER- BRIAN BARIL(HSTX)
C   VERSION- 3.1    DATE- 04/05/01   PROGRAMMER- A. ALLEGRINO (RITSS)
C   VERSION- 3.2    DATE- 06/27/05   PROGRAMMER- FRANK TILLEY (RAYTHEON)
C   VERSION- 3.3    DATE- 03/06/06   PROGRAMMER- FRANK TILLEY (ERT)
C   VERSION- 3.4    DATE- 04/05/06   PROGRAMMER- FRANK TILLEY (IMSG)
C
C   FUNCTION-TO FIND THE CLOUD TOP LEVEL AND RECREATE A TAU (TAUHRS)
C            FOR CLOUD TOP ATTENUATION CORRECTION
C
C   VERSION 1.1- CODE WAS MODIFIED TO ALLOW IT TO BE USED IN THE TOVS
C                PROCESSING SYSTEM.
C
C   VERSION 1.2- INCLUSION INTO RTOVS.
C
C   VERSION 3.0- MODIFICATIONS FOR INCLUSION INTO ATOVS.
C
C   VERSION 3.1- INCREASED THE ARRAY SIZE TO 42 LEVELS (PRFTLV) FROM 40.
C                INCLUDED RETPARM COMMON AREA. (WR#150)
C
C   VERSION 3.2- EXPLICITLY DECLARED VARIABLES CLDTMP, I, ILEVEL, L,
C                LOW, LUP, RATE, TLEVEL, TLOW, AND TLUP.
C
C   VERSION 3.3- ADDED TROPOPAUSE PRESSURE (TROPRS) TO THE CALLING 
C                ARGUMENTS AND ADDED FUNCTIONALITY TO USE THE TROPOPAUSE
C                PRESSURE AS A STARTING POINT FOR FINDING THE CLOUD TOP
C                LEVEL IN THE RETRIEVAL TEMPERATURE PROFILE.(WR 296)
C
C   VERSION 3.4- RESTRICTED SURFACE LEVEL TO <= 1000 MB (LEVEL 40)
C                REMOVED UNUSED COMMON 'TRANSM'
C
C   CALLING ARGUMENTS-
C   NAME     TYPE  I/O  DESCRIPTION
C   ----     ----  ---  --------
C   CLDTMP   REAL   I   CLOUD TOP TEMPERATURE
C   TEMP     REAL   I   RETRIEVAL TEMPERATURE PROFILE
C   TAUIR    REAL   I   TRANSMITTANCES AT RETRIEVAL LEVELS FOR HIRS
C                       CHANNELS 1 THROUGH 11.
C   TROPRS   REAL   I   TROPOPAUSE PRESSURE.
C   ILEVEL    INT   O   CLOUD TOP LEVEL IN THE RETRIEVAL TEMPERATURE
C                       PROFILE.
C   TAUHRS   REAL   O   TRANSMITTANCES FOR HIRS CHANNELS 1 THROUGH 11
C                       AT THE CLOUD TOP LEVEL
C
C   COMMON AREAS- RETPARM, RTPLVL, SPVAL
C
C   LOCAL VARIABLES-
C   NAME     TYPE    DESCRIPTION
C   ----     ----    -----------
C   I, L      INT    LOOP INDEX VARIABLES
C   LOW       INT    TOVS LEVEL BELOW THE CLOUD TOP TEMPERATURE
C   LUP       INT    TOVS LEVEL ABOVE THE CLOUD TOP TEMPERATURE
C   RATE     REAL    TEMPERATURE LAPSE RATE BETWEEN LOW AND LUP
C   TLEVEL   REAL    TEMPERATURE AT A GIVEN TOVS LEVEL
C   TLOW     REAL    TEMPERATURE AT THE TOVS LEVEL BELOW THE CLOUD
C                    TOP PRESSURE
C   TLUP     REAL    TEMPERATURE AT THE TOVS LEVEL ABOVE THE CLOUD
C                    TOP PRESSURE
C   TROPLV    INT    TOVS LEVEL CORRESPONDING TO THE TROPOPAUSE
C                    PRESSURE.
C
C   SUBROUTINES CALLED- NONE
C
C**********************************************************************
C
      INCLUDE 'RETPARM'
      INCLUDE 'RTPLVL'
      INCLUDE 'SPVAL'

      REAL   TEMP(PRFTLV),TAUIR(PRFTLV,11),TAUHRS(PRFTLV,11)
      REAL   CLDTMP,TROPRS

      REAL    RATE, TLEVEL, TLOW, TLUP
      INTEGER I, ILEVEL, L, LOW, LUP, TROPLV
C
C FIND THE TOVS LEVEL CORRESPONDING TO THE TROPOPAUSE PRESSURE.
C USE LEVEL 21 (115 MB) IF THE TROPOPAUSE PRESSURE IS MISSING.
C
      TROPLV = 0
      IF (TROPRS.NE.R4SPV) THEN
         DO I = 2, (PRFTLV -2)
            IF (TROPLV.EQ.0) THEN
               IF (PROFLV(I).GE.TROPRS) TROPLV = I
            END IF
         END DO 
      END IF
C
      IF (TROPLV.EQ.0) TROPLV = 21

C
C FIND CLOUD TOP LEVEL BY SEARCHING FOR THE CLOUD TOP
C TEMPERATURE IN THE RETRIEVED TEMPERATURE PROFILE. START
C BY SETTING THE CLOUD LEVEL AT THE SURFACE (1000 MB).
C
      LUP = 39
      LOW = 40
C
C SEARCH BETWEEN THE TROPOPAUSE AND THE SURFACE.
C
      IF (TROPLV.LT.2) TROPLV = 21
      DO 100 I=TROPLV,PRFTLV
         TLEVEL = TEMP(I)
         IF(CLDTMP.GT.TLEVEL) GOTO 100
         LUP = I-1
         LOW = I
         GOTO 200
  100 CONTINUE
C
  200 CONTINUE
C
C-- IF THE PRESSURE LEVEL IS GREATER THAN 40 (1000 MB),
C   SET IT TO 40.
C
      IF (LOW .GT. 40) THEN
          LOW = 40
          LUP = LOW - 1
      END IF
      TLUP = TEMP(LUP)
      TLOW = TEMP(LOW)
C
      ILEVEL = LOW
C
      IF(TLOW.EQ.TLUP) THEN
         RATE = 1.0
      ELSE
         RATE = (CLDTMP-TLUP)/(TLOW-TLUP)
      ENDIF
C
C COPY TRANSMITTANCES TO TEMPORARY ARRAY
C
      DO I=1,11
         DO L=1,LUP
            TAUHRS(L,I) = TAUIR(L,I)
         END DO
      END DO
C
C COMPUTE THE TRANSMITTANCE AT THE CLOUD TOP LEVEL
C
      DO I=1,11
        TAUHRS(ILEVEL,I) = TAUIR(LUP,I)-(TAUIR(LUP,I)-TAUIR(LOW,I))*RATE
      END DO
C
      RETURN
      END
