       SUBROUTINE INTPAMA(HIRANC,HIRDAT)
       IMPLICIT NONE
C******************************************************************************
C
C   NAME- INTPAMA
C
C   LANGUAGE- FORTRAN      TYPE- SUBROUTINE   COMPUTER- AIX
C
C   VERSION- 1.0   DATE- 06/26/2006   PROGRAMMER- FRANK TILLEY (IMSG)
C
C   FUNCTION- THIS SUBROUTINE FILLS IN AMSU-A BRIGHTNESS TEMPERATURES
C             FOR CHANNELS 4-8 FOR SPOTS WHERE COPIES OF THESE CHANNELS
C             HAVE BEEN SET TO MISSING BECAUSE OF HIGH CLOUD LIQUID
C             WATER VALUES. THIS SUBROUTINE IS TO BE CALLED AFTER THE
C             AMSU-A DATA HAVE BEEN INTERPOLATED/EXTRAPOLATED TO THE
C             HIRS FIELD OF VIEW.
C
C   CALLING ARGUMENTS- 
C   NAME       TYPE    I/O    DESCRIPTION
C   ----       ----    ---    -----------
C   HIRANC     REAL     I     HIRS ANCILLARY BUFFER FOR A DATA FRAME
C   HIRDAT     REAL    I/O    HIRS DATA BUFFER FOR A DATA FRAME
C
C   COMMON AREAS- INSPARM, CLOUDMSK, SPVAL
C
      INCLUDE 'INSPARM'
      INCLUDE 'CLOUDMSK'
      INCLUDE 'SPVAL'
C
C
C   LOCAL VARIABLES-
C   NAME       TYPE     DESCRIPTION
C   ----       ----     -----------
C   CLW        REAL     CLOUD LIQUID WATER AT THE HIRS FOV
C   DELTACH4   REAL     VALUE USED TO ADJUST AMSU-A CHANNEL 4
C   DLINE1-4   REAL     FLOATING POINT LINE INDICES USED IN INTERPOLATION
C   DSPOT1-4   REAL     FLOATING POINT SPOT INDICES USED IN INTERPOLATION 
C   ICNT,JCNT   INT     COUNTERS USED TO CONTROL INTERPOLATION
C   ISPOT       INT     SECONDARY SPOT INDEX
C   IX,JX,KX,LX INT     LINE INDICES USED IN INTERPOLATION
C   JY,JY,KY,LY INT     SPOT INDICES USED IN INTERPOLATION
C   LINE        INT     LINES IN THE HIRS BUFFERS
C   LINE1-4     INT     LINE NUMBERS USED IN INTERPOLATION
C   MHS5       REAL     CHANNEL 5 BRIGHTNESS TEMPERATURE AT THE MHS SPOT
C                       CLOSEST TO THE CENTER OF THE HIRS FOV.
C   SPOT        INT     SPOTS ON A HIRS LINE
C   SPOT1-4     INT     SPOT NUMBERS USED IN INTERPOLATION
C   TERHGT      INT     TERRAIN HEIGHT
C   TERTYP      INT     TERRAIN TYPE (0=SEA, >0 = NONSEA)
C   W1-W4      REAL     WEIGHTS USED IN INTERPOLATION.
C
C******************************************************************************

C  CALLING ARGUMENTS

      REAL    HIRANC(HNSPOT,HTOTLN,HNANC), HIRDAT(HNSPOT,HTOTLN,HDATEL)
       
C  LOCAL VARIABLES

      INTEGER LINE, SPOT, ILINE, JSPOT, ICNT, JCNT, IX, IY, JX, JY 
      INTEGER KX, KY, LX, LY, TERTYP, SPOT1, SPOT2, SPOT3, SPOT4
      INTEGER LINE1, LINE2, LINE3, LINE4, TERHGT, ISPOT
      INTEGER ENDSPOT, ENDLINE
      REAL    DLINE1, DSPOT1, DLINE2, DSPOT2, DLINE3, DSPOT3, DLINE4
      REAL    DSPOT4, W1, W2, W3, W4, CLW, DELTACH4, MHS5

