      LOGICAL FUNCTION XEQY(X,Y,EPSLON)
C
C**********************************************************************
C
C   NAME- XEQY
C
C   LANGUAGE- FORTRAN-77      TYPE- LOGICAL FUNCTION  COMPUTER- CRAY
C
C   VERSION- 1.0    DATE- 12/07/88   PROGRAMMER- KV JARVA
C   VERSION- 3.0    DATE- 05/14/96   PROGRAMMER- ALEX POZDNYAK, FDC
C   VERSION- 3.1    DATE- 06/07/96   PROGRAMMER- tim gardner (hstx)
C      FOR REHOSTING TO THE CRAY, CHANGED ALL R*4 DECLARATIONS TO
C      REAL. 
C
C   FUNCTION- THIS FUNCTION TESTS TWO REAL NUMBERS, X AND Y, TO SEE
C        IF THEY ARE APPROXIMATELY EQUAL.  IF THEY ARE, THE FUNCTION
C        RETURNS A VALUE OF TRUE.  IF NOT, THE RETURNED VALUE IS FALSE.
C
C        NEAR ZERO THE TEST THAT IS PERFORMED JUST CHECKS WHETHER THE
C        GIVEN NUMBERS ARE WITHIN EPSLON OF EACH OTHER.
C        IF THE NUMBERS ARE NOT WITHIN EPSLON/2 OF ZERO BUT ARE OF
C        OPPOSITE SIGN, THEY ARE NOT APPORXIMATELY EQUAL AND THE
C        FUNCTION RETURNS A FALSE.
C        IF NEITHER OF THE FIRST TWO TESTS ARE APPLICABLE WE
C        CHOOSE THE MINIMUM OF THE TWO RATIOS X/Y & Y/X AND TEST
C        WHETHER IT IS GREATER THAN (1. - EPSLON / (1. + EPSLON/2.)).
C        THIS IS EQUIVALENT TO CHECKING WHETHER X AND Y ARE WITHIN
C        N * EPSLON OF EACH OTHER WHERE N REPRESENTS THE REAL NUMBER
C        THAT X & Y ARE SUPPOSED TO APPROXIMATE.
c
c   version 3.1- sign function was substituted for previous check of
c                x and y because under some instances |x/abs(x)| is
c                not 1.0 on the Cray.
C
C   PARAMETERS-
C      VARIABLE                TYPE I/O FUNCTION
C      --------                ---- --- --------
C      X                       REAL  I  ONE VALUE TO TEST
C      Y                       REAL  I  ANOTHER VALUE TO TEST
C      EPSLON                  REAL  I  MEASURE OF CLOSENESS
C
C   SUBPROGRAMS CALLED- NONE
C
C   COMMON AREAS- NONE
C
C**********************************************************************
C
      REAL X, Y, R, EPSLON
C
      IF ((ABS(X) .LE. EPSLON * .5).OR.(ABS(Y) .LE. EPSLON * .5)) THEN
C***     THE CASE FOR NUMBERS NEAR ZERO
           IF (ABS(X-Y) .LE. EPSLON) THEN
                XEQY = .TRUE.
                RETURN
           ENDIF
      ELSE IF (sign(x,y) .ne. x) THEN
C***      THE NUMBERS ARE OF OPPOSITE SIGN AND NEITHER IS WITHIN
C***      (EPSLON / 2) OF ZERO.
            XEQY = .FALSE.
            RETURN
      ELSE
C***      THE CASE FOR NUMBERS WITH SAME SIGN & FAR FROM ZERO
          R = AMIN1(X/Y,Y/X)
          IF ((1. - EPSLON / (1. + EPSLON * .5)) .LE. R) THEN
              XEQY = .TRUE.
              RETURN
          ENDIF
      ENDIF
C
C***  X DOES NOT EQUAL Y
C
      XEQY = .FALSE.
      RETURN
      END
