      SUBROUTINE AMAHIR(HSPOT,HLINE,AMADAT,VALAMA)
      IMPLICIT NONE
C***********************************************************************
C    NAME- AMAHIR
C
C    LANGUAGE- FORTRAN           TYPE- SUBROUTINE     COMPUTER- CRAY
C
C    VERSION- 1.0    DATE- 8/16/00  PROGRAMMER- FRANK TILLEY (RAYTHEON)
C
C   VERSION- 1.2    DATE- 02/27/03   PROGRAMMER- Rickey Rollins (CSC)
C        Replace R4SPV equivalence test with ISR4SPV function
C 
C    FUNCTION-  THIS SUBROUTINE INTERPOLATES AMSU-A BRIGHTNESS
C               TEMPERATURES TO THE HIRS FOOTPRINT WHEN NO HIRS 1B*
C               FILE IS AVAILABLE AND HIRS LATITUDES AND LONGITUDES
C               HAVE BEEN INTERPOLATED FROM AMSU-A DATA.
C
C    FILES-  NONE
C
C    CALLING ARGUMENTS-
C    NAME     TYPE   I/O   DESCRIPTION
C    ----     ----   ---   -----------
C    HSPOT    INT     I    HIRS SPOT ON A LINE.
C
C    HLINE    INT     I    HIRS LINE NUMBER IN A DATA FRAME.
C
C    AMADAT   REAL    I    AMSU-A DATA BUFFER.
C
C    VALAMA   REAL   I/O   AMSU-A DATA INTERPOLATED TO THE HIRS
C                          FOOTPRINT.
C
C    COMMON AREA PARAMETERS- 
C
      INCLUDE 'INPARM'
      INCLUDE 'INSPARM'
      INCLUDE 'NOHIRSCF'
      INCLUDE 'SPVAL'
C
C    LOCAL VARIABLES-
C      VARIABLE      TYPE   DESCRIPTION
C      --------      ----   -----------
C      ANGIDX        INT    ANGLE INDEX FOR AN AMSU-A TO HIRS
C                           SPOT.
C      I             INT    LOOP INDEX.
C      MISSNG        INT    COUNTER TO TRACK ANY MISSING VALUES
C                           IN THE FOUR AMSU-A SPOTS USED IN
C                           INTERPOLATION.
C      RTEMP         REAL   VARIABLE USED TO STORE INTERPOLATED
C                           VALUES.
C      TIMIDX        INT    SCAN TO SCAN TIME INDEX FOR AN 
C                           AMSU-A TO HIRS LINE.
C
C    SUBPROGRAMS CALLED- NONE
C
C    FUNCTIONS USED- NONE
C
C    EXIT STATES- NONE
C**********************************************************************
C 
      INTEGER  HSPOT, HLINE
      REAL     AMADAT(ANSPOT,ATOTLN,ADATEL), VALAMA(ADATEL)

      INTEGER I, TIMIDX, ANGIDX, MISSNG
      REAL    RTEMP
      LOGICAL ISR4SPV
C
C  GET THE TIME INDEX FOR THE HIRS LINE AND SPOT.
C
c     TIMIDX = INDT(HLINE,HSPOT)
ccft Use nearest integer instead of truncation for indexing
      TIMIDX = NINT(INDT(HLINE,HSPOT))
      IF (TIMIDX .LT. 1) TIMIDX = 1
      IF (TIMIDX .GT. (ATOTLN-1)) TIMIDX = ATOTLN -1
C
C     GET THE ANGLE INDEX FOR THE HIRS SPOT
C
      ANGIDX = INDA(HSPOT)
ccft Use nearest integer instead of truncation for indexing
c     ANGIDX = NINT(INDA(HSPOT))
      IF (ANGIDX .LT. 1) ANGIDX = 1
      IF (ANGIDX .GT. (ANSPOT-1)) ANGIDX = ANSPOT -1
C
C     INTERPOLATE AMSU-A CHANNEL BRIGHTNESS TEMPERATURES TO
C     THE HIRS FOOTPRINT. IF AN AMSU-A BRIGHTNESS TEMPERATURE IS 
C     MISSING, MARK THE HIRS SPOT BRIGHTNESS TEMPERATURE AS MISSING.
C
      DO 50 I = 1, ANCHAN
         MISSNG = 0
         IF (ISR4SPV(AMADAT(ANGIDX,TIMIDX,I))) MISSNG=MISSNG+1
         IF (ISR4SPV(AMADAT(ANGIDX,TIMIDX+1,I))) MISSNG=MISSNG+1
         IF (ISR4SPV(AMADAT(ANGIDX+1,TIMIDX,I))) MISSNG=MISSNG+1
         IF (ISR4SPV(AMADAT(ANGIDX+1,TIMIDX+1,I))) MISSNG=MISSNG+1