C
C       COPY THE INTERPOLATED AMSU-A LIMB-CORRECTED BRIGHTNESS TEMPERATURES
C       FOR AMSU-A CHANNELS 4-7 AND ADJUST THEM (IF NECESSARY) FOR PRECIPITATION
C       CONTAMINATION. DO THE SAME FOR MHS CHANNEL 3.
C
      DO LINE = 10, 47
         DO 10 SPOT = 1, 56
            HIRDAT(SPOT,LINE,154) = HIRDAT(SPOT,LINE,24)
            HIRDAT(SPOT,LINE,155) = HIRDAT(SPOT,LINE,25)
            HIRDAT(SPOT,LINE,156) = HIRDAT(SPOT,LINE,26)
            HIRDAT(SPOT,LINE,157) = HIRDAT(SPOT,LINE,27)
            HIRDAT(SPOT,LINE,158) = HIRDAT(SPOT,LINE,28)
            HIRDAT(SPOT,LINE,173) = HIRDAT(SPOT,LINE,165)
            IF (HIRDAT(SPOT,LINE,149) .NE. R4SPV) THEN
               IF (HIRDAT(SPOT,LINE,149) .LT. 0.0) THEN
                   HIRDAT(SPOT,LINE,149) = 0.0
               END IF
            END IF
            CLW = HIRDAT(SPOT,LINE,149)
            MHS5 = HIRDAT(SPOT,LINE,167)

C-- OVER ICE-FREE OCEAN ADJUST AMSU-A CHANNEL 4 FOR CLOUD LIQUID WATER.
C   IF AMSU-A CHANNEL 8 IS MORE THAN 7.4 DEGREES COLDER THAN AMSU-A
C   CHANNEL 7 AND CLOUD LIQUID WATER EXCEEDS 0.25, SET AMSU-A CHANNELS
C   4-7 TO MISSING.

            TERHGT = NINT(HIRANC(SPOT,LINE,8))
            TERTYP = NINT(HIRANC(SPOT,LINE,9))
            IF (TERTYP.EQ.0) THEN
               IF (CLW.GT.0.0) THEN
                  DELTACH4 = (1.566 * CLW) + (2.436 * (CLW**0.3))
                  HIRDAT(SPOT,LINE,154) = HIRDAT(SPOT,LINE,24) - DELTACH4
                  IF ((HIRDAT(SPOT,LINE,27) - HIRDAT(SPOT,LINE,28)) .GT.
     +                6.80 .AND. (CLW .GE. 0.18)) THEN
c  Changed limit from 7.4 to 6.8 on 1 April 2010 FHT
c    +                7.40 .AND. (CLW .GE. 0.18)) THEN
                      HIRDAT(SPOT,LINE,154) = R4SPV
                      HIRDAT(SPOT,LINE,155) = R4SPV
                      HIRDAT(SPOT,LINE,156) = R4SPV
                      HIRDAT(SPOT,LINE,157) = R4SPV
                      HIRDAT(SPOT,LINE,158) = R4SPV
                      HIRDAT(SPOT,LINE,173) = R4SPV
                  END IF
               END IF
C
C-- IF THE CLOUD LIQUID WATER VALUE IS ZERO, MAKE NO ADJUSTMENT. IF IT IS LESS
C   THAN ZERO, SET AMSU-A CHANNELS 4-7 TO MISSING.
C
               IF (CLW.LT.0.0) THEN
                  HIRDAT(SPOT,LINE,154) = R4SPV
                  HIRDAT(SPOT,LINE,155) = R4SPV
                  HIRDAT(SPOT,LINE,156) = R4SPV
                  HIRDAT(SPOT,LINE,157) = R4SPV
                  HIRDAT(SPOT,LINE,158) = R4SPV
                  HIRDAT(SPOT,LINE,173) = R4SPV
               END IF
            ELSE

C-- DO NOT MAKE ANY ADJUSTMENTS OVER SEA ICE, OVER ANTARCTICA, OVER GREENLAND,
C   OR OVER ARCTIC LAND NORTH OF 76 DEGREES NORTH LATITUDE.
C
C--     SEA ICE OR SNOW
               IF (TERTYP.EQ.10.OR.TERTYP.EQ.11) GO TO 10
C--     ANTARCTICA
               IF (HIRANC(SPOT,LINE,1) .LT. -60.0 .AND. TERHGT .GT. 0) THEN
                  GO TO 10
               END IF
C--     GREENLAND
               IF (HIRANC(SPOT,LINE,1) .GT. 60.0 .AND. TERHGT .GT. 1200) THEN
                  GO TO 10
               END IF
C--     ARCTIC LAND NORTH OF 76 DEGREES NORTH LATITUDE.
               IF (HIRANC(SPOT,LINE,1) .GT. 76.0 .AND. TERHGT .GT. 0) THEN
                  GO TO 10
               END IF 
                
            END IF
  10     CONTINUE
      END DO
         
