# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "<stdin>"
!<;
!extra_eps_mod
!
!Author: Robert Clapp, ESMB 463, 7230253
!
! Sun Jan 12 14:02:42 PST 2003
!
!
!Purpose:
!
! Handle the eps for extra operator
!
!To add a new error type:
!
! -add to check_pars
! -add to initializer
! -add to op
!
!
! Currently
!
! -scalar
!
module eps_extra_mod
  use adj_mod
  use param_check_mod
  use basic_util_mod
  use extra_op_mod
  implicit none
  character(len=128),private,save :: eps_method
  real, private,save :: eps
  contains
  logical function init_eps_extra()
    logical :: no_rerurn,is_2d
    type(sep3d) :: tomo_s
    init_eps_extra=.false.
    if (.not. vel_tomo_structure(tomo_s)) then
      write(0,*) "trouble grabbing tomo structure"
      return
    end if
!check to see if parameters are different
!#########################################
! IMPORTANT #
! #
! THIS WHERE WE DESCRIBE HOW TO #
! BUILD DATA_RESID #
! #
! MUST HAVE A CORARLY IN #
! #
! CHECK PARS/OP/INITIAL_OP #
! #
!#########################################
    if (eps_method(1:6).eq."scalar") then
    else
      write(0,*) "Unknown resid method=",trim(eps_method)
      return
    end if
    init_eps_extra=.true.
  end function
  logical function get_extra_dat0(dat)
    real, pointer :: dat(:),junk(:)
    integer :: n
    get_extra_dat0=.false.
    n=get_extra_nrange()
    if (n >0) then
      if (.not. get_extra_d(junk)) then
        write(0,*) "trouble getting extra data"
        return
      end if
      n=get_eps_extra_nrange(n)
      allocate(dat(n))
      n=eps_extra_op(.false.,.false.,junk,dat)
      deallocate(junk)
    end if
    get_extra_dat0=.true.
  end function
  integer function get_eps_extra_nrange(n)
    integer :: n
    get_eps_extra_nrange=0
    if (eps_method(1:6).eq."scalar") then
      get_eps_extra_nrange=n
    else
      call seperr("unrecognized extra_eps_method")
    end if
  end function
  integer function eps_extra_op(adj,add,model,data)
    logical,intent(in) :: adj,add
    real :: model(:),data(:)
    call adjnull(adj,add,model,data)
!BY DEFAULT DIAGONAL 1
    if (eps_method(1:6).eq."scalar") then
      if (.not. adj) then
        data= data+model*eps
      else
        model= model+data*eps
      end if
    else
      write(0,*) "eps_extra_method",trim(eps_method)
      call seperr("Unknown eps_extra_method")
    end if
    eps_extra_op=0
  end function
  logical function eps_constant_pars()
    eps_constant_pars=.true.
  end function
  logical function check_eps_extra_params()
    character(len=128) :: tag
    logical :: stat(100)
    stat=.true.
    check_eps_extra_params=.false.
!#########################################
! IMPORTANT #
! #
! THIS WHERE WE DESCRIBE HOW TO #
! INITIALIZE/CHECK OBJECT PARAMS #
! #
!#########################################
    call from_param("eps_extra_method",eps_method,"scalar")
    call from_param("extra_eps",eps,1.)
    if (eps_method(1:6).eq."scalar") then
    else
      write(0,*) "    ERROR-Unknown eps_reg_method=",trim(eps_method)
      return
    end if
    check_eps_extra_params=.true.
  end function
end module
