      SUBROUTINE CT2RDB(COUNTS,CLCOEF,NUMCHN,NUMSPT,RDIANC,BADLIN)
      IMPLICIT NONE
C
C**********************************************************************
C
C   NAME- CT2RDB
C
C   LANGUAGE- FORTRAN 77  TYPE- SUBROUTINE      COMPUTER- IBM SP
C 
C   VERSION- 1.0    DATE- 01/16/04   PROGRAMMER- FRANK TILLEY (RAYTHEON)
C
C   FUNCTION- THIS ROUTINE CONVERTS THE COUNTS TO RADIANCES BY APPLYING
C             THE CALIBRATION COEFFICIENTS TO THE COUNTS.
C
C   CALLING SEQUENCE PARAMETERS-
C     VARIABLE          TYPE I/O  DESCRIPTION
C     --------          ---- ---  -----------
C     BADLIN            INT   I   AN INPUT INDICATING WHETHER THE CHANNEL
C                                 REFERENCE HAS GOOD CALIBATION COEFFI-
C                                 CIENTS.  IF ONE, THE CHANNEL DOES NOT
C                                 AND HAS ALREADY BEEN FILLED WITH DUMMY
C                                 VALUES.  THUS, IT WILL NOT BE CALCULATED
C                                 IN THIS ROUTINE.
C     COUNTS            INT   I   ARRAY OF COUNTS. DIMENSIONED NUMCHN X
C                                 NUMSPT.
C
C     CLCOEF            REAL  I   ARRAY CONTAINING CALIBRATION
C                                 COEFFICIENTS. DIMENSIONED 3 X NUMCHN.
C                                 FIRST COEFFICIENT IS THE ZEROTH ORDER
C                                 TERM, SECOND COEFFICIENT IS THE
C                                 FIRST ORDER TERM, AND THE THIRD
C                                 COEFFICIENT IS THE SECOND ORDER TERM.
C
C     NUMCHN            INT  I    THE NUMBER OF INPUT CHANNELS.
C
C     NUMSPT            INT  I    THE NUMBER OF SPOTS.
C
C     RDIANC            REAL O    ARRAY CONTAINING THE RADIANCES.
C                                 DIMENSIONED NUMSPT X NUMCHN.
C
      INTEGER    COUNTS(NUMCHN,NUMSPT)
      INTEGER    NUMCHN, NUMSPT, BADLIN(15)
      REAL       CLCOEF(3,NUMCHN),RDIANC(NUMSPT,NUMCHN)
C
C   LOCAL PARAMETERS-
C     VARIABLE          TYPE  DESCRIPTION
C     --------          ----  -----------
C     I                 INT   DO LOOP INDEX VARIABLE.
C
C     J                 INT   DO LOOP INDEX VARIABLE.
C
      INTEGER   I,J
C
C   SUBPROGRAMS CALLED- NONE
C
C   EXIT STATES- NONE
C
C   ASSUMPTIONS- COUNTS OF ZERO OR LESS ARE BAD.
C
C**********************************************************************
C
C  CONVERT THE COUNTS TO RADIANCES. IF ANY COUNT IS ZERO OR LESS,
C  SET THE OUTPUT RADIANCE TO R4SPV.
C
      INCLUDE 'SPVAL'
C
      DO J = 1, NUMCHN
         DO I = 1, NUMSPT
            IF (COUNTS(J,I).LE.0) THEN
               RDIANC(I,J) = R4SPV
            ELSE
               RDIANC(I,J) = CLCOEF(1,J)
               RDIANC(I,J) = RDIANC(I,J) + CLCOEF(2,J)*COUNTS(J,I)
               RDIANC(I,J) = RDIANC(I,J) + CLCOEF(3,J)*(COUNTS(J,I)**2)
            END IF
         END DO
      END DO
C
      RETURN
      END