C
C
C	RUN A BI-LINEAR INTERPOLATION ON AMSU-A CH# 4 THROUGH 8 OVER 
C	TROPICAL OCEANIC AREAS WHICH HAVE BEEN FILTERED FOR CLW>0.0
C
C	CHECK DATA FRAME FOR FOVs WHICH HAVE BEEN FILTERED 
C
      DO LINE = 10, 47
         DO SPOT = 1, 56
            IF (HIRDAT(SPOT,LINE,154) .EQ. R4SPV)  GO TO 20
         END DO
      END DO
C
C	IF NO FILTERED FOVs ARE FOUND, RETURN TO THE CALLING ROUTINE.
C
      GO TO 1000
C
C	START THE BI-LINEAR INTERPOLATION BY LOOKING FOR FILTERED FOVs 
C       OVER SEA.
C
  20  CONTINUE
C
      DO 400  SPOT = 1, 56
         DO 300  LINE = 10, 47
C
            IF (HIRDAT(SPOT,LINE,154).NE.R4SPV) GO TO 300

	    IF ((NINT(HIRANC(SPOT,LINE,9)).EQ.0) .AND. 
     +         (HIRDAT(SPOT,LINE,154).EQ.R4SPV))  THEN
               DLINE1 = 0.0
               DSPOT1 = 0.0
               DLINE2 = 0.0
               DSPOT2 = 0.0
               DLINE3 = 0.0
               DSPOT3 = 0.0
               DLINE4 = 0.0
               DSPOT4 = 0.0
C
C	FIND THE NEAREST FOVs WITH VALID OCEANIC DATA
C
               ILINE = LINE + 1
              
               IF (ILINE .GT. 47)  GO TO 40
               JSPOT = SPOT
C
   30          CONTINUE
C
               IF ((NINT(HIRANC(JSPOT,ILINE,9)) .EQ. 0) .AND.
     +             (HIRDAT(JSPOT,ILINE,154) .NE. R4SPV))  THEN
                  DLINE1 = FLOAT(ILINE - LINE)
                  LINE1 = ILINE
                  DSPOT1 = FLOAT(JSPOT)
                  SPOT1 = JSPOT
               ELSE
                  ILINE = ILINE + 1
                  IF (ILINE .GT. 47) GO TO 40
                  IF (NINT(HIRANC(JSPOT,ILINE,9)) .NE. 0) GO TO 40
                  GO TO 30
               END IF
		
C
   40          CONTINUE
               ILINE = LINE - 1
               IF (ILINE .LT. 10) GO TO 60
               JSPOT = SPOT

   50          CONTINUE
               IF ((NINT(HIRANC(JSPOT,ILINE,9)) .EQ. 0) .AND.
     +             (HIRDAT(JSPOT,ILINE,154) .NE. R4SPV))  THEN
                  DLINE2 = FLOAT(LINE - ILINE)
                  LINE2 = ILINE
                  DSPOT2 = FLOAT(JSPOT)
                  SPOT2 = JSPOT
               ELSE
                  ILINE = ILINE - 1
                  IF (ILINE .LT. 10) GO TO 60
                  IF (NINT(HIRANC(JSPOT,ILINE,9)) .NE. 0) GO TO 60
                  GO TO 50 
               END IF
C
   60          CONTINUE
               JSPOT = SPOT + 1
               IF (JSPOT.GT.56) GO TO 80
               ILINE = LINE
C
   70          CONTINUE 
               IF ((NINT(HIRANC(JSPOT,ILINE,9)) .EQ. 0) .AND.
     +             (HIRDAT(JSPOT,ILINE,154) .NE. R4SPV))  THEN
                  DLINE3 = FLOAT(ILINE)
                  LINE3 = ILINE
                  DSPOT3 = FLOAT(JSPOT - SPOT)
                  SPOT3 = JSPOT
               ELSE
                  JSPOT = JSPOT + 1
                  IF (JSPOT.GT.56) GO TO 80
                  IF (NINT(HIRANC(JSPOT,ILINE,9)) .NE. 0) GO TO 80
                  GO TO 70
               END IF
C
   80          CONTINUE
               JSPOT = SPOT - 1
               IF (JSPOT .LT. 1) GO TO 100
               ILINE = LINE
C
   90          CONTINUE
               IF ((NINT(HIRANC(JSPOT,ILINE,9)) .EQ. 0) .AND.
     +             (HIRDAT(JSPOT,ILINE,154) .NE. R4SPV)) THEN
                  DLINE4 = FLOAT(ILINE)
                  LINE4 = ILINE
                  DSPOT4 = FLOAT(SPOT - JSPOT)
                  SPOT4 = JSPOT
               ELSE
                  JSPOT = JSPOT - 1
                  IF (JSPOT .LT. 1) GO TO 100
                  IF (NINT(HIRANC(JSPOT,ILINE,9)) .NE. 0) GO TO 100
                  GO TO 90
               END IF
