program SourceFWD
  use sep
  implicit none

  integer:: nh,ntr,verb,itr
  real:: lz,lx,ly,lt,gz,t0,x0,ox,oy,oz,os,o1,dx2
  real,allocatable,dimension(:,:):: head,panel
  real,allocatable,dimension(:)  :: time
  logical:: xcor,traces
  call sep_init(SOURCE)


  call from_history('n1',nh)
  call from_history('n2',ntr)
  call from_history('o2',o1)

  call from_param('xcor',xcor,.false.)

  call from_param("x",ox,1500.)
  call from_param("y",oy,6500.)
  call from_param("z",oz,9500.)
  call from_param("s",os,0.0002)
	if (os.gt.1.)os=1./os
  call from_param('verb',verb,10)

  call to_history('n1',ntr);call to_history('o1',o1);call to_history('d1',1.)
  call to_history("n2",1);call to_history('o2',0.);call to_history('d1',1.)
  call sep_close()

  allocate(time(ntr),head(nh,ntr))
  head=0.;time=0.;
  if(nh.eq.2) gz=68.
  write(0,*)' ntr,gz',ntr,gz
  write(0,*)' xcor',xcor
  call sep_read(head)
  ox=ox+head(2,1)
  oy=oy+head(1,1)
  write(0,*)' source loc',ox,oy
  write(0,*)' xy',head(2,1),head(1,1)
  write(0,*)'   slow',os
  write(0,*)'   vel',1/os
  write(0,*)'    z',oz
if (xcor)then
  lx=(ox-head(2,1))**2
  ly=(oy-head(1,1))**2
  lz=(oz-gz)**2
  x0=sqrt(lx + ly +lz)
  t0=sqrt(lx+ly+lz)*os!*ax*ay*az
else
  t0=0.
end if
  write(0,*) 'a t0',t0

  trc:do itr=1,ntr
     lx=(head(2,itr)-ox)**2
     ly=(head(1,itr)-oy)**2
     lz=(oz-gz)**2
     !write(0,*)i,':itr, ly',sqrt(ly)
     dx2=lx+ly+lz
     time(itr)=sqrt(dx2)*os
     if(xcor) time(itr)=time(itr)!-t0
  end do trc

  write(0,*) 'a t0',t0
  write(0,*) 'time(1)',time(1)
  call sep_write(time)
end program SourceFWD
