module differential_mod 

use sep
use adj_mod

implicit none

integer, private     :: nh 
real   , private     :: dh,oh 

contains

! ---------------------------------------------------------------------------
subroutine differential_init( nh_in, dh_in , oh_in)
         integer ::nh_in
         real    ::dh_in,oh_in 
         nh = nh_in
         dh = dh_in
         oh = oh_in
end subroutine
! ---------------------------------------------------------------------------

! ---------------------------------------------------------------------------
integer function differential_exec( adj, add, model, data)
		logical            :: adj, add 
		real, dimension(:) :: model, data 
        integer            :: n, i,ih,ratio

call adjnull( adj, add, model, data)

n=size(data)
ratio=int(n/nh)
if( adj) then
do i=1,ratio
  do ih=1,nh
    model((i-1)*nh+ih) = model((i-1)*nh+ih) + data((i-1)*nh+ih)*abs(oh+dh*(ih-1))
  enddo
enddo
else
do i=1,ratio
  do ih=1,nh
    data((i-1)*nh+ih) = data((i-1)*nh+ih) + model((i-1)*nh+ih)*abs(oh+dh*(ih-1))
  enddo
enddo
end if

differential_exec = 0

end function differential_exec
! ---------------------------------------------------------------------------

end module