C

  100          CONTINUE
C
C	DETERMINE THE NUMBER OF POSSIBLE COMBINATIONS OUT OF 15 AND
C	WHICH COMBINATIONS OF FOVs THAT WILL BE USED FOR INTERPOLATION
C
               ICNT = 0
               JCNT = 0
C
               IF (DLINE1 .NE. 0.0) THEN
                  JCNT = JCNT + 1
                  ICNT = ICNT + 1
               END IF
C
               IF (DLINE2 .NE. 0.0) THEN
                  JCNT = JCNT + 1
                  ICNT = ICNT + 10
               END IF
C
               IF (DLINE3 .NE. 0.0) THEN
                  JCNT = JCNT + 1
                  ICNT = ICNT + 100
               END IF
C
               IF (DLINE4 .NE. 0.0) THEN
                  JCNT = JCNT + 1
                  ICNT = ICNT + 1000
               END IF
C
C	THE FOLLOWING 15 COMBINATIONS FOR INTERPOLATION ARE DONE 
C	STARTING WITH THE ZERO COMBINATION WHICH DOES NOT PROVIDE AN 
C	INTERPOLATED VALUE FOR THIS FILTERED FOV.
C
               IF (JCNT .EQ. 0) GO TO 300
               IF (JCNT .EQ. 1) GO TO 200
               IF (JCNT .EQ. 2) GO TO 210
               IF (JCNT .EQ. 3) GO TO 220
               IF (JCNT .EQ. 4) GO TO 230
C
C	THE FOLLOWING 4 COMBINATIONS ONLY HAVE A SINGLE AVAILABLE 
C	VALUE SO IT IS SIMPLY COPIED INTO THE FILTERED FOV.
C
  200          CONTINUE
               IF (ICNT .EQ. 1) THEN
                  IX = LINE1
                  IY = SPOT1
               END IF
C
               IF (ICNT .EQ. 10) THEN
                  IX = LINE2
                  IY = SPOT2
               END IF
C
               IF (ICNT .EQ. 100) THEN
                  IX = LINE3
                  IY = SPOT3
               END IF
C
               IF (ICNT .EQ. 1000) THEN
                  IX = LINE4
                  IY = SPOT4
               END IF
C
C	NOW COPY THE CLOSEST AVAILABLE DATA INTO THE FILTERED FOV
C
               HIRDAT(SPOT,LINE,154) = HIRDAT(IY,IX,154)
               HIRDAT(SPOT,LINE,155) = HIRDAT(IY,IX,155)
               HIRDAT(SPOT,LINE,156) = HIRDAT(IY,IX,156)
               HIRDAT(SPOT,LINE,157) = HIRDAT(IY,IX,157)
               HIRDAT(SPOT,LINE,158) = HIRDAT(IY,IX,158)
               HIRDAT(SPOT,LINE,173) = HIRDAT(IY,IX,173)
C
               GO TO 300
C
C	THE FOLLOWING 5 COMBINATIONS WILL USE A 2-WAY INTERPOLATION 
C	FOR THE VALUE TO BE COPIED INTO THE FILTERED FOV.
C
  210          CONTINUE
               IF (ICNT .EQ. 11) THEN
                  IX = LINE1
                  IY = SPOT1
                  JX = LINE2
                  JY = SPOT2
                  W2 = DLINE1 / (DLINE2 + DLINE1)
                  W1 = 1.0 - W2
               END IF

C
               IF (ICNT .EQ. 101) THEN
                  IX = LINE1
                  IY = SPOT1
                  JX = LINE3
                  JY = SPOT3
                  W2 = DLINE1 / (DSPOT3 + DLINE1)
                  W1 = 1.0 - W2
               END IF
C
               IF (ICNT .EQ. 110) THEN
                  IX = LINE2
                  IY = SPOT2
                  JX = LINE3
                  JY = SPOT3
                  W2 = DLINE2 / (DSPOT3 + DLINE1)
                  W1 = 1.0 - W2
               END IF
C
               IF (ICNT .EQ. 1001) THEN
                  IX = LINE1
                  IY = SPOT1
                  JX = LINE4
                  JY = SPOT4
                  W2 = DLINE1 / (DSPOT4 + DLINE1)
                  W1 = 1.0 - W2
               END IF
