module OW_ctrill

use OW_type
use OW_parms_areal
use OW_ctrillwei

implicit none



private						:: nwb,node

integer						:: nwb,node
real						:: wb

contains

!---------------------------------------------------------
subroutine owctrl_init(wb_in,node_in)

integer						:: node_in
real						:: wb_in

node=node_in
wb=wb_in
wb=floor(wb/img%z%d)*img%z%d
nwb=floor(wb/img%z%d)+1

end subroutine
!---------------------------------------------------------
!subroutine owctrl(rnd_phase,taper,refl,source,vsal,vel,G1)
subroutine owctrl(taper,refl,source,vsal,vel,G1)

integer					:: iw,inode
real					:: vel(:,:),vsal
real					:: refl(:,:),taper(:)!,rnd_phase(:)
complex					:: source(:,:,:),G1(:,:)

integer, external			:: omp_get_thread_num

! $OMP parallel default(shared) private(inode) !num_threads(6) !firstprivate(wb,nwb)

inode=omp_get_thread_num()+1;

! $OMP do private(iw)

do iw = 1,rec%w%n

        call owctrlwei_init(iw,wb,nwb)
!        call owctrlwei(rnd_phase,taper,refl,source,vsal,vel,G1(iw,:))
        call owctrlwei(taper,refl,source,vsal,vel,G1(iw,:))
          if (mod(iw,10)==1) write(0,5) " FREQUENCY # ",iw," OUT OF ",rec%w%n," FROM NODE: ",inode
5                          format(A13,i3,A8,i5,A12,i3)

end do
! $OMP end do
! $OMP end parallel
end subroutine owctrl
end module
