morton2D Function

public elemental function morton2D(i, j, b) result(code)

Encode 2 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=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~~morton2d~~CallsGraph proc~morton2d morton2D proc~dilatate dilatate proc~morton2d->proc~dilatate
Help

Source Code


Source Code

  elemental function morton2D(i, j, b) result(code)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Encode 2 integer (32 bits) indexes into 1 integer (64 bits) Morton's code.
  !---------------------------------------------------------------------------------------------------------------------------------
  integer(I4P), intent(in)           :: i    !< I index.
  integer(I4P), intent(in)           :: j    !< J 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 indexe.
  integer(I8P)                       :: dj   !< Dilated indexe.
  !---------------------------------------------------------------------------------------------------------------------------------

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