      program factor
      implicit none
      integer dim, n
      parameter (dim=10)
      double precision  a(dim,dim), l(dim,dim), 
     &     u(dim,dim)
      integer ier

      read (5, *) n
      if (n .gt. dim) then
         write (0,*) "Matrix dimensions too large;"
         write (0,*) "  please adjust and re-compile factor.f."
         stop
      end if
      call d_read_matrix(a, n, n, ier)
      if (ier .ne. 0) call usage

      call d_ludecomp(a, l, u, n, ier)
      if (ier .ne. 0) then
         write (0,*) "factor:  Couldn't factor matrix."
      else
         call dg_write_matrix(l, n, n, '', 0)
         write (*,*) ""
         call dg_write_matrix(u, n, n, '', 0)
      end if

      end ! program factor

      subroutine usage()
      write (0,*) "lutest:  Input is n (dimension of square system),"
      write (0,*) "   A (matrix), b (right-hand-side vector)."
      return
      end ! subroutine usage
