anchor.diff:    END IF
     I = 1
     C = 0
  -  CALL HASH_SORTED(H,ARRAY,I,C,ASC)
  -END SUBROUTINE HASH_SORT
  -! ---------------------------------------------------------------------------------------------------------------------------------+
  -RECURSIVE SUBROUTINE HASH_SORTED(H,ARRAY,I,C,ASCENDING)
  -TYPE(HASH), INTENT(IN)    :: H
  +  CALL BTREE_SORTED(BT,ARRAY,I,C,ASC)
  +END SUBROUTINE BTREE_SORT
  +! ---------------------------------------------------------------------------------------------------------------------------------+
  +RECURSIVE SUBROUTINE BTREE_SORTED(BT,ARRAY,I,C,ASCENDING)
  +TYPE(BTREE), INTENT(IN)       :: BT
   INTEGER(KIND=4),INTENT(INOUT) :: ARRAY(:)
   INTEGER(KIND=4),INTENT(IN)    :: I
   INTEGER(KIND=4),INTENT(INOUT) :: C
   LOGICAL(KIND=4),INTENT(IN)    :: ASCENDING
   IF (ASCENDING) THEN
  -  IF (H%HASH(2,I).NE.0) CALL HASH_SORTED(H,ARRAY,H%HASH(2,I),C,ASCENDING)
  +  IF (BT%TREE(2,I).NE.0) CALL BTREE_SORTED(BT,ARRAY,BT%TREE(2,I),C,ASCENDING)
     IF (C.GT.SIZE(ARRAY)) RETURN
     C = C + 1
  -  ARRAY(C) = H%HASH(1,I)
  -  IF (H%HASH(3,I).NE.0) CALL HASH_SORTED(H,ARRAY,H%HASH(3,I),C,ASCENDING)
  +  ARRAY(C) = BT%TREE(1,I)
  +  IF (BT%TREE(3,I).NE.0) CALL BTREE_SORTED(BT,ARRAY,BT%TREE(3,I),C,ASCENDING)
   ELSE
  -  IF (H%HASH(3,I).NE.0) CALL HASH_SORTED(H,ARRAY,H%HASH(3,I),C,ASCENDING)
  +  IF (BT%TREE(3,I).NE.0) CALL BTREE_SORTED(BT,ARRAY,BT%TREE(3,I),C,ASCENDING)
     IF (C.GT.SIZE(ARRAY)) RETURN
     C = C + 1
  -  ARRAY(C) = H%HASH(1,I)
  -  IF (H%HASH(2,I).NE.0) CALL HASH_SORTED(H,ARRAY,H%HASH(2,I),C,ASCENDING)
  +  ARRAY(C) = BT%TREE(1,I)
  +  IF (BT%TREE(2,I).NE.0) CALL BTREE_SORTED(BT,ARRAY,BT%TREE(2,I),C,ASCENDING)
   END IF
  -END SUBROUTINE HASH_SORTED
  -! ---------------------------------------------------------------------------------------------------------------------------------+
  -END MODULE MODHASH
  +END SUBROUTINE BTREE_SORTED
  +! ---------------------------------------------------------------------------------------------------------------------------------+
  +END MODULE MODBTREE
   ! ---------------------------------------------------------------------------------------------------------------------------------+
   PROGRAM HASHTEST
   USE MODHASHCODE
  -USE MODHASH
  +USE MODBTREE
   IMPLICIT NONE
   INTEGER(KIND=4)           :: RES,I,J
   INTEGER(KIND=1),PARAMETER :: IDIV = 11
  
