program SourceInvert

  use sep
  use pathtime
  use solver_tiny!_brad
  use cgstep_mod
  real::modl(5) , mod0(5)! x,y,z,t,v
  real,pointer,dimension(:):: dat,res
  real   ,pointer,dimension(:,:):: glocs

  logical    :: adj,add
  call sep_init(SOURCE)

  call from_aux("geom",'n1',nh)
  call from_aux("geom",'n2',ntr)
  call from_param('adj',adj,.true.)
  call from_param('add',add,.false.)
  call from_history("n1",n1);call from_history('d1',d1);call from_history("o1",o1)
  call from_history("n2",n2)
  call from_history("n3",n3)
  call from_param('verb',verb,10);call from_param('niter',niter,n1)
  call to_history('n1',n1,"OUT");call to_history('o1',o1,"OUT");call to_history('d1',d1,"OUT")
  if(ntr.ne.n2*n3*n1) call seperr("number headers not matched to input")
  call sep_close()

  allocate(dat(n1),glocs(nh,ntr),res(ntr+5)
  glocs=0.;dat=0. ;modl=0. ;mod0=(/10000,10000,5000,3.0,1/4000)
  if(nh.eq.2) gz=68.
  
  call sep_read(time)
  call sep_read(glocs,"geom")
  call pathtime_init(glocs,ntr)   
  call solver(modl,dat,pathtime_lop,cgstep,add,niter,mod0,res)
  st=pathtime_lop(.false.,.false.,modl,dat)
  call cgstep_close ( )
  call sep_write(dat)
  call sep_write(modl,"source")

  deallocate(modl,dat,glocs)
  call exit (0)

end program 
