      SUBROUTINE FLLBUF(HIRDAT,HNSPOT,HTOTLN,HDATEL,HDATOV,HTOTBF,
     1                  LINENO,HIRSPT,BRTEMP,RADTMP)
C***********************************************************************
C
C   NAME-FLLBUF
C
C   LANGUAGE-FORTRAN 77    TYPE-SUBROUTINE    COMPUTER- CRAY   
C
C   VERSION-1.0      DATE- 07/05/91     PROGRAMMER-TERESA SIMMS (SMSRC)
C   VERSION-2.0      DATE- 07/26/95     PROGRAMMER-DIANE BEITZELL (SMSRC)
C        ATOVS-150 - CHANGED FOR ATOVS TO INPUT A 1B* FILE.
C   VERSION-3.0      DATE- 05/15/96     PROGRAMMER-ALEX POZDNYAK (FDC) 
C     FOR REHOSTING TO THE CRAY, CHANGED ALL I*4 DECLARATIONS TO
C     INTEGER AND ALL R*4 DECLARATIONS TO REAL.   
C   VERSION-3.1      DATE- 02/13/98     PROGRAMMER-LEAH WILSON (R-STX) 
C   VERSION-3.2      DATE- 04/03/98     PROGRAMMER-LEAH WILSON (R-STX) 
C
C   FUNCTION- THIS SUBROUTINE FILLS THE HIRS DATA BUFFER, AND THE HIRS
C     DATA OVERLAP BUFFER IF APPROPRIATE, WITH THE COLLOCATED AVHRR SPOT
C     VALUES AND THEIR AVERAGES FOR EACH OF THE FIVE GAC CHANNELS.  THE
C     AVHRR DATA IS CHECKED AGAINST LIMITS FOR EACH CHANNEL BEFORE IT IS
C     PLACED IN THE BUFFER.   IF THE LIMITS ARE EXCEEDED THE VALUES ARE 
C     SET TO MISSING.  FOR CHANNELS 1, 2 & 3A RADIANCES ARE USED, AND FOR
C     CHANNELS 3B, 4, & 5 BRIGHTNESS TEMPERATURES ARE USED.
C 
C   VERSION- 3.1 CORRECT LOCATION OF GAC DATA IN HIRDAT BUFFER - IT STARTS
C      AT LOCATION RETPARM:NUMCHN + 1, SO INCLUDE /RETPARM/.
C   VERSION- 3.2 ADD /MONSTA/ TO UPDATE NBRAMG
C
C   CALLING SEQUENCE PARAMETERS-
C
C    NAME            TYPE  I/O  DESCRIPTION
C    ----            ----  ---  -----------
C    HIRDAT          REAL  I/O  HIRS EXTENDED DATA BUFFER, DIMENSIONED
C                               HNSPOT X HTOTLN X HDATEL PER SPOT.
C    HNSPOT           INT   I   NUMBER OF HIRS SPOTS IN A LINE.
C    HTOTLN           INT   I   TOTAL HIRS LINES IN A DATA FRAME.
C    HDATEL           INT   I   NUMBER OF ELEMENTS FOR EACH SPOT
C                               AND LINE IN THE HIRS DATA BUFFER.
C    HDATOV          REAL  I/O  3D BUFFER CONTAINING THE DATA FRAME OVERLAP.
C    HTOTBF           INT   I   HIRS TOTAL SCAN LINES IN OVERLAP BUFFER.
C    LINENO           INT   I   HIRS SCAN LINE NUMBER IN BUFFER.
C    HIRSPT           INT   I   NUMBER OF EACH HIRS SPOT IN A LINE.
C    BRTEMP          REAL  I/O  BRIGHTNESS TEMPERATURES FOR CHANNELS
C                               3B,4, AND 5.
C    RADTMP          REAL  I/O  RADIANCE VALUES FOR CHANNELS
C                               1,2,3A,3B,4,AND 5.
C
C   COMMON AREA PARAMETERS-
      INCLUDE 'INPCDB'
      INCLUDE 'RETPARM'
      INCLUDE 'MONSTA'
      INCLUDE 'SPVAL'
