      program hicol
      parameter (np=500)
      real*8 a,v
      dimension a(np,np),v(np*(np+1)/2)
      character*40 fin,fout
 
      write(6,'(a,$)')' Enter dimension of matrix: '
      read(5,*)n
      write(6,'(a,$)')' Enter  input file name: '
      read(5,'(a)')fin
      write(6,'(a,$)')' Enter output file name: '
      read(5,'(a)')fout

      open(1,file=fin)
      do i=1,n
       read(1,*)(a(i,j),j=1,n)
      enddo
      close(1)
c
      jj=1
      do i=1,n
       do j=i,n
        v(jj)=a(i,j)
        jj=jj+1
       enddo
      enddo
c
      ia=1
      do ic=1,n
       in=n-ic+1
       call cholesky(v(ia),in)
       ia=ia+in
      enddo
c
      jj=1
      do i=1,n
       do j=i,n
        a(i,j)=v(jj)
        a(j,i)=a(i,j)
        jj=jj+1
       enddo
      enddo
c      
      open(1,file=fout)
      do i=1,n
       write(1,'(1000(f8.3,1x))')(a(i,j),j=1,n)
      enddo
      close(1)
      open(1,file='eigen.out')
      do i=1,n
       write(1,*)a(i,i)
      enddo
      close(1)
c
      end

      subroutine cholesky(a,n)
c
      real*8 a
      dimension a(*)
c
      a(1)=sqrt(a(1))
      do i=2,n
       a(i)=a(i)/a(1)
      enddo
c
      ii=2
      jj=2
      do i=n+1,n*(n+1)/2
       a(i)=a(i)-a(ii)*a(jj)
       jj=jj+1
       if(jj.gt.n)then
        ii=ii+1
        jj=ii
       endif
      enddo
c
      return
      end