C
               IF (ICNT .EQ. 1010) THEN
                  IX = LINE2
                  IY = SPOT2
                  JX = LINE4
                  JY = SPOT4
                  W2 = DLINE2 / (DSPOT4 + DLINE2)
                  W1 = 1.0 - W2
               END IF
C
               IF (ICNT .EQ. 1100) THEN
                  IX = LINE3
                  IY = SPOT3
                  JX = LINE4
                  JY = SPOT4
                  W2 = DSPOT3 / (DSPOT4 + DSPOT3)
                  W1 = 1.0 - W2
               END IF
                
C
C	2-WAY INTERPOLATION OF THE CLOSEST AVAILABLE DATA INTO THE 
C	FILTERED FOV
C
               HIRDAT (SPOT,LINE,154) = (W1 * HIRDAT(IY,IX,154)) +
     +                 (W2 * HIRDAT(JY,JX,154))
               HIRDAT (SPOT,LINE,155) = (W1 * HIRDAT(IY,IX,155)) +
     +                 (W2 * HIRDAT(JY,JX,155))
               HIRDAT (SPOT,LINE,156) = (W1 * HIRDAT(IY,IX,156)) +
     +                 (W2 * HIRDAT(JY,JX,156))
               HIRDAT (SPOT,LINE,157) = (W1 * HIRDAT(IY,IX,157)) +
     +                 (W2 * HIRDAT(JY,JX,157))
               HIRDAT (SPOT,LINE,158) = (W1 * HIRDAT(IY,IX,158)) +
     +                 (W2 * HIRDAT(JY,JX,158))
               HIRDAT (SPOT,LINE,173) = (W1 * HIRDAT(IY,IX,173)) +
     +                 (W2 * HIRDAT(JY,JX,173))
               GO TO 300
C
C	THE FOLLOWING 4 COMBINATIONS WILL USE A 3-WAY INTERPOLATION 
C	FOR THE VALUE TO BE COPIED INTO THE FILTERED FOV.
C
 220           CONTINUE
               IF (ICNT .EQ. 111) THEN
                  IX = LINE1
                  IY = SPOT1
                  JX = LINE2
                  JY = SPOT2
                  KX = LINE3
                  KY = SPOT3
                  W3 = (DLINE1 * DLINE2) / ((DLINE2 * DSPOT3) +
     +                 (DLINE1 * DSPOT3) + (DLINE1 * DLINE2))
                  W2 = (DSPOT3 * W3) / DLINE2
                  W1 = 1.0 - W3 - W2
               END IF
C
               IF (ICNT .EQ. 1011) THEN
                  IX = LINE1
                  IY = SPOT1
                  JX = LINE2
                  JY = SPOT2
                  KX = LINE4
                  KY = SPOT4
                  W3 = (DLINE1 * DLINE2) / ((DLINE2 * DSPOT4) +
     +                 (DLINE1 * DSPOT4) + (DLINE1 * DLINE2))
                  W2 = (DSPOT4 * W3) / DLINE2
                  W1 = 1.0 - W3 - W2
               END IF
C
               IF (ICNT .EQ. 1101) THEN
                  IX = LINE1
                  IY = SPOT1
                  JX = LINE3
                  JY = SPOT3
                  KX = LINE4
                  KY = SPOT4
                  W3 = (DLINE1 * DSPOT3) / ((DSPOT3 * DSPOT4) +
     +                 (DLINE1 * DSPOT4) + (DLINE1 * DSPOT3))
                  W2 = (DSPOT4 * W3) / DSPOT3
                  W1 = 1.0 - W3 - W2
               END IF
C
               IF (ICNT .EQ. 1110) THEN
                  IX = LINE2
                  IY = SPOT2
                  JX = LINE3
                  JY = SPOT3
                  KX = LINE4
                  KY = SPOT4
                  W3 = (DLINE2 * DSPOT3) / ((DSPOT3 * DSPOT4) +
     +                 (DLINE2 * DSPOT4) + (DLINE2 * DSPOT3))
                  W2 = (DSPOT4 * W3) / DSPOT3
                  W1 = 1.0 - W3 - W2
               END IF
