VTK XML Support
Write Rectilinear, Structured, and Unstructured grids in the VTK XML format. Composite multi-block datasets (VTM) and parallel partitioned files (PVTS) are also supported.
A pure Fortran 2003+ library to parse and emit files conforming the VTK XML standard.
Write a structured grid in binary XML format:
use vtk_fortran, only : vtk_file
use penf, only : I4P, R8P
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
! ... fill x, y, z, v ...
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='velocity', 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()All procedures return an integer error code — zero means success.
Contributions are welcome — see the Contributing page.
VTKFortran is distributed under a multi-licensing system:
| Use case | License |
|---|---|
| FOSS projects | GPL v3 |
| Closed source / commercial | BSD 2-Clause |
| Closed source / commercial | BSD 3-Clause |
| Closed source / commercial | MIT |
Anyone interested in using, developing, or contributing to VTKFortran is welcome — pick the license that best fits your needs.