      SUBROUTINE HOTSFC(TSFC8,TSFC18,HIRS8,HIRS18,OVRLND,TSTLIM,NIGHT,
     + TSTLM2,RESULT,ERSTAT)
      IMPLICIT NONE
C***********************************************************************
C
C   NAME-  HOTSFC
C
C   LANGUAGE- VS FORTRAN  TYPE- SUBROUTINE      COMPUTER- CRAY J916
C
C   VERSION- 1.0    DATE- 3/3/93     PROGRAMMER- CARLA A. 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      MODIFY FOR NIGHT USE (WR # 183).
C
C   VERSION- 3.2    DATE- 11/16/01   PROGRAMMER- RICKEY ROLLINS (CSC)
C      PORTED TO IBM SP - DEFINED SUBNAM & NAME                      
C   VERSION- 3.3    DATE- 02/27/03   PROGRAMMER- Rickey Rollins (CSC)
C        Replace R4SPV equivalence test with ISR4SPV function 
C   VERSION- 3.4    DATE- 11/24/04   PROGRAMMER- FRANK TILLEY (RAYTHEON)
C        REMOVED SUBNAM, SINCE IT IS ALREADY DECLARED IN A COMMON.
C        DECLARED CALLING ARGUMENT 'TSTLM2' AS REAL. REMOVED UNUSED
C        CHARACTER VARIABLE 'NAME'. 
C
C   FUNCTION-  THIS SUBROUTINE PERFORMS THE HOT SURFACE TEST.  THE
C              HOT SURFACE TEST IS A RESTORAL CLOUD TEST PERFORMED
C              ON SPOTS OVER LAND THAT WERE PREVIOUSLY DECLARED CLOUDY.
C              IF THE SURFACE TEMPERATURE VALUE COMPUTED FROM HIRS
C              CHANNEL 8 IS GREATER THAN OR EQUAL TO THE TEST LIMIT,
C              THE SPOT IS DECLARED CLEAR.
C
C   CALLING SEQUENCE PARAMETERS-
C   NAME    TYPE   I/O   DESCRIPTION
C   ----    ----   ---   -----------
C   TSFC8   REAL    I    SURFACE TEMPERATURE VALUE COMPUTED FROM
C                        HIRS CHANNEL 8.
C   OVRLND  LOGICAL I    LOGICAL FLAG INDICATING WHETHER HIRS SPOT
C                        IS OVER LAND OR WATER (TRUE = OVER LAND,
C                        FALSE = OVER WATER).
C   TSTLIM  REAL    I    TEST LIMIT FOR THE SURFACE TEMPERATURE VALUE.
C   NIGHT   LOGICAL I    LOGICAL FLAG INDICATING WHETHER HIRS SPOT
C                        IS DURING DAY OR NIGHT (TRUE - NIGHT)
C   TSTLM2  REAL    I    TEST LIMIT FOR THE SURFACE TEMPERAURE VALUE
C                        DURING THE NIGHT.
C   RESULT  INT    I/O   RESULT OF THE HOT SURFACE TEST.  VALUE IS
C                        0 IF THE TEST DETERMINED THE SPOT IS CLOUDY, 1
C                        IF THE TEST DETERMINED THE SPOT CLEAR AND 2 IF
C                        THE TEST WAS NOT PERFORMED.
C   ERSTAT  INT     O    ERROR RETURN CODE
C                         = 0 IF NO ERROR OCCURRED,
C                         = 10 IF NON-FATAL ERROR OCCURRED,
C                         = 99 IF FATAL ERROR OCCURRED.
C
C   LOCAL PARAMETERS-
C   NAME    TYPE   DESCRIPTION
C   ----    ----   -----------
C   STATUS   INT   ERROR STATUS RETURNED FROM HOTSF$.
C
C   SUBPROGRAMS CALLED-  HOTSF$
C
C   EXIT STATES-
C     ERSTAT = 10 : TEST LIMIT IS A MISSING VALUE
C     ERSTAT = 99 : FATAL ERROR RETURNED FROM HOTSF$
C
C   COMMENTS-
C
C    IT IS ASSUMED THAT RESULT HAS BEEN INITIALIZED TO 2 BEFORE THIS
C    ROUTINE IS CALLED.
C
C     THE REFERENCE FOR THIS TEST IS:
C      CHEDIN ET AL, "RECENT PROGRESS IN THE DETERMINATION OF
C      METEOROLOGICAL PARAMETERS FROM THE SATELLITES OF THE TIROS-N
C      SERIES".  TECHNICAL PROCEEDINGS THIRD ITOVS STUDY CONFERENCE,
C      13-19 AUGUST 1986, MADISON, WI.
C
C***********************************************************************
      REAL TSFC8, TSTLIM, HIRS8,HIRS18,TSFC18, TSTLM2
      INTEGER RESULT, ERSTAT
      LOGICAL OVRLND,NIGHT
      LOGICAL ISR4SPV
C
      INTEGER STATUS
C
      INCLUDE 'SPVAL'
C
      ERSTAT = 0
C
C   THE HOT SURFACE TEST IS ONLY PERFORMED FOR SPOTS OVER LAND.
C
      IF (OVRLND) THEN
C
C      IF THE TEST LIMIT IS MISSING, WRITE A WARNING MESSAGE TO THE
C      KIDS MESSAGE LOG FILE AND SKIP THIS TEST.
C
         IF (ISR4SPV(TSTLIM)) THEN
            CALL HOTSF$(101,STATUS)
            ERSTAT = 10
            IF (STATUS .EQ. 99) ERSTAT = 99
            RETURN
         ENDIF
C
C      IF THE HIRS CHANNEL 8 COMPUTED SURFACE TEMPERATURE IS >= THE
C      TEST LIMIT, THE SPOT IS MARKED CLEAR.
C
         IF(NIGHT)THEN
          IF (HIRS8 .GE. TSTLM2) THEN
             RESULT = 1
          ELSE
             RESULT = 0
          ENDIF
         ELSE
          IF (HIRS8 .GE. TSTLIM) THEN
             RESULT = 1
          ELSE
             RESULT = 0
          ENDIF
         ENDIF 
      ENDIF
C
      RETURN
      END
C**********************************************************************
      SUBROUTINE HOTSF$(MSGCOD,STAT)
C
C**********************************************************************
C
C   NAME- HOTSF$
C
C   LANGUAGE- VS FORTRAN  TYPE- SUBROUTINE      COMPUTER- CRAY J916
C
C   VERSION- 1.0    DATE- 3/3/93    PROGRAMMER- CARLA NEIGH (SMSRC)
C   VERSION- 3.0    DATE- 10/07/97  PROGRAMMER- LEAH WILSON (HSTX)
C
C   FUNCTION- THIS SUBROUTINE WRITES OUT ERROR MESSAGES TO THE
C             KIDS MESSAGE LOG FILE FOR THE SUBROUTINE HOTSFC.
C   VERSION- 3.0 WRITE ERROR MESSAGES TO THE KIDS FILE.  INCLUDE /SPGUNT/.
C
C   FILES-
C     DSN OR DESCRIPTIVE TITLE I/O   UNIT  FUNCTIONAL DESCRIPTION
C     ------------------------ ---   ----  ----------------------
C     ...KIDS                   O    KUNIT KRAY INTERACTIVE DOCUMENTATION
C
C   CALLING SEQUENCE PARAMETERS-
C     VARIABLE          TYPE I/O  FUNCTION
C     --------          ---- ---  --------
C     MSGCOD             INT  I   MESSAGE CODE OF ERROR DETECTED.
C     STAT               INT  O   ERROR STATUS CODE
C                                  = 0 IF NO ERROR OCCURRED,
C                                 <> 0 IF ERROR OCCURRED.
C
C   COMMON AREA PARAMETERS-
C
      INCLUDE 'SPGUNT'
      INCLUDE 'ERPARM'
      INCLUDE 'ERINFO'
C
C   LOCAL PARAMETERS-
C     VARIABLE          TYPE  FUNCTION
C     --------          ----  --------
C     I                  INT  DO LOOP CONTROL INDEX.
C     COUNT              INT  COUNTER FOR NUMBER OF TIMES $-ROUTINE
C                             HAS BEEN INVOKED.
C     KMSG             CH*100 KIDS MESSAGE BUFFER
C     C4TEMP            CH*4  HOLDING BUFFER FOR WRITING TO KIDS
C
C   SUBROUTINES CALLED- KIDS
C
C   EXIT STATES-
C       STAT =  1; INDICATING NO OR A NON-FATAL ERROR WAS DETECTED.
C       STAT = 99; INDICATING A FATAL ERROR WAS DETECTED.
C
C***********************************************************************
C
      CHARACTER*4   C4TEMP
      CHARACTER*100 KMSG
      INTEGER   STAT, I, MSGCOD, COUNT
C
      DATA COUNT /0/
      SAVE COUNT
C
C   SET THE SUBROUTINE NAME.
C
      SUBNAM = 'HOTSFC  '
      STAT = 0
C
      COUNT = COUNT + 1
C
      IF (COUNT .LE. 1) THEN
C
C     CHECK FOR VALID MESSAGE CODES.
C
        IF (MSGCOD .EQ. 101) THEN
          KMSG(1:50)='* WARNING * Hot Surface Restoral Test could not '
          KMSG(51:100)='be performed - test limit is a missing value. '
          CALL KIDS(KUNIT,SUBNAM,0,KMSG,0)
C
C
C NOT A VALID MSGCOD
C
        ELSE
          STAT=0
          KMSG = ' Invalid error message code = '
          WRITE(C4TEMP,'(I4)') MSGCOD
          KMSG(31:34) = C4TEMP
          CALL KIDS(KUNIT,SUBNAM,0,KMSG,0)
        ENDIF
      ENDIF
      RETURN
      END