C
C	3-WAY INTERPOLATION OF THE CLOSEST AVAILABLE DATA INTO THE 
C	FILTERED FOV
C
               HIRDAT(SPOT,LINE,154) = (W1 * HIRDAT(IY,IX,154)) +
     +                                 (W2 * HIRDAT(JY,JX,154)) +
     +                                 (W3 * HIRDAT(KY,KX,154))
               HIRDAT(SPOT,LINE,155) = (W1 * HIRDAT(IY,IX,155)) +
     +                                 (W2 * HIRDAT(JY,JX,155)) +
     +                                 (W3 * HIRDAT(KY,KX,155))
               HIRDAT(SPOT,LINE,156) = (W1 * HIRDAT(IY,IX,156)) +
     +                                 (W2 * HIRDAT(JY,JX,156)) +
     +                                 (W3 * HIRDAT(KY,KX,156))
               HIRDAT(SPOT,LINE,157) = (W1 * HIRDAT(IY,IX,157)) +
     +                                 (W2 * HIRDAT(JY,JX,157)) +
     +                                 (W3 * HIRDAT(KY,KX,157))
               HIRDAT(SPOT,LINE,158) = (W1 * HIRDAT(IY,IX,158)) +
     +                                 (W2 * HIRDAT(JY,JX,158)) +
     +                                 (W3 * HIRDAT(KY,KX,158))
               HIRDAT(SPOT,LINE,173) = (W1 * HIRDAT(IY,IX,173)) +
     +                                 (W2 * HIRDAT(JY,JX,173)) +
     +                                 (W3 * HIRDAT(KY,KX,173))
               
               GO TO 300
C
C	THE FOLLOWING COMBINATION WILL USE A 4-WAY INTERPOLATION 
C	FOR THE VALUE TO BE COPIED INTO THE FILTERED FOV.
C
 230           CONTINUE
               IF (ICNT .EQ. 1111) THEN
                  IX = LINE1
                  IY = SPOT1
                  JX = LINE2
                  JY = SPOT2
                  KX = LINE3
                  KY = SPOT3
                  LX = LINE4
                  LY = SPOT4
                  W4 = (DLINE1 * DLINE2 * DSPOT3) /
     +                 ((DSPOT4 * DLINE2 * DSPOT3) +
     +                  (DSPOT4 * DLINE1 * DSPOT3) +
     +                  (DSPOT4 * DLINE1 * DLINE2) +
     +                  (DLINE1 * DLINE2 * DSPOT3))
                  W3 = (DSPOT4 * W4) / DSPOT3
                  W2 = (DSPOT4 * W4) / DLINE2
                  W1 = 1.0 - W4 - W3 - W2
               END IF
C
C	4-WAY INTERPOLATION OF THE CLOSEST AVAILABLE DATA INTO THE 
C	FILTERED FOV
C
               HIRDAT (SPOT,LINE,154) = (W1 * HIRDAT(IY,IX,154)) +
     +                                  (W2 * HIRDAT(JY,JX,154)) +
     +                                  (W3 * HIRDAT(KY,KX,154)) +
     +                                  (W4 * HIRDAT(LY,LX,154))
               HIRDAT (SPOT,LINE,155) = (W1 * HIRDAT(IY,IX,155)) +
     +                                  (W2 * HIRDAT(JY,JX,155)) +
     +                                  (W3 * HIRDAT(KY,KX,155)) +
     +                                  (W4 * HIRDAT(LY,LX,155))
               HIRDAT (SPOT,LINE,156) = (W1 * HIRDAT(IY,IX,156)) +
     +                                  (W2 * HIRDAT(JY,JX,156)) +
     +                                  (W3 * HIRDAT(KY,KX,156)) +
     +                                  (W4 * HIRDAT(LY,LX,156))
               HIRDAT (SPOT,LINE,157) = (W1 * HIRDAT(IY,IX,157)) +
     +                                  (W2 * HIRDAT(JY,JX,157)) +
     +                                  (W3 * HIRDAT(KY,KX,157)) +
     +                                  (W4 * HIRDAT(LY,LX,157))
               HIRDAT (SPOT,LINE,158) = (W1 * HIRDAT(IY,IX,158)) +
     +                                  (W2 * HIRDAT(JY,JX,158)) +
     +                                  (W3 * HIRDAT(KY,KX,158)) +
     +                                  (W4 * HIRDAT(LY,LX,158))
               HIRDAT (SPOT,LINE,173) = (W1 * HIRDAT(IY,IX,173)) +
     +                                  (W2 * HIRDAT(JY,JX,173)) +
     +                                  (W3 * HIRDAT(KY,KX,173)) +
     +                                  (W4 * HIRDAT(LY,LX,173))
C
            END IF
C
  300	 CONTINUE
  400 CONTINUE
