Pure Fortran VTK XML API — a pure Fortran 2003+ OOP library for writing and reading files conforming the VTK XML standard.
- Write Rectilinear, Structured, and Unstructured grids in the VTK XML format
- Composite multi-block datasets (
.vtm) and parallel partitioned files (.pvts) supported - Output formats: ASCII, binary (Base64-encoded), and raw binary appended
- Thread and processor safe — multiple files can be written concurrently under OpenMP or MPI
- OOP design — polymorphic
xml_writerallocated at runtime;vtk_file,pvtk_file,vtm_filetypes expose a clean type-bound-procedure API - All procedures return an integer error code — zero means success
- 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.
Write a structured grid in binary XML format:
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()git clone https://github.com/szaghi/VTKFortran --recursive
cd VTKFortran
cmake -S . -B build -DBUILD_TESTING=ON
cmake --build build && ctest --test-dir buildadd_subdirectory(VTKFortran)
target_link_libraries(your_target VTKFortran::VTKFortran)| Tool | Command |
|---|---|
| CMake | cmake -S . -B build && cmake --build build |
| FoBiS.py | FoBiS.py build -mode static-gnu |
| FPM | fpm build |