subroutine randomnize(field, klev, ampl, ir, ihl, jhl)
use modmpi, only:myid, nprocs
use modglobal, only:ib, ie, imax, jmax, jb, je, kb, ke, kh, ierank, BCxm
integer(KIND=selected_int_kind(6)):: imm, ia, ic, ir
integer ihl, jhl
integer i, j, klev
integer m, mfac
real ran, ampl
real field(ib - ihl:ie + ihl, jb - jhl:je + jhl, kb - kh:ke + kh)
parameter(imm=134456, ia=8121, ic=28411)
if (myid > 0) then
mfac = myid*jmax*imax
do m = 1, mfac
ir = mod((ir)*ia + ic, imm)
end do
end if
! if (ierank .and. BCxm > 1) then
! do j = jb, je
! do i = ib, ie-1
! ir = mod((ir)*ia + ic, imm)
! ran = real(ir)/real(imm)
! field(i, j, klev) = field(i, j, klev) + (ran - 0.5)*2.0*ampl
! end do
! end do
! else
do j = jb, je
do i = ib, ie
ir = mod((ir)*ia + ic, imm)
ran = real(ir)/real(imm)
field(i, j, klev) = field(i, j, klev) + (ran - 0.5)*2.0*ampl
end do
end do
!end if
if (nprocs - 1 - myid > 0) then
mfac = (nprocs - 1 - myid)*imax*jmax
do m = 1, mfac
ir = mod((ir)*ia + ic, imm)
end do
end if
return
end subroutine randomnize