      SUBROUTINE TROCTP(TMPCLD,TPROFI,TROPRS,TROTMP,TROLEV,DPRESS)
      IMPLICIT NONE
C*******************************************************************
C
C   LANGUAGE- FORTRAN     TYPE- MAIN
C
C   VERSION- 1.1    DATE- 01/11/08   PROGRAMMER- FRANK TILLEY (IMSG)
C
C  FUNCTION - CALCULATES CLOUD TOP PRESSURE ABOVE THE TROPOPAUSE WHERE
C             THE TEMPERATURE PROFILE DECREASES ABOVE THE TROPOPAUSE.
C
C   PARAMETERS-
C      VARIABLE                TYPE I/O FUNCTION
C      --------                ---- --- --------
C      TMPCLD                  REAL  I   CLOUD TOP TEMPERATURE AT SPOT.
C      TPROFI(42)              REAL  I   ATMOSPHERIC PROFILE AT TOVS 42
C                                        LEVELS.
C      TROPRS                  REAL  I   TROPOPAUSE PRESSURE.
C      TROTMP                  REAL  I   TROPOPAUSE TEMPERATURE.
C      TROLEV                   INT  I   TOVS LEVEL JUST ABOVE THE
C                                        TROPOPAUSE
C      DPRESS                  REAL  O   CLOUD TOP PRESSURE AT THE SPOT.
C
C*******************************************************************

      INCLUDE 'RETPARM'

      INTEGER L,J,IU,IV,K,IL, TROLEV
      REAL TMPCLD,DPRESS,TPROFI(PRFTLV),TROPRS,SURPRS,TROTMP 
      REAL TMPUP,TMPDN,TMPDF,PRSUP,PRSDF,PRSGD,TMPDFX,PRSCLD,PRSDN
      REAL YPROFI(30),YPRESS(30)
      LOGICAL TROP1
C
C  LOOK UP TABLE FOR ATMOSPHERIC LAYERS
C
      DATA YPRESS /  10.0,  15.0,  20.0,  25.0,  30.0,  50.0,  60.0,
     +               70.0,  85.0, 100.0, 115.0, 135.0, 150.0, 200.0,
     +              250.0, 300.0, 350.0, 400.0, 430.0, 475.0, 500.0,
     +              570.0, 620.0, 670.0, 700.0, 780.0, 850.0, 920.0,
     +              950.0, 1000.0 /
C
C-- INITIALIZE THE CLOUD TOP PRESSURE TO THE TROPOPAUSE PRESSURE.
C
      PRSCLD = TROPRS
C
      IF (ABS(TMPCLD-TROTMP).LE.0.1) THEN
         PRSCLD = TROPRS
         GO TO 200
      END IF

      DO L=1,30
         YPROFI(L) = TPROFI(10+L)
      END DO
C
C-- START AT THE TOVS LEVEL ABOVE THE TROPOPAUSE AND WORK 
C   UPWARD LOOKING FOR A RETRIEVED TEMPERATURE THAT IS LESS
C   THAN THE CLOUD TOP TEMPERATURE.

         DO 10 J = (TROLEV-10),1, -1

C-- IF AN ATOVS PRESSURE LEVEL IS FOUND, KEEP MOVING UPWARD
C   THROUGH THE ATMOSPHERE LOOKING FOR A RETRIEVED TEMPERATURE
C   LESS THAN OR EQUAL TO THE CLOUD TOP TEMPERATURE.

            IF (TMPCLD.LT.YPROFI(J)) GO TO 10
            IU = J+1

C-- IF A TEMPERATURE COOLER THAN THE CLOUD TOP TEMPERATURE IS
C   FOUND ABOVE THE TROPOPAUSE, CONTINUE PROCESSING

            GO TO 70
   10    CONTINUE

C-- IF NO TEMPERATURE COOLER THAN THE CLOUD TOP TEMPERATURE IS
C   FOUND, LEAVE THE CLOUD TOP PRESSURE AS THE TROPOPAUSE PRESSURE.
C
   70 CONTINUE
C
      IF( IU.LE.1 ) GOTO 200
C
C.....  CALCULATE CLOUD TOP PRESSURE
C
C-- DEFINE THE RETRIEVED TEMPERATURES FOR THE LEVELS ABOVE AND
C   BELOW THE CLOUD TOP AND CALCULATE THE ABSOLUTE DIFFERENCE
C   BETWEEN THESE TWO TEMPERATURES.

      TMPUP = YPROFI(IU-1)
      TMPDN = YPROFI(IU)
      TMPDF = TMPDN-TMPUP
C
C-- DEFINE THE RETRIEVAL PRESSURES ABOVE AND BELOW THE CLOUD
C   TOP AND CALCULATE THE DIFFERENCE BETWEEN THESE TWO PRESSURES.
C
      PRSUP = YPRESS(IU-1)
      PRSDN = YPRESS(IU)
      PRSDF = PRSDN-PRSUP
C
C-- DEFINE THE PRESSURE GRADIANT BY DIVIDING THE PRESSURE DIFFERENCE
C   BY THE TEMPERATURE DIFFERENCE
C
      PRSGD = PRSDF/TMPDF
      TMPDFX = ABS(TMPCLD-TMPUP)
      PRSCLD = PRSDN + PRSGD*TMPDFX

      GOTO 200
C
   80 CONTINUE
C....  SETS CLOUD TOP PRESSURE TO 115 MB WHEN IT IS LESS THAN 115 MB
C      (COMMENTED OUT FOR TESTING 9/3/2005  F. TILLEY)
C*    PRSCLD=115.0
      GOTO 200
C
  190 CONTINUE
C.... SET CLOUD TOP PRESSURE TO 1000 MB WHEN CLOUD TOP TEMPERATURE 
C     IS WARMER THAN THE TEMPERATURE AT 1000 MB LEVEL
      PRSCLD=1000.0
C
  200 CONTINUE

      DPRESS = PRSCLD
C     print *,'TROCTP: PRSCLD = ',PRSCLD
C
      RETURN
      END
