anchor.diff:    WRITE(6,'("       HASHCODE OF STR20 ", 4X A20," = ",I11)') STR20, HASHCODE(STR20)
     WRITE(6,'("       HASHCODE OF STR24 ",    A24," = ",I11)') STR24, HASHCODE(STR24)
   
  +  !CALL BTREE_SETBLOCKSIZE(4)
     CALL BTREE_INIT(BT)
  -  WRITE(6,'("CAPACITY = ",I4,", COUNT = ",I4)') SIZE(BT%TREE,2), BT%COUNT
  +  WRITE(6,'("CAPACITY = ",I4,", COUNT = ",I4)') SIZE(BT%TREE), BT%COUNT
   
                                                 !            +------+       +------+------+
  -                                              !  IND       |VALUES|       |BEFORE|AFTER |              44
  +                                              !  IND       |VALUES|       | LEFT | RIGHT|              44
                                                 !            +------+       +------+------+             /  \
     RES = BTREE_ADD(BT,44)                      !   1        |  44  |       |  4   |   2  |           42    64
     RES = BTREE_ADD(BT,64)                      !   2        |  64  |       |  7   |   3  |          /     /   \
  
positive.code: INTEGER(KIND=4),INTENT(INOUT) :: C
  LOGICAL(KIND=4),INTENT(IN)    :: ASCENDING
  IF (ASCENDING) THEN
    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) = BT%TREE(1,I)
    IF (BT%TREE(3,I).NE.0) CALL BTREE_SORTED(BT,ARRAY,BT%TREE(3,I),C,ASCENDING)
  ELSE
    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) = 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 BTREE_SORTED
  ! ---------------------------------------------------------------------------------------------------------------------------------+
  
negative.code:       STOP
      END IF
    END IF
    ALLOCATE(BT%TREE(CAPACITY),STAT=IERR)
    IF (IERR.NE.0) THEN
      WRITE(0,'(A)') '0*** BTREE_ALLOCATE: UNABLE TO ALLOCATE MEMORY FOR BTREE.'
      STOP
    END IF
    BT%TREE = TREENODE(0,0,0)
    BT%CAPACITY = CAPACITY
  END SUBROUTINE BTREE_ALLOCATE
  ! ---------------------------------------------------------------------------------------------------------------------------------+
  INTEGER(KIND=4) FUNCTION BTREE_ADD(BT,HASHCODE)
  TYPE(BTREE),INTENT(INOUT)  :: BT
  INTEGER(KIND=4),INTENT(IN) :: HASHCODE
  
    IF (BT%COUNT.EQ.0) THEN                   ! Special case where this is the first value.
      BT%COUNT = 1
      BT%TREE(BT%COUNT)%HASHCODE = HASHCODE
      BT%TREE(BT%COUNT)%LEFT  = 0
      BT%TREE(BT%COUNT)%RIGHT = 0
      BTREE_ADD = BT%COUNT
      RETURN
    ENDIF
  
    IF (BT%COUNT.EQ.SIZE(BT%TREE)) CALL BTREE_RESIZE(BT,BT%CAPACITY+BLOCKSIZE)
  
    BTREE_ADD = 1                                      ! Start at top of the table.
    DO WHILE (BTREE_ADD.LE.BT%COUNT)
      IF (BTREE_ADD.EQ.0) RETURN
  
      IF (HASHCODE.LT.BT%TREE(BTREE_ADD)%HASHCODE) THEN
        IF (BT%TREE(BTREE_ADD)%LEFT.EQ.0) THEN
          BT%COUNT = BT%COUNT + 1
          BT%TREE(BT%COUNT)%HASHCODE = HASHCODE
          BT%TREE(BTREE_ADD)%LEFT = BT%COUNT
          BTREE_ADD = BT%COUNT
          RETURN
        ELSE
          BTREE_ADD = BT%TREE(BTREE_ADD)%LEFT
        END IF
      ELSE IF (HASHCODE.GT.BT%TREE(BTREE_ADD)%HASHCODE) THEN
        IF (BT%TREE(BTREE_ADD)%RIGHT.EQ.0) THEN
          BT%COUNT = BT%COUNT + 1
          BT%TREE(BT%COUNT)%HASHCODE = HASHCODE
          BT%TREE(BTREE_ADD)%RIGHT = BT%COUNT
          BTREE_ADD = BT%COUNT
          RETURN
        ELSE
          BTREE_ADD = BT%TREE(BTREE_ADD)%RIGHT
        END IF
      ELSE
        RETURN
      END IF
    END DO
  
  END FUNCTION BTREE_ADD
  