subroutine lu1or4( m, n, nelem, lena, indc, indr, lenc, lenr, locc, locr )
integer(ip), intent(in) :: m, n, nelem, lena
integer(ip), intent(in) :: indc(lena), lenc(n), locc(n), lenr(m)
integer(ip), intent(out) :: indr(lena), locr(m)
!------------------------------------------------------------------
! lu1or4 constructs a row list indr, locr
! from a corresponding column list indc, locc,
! given the lengths of both columns and rows in lenc, lenr.
!
! xx Feb 1985: Original version.
! 17 Oct 2000: indc, indr now have size lena to allow nelem = 0.
!
! 10 Jan 2010: First f90 version.
! 12 Dec 2011: Declare intent and local variables.
!------------------------------------------------------------------
integer(ip) :: i, j, jdummy, l, l1, l2, lr
! Initialize locr(i) to point just beyond where the
! last component of row i will be stored.
l = 1
do i = 1, m
l = l + lenr(i)
locr(i) = l
end do
! By processing the columns backwards and decreasing locr(i)
! each time it is accessed, it will end up pointing to the
! beginning of row i as required.
l2 = nelem
j = n + 1
do jdummy = 1, n
j = j - 1
if (lenc(j) > 0) then
l1 = locc(j)
do l = l1, l2
i = indc(l)
lr = locr(i) - 1
locr(i) = lr
indr(lr) = j
end do
l2 = l1 - 1
end if
end do
end subroutine lu1or4