program tomo_op
use sep
use sep3d_struct_mod
use basic_util_mod
use tomo_inverse_shape_mod
implicit none
type(sep3d)       ::  slow_s
integer           :: n(3)
integer,external  :: sreed,srite
real              :: o(3),d(3)
real, pointer :: slow(:)
real, pointer     :: err0(:),dat0(:)

  call sep_init(SOURCE)

  call init_sep3d("in",slow_s,"INPUT")
  call set_n_o_d_3d(slow_s,n,o,d)
  allocate(slow(product(n)))

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



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

  if(.not. load_wt_op(err0))& !done
    call seperr("trouble reading in wt operator")

  if(.not. load_mask_op(slow_s))&  !done
    call seperr("trouble initalizing mask_op")

  if(.not. load_eps_op(slow_s))& !done
    call seperr("trouble initalizing eps_op")

  if(.not. load_shaping_op(slow_s)) &  !done
    call seperr("trouble loading reg_prec")

  if(.not. init_chains(err0,dat0,slow,slow_s)) & !done
    call seperr("trouble initializing chains")

  if(.not. init_solver(slow))& !done
    call seperr("trouble initializing solver")

  if(.not. run_solver(dat0,slow)) & !done
    call seperr("trouble running solver")

  if(4*size(slow)/=srite("out",slow,size(slow)*4)) &
    call seperr("trouble writing out slowness model")

end program
