module tomo_wt_mod
use tomo_wt_diag_mod
use tomo_wt_deriv_mod
implicit none
character(len=16),private, save :: wt_method


contains

logical function load_wt_op(data)
real           :: data(:)

call from_param("wt_method",wt_method,"diag")

if(wt_method(1:4)=="diag")  then
write(0,*) "DIAG",size(data)
  load_wt_op=load_wt_diag_op(data)
else if (wt_method(1:5)=="deriv") then
write(0,*) "DERIV",size(data)
  load_wt_op=load_wt_deriv_op(data)
else
  write(0,*) "trouble wt_method ",trim(wt_method)
  call seperr("")
end if

end function


integer function wt_range()
if(wt_method(1:4)=="diag")  then
  wt_range=wt_diag_range()
else if (wt_method(1:5)=="deriv") then
  wt_range=wt_deriv_range()
else
  write(0,*) "trouble wt_method ",trim(wt_method)
  call seperr("")
end if
write(0,*) "WT RANGE",wt_range
end function

integer function wt_domain()
if(wt_method(1:4)=="diag")  then
  wt_domain=wt_diag_domain()
else if (wt_method(1:5)=="deriv") then
  wt_domain=wt_deriv_domain()
else
  write(0,*) "trouble wt_method ",trim(wt_method)
  call seperr("")
end if
end function

integer function wt_op(adj,add,model,data)
logical,intent(in) :: adj,add
real    :: model(:),data(:)
integer :: n
write(0,*) "IN WT",adj
if(wt_method(1:4)=="diag")  then
  wt_op=wt_diag_op(adj,add,model,data)
else if (wt_method(1:5)=="deriv") then
  wt_op=wt_deriv_op(adj,add,model,data)
else
  write(0,*) "trouble wt_method ",trim(wt_method)
  call seperr("")
end if


end function


end module
