      SUBROUTINE CLDPRS(TMPCLD,TPROFI,DPRESS)
      IMPLICIT NONE
C*******************************************************************
C
C   LANGUAGE- FORTRAN     TYPE- MAIN
C
C   VERSION- 1.0    DATE- 02/06/91   PROGRAMMER- ZHOU SISONG
C   VERSION- 1.1    DATE- 08/13/91   PROGRAMMER- TIM GARDNER (HSTX)
C   VERSION- 1.2    DATE- 09/29/95   PROGRAMMER- LEAH CASEY (HSTX)
C   VERSION- 1.3    DATE- 06/03/96   PROGRAMMER- LEAH CASEY (HSTX)
C   VERSION- 3.0    DATE- 11/13/97   PROGRAMMER- BRIAN BARIL (HSTX)
C   VERSION- 3.1    DATE- 04/05/01   PROGRAMMER- A. ALLEGRINO (RITSS)
C
C  FUNCTION - CALCULATES CLOUD TOP PRESSURE FOR EACH SPOT
C             IN A MINIBOX
C  VERSION- 1.2 MODIFICATIONS FOR INCLUSION INTO RTOVS.
C  VERSION- 1.3 MODS FOR ATTENUATION ABOVE THE CLOUDS.
C  VERSION- 3.0 MODIFICATIONS FOR INCLUSION INTO ATOVS.
C  VERSION- 3.1 INCLUDED COMMON RETPARM AND INCREASED THE SIZE OF
C               THE TPROFI ARRAY TO 42 (PRFTLV)PRFTLV) (WR#150)
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      DPRESS                  REAL  O   CLOUD TOP PRESSURE AT THE SPOT.
C
C*******************************************************************

      INCLUDE 'RETPARM'

      INTEGER L,J,IU,IV,K,IL
      REAL TMPUP,TMPDN,TMPDF,PRSUP,PRSDF,PRSGD,TMPDFX,PRSCLD,PRSDN
      REAL TMPCLD,DPRESS,TPROFI(PRFTLV),YPROFI(20),YPRESS(20)
C
C  LOOK UP TABLE FOR ATMOSPHERIC LAYERS
C
      DATA YPRESS / 115.0, 135.0, 150.0, 200.0, 250.0, 300.0,
     1              350.0, 400.0, 430.0, 475.0, 500.0, 570.0, 620.0,
     2              670.0, 700.0, 780.0, 850.0, 920.0, 950.0, 1000.0 /
C
      DO 200 L=1,20
         YPROFI(L) = TPROFI(20+L)
  200 CONTINUE
C
C  CALCULATE CLOUD TOP PRESSURE FOR EACH SPOT
C  ASSUME THE HEIHEST CLOUD TOP IS AT OR BELOW  100MB LEVEL
C
      DO 100 J=1,20
         IF( TMPCLD.GT.YPROFI(J) ) GOTO 100
C
         IU=J
         GOTO 102
  100 CONTINUE
      GOTO 160
C
  102 CONTINUE
C.....  CHECK IF THERE IS A INVERSION LAYER
      IV=IU+1
      DO 120 K=IV,20
         IF(TMPCLD.LT.YPROFI(K)) GOTO 120
         IU=K
         GOTO 103
  120 CONTINUE
C.....  INVERSION DOES NOT EXIST
      GOTO 150
C
  103 CONTINUE
C....... INVERSION EXISTS, FIND THE LOWER INTERSECTION
      IL=IU+1
      DO 130 L=IL,20
         IF(TMPCLD.GT.YPROFI(L)) GOTO 130
         IU=L
         GOTO 150
  130 CONTINUE
C
  150 CONTINUE
C.....  CALCULATE CLOUD TOP PRESSURE
C
      IF( IU.EQ.1 ) GOTO 101
C
      TMPUP = YPROFI(IU-1)
      TMPDN = YPROFI(IU)
      TMPDF = ABS( TMPDN-TMPUP )
      PRSUP = YPRESS(IU-1)
      PRSDN = YPRESS(IU)
      PRSDF = PRSDN-PRSUP
      PRSGD = PRSDF/TMPDF
      TMPDFX= ABS( TMPCLD-TMPUP )
      PRSCLD= PRSUP + PRSGD*TMPDFX
      GOTO 110
C
  101 CONTINUE
C....  SETS CLOUD TOP PRESSURE TO 115 MB WHEH IT IS LESS THAN 115 MB
      PRSCLD=115.0
      GOTO 110
C
  160 CONTINUE
C.... SET CLOUD TOP PRESSURE TO 1000 MB WHEN CLOUD TOP TEMPERATURE
C     IS HIGHER THAN THE TEMPERATURE AT 1000 MB LEVEL
      PRSCLD=1000.0
C
  110 CONTINUE
      DPRESS = PRSCLD
C
      RETURN
      END
