      SUBROUTINE CLIMTE(TEMP40,LATUDE,TIME,CLASS,PATH,STATUS)
      IMPLICIT NONE
C
C**********************************************************************
C
C   NAME- CLIMTE
C
C   LANGUAGE- VS FORTRAN  TYPE- SUBROUTINE      COMPUTER- CRAY J916
C
C   VERSION- 1.0    DATE- 01/04/94   PROGRAMMER- DAVE MOREL (SMSRC)
C   VERSION- 2.0    DATE- 05/25/94   PROGRAMMER- JEFF MANNING (SMSRC)
C            XATOV-7  ADDED THE PARAMETER FILE /CDBPARM/ BEFORE THE
C            COMMON /COMCDB/.
C   VERSION- 2.1    DATE- 01/31/95   PROGRAMMER- ALEX POZDNYAK (SMSRC)
C     ATOVS-55: ADDED INCLUDE /RETPARM/. IN BOTH GROSS LIMITS CHECK
C               AND CLIMATOLOGICAL CHECK ON TEMPERATURE, ADDED CHECK FOR
C               MISSING TEMPERATURE AND SKIPPED CHECK FOR THAT LEVEL IF
C               MISSING VALUE IS FOUND. ADDED INCLUDE /SPVAL/.
C   VERSION- 2.2    DATE- 12/11/95   PROGRAMMER- CARLA NEIGH (SMSRC)
C     ATOVS-286: ADDED CHECK FOR OBSQUL ALREADY 3 BEFORE SETTING TO
C                2.  ADDED INPUT ARGUMENTS CLASS AND PATH.  ADDED 
C                INCLUDE FOR /MONSTA/ TO ACCUMULATE STATS FOR 
C                BTPRET ARRAY.
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, ALL L*4 TO LOGICAL, AND ALL R*4 DECLARATIONS TO REAL.
C
C   VERSION- 3.1    DATE- 05/06/98   PROGRAMMER- LEAH WILSON, RSTX 
C      CONVERSION TO NEW 8-BYTE CDB UTILITIES.  REMOVE CLIMT$ SINCE
C      CDB UTILITIES HANDLE THE ERROR THIS TRAPPED.  INCLUDE /SPGUNT/.
C      OBSERVATION QUALITY IS NOW DEFINED DIFFERENTLY, SO REMOVE IT
C      FROM THE CALL TO THIS SUBROUTINE.
C
C   VERSION- 3.2    DATE- 02/29/00   PROGRAMMER- LEAH WILSON, RAYTHEON
C      INITIALIZE RPTDAT TO '000000' TO PREVENT SEASON FROM BOMBING IN
C      CASE OF BAD DATES.  THIS FORCES SEASON TO RETURN A ZERO.
C   VERSION- 3.3    DATE- 02/27/03   PROGRAMMER- Rickey Rollins (CSC)
C        Replace R4SPV equivalence test with ISR4SPV function
C
C   FUNCTION- THIS ROUTINE PERFORMS A CLIMATOLOGICAL LIMITS TEST FOR
C      TEMPERATURE AT THE 17 STANDARD LEVELS AND A GROSS LIMITS CHECK
C      ON ALL RETPARM:PRFTLV PRESSURE LEVELS.
C
C   CALLING SEQUENCE PARAMETERS-
C     VARIABLE          TYPE  I/O  FUNCTION
C     --------          ----  ---  --------
C     TEMP40            REAL   I   VECTOR OF LENGTH RETPARM:PRFTLV
C                                  CONTAINING THE RETRIEVAL TEMPERATURE
C                                  PROFILE (K).
C     LATUDE            REAL   I   LATITUDE OF STATION (DEGREES,
C                                  - = SOUTH, + = NORTH)
C     TIME              INT    I   VECTOR OF 2 CONTAINING THE CENTURY
C                                  DAY AND MILLISECOND OF DAY.
C     CLASS             INT    I   RETRIEVAL CLASS NUMBER.
C     PATH              INT    I   RETRIEVAL PATH (1 = CLEAR/CLOUD-CLEARED,
C                                  2 = CLOUDY, 3 = NOHIRS).
C     STATUS            INT    O   ERROR STATUS CODE.
C
C   COMMON AREA PARAMETERS-
      INCLUDE 'RETPARM'
      INCLUDE 'MONSTA'
      INCLUDE 'SPVAL'
      INCLUDE 'SPGUNT'
C
C   LOCAL PARAMETERS-
C     VARIABLE          TYPE  FUNCTION
C     --------          ----  --------
C       K               INT   DO LOOP INDEX VARIABLE.
C       S               INT   VECTOR OF 17 STANDARD LEVEL INDICES.
C       LAT             INT   LATITUDE ZONE.
C       CTEMP           REAL  TEMPERATURE IN CELSIUS.
C       STYPE           INT   SEASON OF THE YEAR.
C       FIRST           LOG   SET TRUE THE FIRST TIME ONLY.
C       STAT            INT   RETURN STATUS CODE FROM REALCOEF
C       DIG1            INT   FIRST DIGIT OF THE YEAR.
C       DIG2            INT   SECOND DIGIT OF THE YEAR.
C       DIG3            INT   FIRST DIGIT OF THE MONTH.
C       DIG4            INT   SECOND DIGIT OF THE MONTH.
C       DIG5            INT   FIRST DIGIT OF THE DAY.
C       DIG6            INT   SECOND DIGIT OF THE DAY.
C       ITIME           INT   VECTOR OF LENGTH 3 TO HOLD THE YYMM,
C                             DDHH, MMSS OF TIME.
C       RPTDAT         CH*6   THE REPORT DATE AS YYMMDD.
C       DIGITS         CH*1   DIGITS 0 - 9.
C       MAXTL          REAL   VECTOR OF LENGTH RETPARM:PRFTLV TO HOLD
C                             THE MAXIMUM TEMPERATURE LIMITS FROM THE
C                             CDB.
C       STDLMT         REAL   ARRAY DIMENSIONED (2,17,12,4) CONTAINING
C                             THE UPPER AND LOWER LIMITS OF TEMPERATURES
C                             AT THE 17 STANDARD LEVELS, AT 12 LATUTIDE
C                             ZONES FOR ALL 4 SEASONS.
C
C   SUBPROGRAMS CALLED-  REALCOEF, ODBTIM
C
C   FUNCTIONS USED- LATZON, SEASON
C
      INTEGER   LATZON, SEASON
