      subroutine inverse(u,n)
      implicit real*8 (a-h,o-x,z),logical*1(y)
      dimension u(n,n)
      double precision,dimension(:,:),allocatable :: 
     *vp,bid
      double precision,dimension(:),allocatable :: v
      allocate (vp(n,n))
      allocate (bid(n,n))
      allocate (v(n))
      bid=u
      call hdiag(u,vp,n,n)
      print*,'inverse : u diagonal'
      call script(u,n,n,n,n)
      do k=1,n
         v(k)=1.d0/u(k,k)
      enddo
      print*,'inverse v'
      call script(v,n,1,n,1)
c      v=1.d0/v
      do k=1,n
         u(k,k)=v(k)
      enddo
      print*,'inverse : u diagonal inverse'
      u=matmul(vp,matmul(u,transpose(vp)))
      bid=matmul(bid,u)
      print*,'inverse : bid apres inversion'
      call script(bid,n,n,n,n)
      print*,'inverse : u apres inversion'
      call script(u,n,n,n,n)
c      call script(v,n,1,n,1)
c      do k=1,n
c         u(:,k)=u(:,k)*v(k)
c      enddo
c      u=matmul(u,transpose(vp))
      deallocate (v)
      deallocate (vp)
      return
      end

