      SUBROUTINE BILINR ( CART2D, MAXI, MAXJ, INTRPI, INTRPJ, VALUE )
C
C**********************************************************************
C
C   NAME- BILINR
C
C   LANGUAGE- FORTRAN 77    TYPE- SUBROUTINE     COMPUTER- CRAY
C
C   VERSION- 1.0    DATE- 12/21/92   PROGRAMMER- J.J. THROWE (SMSRC)
C   VERSION- 3.0    DATE- 05/14/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- 05/13/98   PROGRAMMER- BRIAN BARIL (RSTX)
C      CHANGED FORMAT OF THE CONDITION STATEMENT WHICH DETERMINES
C      IF THE POINT IS ON THE GRID.
C
C   FUNCTION - THIS SUBROUTINE PERFORMS A BILINEAR INTERPOLATION
C              FOR A POINT WITHIN A TWO-DIMENSIONAL CARTESIAN DATA
C              ARRAY.
C
C   COMMON AREA PARAMETERS- NONE
C
C   CALLING SEQUENCE PARAMETERS-
C
C    VARIABLE  TYPE  I/O  DESCRIPTION
C    --------  ----  ---  ----------------------------------------------
C      CART2D   REAL  I   2-D CARTESIAN DATA ARRAY, DIMENSIONED
C                         (MAXI,MAXJ).
C      MAXI     INT   I   I DIMENSION OF CART2D.
C      MAXJ     INT   I   J DIMENSION OF CART2D.
C      INTRPI   REAL  I   THE I CARTESIAN COORDINATE FOR WHICH A VALUE
C                         IS TO BE FOUND.
C      INTRPJ   REAL  I   THE J CARTESIAN COORDINATE FOR WHICH A VALUE
C                         IS TO BE FOUND.
C      VALUE    REAL  O   THE INTERPOLATED VALUE.
C
C   LOCAL PARAMETERS-
C    ARGUMENTS  TYPE    DESCRIPTION
C    --------   ----    ----------------------------------------
C
C    DELTAI      REAL   FRACTIONAL PORTION OF THE I COORDINATE
C                       OF THE CARTESIAN GRID ARRAY.
C    DELTAJ      REAL   FRACTIONAL PORTION OF THE J COORDINATE
C                       OF THE CARTESIAN GRID ARRAY.
C    I , J       INT    INTEGER PORTION OF INTRPI AND INTRPJ.
C
C   FUNCTION USED-  FLOAT, INT
C
C   EXIT STATES-    NONE
C
C   COMMENTS-
C
C           IF ANY OF THE 4 CARTESIAN TWO-DIMENSIONAL VALUES
C           NEEDED FOR INTERPOLATION ARE MISSING VALUES, BILINR
C           RETURNS A MISSING VALUE IN 'VALUE'.
C *********************************************************************
C
      INTEGER  MAXI , MAXJ
      REAL     CART2D(MAXI,MAXJ), INTRPI, INTRPJ, VALUE
C
      REAL     DELTAI , DELTAJ
      INTEGER  I , J
C
      INCLUDE 'SPVAL'
C***********************************************************************
C
C   DETERMINE THE LOCATION OF THE POINT RELATIVE TO THE CARTESIAN GRID.
C
      I = INT(INTRPI)
      J = INT(INTRPJ)
      DELTAI = INTRPI - I
      DELTAJ = INTRPJ - J
C
      VALUE = 0.0
C
C   MAKE SURE THE POINT IS ON THE GRID. IF NOT, FILL VALUE WITH R4SPV.
C
C REPLACED R4SPV BY M_R4SPV WHEN PORTED FROM CRAY TO IBM-SP.

      IF(((INTRPI.LT.1.0).OR.(INTRPI.GT.FLOAT(MAXI))).OR.
     1  ((INTRPJ.LT.1.0).OR.(INTRPJ.GT.FLOAT(MAXJ)))) THEN
      
      VALUE = M_R4SPV
      ELSE      

C
C   IF ALL 4 CORNER VALUES ARE PRESENT PERFORM BILINEAR INTERPOLATION
C
          IF ((CART2D(I,J).EQ.M_R4SPV).OR.(CART2D(I+1,J).EQ.M_R4SPV).OR.
     1 (CART2D(I,J+1).EQ.M_R4SPV).OR.(CART2D(I+1,J+1).EQ.M_R4SPV))THEN
            VALUE = M_R4SPV
          ELSE
            VALUE = CART2D(I,J)*(1.0 - DELTAI)*(1.0 - DELTAJ) +
     1              CART2D(I+1,J)*DELTAI*(1.0 - DELTAJ) +
     2              CART2D(I,J+1)*(1.0 - DELTAI)*DELTAJ +
     3              CART2D(I+1,J+1)*DELTAI*DELTAJ
          END IF

         ENDIF

C
C
      RETURN
      END
