anchor.diff:        STOP
       END IF
     END IF
  -  ALLOCATE(BT%TREE(3,CAPACITY),STAT=IERR)
  +  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 = 0
  +  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
  -INTEGER(KIND=4)            :: I,J
   
     IF (BT%COUNT.EQ.0) THEN                   ! Special case where this is the first value.
       BT%COUNT = 1
  -    BT%TREE(1,BT%COUNT) = HASHCODE
  -    BT%TREE(2,1) = 0
  -    BT%TREE(3,1) = 0
  +    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,2)) CALL BTREE_RESIZE(BT,BT%CAPACITY+BLOCKSIZE)
  -
  -  J = 1                                      ! Start at top of the table.
  -  DO WHILE (J.LE.BT%COUNT)
  -    IF (J.EQ.0) RETURN
  -
  -    IF (HASHCODE.LT.BT%TREE(1,J)) THEN
  -      I = 2
  -    ELSE IF (HASHCODE.GT.BT%TREE(1,J)) THEN
  -      I = 3
  +  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
  -      I = 0
  +      RETURN
       END IF
  -    BTREE_ADD = J
  -    IF (I.EQ.0) RETURN
  -    
  -    IF (BT%TREE(I,J).EQ.0) THEN
  -      BT%COUNT = BT%COUNT + 1
  -      BT%TREE(1,BT%COUNT) = HASHCODE
  -      BT%TREE(I,J) = BT%COUNT
  -      BTREE_ADD = BT%COUNT
  -      J = 0
  -    ELSE
  -      J = BT%TREE(I,J)
  -    END IF
  -
     END DO
   
   END FUNCTION BTREE_ADD
  
positive.code:   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
  
                                                !  +------+------+
  
negative.code: SUBROUTINE BTREE_RESIZE(BT, CAPACITY)
  TYPE(BTREE),INTENT(INOUT)   :: BT                        ! Hash to be resized
  INTEGER(KIND=4),INTENT(IN)  :: CAPACITY                  ! Capacity to which to resize BTREE
  TYPE(TREENODE),ALLOCATABLE  :: TEMP(:)                   ! Temporary storage array for existing data
  INTEGER(KIND=4)             :: OLDCAPACITY,I,IERR        ! Temp variables, error status, and counters
    IF (ALLOCATED(BT%TREE)) THEN
      OLDCAPACITY = SIZE(BT%TREE)
      ALLOCATE(TEMP(OLDCAPACITY),STAT=IERR)
      IF (IERR.NE.0) THEN
        WRITE(0,'(A)') '0*** BTREE_RESIZE: UNABLE TO ALLOCATE TEMPORARY MEMORY FOR BTREE.'
        STOP
      END IF
      TEMP = BT%TREE
      CALL BTREE_ALLOCATE(BT, CAPACITY)
      DO I = 1, MIN(OLDCAPACITY,CAPACITY)
          BT%TREE(I) = TEMP(I)
      END DO
      DEALLOCATE(TEMP,STAT=IERR)
      IF (IERR.NE.0) THEN
  