! Kirchhoff modeling and migration.
! adj=0 means model. adj=1 means migrate.
! <in.H Kirchhoff adj= vel=vel.H > out.H

program res_o2a

use sep
use res_o2a_mod

implicit none

integer 				:: na1,na2,na3, no1,no2,no3
integer					:: i3
real, allocatable, dimension (:,:) 	:: adcig_out(:,:), adcig_in(:,:)
real 					:: oa1,da1,oa2,da2,oa3,da3,oo1,do1,oo2,do2,oo3,do3
logical					:: adj

  call initpar()

  call from_history('n1',na1);  call from_history('n2',na2); call from_history('n3',na3)
  call from_history('o1',oa1);  call from_history('o2',oa2); call from_history('o3',oa3)
  call from_history('d1',da1);  call from_history('d2',da2); call from_history('d3',da3)

  call from_history('odcig','n1',no1);  call from_history('odcig','n2',no2); call from_history('odcig','n3',no3)
  call from_history('odcig','o1',oo1);  call from_history('odcig','o2',oo2); call from_history('odcig','o3',oo3)
  call from_history('odcig','d1',do1);  call from_history('odcig','d2',do2); call from_history('odcig','d3',do3)

  call to_history('n1',na1);  call to_history('d1',da1);  call to_history('o1',oa1);
  call to_history('n2',na2);  call to_history('d2',da2);  call to_history('o2',oa2);
  call to_history('n3',na3);  call to_history('d3',da3);  call to_history('o3',oa3);

!  call from_param('maxang',angle,85)
  call from_param('adj',adj,.true.)

  allocate(adcig_in(n1,n2),adcig_out(n1,n2))

  adcig_in=0.; adcig_out=0
do i3=1,na3
  if ( adj ) then
    call sreed( 'in', adcig_in, n1*n2*4)
  else
    call sreed( 'in', adcig_out, n1*n2*4)
  end if
  call res_o2a_init(vrms,angle,n1,d1,o1,n2,d2,o2)!,n3,d3,o3)
  stat = res_o2a_lop( adj, .false., adcig_out, adcig_in)
  if ( adj ) then
    call srite( 'out', adcig_out, n1*n2*4)
  else
    call srite( 'out', adcig_in, n1*n2*4)
  end if
end do
end program res_o2a