C
C
C**********************************************************************
C
      REAL        TEMP40(PRFTLV), LATUDE
      INTEGER     TIME(2), STATUS, CLASS, PATH
C
      INTEGER     K, LAT, STYPE, STAT, S(17), ITIME(3)
      INTEGER     DIG1, DIG2, DIG3, DIG4, DIG5, DIG6
      REAL        CTEMP
      LOGICAL     FIRST
      LOGICAL ISR4SPV
      REAL        MAXTL(PRFTLV), STDLMT(2,17,12,4)
      CHARACTER*6 RPTDAT
      CHARACTER*1 DIGITS(10)
C
      DATA S/40,37,35,31,28,26,25,24,23,20,18,16,15,13,11,10,9/
      DATA DIGITS/'0','1','2','3','4','5','6','7','8','9'/
C
      SAVE FIRST
C
C     INITIALIZE VARIABLE.
C
      STATUS = 0
      FIRST = .TRUE.
C
C     GET THE LIMITS FROM THE CDB.
C
      IF(FIRST) THEN
         FIRST = .FALSE.
         CALL REALCOEF(CDBUNT,'RAOBMTCH','RMCDB   ','MAXTEMP ',PRFTLV,
     1                 0,0,0,MAXTL,'GET',STATUS)
         IF(STATUS.NE.0) GO TO 120
         CALL REALCOEF(CDBUNT,'RAOBMTCH','RMCDB   ','STDTPLIM',2,
     1                 17,12,4,STDLMT,'GET',STATUS)
         IF(STATUS.NE.0) GO TO 120
      ENDIF
      RPTDAT = '000000'
C
C     SET THE QUALITY TO BAD '3', IF THE GROSS LIMITS ARE EXCEEDED.
C
      DO 30 K = 1, PRFTLV
         IF(ISR4SPV(TEMP40(K))) GOTO 30
         IF(TEMP40(K) .GT. MAXTL(K)) THEN
            BTPRET(PATH,CLASS) = BTPRET(PATH,CLASS) + 1
            RETURN
         ENDIF
   30 CONTINUE
C
C     CONVERT THE TIME TO YYMM, DDHH, MMSS AS INTEGERS.
C
      CALL ODBTIM(TIME(1),TIME(2),ITIME)
C
C     CONVERT THE TIME TO YYMM, DDHH, MMSS AS INTEGERS TO YYMMDD AS
C     CHARACTER*6.
C
      DIG1 = ITIME(1) / 1000
      DIG2 = (ITIME(1) - DIG1 * 1000) / 100
      DIG3 = (ITIME(1) - DIG1 * 1000 - DIG2 * 100) / 10
      DIG4 = ITIME(1) - DIG1 * 1000 - DIG2 * 100 - DIG3 * 10
      DIG5 = ITIME(2) / 1000
      DIG6 = (ITIME(2) - DIG5 * 1000) / 100
C
      DO 40 K = 0, 9
         IF(DIG1 .EQ. K) RPTDAT(1:1) = DIGITS(K+1)
         IF(DIG2 .EQ. K) RPTDAT(2:2) = DIGITS(K+1)
         IF(DIG3 .EQ. K) RPTDAT(3:3) = DIGITS(K+1)
         IF(DIG4 .EQ. K) RPTDAT(4:4) = DIGITS(K+1)
         IF(DIG5 .EQ. K) RPTDAT(5:5) = DIGITS(K+1)
         IF(DIG6 .EQ. K) RPTDAT(6:6) = DIGITS(K+1)
   40 CONTINUE
C
C     CALL LATZON AND SEASON FUNCTIONS TO GET LOCATION
C     OF LIMITS IN ARRAYS STDLMT.
C
      LAT =   LATZON(LATUDE)
      STYPE = SEASON(RPTDAT)
C
C     CHECK LATITUDE OR REPORT DATE ARE NOT OUT OF RANGE
C
      IF ((LAT .EQ. 0) .OR. (STYPE .EQ. 0)) THEN
         RETURN
      ELSE
C
C        PERFORM THE CLIMATOLOGICAL LIMIT TESTS FOR TEMPERATURE,
C        AT THE 17 STANDARD LEVELS.
C
         DO 50 K = 1, 17
C
C           THE LOWER AND UPPER LIMITS ARE IN CELSIUS SO CTEMP IS
C           USED TO HOLD THE TEMPERATURE CONVERTED FROM KELVIN TO
C           CELSIUS.
C
            IF (ISR4SPV(TEMP40(S(K)))) GOTO 50
            CTEMP = TEMP40(S(K)) - 273.16
            IF ((CTEMP .LT. STDLMT(1,K,LAT,STYPE)) .OR.
     1              (CTEMP .GT. STDLMT(2,K,LAT,STYPE))) THEN
               BTPRET(PATH,CLASS) = BTPRET(PATH,CLASS) + 1
               RETURN
            ENDIF
   50    CONTINUE
      ENDIF
C
      RETURN
C
C     ERROR IN CDB MANAGEMENT ROUTINE.
C
  120 STATUS=99
      RETURN
      END
