c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1990  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     ################################################################
c     ##                                                            ##
c     ##  subroutine column  --  access Hessian elements by column  ##
c     ##                                                            ##
c     ################################################################
c
c
c     "column" takes the off-diagonal Hessian elements stored
c     as sparse rows and sets up indices to allow column access
c
c
      subroutine column (nvar,h_init,h_stop,h_index,
     &                   c_init,c_stop,c_index,c_value)
      implicit none
      include 'sizes.i'
      integer i,j,k,m,nvar
      integer h_init(maxvar),h_stop(maxvar)
      integer c_init(maxvar),c_stop(maxvar)
      integer h_index(maxhess),c_index(maxhess)
      integer c_value(maxhess)
c
c
c     zero out beginning and end marker for each column
c
      do i = 1, nvar
         c_init(i) = 0
         c_stop(i) = 0
      end do
c
c     count the number of elements in each column
c
      do i = 1, nvar
         do j = h_init(i), h_stop(i)
            k = h_index(j)
            c_stop(k) = c_stop(k) + 1
         end do
      end do
c
c     set each beginning marker just beyond
c     the last element for its column
c
      c_init(1) = c_stop(1) + 1
      do i = 2, nvar
         c_init(i) = c_init(i-1) + c_stop(i)
      end do
c
c     set column index by scanning rows in reverse order
c
      do i = nvar, 1, -1
         do j = h_init(i), h_stop(i)
            k = h_index(j)
            m = c_init(k) - 1
            c_init(k) = m
            c_index(m) = i
            c_value(m) = j
         end do
      end do
c
c     convert "c_stop" from number of elements
c     in column to end marker for the column
c
      do i = 1, nvar
         c_stop(i) = c_init(i) + c_stop(i) - 1
      end do
      return
      end