C
C   MAKE A SEMI-FINAL SWEEP THROUGH THE DATA FRAME LOOKING FOR MISSING
C   AMSU-A CHANNEL 4-8 VALUES OVER WATER. WHERE THESE CHANNEL DATA
C   ARE MISSING OVER WATER, COPY IN THE OBSERVED CHANNEL VALUES
C   ONLY IF THE ATOVS FOV CLOUD MASK SHOWS THE SPOT TO BE CLEAR.
C
      DO LINE = 10, 47
         DO SPOT = 1, 56
            TERTYP = NINT(HIRANC(SPOT,LINE,9))
            IF (TERTYP.EQ.0.AND.CLDMSK(SPOT,LINE).EQ.0) THEN
               IF (HIRDAT(SPOT,LINE,154).EQ.R4SPV) THEN
                  HIRDAT(SPOT,LINE,154) = HIRDAT(SPOT,LINE,24)
               END IF
               IF (HIRDAT(SPOT,LINE,155).EQ.R4SPV) THEN
                  HIRDAT(SPOT,LINE,155) = HIRDAT(SPOT,LINE,25)
               END IF
               IF (HIRDAT(SPOT,LINE,156).EQ.R4SPV) THEN
                  HIRDAT(SPOT,LINE,156) = HIRDAT(SPOT,LINE,26)
               END IF
               IF (HIRDAT(SPOT,LINE,157).EQ.R4SPV) THEN
                  HIRDAT(SPOT,LINE,157) = HIRDAT(SPOT,LINE,27)
               END IF
               IF (HIRDAT(SPOT,LINE,158).EQ.R4SPV) THEN
                  HIRDAT(SPOT,LINE,158) = HIRDAT(SPOT,LINE,28)
               END IF
               IF (HIRDAT(SPOT,LINE,173).EQ.R4SPV) THEN
                  HIRDAT(SPOT,LINE,173) = HIRDAT(SPOT,LINE,165)
               END IF
            END IF
         END DO
      END DO
C
C MAKE ANOTHER SWEEP THROUGH THE DATA FRAME LOOKING FOR MISSING
C AMSU-A CHANNEL 4-8 VALUES OVER WATER WHERE THE ATOVS FOV CLOUD
C MASK SHOWS THE SPOTS TO BE CLOUDY.  IF A SPOT OVER WATER IS MISSING,
C SEARCH THE SCAN LINE UP TO 10 SPOTS TO EITHER SIDE LOOKING FOR THE
C FIRST SPOT OVER WATER WHERE THE AMSU-A CHANNEL DATA ARE NOT MISSING
C AND REPLACE THE MISSING VALUE WITH THAT VALUE.
C
      DO LINE = 10, 47
         DO SPOT = 1, 56
            TERTYP = NINT(HIRANC(SPOT,LINE,9))
            IF (TERTYP.EQ.0.AND.CLDMSK(SPOT,LINE).NE.0) THEN
               IF (HIRDAT(SPOT,LINE,154).EQ.R4SPV) THEN
                  IF (SPOT.GE.1.AND.SPOT.LE.10) THEN
                     ENDSPOT = 1 
                  ELSE
                     ENDSPOT = SPOT-10
                  END IF
                  DO ISPOT = SPOT, ENDSPOT, -1
                     IF (NINT(HIRANC(ISPOT,LINE,9)) .EQ. 0) THEN
                        IF (HIRDAT(SPOT,LINE,154).EQ.R4SPV) THEN
                           IF (HIRDAT(ISPOT,LINE,154).NE.R4SPV) THEN
                              HIRDAT(SPOT,LINE,154) = HIRDAT(ISPOT,LINE,154)
                              HIRDAT(SPOT,LINE,155) = HIRDAT(ISPOT,LINE,155)
                              HIRDAT(SPOT,LINE,156) = HIRDAT(ISPOT,LINE,156)
                              HIRDAT(SPOT,LINE,157) = HIRDAT(ISPOT,LINE,157)
                              HIRDAT(SPOT,LINE,158) = HIRDAT(ISPOT,LINE,158)
                              HIRDAT(SPOT,LINE,173) = HIRDAT(ISPOT,LINE,173)
                           END IF
                        END IF
                     END IF
                  END DO
               END IF
               IF (HIRDAT(SPOT,LINE,154).EQ.R4SPV) THEN
                  IF (SPOT+10.GT.56) THEN
                     ENDSPOT = 56
                  ELSE
                     ENDSPOT = SPOT+10
                  END IF
                  DO ISPOT = SPOT, ENDSPOT
                     IF (NINT(HIRANC(ISPOT,LINE,9)) .EQ. 0) THEN
                        IF (HIRDAT(SPOT,LINE,154).EQ.R4SPV) THEN
                           IF (HIRDAT(ISPOT,LINE,154).NE.R4SPV) THEN
                              HIRDAT(SPOT,LINE,154) = HIRDAT(ISPOT,LINE,154)
                              HIRDAT(SPOT,LINE,155) = HIRDAT(ISPOT,LINE,155)
                              HIRDAT(SPOT,LINE,156) = HIRDAT(ISPOT,LINE,156)
                              HIRDAT(SPOT,LINE,157) = HIRDAT(ISPOT,LINE,157)
                              HIRDAT(SPOT,LINE,158) = HIRDAT(ISPOT,LINE,158)
                              HIRDAT(SPOT,LINE,173) = HIRDAT(ISPOT,LINE,173)
                           END IF
                        END IF
                     END IF
                  END DO
               END IF
            END IF
         END DO
      END DO
