program tomo_ops
use sep
use sep3d_struct_mod
use basic_util_mod
use tomo_inverse_shape_mod
implicit none
type(sep3d)       ::  slow_s,dt_s
integer           :: n(3),ierr,i
integer,external  :: sreed,srite
real              :: o(3),d(3)
real, allocatable :: slow(:)
real, pointer     :: err0(:),reg0(:),dt(:)
logical           :: adj,add

  call sep_init(SOURCE)
  call from_param("add",add,.false.)
  call from_param("adj",adj,.false.)
  

  call init_sep3d("model",slow_s,"INPUT")
  call init_sep3d("data",dt_s,"INPUT")
  call auxclose("data")
  call auxclose("model")
  call auxinout("model")
  call auxinout("data")

  if(.not. load_tomo_op(slow_s,err0)) &
    call seperr("trouble reading in tomo_op")


  call set_n_o_d_3d(slow_s,n,o,d)
  allocate(slow(product(n)))

  if(4*size(slow)/=sreed("model",slow,size(slow)*4)) &
    call seperr("trouble reading in slowness model")

  allocate(dt(product(dt_s%n(1:sep3d_ndims(dt_s)))))

  if(4*size(dt)/=sreed("data",dt,size(dt)*4)) &
    call seperr("trouble reading in travel time op")


  ierr=tomo_op(adj,add,slow,dt)

  if(.not. adj)  then
    call sseek("data",0,0)
    ierr= srite("data",dt,size(dt)*4)
  else
    call sseek("model",0,0)
    ierr= srite("model",slow,size(slow)*4)
  end if

 

end program