positive.code: !
  END MODULE MODHASHCODE
  ! ---------------------------------------------------------------------------------------------------------------------------------+
                                                       MODULE MODHASH
  ! ---------------------------------------------------------------------------------------------------------------------------------+
  IMPLICIT NONE
  PRIVATE
  PUBLIC :: HASH,HASH_RESIZE,HASH_ADD,HASH_SORT
  TYPE HASH
    INTEGER(KIND=4)             :: CAPACITY
    INTEGER(KIND=4)             :: COUNT
    INTEGER(KIND=4),ALLOCATABLE :: HASH(:,:)
  END TYPE HASH
  INTEGER(KIND=4),PARAMETER     :: DEFAULT_BLOCKSIZE = 64
  INTEGER(KIND=4)               :: BLOCKSIZE
  ! ---------------------------------------------------------------------------------------------------------------------------------+
                                                             CONTAINS
  ! ---------------------------------------------------------------------------------------------------------------------------------+
  SUBROUTINE HASH_RESIZE(H, CAPACITY)
  TYPE(HASH),INTENT(INOUT) :: H
  INTEGER(KIND=4),INTENT(IN)   :: CAPACITY
  INTEGER(KIND=4),ALLOCATABLE  :: TEMP(:,:)
  INTEGER(KIND=4)              :: OLDCAPACITY,I,J,IERR
    IF (ALLOCATED(H%HASH)) THEN
      OLDCAPACITY = SIZE(H%HASH,2)
      ALLOCATE(TEMP(3,OLDCAPACITY),STAT=IERR)
      IF (IERR.NE.0) THEN
        WRITE(0,'(A)') '0*** UNABLE TO ALLOCATE TEMPORARY MEMORY FOR HASH.'
        STOP
      END IF
      TEMP = H%HASH
      CALL HASH_ALLOCATE(H, CAPACITY)
      DO J = 1, MIN(OLDCAPACITY,CAPACITY)
        DO I = 1,3
          H%HASH(I,J) = TEMP(I,J)
        END DO
      END DO
      DEALLOCATE(TEMP,STAT=IERR)
      IF (IERR.NE.0) THEN
        WRITE(0,'(A)') '0*** UNABLE TO DEALLOCATE TEMPORARY MEMORY FOR HASH.'
        STOP
      END IF
    ELSE
      CALL HASH_ALLOCATE(H, CAPACITY)
    END IF
  END SUBROUTINE HASH_RESIZE
  ! ---------------------------------------------------------------------------------------------------------------------------------+
  SUBROUTINE HASH_ALLOCATE(H, CAPACITY)
  TYPE(HASH),INTENT(INOUT) :: H
  INTEGER(KIND=4),INTENT(IN)   :: CAPACITY
  INTEGER(KIND=4)              :: IERR
    IF (ALLOCATED(H%HASH)) THEN
      DEALLOCATE(H%HASH,STAT=IERR)
      IF (IERR.NE.0) THEN
        WRITE(0,'(A)') '0*** UNABLE TO DEALLOCATE MEMORY FOR HASH.'
        STOP
      END IF
    END IF
    ALLOCATE(H%HASH(3,CAPACITY),STAT=IERR)
    IF (IERR.NE.0) THEN
      WRITE(0,'(A)') '0*** UNABLE TO ALLOCATE MEMORY FOR HASH.'
      STOP
    END IF
    H%HASH = 0
    H%CAPACITY = CAPACITY
  END SUBROUTINE HASH_ALLOCATE
  ! ---------------------------------------------------------------------------------------------------------------------------------+
  INTEGER(KIND=4) FUNCTION HASH_ADD(H,HASHCODE)
  TYPE(HASH),INTENT(INOUT) :: H
  INTEGER(KIND=4),INTENT(IN)   :: HASHCODE
  INTEGER(KIND=4)              :: I,J
  
    IF (H%COUNT.EQ.0) THEN                   ! Special case where this is the first value.
      H%COUNT = 1
      H%HASH(1,H%COUNT) = HASHCODE
      H%HASH(2,1) = 0
      H%HASH(3,1) = 0
      HASH_ADD = H%COUNT
      RETURN
    ELSE IF (H%COUNT.EQ.SIZE(H%HASH,2)) THEN
      WRITE(0,'(A)') '0*** HASH IS FULL.'
      FLUSH(0)
      STOP
    ENDIF
  
    J = 1                                      ! Start at top of the table.
    DO WHILE (J.LE.H%COUNT)
      IF (J.EQ.0) RETURN
  
      IF (HASHCODE.LT.H%HASH(1,J)) THEN
        I = 2
      ELSE IF (HASHCODE.GT.H%HASH(1,J)) THEN
        I = 3
      ELSE
        I = 0
      END IF
      HASH_ADD = J
      IF (I.EQ.0) RETURN
      
      IF (H%HASH(I,J).EQ.0) THEN
        H%COUNT = H%COUNT + 1
        H%HASH(1,H%COUNT) = HASHCODE
        H%HASH(I,J) = H%COUNT
        HASH_ADD = H%COUNT
        J = 0
      ELSE
        J = H%HASH(I,J)
      END IF
  
    END DO
  
  END FUNCTION HASH_ADD
  ! ---------------------------------------------------------------------------------------------------------------------------------+
  SUBROUTINE HASH_SORT(H, ARRAY, ASCENDING)
  TYPE(HASH), INTENT(IN)                 :: H
  INTEGER(KIND=4),INTENT(INOUT)          :: ARRAY(:)
  LOGICAL(KIND=4),INTENT(IN),   OPTIONAL :: ASCENDING
  INTEGER(KIND=4)                        :: I,C
  
