C     ******************************************************************
C     ******************************************************************

      subroutine inilist(n)

C     SCALAR ARGUMENT
      integer n

C     This subroutine initiates the list of nodes.

C     PARAMETERS
      include "dim.f"

C     COMMON SCALARS
      integer qi,qf,qlim

C     COMMON ARRAYS
      character * 5 listtype
      double precision llist(lmax),ulist(lmax)

C     COMMON BLOCKS
      common /list/llist,ulist,qi,qf,qlim,listtype

      if ( listtype .eq. 'QUEUE' ) then
          call inilistq(n)
      else ! if ( listtype .eq. 'STACK' ) then
          call inilists()
      end if

      end 

C     ******************************************************************
C     ******************************************************************

      subroutine putnode(n,l,u,overflow)

C     SCALAR ARGUMENTS
      integer n
      logical overflow

C     ARRAY ARGUMENTS
      double precision l(n),u(n)

C     This subroutine put a new node in the list.

C     PARAMETERS
      include "dim.f"

C     COMMON SCALARS
      integer qi,qf,qlim

C     COMMON ARRAYS
      character * 5 listtype
      double precision llist(lmax),ulist(lmax)

C     COMMON BLOCKS
      common /list/llist,ulist,qi,qf,qlim,listtype

      if ( listtype .eq. 'QUEUE' ) then
          call putnodeq(n,l,u,overflow)
      else ! if ( listtype .eq. 'STACK' ) then
          call putnodes(n,l,u,overflow)
      end if

      end

C     ******************************************************************
C     ******************************************************************

      subroutine getnode(n,l,u,underflow)

C     SCALAR ARGUMENTS
      integer n
      logical underflow

C     ARRAY ARGUMENTS
      double precision l(n),u(n)

C     This subroutine get a node from the list.

C     PARAMETERS
      include "dim.f"
 
C     COMMON SCALARS
      integer qi,qf,qlim

C     COMMON ARRAYS
      character * 5 listtype
      double precision llist(lmax),ulist(lmax)

C     COMMON BLOCKS
      common /list/llist,ulist,qi,qf,qlim,listtype

      if ( listtype .eq. 'QUEUE' ) then
          call getnodeq(n,l,u,underflow)
      else ! if ( listtype .eq. 'STACK' ) then
          call getnodes(n,l,u,underflow)
      end if

      end

C     ******************************************************************
C     ******************************************************************

      subroutine inilists()

C     This subroutine initiates the list of nodes.

C     PARAMETERS
      include "dim.f"

C     COMMON SCALARS
      integer qi,qf,qlim

C     COMMON ARRAYS
      character * 5 listtype
      double precision llist(lmax),ulist(lmax)

C     COMMON BLOCKS
      common /list/llist,ulist,qi,qf,qlim,listtype

      qf = 0

      end 

C     ******************************************************************
C     ******************************************************************

      subroutine putnodes(n,l,u,overflow)

C     SCALAR ARGUMENTS
      integer n
      logical overflow

C     ARRAY ARGUMENTS
      double precision l(n),u(n)

C     This subroutine put a new node in the list.

C     PARAMETERS
      include "dim.f"

C     COMMON SCALARS
      integer qi,qf,qlim

C     COMMON ARRAYS
      character * 5 listtype
      double precision llist(lmax),ulist(lmax)

C     LOCAL SCALARS
      integer i,ind

C     COMMON BLOCKS
      common /list/llist,ulist,qi,qf,qlim,listtype

      if ( ( qf + 1 ) * n .gt. lmax ) then
          overflow = .true.
          return
      end if

      qf = qf + 1

      do i = 1,n
          ind = ( qf - 1 ) * n + i
          llist(ind) = l(i)
          ulist(ind) = u(i)
      end do

      overflow = .false.

      end

C     ******************************************************************
C     ******************************************************************

      subroutine getnodes(n,l,u,underflow)

C     SCALAR ARGUMENTS
      integer n
      logical underflow

C     ARRAY ARGUMENTS
      double precision l(n),u(n)

C     This subroutine get a node from the list.

C     PARAMETERS
      include "dim.f"
 
C     COMMON SCALARS
      integer qi,qf,qlim

C     COMMON ARRAYS
      character * 5 listtype
      double precision llist(lmax),ulist(lmax)

C     LOCAL SCALARS
      integer i,ind

C     COMMON BLOCKS
      common /list/llist,ulist,qi,qf,qlim,listtype

      if ( qf .le. 0 ) then
          underflow = .true.
          return
      end if

      do i = 1,n
          ind = ( qf - 1 ) * n + i
          l(i) = llist(ind)
          u(i) = ulist(ind)
      end do

      qf = qf - 1

      underflow = .false.

      end

C     ******************************************************************
C     ******************************************************************

      subroutine inilistq(n)

C     SCALAR ARGUMENTS
      integer n

C     This subroutine initiates the list of nodes.

C     PARAMETERS
      include "dim.f"

C     COMMON SCALARS
      integer qi,qf,qlim

C     COMMON ARRAYS
      character * 5 listtype
      double precision llist(lmax),ulist(lmax)

C     COMMON BLOCKS
      common /list/llist,ulist,qi,qf,qlim,listtype

      qlim = int( lmax / n )

      qi = 0
      qf = 0

      end 

C     ******************************************************************
C     ******************************************************************

      subroutine putnodeq(n,l,u,overflow)

C     SCALAR ARGUMENTS
      integer n
      logical overflow

C     ARRAY ARGUMENTS
      double precision l(n),u(n)

C     This subroutine put a new node in the list.

C     PARAMETERS
      include "dim.f"

C     COMMON SCALARS
      integer qi,qf,qlim

C     COMMON ARRAYS
      character * 5 listtype
      double precision llist(lmax),ulist(lmax)

C     LOCAL SCALARS
      integer i,ind

C     COMMON BLOCKS
      common /list/llist,ulist,qi,qf,qlim,listtype

      if ( mod( qf + 1, qlim ) .eq. qi ) then
          overflow = .true.
          return
      end if

      do i = 1,n
          ind = qf * n + i
          llist(ind) = l(i)
          ulist(ind) = u(i)
      end do

      qf = mod( qf + 1, qlim )

      overflow = .false.

      end

C     ******************************************************************
C     ******************************************************************

      subroutine getnodeq(n,l,u,underflow)

C     SCALAR ARGUMENTS
      integer n
      logical underflow

C     ARRAY ARGUMENTS
      double precision l(n),u(n)

C     This subroutine get a node from the list.

C     PARAMETERS
      include "dim.f"
 
C     COMMON SCALARS
      integer qi,qf,qlim

C     COMMON ARRAYS
      character * 5 listtype
      double precision llist(lmax),ulist(lmax)

C     LOCAL SCALARS
      integer i,ind

C     COMMON BLOCKS
      common /list/llist,ulist,qi,qf,qlim,listtype

      if ( qi .eq. qf ) then
          underflow = .true.
          return
      end if

      do i = 1,n
          ind = qi * n + i
          l(i) = llist(ind)
          u(i) = ulist(ind)
      end do

      qi = mod( qi + 1, qlim )

      underflow = .false.

      end

