      INTEGER FUNCTION EXCH(J1, J2, DSA, LDSA, HASH, LHASH, OFFSET)
      INTEGER DSA(LDSA), HASH(LHASH), OFFSET
      INTEGER OUTUT, SYMLEN, OUTUT2, OUTUT3, OUTUT4
      COMMON /PARAMS/ INUT, OUTUT, NOCHAR, SYMLEN, OUTUT2, OUTUT3,
     *    OUTUT4
C
C     DSA(HASH(J1)+OFFSET) CONTAINS ELE TO BE COMPARED
C      DSA(HASH(J2)+OFFSET) CONTAINS ELE TO BE COMPARED
C
      JJ1 = HASH(J1) + OFFSET
      JJ2 = HASH(J2) + OFFSET
      DO 40 I=1,SYMLEN
        K1 = JJ1 + I - 1
        K2 = JJ2 + I - 1
        IF (DSA(K1)) 10, 20, 20
   10   IF (DSA(K2)) 30, 50, 50
   20   IF (DSA(K2)) 70, 30, 30
   30   IF (DSA(K1)-DSA(K2)) 70, 40, 50
   40 CONTINUE
C
C     COMPARISON SHOWS ELEMENTS IN PROPER ORDER
C
   50 EXCH = 0
   60 RETURN
C
C     COMPARISON SHOWS NEED FOR EXCHANGE
C
   70 I = HASH(J1)
      HASH(J1) = HASH(J2)
      HASH(J2) = I
      EXCH = -1
      GO TO 60
      END
