Program Corr
  !##################################################
  !#                                              
  !#  cross-correlate every trace with every other
  !#     <in.H is complex, and n1 is a power of 2
  !#     >out.H is real n1,n2,n2
  !##################################################
  use SEP
  use fft

  implicit none
  integer :: i,j
  integer :: n1,n2,n3,esize,nlags
  real    :: o1,o2,o3,d1,d2,d3
!  complex, allocatable,dimension(:)    ::res
  complex, allocatable,dimension(:,:)  ::data,res
  complex, allocatable,dimension(:)::temp

  call sep_init(SOURCE)
  call from_history('n1',n1)
  call from_history('n2',n2)
  call from_history('o1',o1)
  call from_history('o2',o2)
  call from_history('d1',d1)
  call from_history('d2',d2)
  call from_history('n3',n3)
  call from_history('o3',o3)
  call from_history('d3',d3)
  call from_param('nlags',nlags,128)
  call from_history('esize',esize,4)



  write(0,*) 'nlags',nlags
  call to_history('n3',nlags)
  call to_history('n2',n2)
  call to_history('n1',n1)
  call to_history('o3',-d3)
  call to_history('o2',o2)
  call to_history('o3',o3)
  call to_history('d1',d1)
  call to_history('d2',d2)
  call to_history('d3',d3)
  call to_history('esize',4)
  call sep_close()
  !write(0,*) d1
  allocate(data(n1,n3))
  allocate(res(n1,n3))
!  allocate(temp(n3))
  call sreed('in', data, n1*n3*esize)

  if (esize == 4) call seperr('piss off')
  write(0,*) 'data is of size',size(data,1),'stations, x',size(data,2),'frequencies.'

  do i=1,n1
     do j=1,n1
        !write(0,*) 'here2' 
           res(j,:)=data(i,:) * conjg(data(j,:)) 
!           res(j,:)=temp(:)
        end do
!        if(mod(i,5)==0) write(0,*) 'Finished panel:', i
        write(0,*) 'Finished panel:', i
        call sep_write((res(:,:)))
     end do
     deallocate(data)
     deallocate(res)
  !call sep_write(output)
  !deallocate(output)
end Program Corr











