MORTon Indexer (Z-order) Fortran environment — a pure Fortran 2003+ library to encode and decode multidimensional integer indexes into Morton's Z-order.
- Encode two 32-bit indexes into a 64-bit Morton code with
morton2D - Encode three 32-bit indexes into a 64-bit Morton code with
morton3D(up to 21 significant bits per axis) - Decode Morton codes back to indexes with
demorton2D/demorton3D - All four procedures are
elemental— apply directly to scalars or arrays - Pure Fortran, no C extensions, single 194-line module
- Stefano Zaghi — @szaghi
Contributions are welcome — see the Contributing page.
This project is distributed under a multi-licensing system:
- FOSS projects: GPL v3
- Closed source / commercial: BSD 2-Clause, BSD 3-Clause, or MIT
Anyone interested in using, developing, or contributing to this project is welcome — pick the license that best fits your needs.
Encode a 3D index tuple and decode it back:
use, intrinsic :: iso_fortran_env, only : int32, int64
use mortif
implicit none
integer(int32) :: i, j, k
integer(int64) :: code
code = morton3D(i=0_int32, j=1_int32, k=0_int32)
print '(A,I20)', "Morton code of {0,1,0}: ", code ! 2
call demorton3D(code=code, i=i, j=j, k=k)
print '(A,3(I0,1X))', "Decoded: ", i, j, k ! 0 1 0Elemental use on arrays:
use, intrinsic :: iso_fortran_env, only : int32, int64
use mortif
implicit none
integer(int32) :: ix(4) = [0, 1, 2, 3]
integer(int32) :: iy(4) = [0, 0, 1, 1]
integer(int64) :: codes(4)
codes = morton2D(i=ix, j=iy) ! [0, 1, 4, 5]git clone https://github.com/szaghi/MORTIF --recursive
cd MORTIF
FoBiS.py build -mode tests-gnu
./scripts/run_tests.shmkdir build && cd build
cmake -DMORTIF_ENABLE_TESTS=ON ..
cmake --build . && ctest| Tool | Command |
|---|---|
| FoBiS.py | FoBiS.py build -mode static-gnu |
| GNU Make | make -j 1 |
| CMake | cmake .. && cmake --build . |