       SUBROUTINE LEVTOV(PRESS,TOVLEV)
       IMPLICIT NONE
C***************************************************************
C
C  NAME- LEVTOV
C
C  LANGUAGE- FORTRAN     TYPE- SUBROUTINE  COMPUTER- AIX
C
C  VERSION- 1.0    DATE- 10/17/06  PROGRAMMER- FRANK TILLEY (IMSG)
C
C  FUNCTION- THIS SUBROUTINE RETURNS THE TOVS LEVEL NUMBER
C            CORRESPONDING TO A GIVEN PRESSURE. IT USES THE SAME
C            CONVENTIONS USED IN CALCULATING THE SURFACE MODEL
C            LEVEL FOR ATOVS RETRIEVALS.
C
C  CALLING ARGUMENTS-
C  NAME     TYPE  I/O  DESCRIPTION
C  ----     ----  ---  -----------
C  PRESS    REAL   I   PRESSURE (MB) FOR WHICH THE TOVS LEVEL
C                      IS TO BE CALCULATED.
C  TOVLEV    INT   O   TOVS LEVEL CORRESPONDING TO THE INPUT 
C                      PRESSURE
C
C  LOCAL VARIABLES-
C  NAME     TYPE   DESCRIPTION
C  ----     ----   -----------
C  DELTAP   REAL   ABSOLUTE DIFFERENCE BETWEEN THE INPUT PRESSURE
C                  AND THE PRESSURE AT A TOVS LEVEL.
C  LEV       INT   LOOP INDEX
C  SAVEDP   REAL   SAVED ABSOLUTE DIFFERENCE IN PRESSURE FOR USE
C                  IN COMPARISON WITH DELTAP.
C
C  EXIT STATES-  LEVTOV IS RETURNED AS 0 IF NO LEVEL CAN BE
C                DETERMINED.
C  
C***************************************************************
C
       INCLUDE 'RETPARM'
       INCLUDE 'RTPLVL'
C
       INTEGER  TOVLEV
       REAL     PRESS
C
       REAL     DELTAP, SAVEDP
       INTEGER  LEV
C
       TOVLEV = 0

C-- INITIALIZE THE SAVED PRESSURE TO AN UNREALISTICALLY HIGH
C   VALUE

       SAVEDP = 9999.0

C-- LOOP THROUGH THE TOVS PRESSURE ARRAY LOOKING FOR A LEVEL
C   WHOSE PRESSURE IS CLOSEST TO THE PRESSURE FOR WHICH A
C   TOVS LEVEL IS TO BE CALCULATED. START AT THE BOTTOM OF
C   THE ATMOSPHERE AND WORK UPWARD.

       DO LEV = 40, 1, -1
          DELTAP = ABS(PRESS - PROFLV(LEV))
          IF (DELTAP .LE. SAVEDP) THEN
             TOVLEV = LEV
          END IF
          SAVEDP = DELTAP
       END DO


       IF (PRESS.GT.1000.0.AND.TOVLEV.EQ.0) THEN
          print *,'LEVTOV: TOVLEV set to 0 because input pressure ',
     +            PRESS,' is unreasonable' 
       END IF

C
       RETURN
       END
