      SUBROUTINE RESTOR2(CLOUDY,RESULT,HIRS8,HIRS18,ERSTAT)
      IMPLICIT NONE
C***********************************************************************
C
C   NAME-  RESTOR2
C
C   LANGUAGE- VS FORTRAN  TYPE- SUBROUTINE      COMPUTER- CRAY J916
C
C   VERSION- 1.0     DATE- 2/11/93    PROGRAMMER- CARLA NEIGH, SMSRC
C   VERSION- 3.0    DATE- 05/29/96   PROGRAMMER- LEAH WILSON (HSTX)
C          SYNTAX MODS FOR ATOVS BASELINE ON CRAY.
C   VERSION- 3.1     DATE- 12/11/01   PROGRAMMER- M.P.FERGUSON (RITSS)
C          PROGRAM MODIFED TO PASS HIRS AND 18 TO SUBROUTINE HOTSFC, 
C          AS WELL AS THE HIRS 18 SURFACE TEMPERATURE ESTIMATE, AND 
C          THE NIGHT THRESHOLD, TESTLIM2 (WR # 183).
C
C   FUNCTION-  THIS SUBROUTINE IS THE DRIVER FOR THE RESTORAL CLOUD
C              TESTS ON A SINGLE HIRS SPOT.  AT THIS TIME THE ONLY
C              RESTORAL TEST PERFORMED IS THE HOT SURFACE TEST.
C              THE RESTORAL TESTS ARE PERFORMED ONLY ON HIRS SPOTS
C              WHICH WERE PREVIOUSLY FOUND TO BE CLOUDY.  IF ANY
C              RESTORAL TEST CONDITIONS ARE PASSED, THE SPOT IS
C              RESET TO CLEAR.
C
C   CALLING SEQUENCE PARAMETERS-
C   NAME    TYPE   I/O   DESCRIPTION
C   ----    ----   ---   -----------
C   CLOUDY LOGICAL I/O   LOGICAL FLAG SET TO FALSE IF ANY OF THE
C                        RESTORAL TEST CONDITIONS ARE PASSED, OTHERWISE
C                        REMAINS TRUE.
C   RESULT   INT   I/O   RESTORAL TEST RESULTS.  VALUE IS 0 IF THE
C                        TEST DETERMINED THE SPOT IS CLOUDY, 1 IF
C                        THE TEST DETERMINED THE SPOT IS NOT CLOUDY,
C                        AND 2 IF THE TEST WAS NOT PERFORMED.  THIS
C                        VALUE IS ASSUMED TO BE 2 ON INPUT.
C   ERSTAT   INT    O    ERROR STATUS CODE
C                         = 0 IF NO ERROR OCCURRED,
C                         = 99 IF FATAL ERROR OCCURRED.
C
C   COMMON AREA PARAMETERS- REGCOE, CLDPRC, CLDDAT
C
C   LOCAL PARAMETERS-
C   NAME    TYPE   DESCRIPTION
C   ----    ----   -----------
C   STATUS  INT    STATUS CODE RETURNED FROM CALLED ROUTINES.
C
C   SUBPROGRAMS CALLED- HOTSFC
C
C   EXIT STATES-
C      ERSTAT = 99 : FATAL ERROR RETURNED FROM A CALLED SUBROUTINE.
C
C   COMMENTS-
C     THIS ROUTINE IS CALLED ONLY FOR SPOTS WHICH WERE PREVIOUSLY
C     DETERMINED TO BE CLOUDY.
C
C***********************************************************************
C
      LOGICAL CLOUDY
      INTEGER RESULT, ERSTAT
C
      INTEGER STATUS
      REAL HIRS8,HIRS18
C
      INCLUDE 'REGCOE'
      INCLUDE 'CLDPRC'
      INCLUDE 'CLDDAT'

C
      ERSTAT = 0
C
C   PERFORM THE RESTORAL TEST IF THE PROCESSING FLAG IS TRUE.
C
      IF (PRHSFC) THEN
         CALL HOTSFC(TSFC8,TSFC18,HIRS8,HIRS18,OVRLND,HSTSLM,NIGHT,
     +    HSTSL2,RESULT,STATUS)
C-- For cloud-cleared retrievals set the RESULT to 1
         result = 1
         IF (STATUS .EQ. 99) THEN
            ERSTAT = 99
            RETURN
         ENDIF
      ENDIF
C
C   IF THE RESTORAL TEST DETERMINES THAT THE SPOT IS CLEAR, SET THE
C   CLOUDY FLAG TO FALSE.
C
      IF (RESULT.EQ.1) THEN
         CLOUDY = .FALSE.
      ENDIF
C
      RETURN
      END
