module row_mod

!use velsimp6
use planemod2
implicit none
integer, private :: nm,bm
contains
subroutine row_init(t0,dt,q0,dq,nt,nx,nq,s0,ds,ns)
    real    :: t0
    real    :: dt
    real    :: x0
    real    :: dx
    real    :: q0,s0
    real    :: dq,ds
    integer    :: nt
    integer    :: nx
    integer    :: nq,ns
    integer    :: verb
write(0,*) 'row init'
call planemod_init(t0,dt,q0,dq,nt,nx,nq)
call velsimp6_init  (t0,dt,s0,ds,nt,nx,ns)
nm=nt*ns
bm=nt*(ns+nq)
!    nthreads = 1
end subroutine row_init
!----------------------------------------------------------------
integer function row_lop(adj,add,model,data) result(st)  
  logical            :: adj,add
  real, dimension(:) :: model, data
  call row_lop2(velsimp6_lop,planemod_op,adj,add, &
  model(1:nm),model(nm+1:bm),data)
  st=0
end function row_lop
!----------------------------------------------------------------
subroutine row_lop2(oper1,oper2,adj,add,mod1,mod2,dat)
    interface
       function oper1 (adj, add, mod, dat) result (stat)
         integer              :: stat
         logical, intent (in) :: adj, add
         real, dimension (:)  :: mod, dat
       end function oper1
       function oper2 (adj, add, mod, dat) result (stat)
         integer    :: stat
         logical, intent (in) :: adj, add
         real, dimension (:)  :: mod, dat
       end function oper2
    end interface
    logical, intent (in)  :: adj, add
    real, dimension (:)   :: mod1, mod2, dat
    integer               :: stat1, stat2,st
    if (adj) then
       stat1 = oper1 (.true., add, mod1, dat)
       stat2 = oper2 (.true., add, mod2, dat)
    else
       stat1 = oper1 (.false., add  , mod1, dat)
       stat2 = oper2 (.false.,.true., mod2, dat)
    end if
    st=stat1+stat2
  end subroutine row_lop2
end module row_mod