C
C   LOCAL PARAMETERS-
C
C    NAME        TYPE   DESCRIPTION
C    ----        ----   -----------
C    I,J,K       INT    DO LOOP INDEXES.
C    AVG         REAL   AVERAGE VALUE OF THE 17 COLLOCATED SPOTS FOR
C                       AN AVHRR CHANNEL.
C    DUM         REAL   DUMMY ARGUMENT FOR CALL TO VAVG.
C    HCNT        INT    KEEPS TRACK OF LOCATION IN HIRDAT WHOSE
C                       VALUE MUST BE FILLED IN.
C    CHN         INT    KEEPS TRACK OF CHANNEL NUMBER.
C
C    SUBPROGRAMS CALLED - VAVG, KIDS
C
C    EXIT STATES - NONE
C
C**********************************************************************
C
      INTEGER   HCNT,CHN,HNSPOT,HTOTLN,HDATEL,HTOTBF,
     1          LINENO,HIRSPT,I,J,K
      REAL      HIRDAT(HNSPOT,HTOTLN,HDATEL),
     1          HDATOV(HNSPOT,HTOTBF,HDATEL),
     2          RADTMP(6*17),BRTEMP(3*17),AVG,DUM
C
C  FILL HIRDAT WITH CHANNEL DATA AND THEIR AVERAGES.
C
      HCNT=NUMCHN+1
      CHN=1
C
      DO 20 I=1,86,17
C
C  COPY DATA FROM 17 COLLOCATED SPOTS TO HIRDAT.
C
         DO 10 J=1,17
C
C  DO A QUALITY CHECK ON THE DATA BEFORE FILLING THE BUFFER.
C
           IF (CHN .LE. 3) THEN
            IF(RADTMP(I+(J-1)) .LT. GMINBT(CHN) .OR.
     1         RADTMP(I+(J-1)) .GT. GMAXBT(CHN)) THEN
                  RADTMP(I+(J-1)) = R4SPV
                  NBRAMG(CHN) = NBRAMG(CHN) + 1
            ENDIF
            HIRDAT(HIRSPT,LINENO,HCNT)=RADTMP(I+(J-1))
            IF(LINENO .GT. HTOTLN-HTOTBF)
     1        HDATOV(HIRSPT,LINENO-HTOTLN+HTOTBF,HCNT)=RADTMP(I+(J-1))
           ELSE
            K = I - (3*17)
            IF(BRTEMP(K+(J-1)) .LT. GMINBT(CHN) .OR.
     1         BRTEMP(K+(J-1)) .GT. GMAXBT(CHN)) THEN
                  BRTEMP(K+(J-1)) = R4SPV
                  NBRAMG(CHN) = NBRAMG(CHN) + 1
            ENDIF
            HIRDAT(HIRSPT,LINENO,HCNT)=BRTEMP(K+(J-1))
            IF(LINENO .GT. HTOTLN-HTOTBF)
     1        HDATOV(HIRSPT,LINENO-HTOTLN+HTOTBF,HCNT)=BRTEMP(K+(J-1))
           ENDIF
           HCNT=HCNT+1
   10    CONTINUE
C
C  AVERAGE 17 SPOTS FOR THAT CHANNEL AND PLACE IT IN HIRDAT.
C
         IF (CHN .LE. 3) THEN
            CALL VAVG(RADTMP(I),17,AVG,DUM)
         ELSE
            CALL VAVG(BRTEMP(K),17,AVG,DUM)
         ENDIF
         HIRDAT(HIRSPT,LINENO,HCNT)=AVG
         IF (LINENO .GT. HTOTLN-HTOTBF)
     1      HDATOV(HIRSPT,LINENO-HTOTLN+HTOTBF,HCNT)=AVG
         HCNT=HCNT+1
         CHN=CHN+1
   20 CONTINUE
C
      RETURN
      END