negative.code: CHARACTER(LEN=16)         :: STR16 = '   Some String  '
  CHARACTER(LEN=20)         :: STR20 = '1 34 tmp xyz  t '
  CHARACTER(LEN=24)         :: STR24 = '  ABCDEFGHIJKLMNO       '
  TYPE(BTREE)               :: BT
  INTEGER(KIND=4)           :: ASC(10),DESC(10)
    WRITE(6,'("0*** HASHTEST - INTEGER ********")')
    WRITE(6,'("       HASHCODE OF INT1  ",I20,    " = ",I11)')  INT1, HASHCODE( INT1)
    WRITE(6,'("       HASHCODE OF INT2  ",I20,    " = ",I11)')  INT2, HASHCODE( INT2)
    WRITE(6,'("       HASHCODE OF INT4  ",I20,    " = ",I11)')  INT4, HASHCODE( INT4)
    WRITE(6,'("       HASHCODE OF INT8  ",I20,    " = ",I11)')  INT8, HASHCODE( INT8)
    WRITE(6,'("0*** HASHTEST - REAL    ********")')
    WRITE(6,'("       HASHCODE OF REAL4 ",G20.10, " = ",I11)') REAL4, HASHCODE(REAL4)
    WRITE(6,'("       HASHCODE OF REAL8 ",G20.10, " = ",I11)') REAL8, HASHCODE(REAL8)
    WRITE(6,'("0*** HASHTEST - STRING  ********")')
    WRITE(6,'("       HASHCODE OF STR12 ",12X,A12," = ",I11)') STR12, HASHCODE(STR12)
    WRITE(6,'("       HASHCODE OF STR16 ", 8X,A16," = ",I11)') STR16, HASHCODE(STR16)
    WRITE(6,'("       HASHCODE OF STR20 ", 4X A20," = ",I11)') STR20, HASHCODE(STR20)
    WRITE(6,'("       HASHCODE OF STR24 ",    A24," = ",I11)') STR24, HASHCODE(STR24)
  
    CALL BTREE_INIT(BT)
    WRITE(6,'("CAPACITY = ",I4,", COUNT = ",I4)') SIZE(BT%TREE,2), BT%COUNT
  
                                                !            +------+       +------+------+
                                                !  IND       |VALUES|       |BEFORE|AFTER |              44
                                                !            +------+       +------+------+             /  \
    RES = BTREE_ADD(BT,44)                      !   1        |  44  |       |  4   |   2  |           42    64
    RES = BTREE_ADD(BT,64)                      !   2        |  64  |       |  7   |   3  |          /     /   \
    RES = BTREE_ADD(BT,87)                      !   3        |  87  |       |  5   |   0  |        14    60    87
    RES = BTREE_ADD(BT,42)                      !   4        |  42  |       |  6   |   0  |          \        /
    RES = BTREE_ADD(BT,85)                      !   5        |  85  |       |  8   |   0  |           18    85
    RES = BTREE_ADD(BT,14)                      !   6        |  14  |       |  0   |  10  |                /
    RES = BTREE_ADD(BT,60)                      !   7        |  60  |       |  0   |   0  |              78
    RES = BTREE_ADD(BT,78)                      !   8        |  78  |       |  9   |   0  |             /
    RES = BTREE_ADD(BT,72)                      !   9        |  72  |       |  0   |   0  |           72
    RES = BTREE_ADD(BT,18)                      !  10        |  18  |       |  0   |   0  |
                                                !            +------+       +------+------+
  
    WRITE(6,'("CAPACITY = ",I4,", COUNT = ",I4)') SIZE(BT%TREE,2), BT%COUNT
  
    DO I = 1, BT%COUNT
      WRITE(6,'(3I8)') (BT%TREE(J,I),J=1,3)
    END DO
  
                                                !  +------+------+
                                                !  | ASC  | DESC |
  