Skip to content

About

pure Fortran VTK (XML) API

Topics

Resources

Contributing

Stars

160 stars

Watchers

21 watching

Forks

Repository files navigation

VTKFortran

Pure Fortran VTK XML API

a pure Fortran 2008 OOP library for writing and reading files conforming the VTK XML standard.

GitHub tag GitHub issues CI coverage License

📐 VTK Topologies
Image (.vti), Rectilinear (.vtr), Structured (.vts), and Unstructured (.vtu) grids, polygonal data (.vtp); composite multi-block (.vtm), parallel partitioned (.pvti, .pvtr, .pvts, .pvtu, .pvtp) datasets, and time series (.pvd)
🗜️ Output Formats
ASCII, Base64-encoded binary, and raw binary appended; optional zlib compression of binary data; every file read back with action='read'
⚡ Parallel Safe
Thread and processor safe — multiple files can be written concurrently under OpenMP or MPI
🎨 OOP Design
Polymorphic xml_writer allocated at runtime, xml_reader to read back; vtk_file, pvtk_file, vtm_file, pvd_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

For full documentation (guide, API reference, usage examples, etc.) see the VTKFortran website.


Authors

Contributions are welcome — see the Contributing page.

Copyrights

This project is distributed under a multi-licensing system:

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
cd VTKFortran
fobis fetch                     # dependencies into src/third_party/ (pip install FoBiS.py)
cmake -S . -B build -DBUILD_TESTING=ON
cmake --build build && ctest --test-dir build

As a subdirectory dependency — place a clone (with its dependencies fetched) 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 && cd VTKFortran
fobis fetch                       # dependencies into src/third_party/
fobis build --mode static-gnu     # static library
fobis build --mode tests-gnu      # build and place tests in ./exe/
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.

About

pure Fortran VTK (XML) API

Topics

Resources

Contributing

Stars

160 stars

Watchers

21 watching

Forks

Releases

Packages

Used by

Contributors

Languages