Appearance
Installation
Prerequisites
A Fortran 2008 compiler is required:
| Compiler | Version |
|---|---|
| GNU gfortran | 12 or newer: 12.5, 13.4, 14.3 and 16.2 pass every test (the CI: 16.2); 11.5 builds, but the two .vtm tests crash |
| Intel Fortran (ifx) | 2025.3 passes every test (the fobos Intel modes run ifx; the discontinued ifort is not tested) |
| NVIDIA nvfortran | 26.9 passes every test (built with CMake: the fobos file has no NVIDIA modes) |
Measured on 2026-11-10 by building the tests (tests-gnu-debug, tests-intel, CMake for nvfortran) and running them. With nvfortran 26.9, VTKFortran 3.0.0 and older fail 3 tests: they hit three bugs of the compiler (move_alloc of a deferred-length character, endfile on a stream file, an array component assigned a section of itself), now worked around.
One-line install
bash
curl -fsSL https://github.com/szaghi/VTKFortran/releases/latest/download/install.sh | bashIt installs the latest release into ~/.local with the build system you choose among those VTKFortran ships (--build fobis|fpm|cmake: a menu asks when you do not say), the compiler you name (--fc, --gnu, --intel), one install per compiler (lib/vtkfortran/<compiler>-<version>/, include/vtkfortran/<compiler>-<version>/), and makes it usable through pkg-config (pkg-config --cflags --libs vtkfortran, with PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig). The release carries VTKFortran's dependencies (BeFoR64, FACE, FoXy, PENF, StringiFor), so CMake needs no network. It builds the library without the optional zlib and HDF5 (VTKHDF) support: for those, build VTKFortran as below. Pass options after bash -s --, e.g. ... | bash -s -- --build cmake --prefix /opt/vtkfortran; --help lists them all, --uninstall removes the install. The installer is FoBiS's (One-line installer).
Download
Clone the repository, then fetch its third-party dependencies with FoBiS.py (they are listed in the [dependencies] section of fobos):
bash
git clone https://github.com/szaghi/VTKFortran
cd VTKFortran
pip install FoBiS.py
fobis fetchCMake and FoBiS.py builds need the fetched dependencies; fpm fetches its own (see fpm.toml).
Third-Party Dependencies
fobis fetch places them under src/third_party/:
| Library | Purpose |
|---|---|
| PENF | Portable numeric kind parameters (I4P, R8P, etc.) — used everywhere |
| BeFoR64 | Base64 encode/decode for binary XML data |
| StringiFor | OOP string type used throughout the writer classes |
| FoXy | XML streaming (xml_writer, used by the writers) and file indexing (xml_index, used by the readers) |
| FACE | ANSI terminal colour output |
Build with CMake (preferred)
CMake is the recommended build system for library use and integration into other projects.
bash
cmake -S . -B build
cmake --build buildRun the test suite
bash
cmake -S . -B build -DBUILD_TESTING=ON
cmake --build build
ctest --test-dir buildThe test of files written from OpenMP threads runs serially by default (built without OpenMP); with -DVTKFORTRAN_TEST_OPENMP=ON it runs its threads, which needs a thread-safe build of the library, see Threads and processes.
Run a single named test:
bash
ctest --test-dir build -R vtk_fortran_write_vtu --output-on-failureEach test program prints Are all tests passed? T (or F) and exits with a non-zero status when a check fails. CTest runs each test in its own directory, build/src/tests/run/<test name>/, where its VTK files are left for inspection; the executables are in build/src/tests/.
CMake subdirectory integration
To embed VTKFortran in an existing CMake project, place a clone (with its dependencies fetched) alongside your sources and add to your CMakeLists.txt:
cmake
add_subdirectory(VTKFortran)
target_link_libraries(your_target VTKFortran::VTKFortran)Build with FoBiS.py
FoBiS.py (CLI fobis) is also used for coverage analysis and documentation generation.
List all build modes
bash
fobis build --lmodesBuild and run tests
bash
fobis build --mode tests-gnu
scripts/run_tests.shCompiled test executables are placed in ./exe/. scripts/run_tests.sh runs each executable and reports pass/fail from its exit status (it runs them in the current directory, where they write their VTK files).
Build the library
bash
# Static library (GNU gfortran)
fobis build --mode static-gnu
# Shared library (GNU gfortran)
fobis build --mode shared-gnu
# Intel Fortran variants
fobis build --mode static-intel
fobis build --mode shared-intelDebug builds
bash
fobis build --mode static-gnu-debug
fobis build --mode tests-gnu-debug # with zlib, as the CICoverage and documentation
bash
fobis rule --ex makecoverage # build + run tests + gcov report
fobis rule --ex makedoc # build the API reference (formal) and the VitePress site (needs formal and npm)makecoverage calls scripts/compute-coverage.sh, which automatically selects the gcov-N binary that matches the installed gfortran version. If you run the script directly, ensure that gfortran is on $PATH so the version is detected correctly.
Build with FPM
bash
fpm build --profile releasefpm 0.13.0 or newer is required (fpm.toml uses the [features] table). fpm builds the library (and fetches its dependencies); the test programs are built with CMake or FoBiS.py.
Optional zlib compression
The compression of binary data (compressor='zlib', format='raw-zlib', see Compressed binary data) needs zlib and the preprocessor macro VTKFORTRAN_USE_ZLIB at build time. Without it the library builds and works as usual, and requesting zlib makes initialize return a non-zero error. Install the zlib development files first (e.g. apt install zlib1g-dev).
CMake: enable the option; zlib is found with find_package(ZLIB).
bash
cmake -S . -B build -DVTKFORTRAN_USE_ZLIB=ON
cmake --build buildFoBiS.py: the tests-gnu-debug mode (the CI one) is built with zlib. For other modes, or your own fobos, add -DVTKFORTRAN_USE_ZLIB to cflags and link zlib with ext_libs = z.
fpm: pass the macro and link zlib. With GNU ld, --no-as-needed is needed because zlib is listed before the library that uses it:
bash
fpm build --flag "-DVTKFORTRAN_USE_ZLIB" --link-flag "-Wl,--no-as-needed -lz"Optional HDF5 (VTKHDF)
The VTKHDF format, the HDF5-based VTK format (format='vtkhdf', see VTKHDF), is being added step by step (issue #51): every topology is written now. It needs the HDF5 C library, 1.10 or newer, and the preprocessor macro VTKFORTRAN_USE_HDF5; without it the library builds and works as usual, and format='vtkhdf' is an error. VTKFortran calls the HDF5 C API directly (iso_c_binding): no HDF5 Fortran module is needed, so any HDF5 build works with any Fortran compiler, serial or parallel (a parallel HDF5 needs the MPI libraries at link time). Install the HDF5 development files first (e.g. apt install libhdf5-dev).
CMake: enable the option; HDF5 is found with find_package(HDF5 COMPONENTS C) (point it to an HDF5 with -DHDF5_ROOT=...), and MPI too when HDF5 is a parallel build.
bash
cmake -S . -B build -DVTKFORTRAN_USE_HDF5=ON
cmake --build buildFoBiS.py: the modes static-gnu-hdf5 and tests-gnu-debug-hdf5 build with zlib and HDF5. The HDF5 library is selected by a varset of the fobos file: the default one, ubuntu, is Ubuntu's libhdf5-dev; add one for another HDF5 ($HDF5_LIB its directory, $HDF5_EXT the libraries to link) and select it with --varset:
bash
fobis build --mode tests-gnu-debug-hdf5 --varset my_hdf5fpm: pass the macro and link HDF5:
bash
fpm build --flag "-DVTKFORTRAN_USE_HDF5" --link-flag "-L/path/to/hdf5/lib -lhdf5"One file from MPI ranks
The ranks of an MPI communicator write one .vtkhdf file together (initialize(..., comm=), see the cookbook: Write one .vtkhdf from MPI ranks) with the macro VTKFORTRAN_USE_MPI too, a parallel HDF5 (e.g. apt install libhdf5-openmpi-dev) and MPI for Fortran (mpi_f08) and C: the communicator is handed to HDF5 by a small C source, src/mpi/vtk_fortran_mpi.c, that needs the HDF5 headers. Without the macro the library builds as usual and comm is an error.
CMake: both options; MPI is found with find_package(MPI COMPONENTS C Fortran), and the MPI test runs on 4 ranks (add -DMPIEXEC_PREFLAGS=--oversubscribe for Open MPI on fewer cores).
bash
cmake -S . -B build -DVTKFORTRAN_USE_HDF5=ON -DVTKFORTRAN_USE_MPI=ON
cmake --build buildFoBiS.py: the modes static-gnu-hdf5-mpi and tests-gnu-debug-hdf5-mpi build with mpif90 and mpicc; their varset also gives the HDF5 headers ($HDF5_INC). The varset ubuntu-openmpi is Ubuntu's libhdf5-openmpi-dev; toolchain-image is the HDF5 of the CI's toolchain image (ghcr.io/szaghi/fortran-toolchains:gnu-16.2: gfortran 16.2, Open MPI 5.0.11, HDF5 2.3.0, all built by the same compiler):
bash
fobis build --mode tests-gnu-debug-hdf5-mpi --varset ubuntu-openmpi
mpirun -np 4 exe/vtk_fortran_write_vtkhdf_ranksCompression from ranks (compressor='zlib' with comm): an HDF5 1.10.2 or later built parallel with the deflate filter (zlib), which has parallel filtered writes (H5_HAVE_PARALLEL_FILTERED_WRITES in H5pubconf.h); initialize returns an error otherwise. The writes of a deflated dataset are collective (a transfer property list made by the C source).
fpm: not supported (the C source, outside src/lib, needs the macro and the HDF5 headers).