C
         IF (MISSNG.GT.0) THEN
            VALAMA(I) = R4SPV
            GO TO 50
         END IF
C
C        INTERPOLATE AMSU-A BRIGHTNESS TEMPERATURES TO THE HIRS
C        FOOTPRINT.
C
         RTEMP = AA2HIR(4,HSPOT,HLINE) * AMADAT(ANGIDX,TIMIDX,I) +
     +           AA2HIR(2,HSPOT,HLINE) * AMADAT(ANGIDX,TIMIDX+1,I) +
     +           AA2HIR(3,HSPOT,HLINE) * AMADAT(ANGIDX+1,TIMIDX,I) +
     +           AA2HIR(1,HSPOT,HLINE) * AMADAT(ANGIDX+1,TIMIDX+1,I)
C
C        STORE THE INTERPOLATED BRIGHTNESS TEMPERATURE IN THE OUTPUT
C        BUFFER.
C
         VALAMA(I) = RTEMP
C
   50 CONTINUE
C 
C     INTERPOLATE CLOUD CLEARED AMSU-A CHANNELS 4 THROUGH 6.
C
      DO 60 I = 21,23
         MISSNG = 0
         IF (ISR4SPV(AMADAT(ANGIDX,TIMIDX,I))) MISSNG=MISSNG+1
         IF (ISR4SPV(AMADAT(ANGIDX,TIMIDX+1,I))) MISSNG=MISSNG+1
         IF (ISR4SPV(AMADAT(ANGIDX+1,TIMIDX,I))) MISSNG=MISSNG+1
         IF (ISR4SPV(AMADAT(ANGIDX+1,TIMIDX+1,I))) MISSNG=MISSNG+1
C
         IF (MISSNG.GT.0) THEN
            VALAMA(I) = R4SPV
            GO TO 60
         END IF
C
C        INTERPOLATE AMSU-A BRIGHTNESS TEMPERATURES TO THE HIRS
C        FOOTPRINT.
C
         RTEMP = AA2HIR(4,HSPOT,HLINE) * AMADAT(ANGIDX,TIMIDX,I) +
     +           AA2HIR(2,HSPOT,HLINE) * AMADAT(ANGIDX,TIMIDX+1,I) +
     +           AA2HIR(3,HSPOT,HLINE) * AMADAT(ANGIDX+1,TIMIDX,I) +
     +           AA2HIR(1,HSPOT,HLINE) * AMADAT(ANGIDX+1,TIMIDX+1,I)
C
C        STORE THE INTERPOLATED BRIGHTNESS TEMPERATURE IN THE OUTPUT
C        BUFFER.
C
         VALAMA(I) = RTEMP
C
   60 CONTINUE
C 
C     INTERPOLATE PRECIP SCREENED AMSU-A CHANNELS 4 AND 5
C
      DO 70 I = 25, 26
         MISSNG = 0
         IF (ISR4SPV(AMADAT(ANGIDX,TIMIDX,I))) MISSNG=MISSNG+1
         IF (ISR4SPV(AMADAT(ANGIDX,TIMIDX+1,I))) MISSNG=MISSNG+1
         IF (ISR4SPV(AMADAT(ANGIDX+1,TIMIDX,I))) MISSNG=MISSNG+1
         IF (ISR4SPV(AMADAT(ANGIDX+1,TIMIDX+1,I))) MISSNG=MISSNG+1
C
         IF (MISSNG.GT.0) THEN
            VALAMA(I) = R4SPV
            GO TO 70
         END IF
C
C        INTERPOLATE AMSU-A BRIGHTNESS TEMPERATURES TO THE HIRS
C        FOOTPRINT.
C
         RTEMP = AA2HIR(4,HSPOT,HLINE) * AMADAT(ANGIDX,TIMIDX,I) +
     +           AA2HIR(2,HSPOT,HLINE) * AMADAT(ANGIDX,TIMIDX+1,I) +
     +           AA2HIR(3,HSPOT,HLINE) * AMADAT(ANGIDX+1,TIMIDX,I) +
     +           AA2HIR(1,HSPOT,HLINE) * AMADAT(ANGIDX+1,TIMIDX+1,I)
C
C        STORE THE INTERPOLATED BRIGHTNESS TEMPERATURE IN THE OUTPUT
C        BUFFER.
C
         VALAMA(I) = RTEMP
C
   70 CONTINUE
C
      RETURN
      END
