VTKFortran
April 4, 2026 ยท View on GitHub
Pure Fortran VTK XML API
a pure Fortran 2003+ OOP library for writing and reading files conforming the VTK XML standard.
| ๐ VTK Topologies Rectilinear ( .vtr), Structured (.vts), and Unstructured (.vtu) grids; composite multi-block (.vtm) and parallel partitioned (.pvts) datasets | ๐๏ธ Output Formats ASCII, Base64-encoded binary, and raw binary appended | โก Parallel Safe Thread and processor safe โ multiple files can be written concurrently under OpenMP or MPI | ๐จ OOP Design Polymorphic xml_writer allocated at runtime; vtk_file, pvtk_file, vtm_file expose a clean type-bound-procedure API |
|---|---|---|---|
| ๐ข All Numeric Kinds All PENF kinds ( I1PโI8P, R4PโR8P) and array ranks 1โ4 supported in data arrays | โ
Error Codes Every procedure returns an integer error code โ zero means success | ๐ Multi-licensed GPL v3 ยท BSD 2/3-Clause ยท MIT | ๐ฆ Multiple build systems CMake, FoBiS.py, fpm, Make |
Documentation
For full documentation (guide, API reference, usage examples, etc.) see the VTKFortran website.
Authors
- Stefano Zaghi โ @szaghi
Contributions are welcome โ see the Contributing page.
Copyrights
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.
Quick start
use vtk_fortran, only : vtk_file
use penf, only : I4P, R8P
implicit none
type(vtk_file) :: a_vtk_file
integer, parameter :: nx1=0, nx2=9, ny1=0, ny2=5, nz1=0, nz2=5
integer, parameter :: nn=(nx2-nx1+1)*(ny2-ny1+1)*(nz2-nz1+1)
real(R8P) :: x(nx1:nx2,ny1:ny2,nz1:nz2)
real(R8P) :: y(nx1:nx2,ny1:ny2,nz1:nz2)
real(R8P) :: z(nx1:nx2,ny1:ny2,nz1:nz2)
real(R8P) :: v(nx1:nx2,ny1:ny2,nz1:nz2)
integer :: error
error = a_vtk_file%initialize(format='binary', filename='output.vts', &
mesh_topology='StructuredGrid', &
nx1=nx1, nx2=nx2, ny1=ny1, ny2=ny2, nz1=nz1, nz2=nz2)
error = a_vtk_file%xml_writer%write_piece(nx1=nx1, nx2=nx2, ny1=ny1, ny2=ny2, nz1=nz1, nz2=nz2)
error = a_vtk_file%xml_writer%write_geo(n=nn, x=x, y=y, z=z)
error = a_vtk_file%xml_writer%write_dataarray(location='node', action='open')
error = a_vtk_file%xml_writer%write_dataarray(data_name='pressure', x=v, one_component=.true.)
error = a_vtk_file%xml_writer%write_dataarray(location='node', action='close')
error = a_vtk_file%xml_writer%write_piece()
error = a_vtk_file%finalize()
See src/tests/ for more examples covering rectilinear, unstructured, multi-block, parallel, and volatile XML output.
Install
CMake
Clone, build, and test:
git clone https://github.com/szaghi/VTKFortran --recursive
cd VTKFortran
cmake -S . -B build -DBUILD_TESTING=ON
cmake --build build && ctest --test-dir build
As a subdirectory dependency โ place a recursive clone alongside your sources and add to your CMakeLists.txt:
add_subdirectory(VTKFortran)
target_link_libraries(your_target VTKFortran::VTKFortran)
FoBiS.py
git clone https://github.com/szaghi/VTKFortran --recursive && cd VTKFortran
FoBiS.py build -mode static-gnu # static library
FoBiS.py build -mode tests-gnu # build and place tests in ./exe/
bash scripts/run_tests.sh # run tests
fpm
Requires at least version v0.13.0!
Building library in current directory
fpm build --compiler gfortran/ifx/... --profile release
The library may be installed to a custom location with
fpm install --compiler gfortran/ifx/... --profile release --prefix /target_path
Please refer to the fpm.toml file for further available profiles and features.
GNU Make
make