program OW_had

use sep 
use OW_type
use OW_parms_areal
use OW_hadam

implicit none

integer						:: i,j,k,hij
integer,allocatable					:: HD(:,:)
real,allocatable					:: tempr(:,:),CHD(:,:)
complex, allocatable				:: tfld(:)

 call sep_init()
 call sep_begin_prog()

open(unit=2,file="logfile.txt")

!---------------------------------------
! IO
!
 call owparam(.false.)

!--------------------------------------------------

!      allocate(HD(2*sog%xm%n*sou%w%n,sog%z%n))
      allocate(HD(2*sog%xm%n*sou%w%n,2*sog%xm%n*sou%w%n))
      do i=1,2*sog%xm%n
!         do j=1,sog%z%n
         do j=1,2*sog%xm%n
            do k=1,sou%w%n
!               call owhadamard((i-1)*sou%w%n+k,j,sog%xm%n,sog%z%n,hij)
               call owhadamard((i-1)*sou%w%n+k,(j-1)*sou%w%n+k,2*sog%xm%n*sog%z%n,2*sog%xm%n*sog%z%n,hij)
!               if(mod(k,2).eq.0) then
                  HD((i-1)*sou%w%n+k,(j-1)*sou%w%n+k)=hij
!               else
!                  HD((i-1)*sou%w%n+k,j)=-hij
!               end if 
            end do
         end do
      end do
      do i=1,2*sog%xm%n*sou%w%n
         write(2,8) HD(i,:)
      end do
8 format(1024I3)
!      allocate(tempr(2*sog%xm%n*sou%w%n,sog%z%n));tempr=0.
!      do i=1,sog%xm%n
!         tempr(2*(i-1)*sou%w%n+1:(2*i-1)*sou%w%n,:)=HD((i-1)*sou%w%n+1:i*sou%w%n,:)
!         tempr((2*i-1)*sou%w%n+1:2*i*sou%w%n,:)=HD((i-1+sog%xm%n)*sou%w%n+1:(i+sog%xm%n)*sou%w%n,:)
!      end do
!      HD=tempr
!
!      deallocate(tempr)
!      allocate(tfld(sou%w%n),CHD(2*sog%xm%n*sou%w%n,sog%z%n))
!      call owfftw(tfld,sou%w%n)
!      do i=1,2*sog%xm%n
!         do j=1,sog%z%n
!            tfld=0.
!            tfld=cmplx(HD((i-1)*sou%w%n+1:i*sou%w%n,j),0); call sfftw_execute(planF); CHD((i-1)*sou%w%n+1:i*sou%w%n,j)=atan(imag(tfld)/real(tfld))
!							! /sqrt(1.*sou%w%n))
!         end do
!      end do
!      deallocate(tfld,HD,CHD)
close(2)
call sep_end_prog()
end program OW_had
