      SUBROUTINE GETSML(SKNTMP,SST,SURELV,SML)
      IMPLICIT NONE
C
C**********************************************************************
C
C   NAME- GETSML
C
C   LANGUAGE- VS FORTRAN     TYPE- SUBROUTINE    COMPUTER- CRAY J916
C
C   VERSION- 1.0    DATE- 07/19/94   PROGRAMMER- M. LIU (HUGHES STX)
C   VERSION- 2.0    DATE- 02/08/95   PROGRAMMER- L. WILSON (HSTX) 
C     VERSION- 2.0 MODIFICATION FOR ADDITION TO RTOVS SPGDVR.
C   VERSION- 2.1    DATE- 07/21/95   PROGRAMMER- LI LU (SMSRC)
C   VERSION- 3.0    DATE- 05/14/96   PROGRAMMER- ALEX POZDNYAK, FDC
C      FOR REHOSTING TO THE CRAY, CHANGED ALL I*4 DECLARATIONS TO
C      INTEGER AND ALL R*4 DECLARATIONS TO REAL.
C   VERSION- 3.1    DATE- 10/09/97   PROGRAMMER- LEAH WILSON (HSTX)
C   VERSION- 3.2    DATE- 12/29/99   PROGRAMMER- LEAH WILSON (RAYTHEON)
C   VERSION- 4.0    DATE- 02/27/03   PROGRAMMER- Rickey Rollins (CSC)
C        Replace R4SPV equivalence test with ISR4SPV function
C   VERSION- 4.1    DATE- 09/27/04   PROGRAMMER- FRANK TILLEY (RAYTHEON)
C
C   FUNCTION-THIS SUBROUTINE DETERMINES A RETRIEVAL'S SURFACE MODEL
C            LEVEL FROM ITS SURFACE ELEVATION AND SURFACE TEMPERATURE.
C   VERSION- 3.1  ALLOW SURFACE MODEL LEVELS UP TO LEVEL 42.
C   VERSION- 3.2  ADD CHECK FOR TSFC = 0.0. 
C   VERSION- 4.1  REMOVED CODE THAT SET THE SML TO 40 IF THE CALCULATED
C                 PRESSURE EXCEEDS 1013 MB.
C
C   CALLING SEQUENCE PARAMETERS -
C     VARIABLE          TYPE  I/O  DESCRIPTION
C     --------          ----  ---  ----------------------------------
C     SKNTMP            REAL   I   DERIVED SKIN TEMPERATURE.
C     SST               REAL   I   SEA SURFACE TEMPERATURE.
C     SURELV            REAL   I   SURFACE ELEVATION.
C     SML               INT    O   SURFACE MODEL LEVEL.
C
C   FUNCTIONS USED- EXP, ABS
C
C   COMMON AREAS- SPVAL, RETPARM, RTPLVL
C
C   LOCAL VARIABLES-
C   VARIABLE   TYPE  FUNCTION
C   --------   ----  --------
C   DP         REAL  DIFFERENCE BETWEEN A RETRIEVAL LEVEL PRESSURE AND
C                    THE SURFACE PRESSURE.
C   NEWL        INT  INDEX TO THE RETRIEVAL PRESSURE LEVEL ARRAY.
C   NPRTP1      INT  USE TO SET UP THE INDEX TO RETRIEVAL PRESSURE LEVEL
C                    FROM 40, 39,... AND UPWARD.
C   PREF       REAL  SURFACE REFERENCE PRESSURE (1013MB).
C   PSFC       REAL  CALCULATED SURFACE PRESSURE.
C   RG         REAL  SPECIFIC GAS CONSTANT DIVIDED BY THE GRAVITATIONAL
C                    ACCELERATION (29.287 DEG K -1).
C   SAVEP      REAL  SMALLEST DIFFERENCE BETWEEN A RETRIEVAL LEVEL
C                    PRESSURE AND THE SURFACE PRESSURE.
C   TSFC       REAL  SURFACE TEMPERATURE.
C   L           INT  LOOP INDEX.
C
C   EXIT STATUS-  NONE
C
C   COMMENTS- SURFACE MODEL LEVEL IS THE CLOSEST RETRIEVAL PRESSURE 
C	      LEVEL. IF SURFACE TEMPERATURE IS NOT AVAILABLE, SML IS SET 
C	      AS I4SPV.
C**********************************************************************
C
      INCLUDE 'SPVAL'
      INCLUDE 'RETPARM'
      INCLUDE 'RTPLVL'
C
      REAL      SKNTMP,SST,SURELV
      INTEGER   SML
C
      INTEGER   L,NEWL,NPRTP1
      REAL      DP,RG,PREF,TSFC,PSFC,SAVEP
      LOGICAL ISR4SPV
C
      DATA PREF /1013.0/
      DATA RG /29.287/
C
C  CHECK FOR AVAILABILITY OF DERIVED SKIN TEMPERATURE
C
      IF (ISR4SPV(SKNTMP) .AND. ISR4SPV(SST)) THEN
         IF (SURELV .EQ. 0.0) THEN
            SML = 40
         ELSE
            SML = I4SPV
         ENDIF
         GO TO 1000
      ENDIF
C
C.... CALCULATE PRESSURE AT SURFACE(MB)
C
      IF (.NOT. ISR4SPV(SKNTMP)) THEN
         TSFC = SKNTMP
      ELSE
         TSFC = SST
      ENDIF
C                                                                    
C.... IF BAD DATA COMES IN, IT IS POSSIBLE THAT THE SKNTMP = R4SPV   
C     BUT SST = 0.0, SO THE CHECK ABOVE WOULD SET TSFC = 0.0, CAUSING
C     PROBLEMS CALCULATING PSFC.  IF THIS HAPPENS, SET THE SURFACE   
C     MODEL LEVEL TO MISSING AND EXIT.                               
                                                                     
      IF(TSFC.LE.0.0) THEN                                           
         SML = I4SPV                                                 
         GO TO 1000                                                  
      ENDIF                                                          
C                                                                    
      PSFC = PREF/(EXP(SURELV/(RG*TSFC)))
C
C.... CALCULATE THE RETRIEVAL'S SURFACE MODEL LEVEL
C
ccft  IF (PSFC .GE. PREF) THEN
C
C.... USE 1000 MB AS ITS SURFACE PRESSURE
C
ccft     SML = 40
ccft  ELSE
C
C.... FIND THE CLOSEST RETRIEVAL PRESSURE LEVEL AS ITS LEVEL
C
         NPRTP1 = 42 + 1
         SAVEP = PREF
         DO 80 L = 1, 20
            NEWL = NPRTP1 - L
            DP = ABS(PROFLV(NEWL) - PSFC)
            IF (DP .LE. SAVEP) THEN
               SML = NEWL
               SAVEP = DP
            ENDIF
   80    CONTINUE
C
ccft  END IF
C
 1000 RETURN
      END
