*CMZ :          23/08/93  13.30.10  by  Jonathan Butterworth
*-- Author :
      SUBROUTINE NODAUD (PARENT,TNODE,NEWNOD,NEWLFT,TREE)
      INTEGER PARENT,TNODE,NEWNOD,TREE(4,1000),SON,NEWLFT
      INTEGER SNODES(100)
      INTEGER PNODES,MNODES
      SAVE
      IF(100.GT.100) GOTO 200
      PNODES=0
      MNODES=100
      PNODES=PNODES+1
      IF(PNODES.GT.MNODES) GOTO 160
      SNODES(PNODES)=PARENT
 10   IF(TNODE.GT.TREE(1,PARENT)) GOTO 40
      IF(PNODES.LE.0) GOTO 150
      PARENT=SNODES(PNODES)
      IF(TREE(4,PARENT).GE.0) GOTO 20
      SON=TREE(2,PARENT)
      GOTO 30
 20   SON=TREE(3,PARENT)
 30   IF(SON.LE.0) GOTO 70
      PARENT=SON
      PNODES=PNODES+1
      IF(PNODES.GT.MNODES) GOTO 160
      SNODES(PNODES)=PARENT
      GOTO 70
 40   IF(PNODES.LE.0) GOTO 150
      PARENT=SNODES(PNODES)
      IF(TREE(4,PARENT).LE.0) GOTO 50
      SON=TREE(2,PARENT)
      GOTO 60
 50   SON=TREE(3,PARENT)
 60   IF(SON.LE.0) GOTO 70
      PARENT=SON
      PNODES=PNODES+1
      IF(PNODES.GT.MNODES) GOTO 160
      SNODES(PNODES)=PARENT
 70   IF(SON.GE.0) GOTO 10
      IF(TNODE.NE.-SON) GOTO 220
      GOTO 80
 80   IF(TREE(4,PARENT).GE.0) GOTO 100
      IF(SON.NE.TREE(3,PARENT)) GOTO 90
      TREE(3,PARENT)=NEWNOD
      GOTO 120
 90   TREE(2,PARENT)=NEWNOD
      GOTO 120
 100  IF(SON.NE.TREE(2,PARENT)) GOTO 110
      TREE(2,PARENT)=NEWNOD
      GOTO 120
 110  TREE(3,PARENT)=NEWNOD
 120  SON=NEWNOD
 130  IF(TREE(2,PARENT).EQ.SON.AND.TREE(4,PARENT).LT.0.OR.TREE(3,PARENT
     1).EQ.SON.AND.TREE(4,PARENT).GT.0) GOTO 140
      SON=PARENT
      PNODES=PNODES-1
      IF(PNODES.LT.0) GOTO 180
      IF(PNODES.LE.0) GOTO 150
      PARENT=SNODES(PNODES)
      GOTO 130
 140  TREE(1,PARENT)=NEWLFT
 150  RETURN
 160  WRITE(6,170)
 170  FORMAT(' NODAUD STACK OVERFLOW')
      STOP
 180  WRITE(6,190)
 190  FORMAT(' NODAUD STACK UNDERFLOW')
      STOP
 200  WRITE(6,210)
 210  FORMAT(' NODAUD IMPOSSIBLE')
      STOP
 220  WRITE(6,230) TNODE,TREE(SON,PARENT)
 230  FORMAT(' LOOKING FOR BUCKET ',I10,'  BUT FOUND ',I10)
      STOP
      END
