          SUBROUTINE NEXT(MOD,INMOD)
          COMMON/LINKIT/ISTRT,LINKS(6,15)
          INDEX=2
100       MOD1=LINKS(INDEX,MOD)
          IF(MOD1.EQ.0)GO TO 102
          MOD=MOD1
          GO TO 2
102       IF(INDEX.GE.6)GO TO 101
          INDEX=INDEX+1
          GO TO 100
101       IF(MOD.EQ.INMOD)GO TO 2
          IPAR=LINKS(1,MOD)
          INDEX=1
104       INDEX=INDEX+1
          ITEST=LINKS(INDEX,IPAR)
          IF(ITEST.EQ.MOD)GO TO 103
          GO TO 104
103       MOD=IPAR
          GO TO 102
2         RETURN
          RETURN
          END
