program OWcorrs

use sep 

implicit none

real						:: d1,o1,o3,d3
integer						:: n1,n3
integer						:: i,j,k,l,m,n
real, allocatable					:: input(:,:),corrmat(:,:)
complex, allocatable				:: cinput(:,:)

 call sep_init()
 call sep_begin_prog()

!----------------------------------------------------
! Memory Allocation
!
 call from_history("n1",n1);	call from_history("d1",d1);	call from_history("o1",o1)
 call from_history("n3",n3);	call from_history("d3",d3);	call from_history("o3",o3)  

 call to_history("n1",n3);	call to_history("d1",d3);	call to_history("o1",o3)
 call to_history("n3",n3);	call to_history("d3",d3);	call to_history("o3",o3)  

allocate(input(n1,n3),corrmat(n3,n3))
open(unit=2,file="lixo")
!--------------------------------------------------
! Reading source fctn and velocity
 call sreed("in",input,n1*n3*4)
do i=1,n3
   do j=1,n3
      corrmat(i,j)=dot_product(input(:,i),input(:,j))/(n1*sqrt(sum(input(:,i)**2))*sqrt(sum(input(:,j)**2)))
write(2,*) corrmat(i,j)
   end do
end do

 call srite("out",corrmat,n3*n3*4)
close(2)
call sep_end_prog()
end program
