      SUBROUTINE LINEAR (NETTOP,LOBUS,LBOLD,NLAST,LLNET)

      iNCLUDE 'PARX.INS'
      INCLUDE 'CNFLAG.INS'
      INCLUDE 'CNSPC0.INS'
      INCLUDE 'CNSPDI.INS'
      INCLUDE 'CNSPRE.INS'
      INCLUDE 'CNSPC2.INS'
      INCLUDE 'CNSPVI.INS'
      INCLUDE 'CNUNIT.INS'
      INCLUDE 'CNSPWK.INS'

C     parameter defination

      INTEGER NETTOP, LOBUS, LBOLD, NLAST, LLNET

C     local variable defination
      INTEGER MODE

      write(6,*) 'Entering Subroutine LINEAR'

      write(6,*) 'NLAST = ', NLAST


      IF((NETTOP.EQ.1).OR.(LOBUS.NE.LBOLD))THEN
        CALL ORDER(NLAST,LLNET)
C       do 10 I = 1, NLAST
C         write(6,*) 'FELIST[', I, '] = ', FELIST(I)
C         write(6,*) 'IBUSO[', I, '] = ', IBUSO(I)
C10     continue
      ENDIF
 
      CALL ACOREC(NLAST,LLNET)
 
C     do 20 I = 1, NLAST
C       write(6,*) 'INDEX[', I, '] = ', INDEX(I)
C20   continue

      WRITE(6,*) 'SET_UP before AFACTC'

      CALL SET_UP(RELEM,CELEM,STAIRS,CORNO,NODIA,INDEX,IBUSO,
     &            PNODIA,NLAST)

      MODE=1
      CALL AFACTC(MODE,NLAST)

      DO 30  I=1,NLAST-1
        WRITE(6,6000)I,IBUSO(I),NODIA(I)
        NE=NODIA(I)
        IS=INDEX(I)
        WRITE(6,6010)(CORNO(IR),IR=IS,IS+NE-1)
        WRITE(6,6020)(RELEM(IR),IR=IS,IS+NE-1)
        WRITE(6,6020)(CELEM(IR),IR=IS,IS+NE-1)
 30   CONTINUE

      WRITE(6,6110)
      WRITE(6,6120) (STAIRS(I),I=1,NLAST)

      WRITE(6,*) 'SET_UP after AFACTC'

      CALL SET_UP(RELEM,CELEM,STAIRS,CORNO,NODIA,INDEX,IBUSO,
     &            PNODIA,NLAST)

      write(6,*) 'Exiting Subroutine LINEAR'

 6000 FORMAT(//,1X,'ROW =',I5,'OLD BUS=',I5,'NO. ELEMENTS=',I5,/)
 6010 FORMAT(1X,10I10)
 6020 FORMAT(1X,10G12.4)
 6110 FORMAT(/,1X,'STAIRS')
 6120 FORMAT(/,1X,10G12.5)

      END

