      SUBROUTINE PRDCHN(NSPOTS,NLINES,NDATEL,HIRDAT,SPOT,LINE,LOCHAN,
     1                  HICHAN,CHNAVL,RGCOEF,PRDVAL,ERSTAT)
C***********************************************************************
C
C   NAME- PRDCHN
C
C   LANGUAGE- VS FORTRAN  TYPE- SUBROUTINE      COMPUTER- HDS 9000
C
C   VERSION- 1.0    DATE-  2/8/93    PROGRAMMER- CARLA NEIGH
C   VERSION- 3.0    DATE- 05/29/96   PROGRAMMER- LEAH CASEY (HSTX)
C       SYNTAX MODS FOR ATOVS BASELINE ON CRAY.
C   VERSION- 4.0    DATE- 02/27/03   PROGRAMMER- Rickey Rollins (CSC)
C        Replace R4SPV equivalence test with ISR4SPV function 
C
C   FUNCTION- THIS SUBROUTINE COMPUTES A PREDICTED CHANNEL VALUE FROM
C             A GIVEN SET OF HIRS CHANNELS USING REGRESSION
C             COEFFICIENTS.
C
C   CALLING SEQUENCE PARAMETERS-
C   NAME    TYPE   I/O   DESCRIPTION
C   ----    ----   ---   -----------
C   NSPOTS   INT    I    TOTAL NUMBER OF HIRS SPOTS IN A SCAN LINE.
C   NLINES   INT    I    TOTAL NUMBER OF HIRS SCAN LINES IN THE HIRS
C                        DATA BUFFER.
C   NDATEL   INT    I    TOTAL NUMBER OF DATA ELEMENTS IN THE HIRS
C                        DATA BUFFER.
C   HIRDAT   REAL   I    3D ARRAY (DIM NSPOTS X NLINES X NDATEL)
C                        CONTAINING THE HIRS DATA BUFFER FOR AN
C                        EXTENDED DATA FRAME.
C   SPOT     INT    I    HIRS SPOT NUMBER FOR WHICH PREDICTED CHANNEL
C                        VALUE IS BEING COMPUTED.
C   LINE     INT    I    HIRS LINE NUMBER FOR WHICH PREDICTED CHANNEL
C                        VALUE IS BEING COMPUTED.
C   LOCHAN   INT    I    HIRS CHANNEL NUMBER FOR LOW END OF RANGE OF
C                        PREDICTOR CHANNELS.
C   HICHAN   INT    I    HIRS CHANNEL NUMBER FOR HIGH END OF RANGE OF
C                        PREDICTOR CHANNELS.
C   CHNAVL   INT    I    HIRS CHANNEL AVAILABILITY BIT FLAGS.  A BIT
C                        IS SET TO 1 IF THE HIRS CHANNEL IS
C                        AVAILABLE, OTHERWISE THE BIT IS SET TO 0.
C                        (BITS ARE ORDERED FROM LEFT TO RIGHT.)
C   RGCOEF   REAL   I    2D ARRAY (DIM HICHAN-LOCHAN+2,NSPOTS)
C                        CONTAINING THE REGRESSION COEFFICIENTS USED
C                        TO COMPUTE THE PREDICTED VALUE.
C   PRDVAL   REAL   O    PREDICTED CHANNEL VALUE.
C   ERSTAT   INT    O    ERROR RETURN CODE-
C                          = 0 IF NO ERROR OCCURRED.
C                          = 1 IF REGRESSION COEFFICIENTS CONTAIN
C                              A MISSING VALUE.
C
C   LOCAL PARAMETERS-
C   NAME    TYPE   DESCRIPTION
C   ----    ----   -----------
C   CHAN    INT    DO LOOP COUNTER FOR CHANNEL.
C   SUM     REAL   SUM OF REGRESSION VALUES USED TO COMPUTE PREDICTED
C                  VALUE.
C
C   FUNCTIONS USED- BTEST
C
C   EXIT STATES-
C    ERSTAT = 1 : REGRESSION COEFFICIENTS CONTAIN A MISSING VALUE.
C
C   COMMENTS-
C     THE CHANNELS USED FOR THE REGRESSION COMPUTATION MUST BE
C     IN CONSECUTIVE ORDER FROM LOCHAN TO HICHAN.
C     IF ANY OF THE CHANNEL VALUES NEEDED TO COMPUTE THE PREDICTED
C     VALUE ARE MISSING, THE PREDICTED VALUE IS RETURNED AS A
C     MISSING VALUE WITH AN ERROR STATUS CODE OF ZERO.
C
C***********************************************************************
C
      INTEGER NSPOTS, NLINES, NDATEL, SPOT, LINE, LOCHAN, HICHAN
      INTEGER CHNAVL, ERSTAT
      REAL HIRDAT(NSPOTS,NLINES,NDATEL), PRDVAL
      REAL RGCOEF(HICHAN-LOCHAN+2,NSPOTS)
      LOGICAL   ISR4SPV
C
      INTEGER CHAN
      REAL SUM
C
      INCLUDE 'SPVAL'
C
      ERSTAT = 0
      SUM = 0.0
C
C    COMPUTATION OF THE PREDICTED VALUE FOR THE SPOT IS OF THE FORM:
C
C     PRDVAL = RGCOEF(1) + RGCOEF(2)*HIRS_VALUE(LOCHAN) +
C              RGCOEF(3)*HIRS_VALUE(LOCHAN+1) +   ...   +
C              RGCOEF(HICHAN-LOCHAN+2)*HIRS_VALUE(HICHAN)
C
C    ACCUMULATE THE SUMMATION OF THE PRODUCTS OF REGRESSION COEFFICIENTS
C    AND HIRS CHANNEL VALUES FIRST.
C
      DO 10 CHAN = LOCHAN, HICHAN
C
C       IF A REGRESSION COEFFICIENT FOR THE SPOT IS MISSING,
C       RETURN AN ERROR STATUS OF 1.
C
         IF (ISR4SPV(RGCOEF(CHAN-LOCHAN+2,SPOT))) THEN
            PRDVAL = R4SPV
            ERSTAT = 1
            RETURN
         ENDIF
C
C       COMPUTE THE SUM OF REGRESSION VALUES.  IF ANY OF THE HIRS
C       CHANNEL VALUES ARE MISSING, A MISSING VALUE IS RETURNED FOR
C       THE PREDICTED VALUE WITH A ZERO ERROR STATUS CODE.
C
         IF ((BTEST(CHNAVL,32-CHAN)).AND.(.NOT. ISR4SPV(HIRDAT(SPOT,LINE,CHAN))
     1      )) THEN
C
              SUM = SUM + RGCOEF(CHAN-LOCHAN+2,SPOT) *
     1                    HIRDAT(SPOT,LINE,CHAN)
C
         ELSE
              PRDVAL = R4SPV
              RETURN
         ENDIF
C
   10 CONTINUE
C
C    ADD THE FIRST REGRESSION COEFFICIENT TO THE SUM TO GET THE
C    PREDICTED VALUE.  IF THE REGRESSION COEFFICIENT IS MISSING, RETURN
C    AN ERROR STATUS OF 1.
C
      IF (.NOT. ISR4SPV(RGCOEF(1,SPOT))) THEN
         PRDVAL = RGCOEF(1,SPOT) + SUM
      ELSE
         PRDVAL = R4SPV
         ERSTAT = 1
      ENDIF
C
      RETURN
      END
