Skip to content

szaghi/VTKFortran

Repository files navigation

VTKFortran

Pure Fortran VTK XML API

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

GitHub tag GitHub issues CI coverage License

📐 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 (I1PI8P, R4PR8P) 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

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 --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

About

pure Fortran VTK (XML) API

Topics

Resources

Contributing

Stars

157 stars

Watchers

21 watching

Forks

Packages

 
 
 

Contributors