C
C MAKE A FINAL SWEEP THROUGH THE DATA FRAME LOOKING FOR MISSING AMSU-A
C CHANNEL 4-8 VALUES OVER WATER WHERE THE ATOVS FOV CLOUD MASK SHOWS THE
C SPOTS TO BE CLOUDY.  IF A SPOT OVER WATER IS STILL MISSING AFTER THE
C SEARCH ALONG THE SCAN LINE HAS PERFORMED, PERFORM ANOTHER SEARCH 
C FOR THE SAME SPOT NUMBER WITHIN +/- 10 ROWS.
C
      DO SPOT = 1, 56
         DO LINE = 10, 47
            TERTYP = NINT(HIRANC(SPOT,LINE,9))
            IF (TERTYP.EQ.0.AND.CLDMSK(SPOT,LINE).NE.0) THEN
               IF (HIRDAT(SPOT,LINE,154).EQ.R4SPV) THEN
                  ENDLINE = LINE
                  IF (ENDLINE-10.LT.10) THEN
                     ENDLINE = 10
                  ELSE
                     ENDLINE = LINE - 10
                  END IF
                  DO ILINE = LINE, ENDLINE, -1
                     IF (NINT(HIRANC(SPOT,ILINE,9)) .EQ. 0) THEN
                        IF (HIRDAT(SPOT,LINE,154).EQ.R4SPV) THEN
                           IF (HIRDAT(SPOT,ILINE,154).NE.R4SPV) THEN
                              HIRDAT(SPOT,LINE,154) = HIRDAT(SPOT,ILINE,154)
                              HIRDAT(SPOT,LINE,155) = HIRDAT(SPOT,ILINE,155)
                              HIRDAT(SPOT,LINE,156) = HIRDAT(SPOT,ILINE,156)
                              HIRDAT(SPOT,LINE,157) = HIRDAT(SPOT,ILINE,157)
                              HIRDAT(SPOT,LINE,158) = HIRDAT(SPOT,ILINE,158)
                              HIRDAT(SPOT,LINE,173) = HIRDAT(SPOT,ILINE,173)
                           END IF
                        END IF
                     END IF
                  END DO
               END IF
               IF (HIRDAT(SPOT,LINE,154).EQ.R4SPV) THEN
                  ENDLINE = LINE
                  IF (ENDLINE+10.GT.47) THEN
                     ENDLINE = 47
                  ELSE
                     ENDLINE = LINE + 10
                  END IF
                  DO ILINE = LINE, ENDLINE
                     IF (NINT(HIRANC(SPOT,ILINE,9)) .EQ. 0) THEN
                        IF (HIRDAT(SPOT,LINE,154).EQ.R4SPV) THEN
                           IF (HIRDAT(SPOT,ILINE,154).NE.R4SPV) THEN
                              HIRDAT(SPOT,LINE,154) = HIRDAT(SPOT,ILINE,154)
                              HIRDAT(SPOT,LINE,155) = HIRDAT(SPOT,ILINE,155)
                              HIRDAT(SPOT,LINE,156) = HIRDAT(SPOT,ILINE,156)
                              HIRDAT(SPOT,LINE,157) = HIRDAT(SPOT,ILINE,157)
                              HIRDAT(SPOT,LINE,158) = HIRDAT(SPOT,ILINE,158)
                              HIRDAT(SPOT,LINE,173) = HIRDAT(SPOT,ILINE,173)
                           END IF
                        END IF
                     END IF
                  END DO
               END IF
            END IF
         END DO
      END DO
            
C
 1000 CONTINUE
      RETURN
      END
