!!
!! The routine calculates synthetic primaries from a dataset
!! previously submitted to any noise attenuation process. It
!! is based on the Aki-Richards AVO equation
!!
!!               r()=A + B[sin()]^2 + C[sin()*tan()]^2
!!
!!          
!!
!!

  program Drop

  use sep

  implicit none
  
  real		  		    		:: theta,amin, amax
  integer                         		:: i2,ia,ib
  integer					:: n1,n2,n3
  real                            		:: o1,o2,o3,d1,d2,d3
  real,dimension(:,:),allocatable 		:: cmp
  
  call sep_init()
  call sep_begin_prog()

  !! get info from history file
    call from_history("n1",n1);   call from_history("n2",n2);   call from_history("n3",n3,1)
    call from_history("d1",d1);   call from_history("d2",d2);   call from_history("d3",d3,1.)
    call from_history("o1",o1);   call from_history("o2",o2);   call from_history("o3",o3,1.)

  !! get info from parameter
  call from_param("amin",amin,10.);   call from_param("amax",amax,30.);

  !! write info out to history file
  call to_history("n1",n1);call to_history("n2",n2);call to_history("n3",1);call to_history("n4",n3);call to_history("n5",1);call to_history("n6",1)
  call to_history("d1",d1);call to_history("d2",d2);call to_history("d3",1.);call to_history("d4",d3);call to_history("d5",1.);call to_history("d6",1.)
  call to_history("o1",o1);call to_history("o2",o2);call to_history("o3",1.);call to_history("o4",o3);call to_history("o5",1.);call to_history("o6",1.)

!! allocate working space
  allocate(cmp(n1,n2))
call sep_read(cmp)
ia = int((amin-o2)/d2 + 1); ib = int((amax-o2)/d2 + 1);write (0,*) ia, ib
cmp(:,ia:ib)=0.
!do i2=1,n2
!   theta=(i2-1)*d2+o2 
!   if (theta <= amax .and. theta >= amin) cmp(:,i)=0.
!end do
call sep_write(cmp)
!! clean up
deallocate(cmp)
call sep_end_prog()
end program Drop
