# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "<stdin>"
module hesang  
! computes "diagonal of Hessian" in angle domain
  use adj_mod

  implicit none
  real, private		 			:: o2, d2
  real,private,dimension(:),allocatable		:: aa		!mask
  integer, private				:: n1,n2

  contains

  subroutine hesang_init(n1_in,n2_in,aa_in)			!,mask_in)
    integer			:: n1_in, n2_in
    real,dimension(n1_in*n2_in)	:: aa_in			!mask_in

    n1 = n1_in
    n2 = n2_in
    allocate(aa(n1*n2))
    aa = aa_in
!    allocate(mask(n1*n2))
!    mask = mask_in
  end subroutine hesang_init

  function hesang_lop ( adj, add, xx, yy) result(stat)
    integer            :: stat 
    logical,intent(in) :: adj,add 
    real,dimension(:)  :: xx,yy 
    call adjnull (adj,add,xx,yy )
    call hesang_lop2(adj,add,xx,yy )
    stat=0
  end function hesang_lop

  subroutine hesang_lop2(adj,add,xx,yy)
    logical,intent(in)   :: adj,add 
    real, dimension (:)  :: xx,yy
    integer i, j       
  
    do j = 1, n1*n2
	if ( adj) then
		xx(j)=xx(j)+yy(j)*aa(j)
	else
		yy(j)=yy(j)+xx(j)*aa(j)
	end if
    end do

  end subroutine hesang_lop2

  subroutine hesang_close()
    deallocate(aa)
  end subroutine hesang_close

end module hesang
