      SUBROUTINE PRDHIR(SFCTYP,TERHGT,TCLEAR,XLAT,T45678,UPRLAT,LOWLAT)
      IMPLICIT NONE
C
C**********************************************************************
C
C   NAME- PRDHIR
C
C   LANGUAGE- VS FORTRAN  TYPE- MAIN
C
C   VERSION- 1.0    DATE- 02/06/91   PROGRAMMER- ZHOU SISONG
C   VERSION- 1.1    DATE- 10/31/91   PROGRAMMER- TIM GARDNER (HSTX)
C   VERSION- 2.0    DATE- 09/27/95   PROGRAMMER- LEAH CASEY (HSTX)
C   VERSION- 2.1    DATE- 06/03/96   PROGRAMMER- LEAH CASEY (HSTX)
C   VERSION- 3.0    DATE- 11/13/97   PROGRAMMER- BRIAN BARIL (HSTX)
C   VERSION- 3.1    DATE- 01/08/99   PROGRAMMER- BRIAN BARIL (RITS)
C   VERSION- 3.2    DATE- 11/22/99   PROGRAMMER- A. ALLEGRINO (RAYTHEON)
C   VERSION- 3.3    DATE- 12/01/99   PROGRAMMER- A. ALLEGRINO (RAYTHEON)
C   VERSION- 3.4    DATE- 02/10/00   PROGRAMMER- A. ALLEGRINO (RAYTHEON)
C   VERSION- 3.5    DATE- 10/22/01   PROGRAMMER- A. ALLEGRINO (RAYTHEON)
C   VERSION- 3.6    DATE- 09/17/03   PROGRAMMER- F. TILLEY (RAYTHEON)
C   VERSION- 3.7    DATE- 01/20/04   PROGRAMMER- F. TILLEY (RAYTHEON)
C   VERSION- 3.8    DATE- 05/20/04   PROGRAMMER- F. TILLEY (RAYTHEON)
C
C   FUNCTION-*$ED23TG* PREDICTS HIRS 4-8 TEMPS. USING HIRS 1-3 AND
C       AMSUA 5,7,& 9 VALUES.
C   VERSION- 2.0 INCLUSION INTO RTOVS CLDTOP ROUTINE.
C   VERSION- 2.1 MODS FOR ATTENUATION ABOVE THE CLOUDS.
C   VERSION- 3.0 MODIFICATIONS FOR INCLUSIONS INTO ATOVS.
C   VERSION- 3.1 ADDED A CONDITION IN WHICH IF OVER LAND FOR ZONE
C                ONE, USE ZONE 2 COEFS. OTHERWISE USE ZONE 1.
C   VERSION- 3.2 CHANGED THE TEST OVER LAND FOR ZONE 1 TO INCLUDE
C                SNOW COVERED LAND (TERRAIN TYPE = SNOW)
C   VERSION- 3.3 CHANGED THE CODE TO USE ZONE 2 COEFFICIENTS FOR ZONE 1
C                FOR ALL TERRAIN TYPES.
C   VERSION- 3.4 CHANGED THE CODE TO USE ZONE 1 COEFFICIENTS FOR ZONE 1
C                FOR ALL TERRAIN TYPES.
C   VERSION- 3.5 CHANGED THE CODE TO USE COMPUTED COEFFICIENTS WITHIN 
C                CERTAIN LATITUDE TRANSITION ZONES AS DEFINED VIA THE
C                SOFTFLAGS FILE. (WR#176)
C   VERSION- 3.6 ADDED 'TERHGT' TO CALLING ARGUMENTS AND MADE THE USE
C                OF AMSU-A CHANNEL COMBINATIONS DEPENDENT UPON SURFACE
C                TYPE AND TERRAIN HEIGHT.
C                  AMSU-A 4, 5, 6    OCEAN
C                  AMSU-A 5, 6, 7    NON-SEA BELOW 1600 METERS
C                  AMSU-A 6, 7, 8    NON-SEA ABOVE 1600 METERS 
C   VERSION- 3.7 ADDED ANOTHER SET OF CHANNEL COMBINATIONS FOR 
C                ELEVATIONS ABOVE 2900 METERS. 
C                  AMSU-A 4, 5, 6    OCEAN
C                  AMSU-A 5, 6, 7    NON-SEA BELOW 1600 METERS
C                  AMSU-A 6, 7, 8    NON-SEA BETWEEN 1600-2900 METERS
C                  AMSU-A 7, 8, 9    NON-SEA ABOVE 2900 METERS
C                ADDING AMSU-A CHANNEL 9 REQUIRED INCREASING THE
C                SIZE OF THE TCLEAR ARRAY.
C   VERSION- 3.8 ADDED CODE TO COMPUTE INTERPOLATION SLOPES AND
C                INTERCEPTS LOCALLY INSTEAD OF HAVING THEM PASSED
C                IN FROM THE CALLING ROUTINE. (WR #257)
C   
C
C   PARAMETERS-
C      VARIABLE                TYPE I/O FUNCTION
C      --------                ---- --- --------
C      SFCTYP                  INT   I   SURFACE TYPE
C      TERHGT                  INT   I   TERRAIN HEIGHT
C      TCLEAR(27)              REAL  I/O HIRS AND AMSU-A CLEAR B. TEMPS.
C      XLAT                    REAL  I   LATITUDE OF MINIBOX.
C      T45678                  REAL  I   COEFFICIENTS FOR PREDICTING
C                                        HIRS CHANNELS 4-8.
C      UPRLAT(4)               REAL  I   NORTHERNMOST LATITUDE LIMIT FOR
C                                        INTERPOLATION
C      LOWLAT(4)               REAL  I   SOUTHERNMOST LATITUDE LIMIT FOR
C                                        INTERPOLATION
C      COEFA,COEFB,COEFC       REAL      THE INTERPOLATED COEFFICIENTS USED
C                                        IN THE LATITUDE TRANSITION AREAS.
C      CHKFLAG                 REAL      A FLAG WHICH DECLARES IF THE LATITUDE
C                                        IS WITHIN THE INTERPOLATION ZONES.
C      SLOPEA,SLOPEB,SLOPEC    REAL      LOCALLY COMPUTED SLOPES FOR GENERATING
C                                        COEFA, COEFB, AND COEFC
C      INTRCA,INTRCB,INTRCC    REAL      LOCALLY COMPUTED INTERCEPTS FOR
C                                        GENERATING COEFA, COEFB, AND COEFC
C
C     COMMON AREAS- NONE
C
C     SUBROUTINES CALLED- NONE
C
C**********************************************************************
C
C
      REAL   TCLEAR(27), XLAT, SUM4, SUM5, SUM6, SUM7, SUM8
      REAL   T45678(7,5,5), COEFA,COEFB,COEFC
      REAL   SLOPEA, SLOPEB, SLOPEC, INTRCA, INTRCB, INTRCC
      REAL   UPRLAT(4),LOWLAT(4)
      REAL   SLOPE(7,5,4), INTRC(7,5,4)
      INTEGER   SFCTYP, TERHGT, NZ, STATUS,I,L,CHKFLAG
      INTEGER AMSUCH, INZ, CHN, ICOEF
C
      IF(XLAT.GT.60.0) THEN
         NZ=1
      ELSEIF(XLAT.GT.30.0) THEN
         NZ=2
      ELSEIF(XLAT.GT.-30.0) THEN
         NZ=3
      ELSEIF(XLAT.GT.-60.0) THEN
         NZ=4
      ELSE
         NZ=5
      ENDIF
C
C ============================>
C  PREDICT HIRS/2 CH. 4,5,6,7&8 RADIANCES FROM HIRS/2 CH. 1,2&3
C  AND AMSUA CH. 5,7, & 9
C  9/17/03 BASE THE AMSU-A CHANNELS TO USE BASED ON TERRAIN TYPE
C  AND TERRAIN HEIGHT.
C
      SUM4=0.0
      SUM5=0.0
      SUM6=0.0
      SUM7=0.0
      SUM8=0.0
C
C SET THE STARTING POINT IN THE TCLEAR ARRAY FOR EXTRACTING 
C AMSU-A CHANNEL BRIGHTNESS TEMPERATURES.
C  
C   OVER OCEAN USE AMSU-A CHANNELS 4, 5, AND 6
C
      IF (SFCTYP.EQ.0) THEN
         AMSUCH = 21
      END IF
C
C   OVER NON-SEA BELOW 1600 METERS USE AMSU-A CHANNELS 5, 6, 
C   AND 7.
C   BETWEEN 1600 AND 2900 METERS USE AMSU-A CHANNELS, 6, 7, AND 8.
C   ABOVE 2900 METERS USE AMSU-A CHANNELS 7, 8, AND 9
C
      IF (SFCTYP.NE.0) THEN
         IF (TERHGT.LT.1600) 
     +      AMSUCH = 22
         IF (TERHGT.GE.1600.AND.TERHGT.LE.2900)
     +      AMSUCH = 23
         IF (TERHGT.GT.2900)
     +      AMSUCH = 24
      END IF
C
C  COMPUTE SLOPES AND INTERCEPTS FOR INTERPOLATION WITHIN TRANSITION
C  ZONES
C
      DO INZ=1,4
         DO CHN = 1,5
            DO ICOEF= 1,7
               SLOPE(ICOEF,CHN,INZ) = (T45678(ICOEF,CHN,INZ) -
     +                                T45678(ICOEF,CHN,INZ+1)) /
     +                                (UPRLAT(INZ) - LOWLAT(INZ))
               INTRC(ICOEF,CHN,INZ) = T45678(ICOEF,CHN,INZ) -
     +                                (SLOPE(ICOEF,CHN,INZ)*UPRLAT(INZ)) 
            END DO
         END DO
      END DO
C
C  CHECK THE LATITUDE FOR EACH SPOT AND IF IT FALLS WITHIN THE
C  TRANSITION ZONES COMPUTE COEFA AND COEFB AND APPLY THESE TO THE 
C   TEMPERATURES. (ASA,10/22/01)
C
      DO 400 L=1,3
       CHKFLAG =0
       DO I=1,4
         IF(XLAT.LT.UPRLAT(I) .AND. XLAT.GT.LOWLAT(I)) THEN
          COEFA = SLOPE(L+1,1,I)*XLAT + INTRC(L+1,1,I)
          COEFB = SLOPE(L+4,1,I)*XLAT + INTRC(L+4,1,I)
          SUM4=SUM4+COEFA*TCLEAR(L)+COEFB*TCLEAR(L+AMSUCH)
C
          COEFA = SLOPE(L+1,2,I)*XLAT + INTRC(L+1,2,I)
          COEFB = SLOPE(L+4,2,I)*XLAT + INTRC(L+4,2,I)
          SUM5=SUM5+COEFA*TCLEAR(L)+COEFB*TCLEAR(L+AMSUCH)
C
          COEFA = SLOPE(L+1,3,I)*XLAT + INTRC(L+1,3,I)
          COEFB = SLOPE(L+4,3,I)*XLAT + INTRC(L+4,3,I)
          SUM6=SUM6+COEFA*TCLEAR(L)+COEFB*TCLEAR(L+AMSUCH)
C
          COEFA = SLOPE(L+1,4,I)*XLAT + INTRC(L+1,4,I)
          COEFB = SLOPE(L+4,4,I)*XLAT + INTRC(L+4,4,I)
          SUM7=SUM7+COEFA*TCLEAR(L)+COEFB*TCLEAR(L+AMSUCH)
C
          COEFA = SLOPE(L+1,5,I)*XLAT + INTRC(L+1,5,I)
          COEFB = SLOPE(L+4,5,I)*XLAT + INTRC(L+4,5,I)
          SUM8=SUM8+COEFA*TCLEAR(L)+COEFB*TCLEAR(L+AMSUCH)
C
          CHKFLAG =1
         ENDIF
        ENDDO
C
        IF(CHKFLAG .EQ. 0) THEN
           SUM4 =
     1     SUM4+T45678(L+1,1,NZ)*TCLEAR(L)+T45678(L+4,1,NZ)*
     2     TCLEAR(L+AMSUCH)
          SUM5 =
     1     SUM5+T45678(L+1,2,NZ)*TCLEAR(L)+T45678(L+4,2,NZ)*
     2     TCLEAR(L+AMSUCH)
          SUM6 =
     1     SUM6+T45678(L+1,3,NZ)*TCLEAR(L)+T45678(L+4,3,NZ)*
     2     TCLEAR(L+AMSUCH)
          SUM7 =
     1     SUM7+T45678(L+1,4,NZ)*TCLEAR(L)+T45678(L+4,4,NZ)*
     2     TCLEAR(L+AMSUCH)
          SUM8 =
     1     SUM8+T45678(L+1,5,NZ)*TCLEAR(L)+T45678(L+4,5,NZ)*
     2     TCLEAR(L+AMSUCH)
         ENDIF
C
  400 CONTINUE
C
C RESET THE VARIABLE CHKFLAG TO INCLUDE THE INTERCEPTS INTO THE SUMS
C AND FINALIZE THE PREDICTED TEMPERATURES
C
      CHKFLAG =0
      DO I=1,4
       IF(XLAT.LT.UPRLAT(I) .AND. XLAT.GT.LOWLAT(I)) THEN
        COEFC = SLOPE(1,1,I)*XLAT + INTRC(1,1,I)
        TCLEAR(4) = COEFC + SUM4
C
        COEFC = SLOPE(1,2,I)*XLAT + INTRC(1,2,I)
        TCLEAR(5) = COEFC + SUM5
C
        COEFC = SLOPE(1,3,I)*XLAT + INTRC(1,3,I)
        TCLEAR(6) = COEFC + SUM6
C
        COEFC = SLOPE(1,4,I)*XLAT + INTRC(1,4,I)
        TCLEAR(7) = COEFC + SUM7
C
        COEFC = SLOPE(1,5,I)*XLAT + INTRC(1,5,I)
        TCLEAR(8) = COEFC + SUM8
        CHKFLAG=1
       ENDIF
      ENDDO
C
      IF(CHKFLAG .EQ. 0) THEN
        TCLEAR(4) = T45678(1,1,NZ) + SUM4
        TCLEAR(5) = T45678(1,2,NZ) + SUM5
        TCLEAR(6) = T45678(1,3,NZ) + SUM6
        TCLEAR(7) = T45678(1,4,NZ) + SUM7
        TCLEAR(8) = T45678(1,5,NZ) + SUM8
      ENDIF
C
 1000 CONTINUE
      RETURN
      END
