morton3D Function

public elemental function morton3D(i, j, k, b) result(code)

Encode 3 integer (32 bits) indexes into 1 integer (64 bits) Morton's code.

Arguments

Type IntentOptional AttributesName
integer(kind=I4P), intent(in) :: i

I index.

integer(kind=I4P), intent(in) :: j

J index.

integer(kind=I4P), intent(in) :: k

K index.

integer(kind=I2P), intent(in), optional :: b

Number of significant bits of 'i' (2/4/8/16/32).

Return Value integer(kind=I8P)

Morton's code.

Calls

proc~~morton3d~~CallsGraph proc~morton3d morton3D proc~dilatate dilatate proc~morton3d->proc~dilatate
Help

Called By

proc~~morton3d~~CalledByGraph proc~morton3d morton3D proc~test_morton3d test_morton3D proc~test_morton3d->proc~morton3d proc~test_16_16_16 test_16_16_16 proc~test_16_16_16->proc~morton3d program~mortif_test_correctness mortif_test_correctness program~mortif_test_correctness->proc~test_morton3d
Help

Source Code


Source Code

  elemental function morton3D(i, j, k, b) result(code)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Encode 3 integer (32 bits) indexes into 1 integer (64 bits) Morton's code.
  !<
  !< @note Due to 64 bits limit of the Morton's code, the 3 allowed-side of indexes is limited to 21 bits.
  !---------------------------------------------------------------------------------------------------------------------------------
  integer(I4P), intent(in)           :: i    !< I index.
  integer(I4P), intent(in)           :: j    !< J index.
  integer(I4P), intent(in)           :: k    !< K index.
  integer(I2P), intent(in), optional :: b    !< Number of significant bits of 'i' (2/4/8/16/32).
  integer(I8P)                       :: code !< Morton's code.
  integer(I8P)                       :: di   !< Dilated indexes.
  integer(I8P)                       :: dj   !< Dilated indexes.
  integer(I8P)                       :: dk   !< Dilated indexes.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  if (present(b)) then
    di = dilatate(i=i, b=b, z=2_I1P)
    dj = dilatate(i=j, b=b, z=2_I1P)
    dk = dilatate(i=k, b=b, z=2_I1P)
  else
    di = dilatate(i=i, b=32_I2P, z=2_I1P)
    dj = dilatate(i=j, b=32_I2P, z=2_I1P)
    dk = dilatate(i=k, b=32_I2P, z=2_I1P)
  endif
  code = ishft(dk,2) + ishft(dj,1) + di
  !---------------------------------------------------------------------------------------------------------------------------------
  endfunction morton3D