      SUBROUTINE RADCOL(OLRBT,HIROBS,CCHIRBT,ECOFSZ,ECOF37,OLR1ST,OLR,LC1,
     +                  LC2,LC3,LC4,CCOLR,ERSTAT)
      IMPLICIT NONE
C***********************************************************************
C
C   NAME-RADCOL
C
C   LANGUAGE-FORTRAN      TYPE-SUBROUTINE    COMPUTER- IBM SP
C
C   VERSION-1.0   DATE-09/06/95  PROGRAMMER- LEAH WILSON (HUGHES STX)
C   VERSION-1.1   DATE-09/05/96  PROGRAMMER- LEAH WILSON (HUGHES STX)
C   VERSION-1.2   DATE-02/24/97  PROGRAMMER- LEAH WILSON (HUGHES STX)
C   VERSION-3.0   DATE-11/13/97  PROGRAMMER-BRIAN BARIL (HSTX)
C   VERSION-3.1   DATE-03/05/98  PROGRAMMER-LEAH WILSON (RSTX)
C   VERSION- 4.0    DATE- 02/27/03   PROGRAMMER- Rickey Rollins (CSC)
C   VERSION- 4.1  DATE- 03/16/05 PROGRAMMER- FRANK TILLEY (RAYTHEON)
C
C   FUNCTION- THIS SUBROUTINE COMPUTES THE OUTGOING AND DOWNWELLING
C             LONGWAVE RADIATION AT EACH SPOT, AND COMPUTES THE LAYER
C             COOLING RATES FOR 4 LAYERS.
C
C   VERSION- 1.1  UNCOMMENT EVERYTHING FOR INCLUSION INTO SPGDVR.
C   VERSION- 1.2  PASS OLR AND LC1-4 INTO ROUTINE TO STORE
C                 RADIATION PARAMETERS.
C   VERSION- 3.0  MODIFICATIONS FOR INCLUSION INTO ATOVS.
C                 ADDED CALL TO OLRCOE.
C   VERSION- 3.1  ADD CHECK FROM OLRCOE TO NOT CONTINUE IF ERSTAT <>0.
C                 ADD ERSTAT TO CALLING ARGUMENT SO RADCOL IS NOT
C                 CALLED AGAIN IF OLRCOE RETURNED AN ERROR.
C   VERSION- 4.0    DATE- 02/27/03   PROGRAMMER- Rickey Rollins (CSC)
C        Replace R4SPV equivalence test with ISR4SPV function.
C
C   VERSION- 4.1  ADDED CALLING ARGUMENTS 'HIROBS' AND 'ECOFSZ' AND
C                 CHANGED OLR CALCULATION TO USE THESE VALUES TO
C                 MAKE OLR USING NON LIMB-CORRECTED HIRS DATA (WR #265).
C
C   CALLING ARGUMENTS-
C   VARIABLE               TYPE  I/O   DESCRIPTION
C   --------               ----  ---   -----------
C   OLRBT                   REAL  I    HIRS BRIGHTNESS TEMPERATURES
C                                      (LIMB CORRECTED).
C   HIROBS                  REAL  I    HIRS BRIGHTNESS TEMPERATURES
C                                      (NOT LIMB CORRECTED).
C   CCHIRBT                 REAL  I    CLOUD-CLEARED LIMB CORRECTED
C                                      HIRS BRIGHTNESS TEMPERATURES.
C   ECOFSZ                  REAL  I    ELLINGSON COEFFICIENTS BASED
C                                      ON THE SATELLITE ZENITH ANGLE
C                                      OF THE HIRS SPOT.
C   ECOF37                  REAL  I    ELLINGSON COEFFICIENTS CLOSEST
C                                      TO NADIR FOR USE WITH LIMB-CORRECTED
C                                      BRIGHTNESS TEMPERATURES
C   OLR1ST                  LOG  I/O   TRUE IF THIS IS THE FIRST CALL
C                                      TO RADCOL
C   OLR,LC1-4               REAL  O    STORES RADIATION PARAMETERS.
C   CCOLR                   REAL  O    OUTGOING LONGWAVE RADIATION FROM
C                                      CLOUD-CLEARED HIRS CHANNELS.
C   ERSTAT                  INT   O    ERROR STATUS
C
C   SUBPROGRAMS CALLED- NONE
C
C   FUNCTIONS USED-     RLWPLK
C
      REAL  RLWPLK
C
C   COMMON AREAS- CLIMATE SPVAL
C
C***********************************************************************
C
      INCLUDE 'CLIMATE'
      INCLUDE 'SPVAL'

      LOGICAL   OLR1ST
      INTEGER   ERSTAT
      REAL      OLRBT(19),HIROBS(19),ECOFSZ(5),OLR,LC1,LC2,LC3,LC4
      REAL      CCHIRBT(19), ECOF37(5), CCOLR

      INTEGER   IC, ICH, HIRCHN(4), I, J, LN, NEND, ITYPE, LW
      REAL      WAVRAD(6,19),RHOLD(6),TBO,TBM,WV
      LOGICAL   ISR4SPV
      DATA HIRCHN/3,10,11,12/
C
C...INITIALIZE STORAGE ARRAYS TO ZERO BETWEEN SPOTS
C
      TBO = 0.0
      TBM = 0.0
      IF (OLR1ST) THEN
         CALL OLRCOE(ERSTAT)
         IF(ERSTAT.NE.0) RETURN
      ENDIF
      DO 50 I=1,6
         RHOLD(I) = 0.0
         IF(OLR1ST) OCHN(I) = 0
         DO 25 J=1,19
            WAVRAD(I,J) = 0.0
            IF(OLR1ST) LWCHN(I,J) = 0
   25    CONTINUE
   50 CONTINUE
C
C...LOOP OVER CLIMATE TYPES FOR : DLR AND 4 LAYER COOLING RATES.
C
      NEND = 6
      DO 300 ITYPE=2,NEND
C
C...STORE CHANNELS TO BE USED FOR THIS PARAMETER IN THE LWCHN ARRAY
C...BASED ON THE CHANNEL USAGE FLAGS (LWRCHN) STORED IN THE CDB.  ONLY
C...NEED TO DO THIS FOR FIRST CALL TO RADCOL.
C
         IF(OLR1ST) THEN
            LW=1
            DO 100 IC=1,12
               IF(LWRCHN(ITYPE,IC).EQ.0) GO TO 100
               LWCHN(ITYPE,LW) = IC
               OCHN(ITYPE) = OCHN(ITYPE) + 1
               LW = LW + 1
  100       CONTINUE
         ENDIF
C
C...CALCULATE CORRECTED BRIGHTNESS TEMPERATURE (TBO) AND PERFORM
C...MODEL BRIGHTNESS TEMPERATURE CONVERSION (TBM) ON HIRS
C...CHANNELS 1-12.
C
         DO 200 IC = 1,12
            IF(.NOT. ISR4SPV(OLRBT(IC))) THEN
               TBO = BNDCOR(2,IC)*OLRBT(IC) + BNDCOR(1,IC)
               TBM = LWRBTS(ITYPE,IC) * TBO + LWRBTI(ITYPE,IC)
               WV = WVNO(IC)
               IF(TBM.GT.0.0) WAVRAD(ITYPE,IC) = RLWPLK(WV,TBM)
            ELSE
               WAVRAD(ITYPE,IC) = R4SPV
            ENDIF
  200    CONTINUE
  300 CONTINUE
C
C...CALCULATE PARAMETERS (DLR, LC1 THROUGH LC4).
C
      DO 500 ITYPE = 2,NEND
         LN = OCHN(ITYPE)
         DO 400 ICH=1,LN
Cccft            IF(.NOT. ISR4SPV(N(ITYPE,LWCHN(ITYPE,ICH)))) THEN
c Changed to check for positive values rather than missing values.
            IF (WAVRAD(ITYPE,LWCHN(ITYPE,ICH)).GT.0.0) THEN
               RHOLD(ITYPE) = LWRREG(ITYPE,LWCHN(ITYPE,ICH))
     1                        * WAVRAD(ITYPE,LWCHN(ITYPE,ICH)) + RHOLD(ITYPE)
            ELSE
               RHOLD(ITYPE) = R4SPV
               GO TO 410
            ENDIF
  400    CONTINUE
         RHOLD(ITYPE) = RHOLD(ITYPE) + LWRINT(ITYPE)
  410    CONTINUE
c        IF(ITYPE.EQ.2) DLR = RHOLD(ITYPE)
         IF(ITYPE.EQ.3) LC1 = RHOLD(ITYPE)
         IF(ITYPE.EQ.4) LC2 = RHOLD(ITYPE)
         IF(ITYPE.EQ.5) LC3 = RHOLD(ITYPE)
         IF(ITYPE.EQ.6) LC4 = RHOLD(ITYPE)
  500 CONTINUE
C
C USE NON LIMB-CORRECTED HIRS BRIGHTNESS TEMPERATURES
C TO COMPUTE OLR. PERFORM BAND CORRECTION FOR HIRS
C CHANNELS 1-12.
ccft Try making OLR without performing band correction
c    (5/26/2005)
C
      DO IC = 1,12
         IF (.NOT. ISR4SPV(HIROBS(IC))) THEN
ccft            TBO = BNDCOR(2,IC)*HIROBS(IC) + BNDCOR(1,IC)
ccft            TBM = LWRBTS(1,IC) * TBO + LWRBTI(1,IC)
            TBM = HIROBS(IC)
            WV = WVNO(IC)
            IF(TBM.GT.0.0) WAVRAD(1,IC) = RLWPLK(WV,TBM)
         ELSE
            WAVRAD(1,IC) = R4SPV
         ENDIF
      END DO
C
C IF ANY HIRS CHANNEL USED IN THE OLR CALCULATION IS MISSING
C SET OLR TO A MISSING VALUE. OTHERWISE CALCULATE OLR.
C
      DO ICH = 1, 4
         IF (.NOT. ISR4SPV(WAVRAD(1,HIRCHN(ICH)))) THEN
            RHOLD(1) = ECOFSZ(ICH) * WAVRAD(1,HIRCHN(ICH)) + RHOLD(1)
         ELSE
            RHOLD(1) = R4SPV
            GO TO 510
         END IF
      END DO
      OLR = RHOLD(1) + ECOFSZ(5)

C
C CALCULATE OLR USING CLOUD-CLEARED HIRS CHANNELS
C
      DO IC = 1,12
         IF (.NOT. ISR4SPV(CCHIRBT(IC))) THEN
            TBM = CCHIRBT(IC)
            WV = WVNO(IC)
            IF(TBM.GT.0.0) WAVRAD(2,IC) = RLWPLK(WV,TBM)
         ELSE
            WAVRAD(2,IC) = R4SPV
         ENDIF
      END DO

      RHOLD(2) = 0.0
      DO ICH = 1, 4
         IF (.NOT. ISR4SPV(WAVRAD(2,HIRCHN(ICH)))) THEN
            RHOLD(2) = ECOF37(ICH) * WAVRAD(2,HIRCHN(ICH)) + RHOLD(2)
         ELSE
            RHOLD(2) = R4SPV
            GO TO 510
         END IF
      END DO
      CCOLR = RHOLD(2) + ECOF37(5)

  510 CONTINUE
    
      OLR1ST = .FALSE.
C
      RETURN
      END
