module ident_mod  
  use adj_mod

  implicit none

  integer, private 				:: nz, nax
  real, dimension(:), pointer, private 		:: mask

  contains

!---------------------------------------------------------------------------------    
  subroutine ident_init(nz_in, nax_in, mask_in) 

  implicit none
    
    optional		:: mask_in
    real		:: mask_in(:)
    real    :: z0_in, dz_in 
    integer :: nz_in, nax_in

    nz  = nz_in ; nax = nax_in
    allocate(mask(nz*nax))
    mask=1
    where(mask_in.eq.0.0)
      mask = 0
    end where

  end subroutine

!---------------------------------------------------------------------------------
  integer function ident_lop( adj, add, model, data)
    real, dimension(:)            :: model, data
    logical                       :: adj,add
    call adjnull( adj, add, model, data)
    if (adj) then
      model = model + data*mask
    else
      data  = data + model*mask
    end if 
    ident_lop = 0
  end function
!---------------------------------------------------------------------------------

!---------------------------------------------------------------------------------
!  integer function lapwght_lop( adj, add, model, data)
!    integer                       :: stat
!    real, dimension(:)            :: model, data
!    real, dimension(:), pointer   :: temp
!    logical                       :: adj,add
!    allocate( temp(m1*m2) )
!    temp=0
!    call laplac2_init( m1, m2)
!    call chain0( modelwt_lop, laplac2_lop, adj, add, model, data, temp&
!      & )
!    call laplac2_close()
!    deallocate( temp )
!    lapwght_lop = 0
!  end function
!---------------------------------------------------------------------------------
!---------------------------------------------------------------------------------
!  integer function modelwt_lop( adj, add, model, data)
!    real, dimension(:)            :: model, data
!    logical                       :: adj,add
!    call adjnull( adj, add, model, data)
!    if (adj) then
!      model = model + data*model_wt
!    else
!      data  = data + model*model_wt
!    end if 
!    modelwt_lop = 0
!  end function
!---------------------------------------------------------------------------------
end module 
