# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "<stdin>"
!
!
! Module for do inversion
!
!
module tomo_inv_mod
  use tomo_lin_cg_mod
  implicit none
  character(len=128), private,save :: inv_method
  logical, private, save :: verb
  contains
  logical function init_tomo_inversion()
    init_tomo_inversion=.false.
    if (inv_method(1:6) .eq. "lin_cg") then
      if (verb) then
        write(0,*) "    Using linear CG method for inversion"
      end if
      if (.not. init_lin_cg_inverse()) then
        write(0,*) "    ERROR: initializing linear CG"
        return
      end if
    else
      write(0,*) "  Unimplemented inversion_method",trim(inv_method)
      return
    end if
    init_tomo_inversion=.true.
  end function
  logical function tomo_inversion()
    tomo_inversion=.false.
    if (inv_method(1:6) .eq. "lin_cg") then
      if (.not. lin_cg_inverse()) then
        write(0,*) "    ERROR: initializing linear CG"
        return
      end if
    else
      write(0,*) "  Unimplemented inversion_method",trim(inv_method)
      return
    end if
    tomo_inversion=.true.
  end function
  logical function check_tomo_inv_params()
    check_tomo_inv_params=.false.
    call from_param("verb",verb,.false.)
    call from_param("inversion_method",inv_method,"lin_cg")
    if (inv_method(1:6) .eq. "lin_cg") then
      if (.not. check_lin_cg_pars()) then
        write(0,*) "    ERROR-trouble grab linear cg_pars"
        return
      end if
    else
      write(0,*) "  Invalid inversion_method=",trim(inv_method)
      return
    end if
    check_tomo_inv_params=.true.
  end function
end module
