module OW_define

use OW_type
use OW_parms_areal

contains
!===================================================================================
  subroutine ow_blk()
    integer  :: iwb, izb

    wblk%bres = .false.
    zblk%bres = .false.

    wblk%db = sou%w%d
    zblk%db = v%z%d

    wblk%nb = sou%w%n / node ! sou%w%n / wbn
    zblk%nb = nz      / zbn

    wblk%nb_rem = mod(sou%w%n, node) ! mod(sou%w%n, wbn)
    zblk%nb_rem = mod(nz   ,   zbn)

    if(wblk%nb_rem /= 0) then
       wblk%nb = wblk%nb + 1
       wblk%bres = .true.
    end if

    if(zblk%nb_rem /= 0) then
       zblk%nb = zblock%nb + 1
       zblk%bres = .true.
    end if

    allocate(wblk%blen(wblk%nb), wblk%os(wblock%nb), wblk%indx(wblk%nb))
    allocate(zblk%blen(zblk%nb), zblk%os(zblock%nb), zblk%indx(zblk%nb))

    wblk%blen = node ! wblk%ns
    zblk%blen = zbn

    if(wblk%bres) wblk%blen(wblk%nb) = wblk%nb_rem
    if(zblk%bres) zblk%blen(zblk%nb) = zblk%nb_rem

    do iwb=1, wblk%nb
       wblk%os(iwb)   = sou%w%o + (iwb-1)*wblk%ns*sou%w%d
       wblk%indx(iwb) = 1 + (iwb-1)*wblk%ns
    end do

    do izb=1, zblk%nb
       zblk%os(izb)   = v%z%o + (izb-1)*zblk%ns*v%z%d
       zblk%indx(izb) = 1 + (izb-1)*zblk%ns
    end do
write(0,*)"zblock%indx", zblk%indx
write(0,*)"zblock%nb", zblk%nb
  end subroutine
!===================================================================================
