program main
  use base_struct_mod
  use base_ioutil_mod
  use hes_fdecon_mod2
  use sep
  implicit none

  type(hes_grid)                      :: hgrid
  real, dimension(:,:,:), allocatable :: modl
  real, dimension(:,:,:), allocatable :: data
  character(len=256)                  :: modl_, data_, hess_
  integer                             :: stat


  call sep_init(SOURCE)
  call getch_add_string("head=/dev/null")
  call getch_add_string("noheader=y")
  call set_no_putch()
  call sep_begin_prog()

  modl_ = "modl"
  data_ = "data"
  hess_ = "hess"

  call auxout(modl_)
  call auxin (hess_)
  call auxin (data_)

  call hinaxis(hess_, hgrid%ax_offd, 1)
  call hinaxis(hess_, hgrid%ay_offd, 2)
  call hinaxis(hess_, hgrid%az_offd, 3)
  call hinaxis(hess_, hgrid%ax_modl, 4)
  call hinaxis(hess_, hgrid%ay_modl, 5)
  call hinaxis(hess_, hgrid%az_modl, 6)

  call houaxis(modl_, hgrid%ax_modl, 1)
  call houaxis(modl_, hgrid%ay_modl, 2)
  call houaxis(modl_, hgrid%az_modl, 3)


  call from_param("nx_offd_pad_beg", hgrid%nx_offd_pad_beg, 0)
  call from_param("nx_offd_pad_end", hgrid%nx_offd_pad_end, 0)
  call from_param("ny_offd_pad_beg", hgrid%ny_offd_pad_beg, 0)
  call from_param("ny_offd_pad_end", hgrid%ny_offd_pad_end, 0)
  call from_param("nz_offd_pad_beg", hgrid%nz_offd_pad_beg, 0)
  call from_param("nz_offd_pad_end", hgrid%nz_offd_pad_end, 0)

  allocate(data(hgrid%ax_modl%n,hgrid%ay_modl%n,hgrid%az_modl%n))
  allocate(modl(hgrid%ax_modl%n,hgrid%ay_modl%n,hgrid%az_modl%n))

  call sep_read(data, data_)

  stat = hes_fdecon_init(hgrid, hess_)

  stat = hes_fdecon_oper(modl, data)

  stat = hes_fdecon_clos()

  call sep_write(modl, modl_)

end program
