A KISS pure Fortran Library to parse and emit files conforming VTK (XML) standard
Main features | Copyrights | Documentation | A Taste of VTKFortran
The importers are under developing.
VTKFortran can be safely used in parallel environments, handling multiple concurrent files: it is thread/processor-safe, meaning that it can be safely used into parallel architectures using OpenMP and/or MPI paradigms.
VTKFortran is an open source project, it is distributed under a multi-licensing system:
Anyone is interest to use, to develop or to contribute to VTKFortran is welcome, feel free to select the license that best matches your soul!
More details can be found on wiki.
Go to Top
Besides this README file the VTKFortran documentation is contained into its own wiki. Detailed documentation of the API is contained into the GitHub Pages that can also be created locally by means of ford tool.
Go to Top
Let us assume our aim being to save our pure Fortran data into a VTK structured grid file in binary XML form. This is simple as
use vtk_fortran, only : vtk_file
type(vtk_file) :: a_vtk_file ! A VTK file.
integer, parameter :: nx1=0_I4P ! X lower bound extent.
integer, parameter :: nx2=9_I4P ! X upper bound extent.
integer, parameter :: ny1=0_I4P ! Y lower bound extent.
integer, parameter :: ny2=5_I4P ! Y upper bound extent.
integer, parameter :: nz1=0_I4P ! Z lower bound extent.
integer, parameter :: nz2=5_I4P ! Z upper bound extent.
integer, parameter :: nn=(nx2-nx1+1)*(ny2-ny1+1)*(nz2-nz1+1) ! Number of elements.
real :: x(nx1:nx2,ny1:ny2,nz1:nz2) ! X coordinates.
real :: y(nx1:nx2,ny1:ny2,nz1:nz2) ! Y coordinates.
real :: z(nx1:nx2,ny1:ny2,nz1:nz2) ! Z coordinates.
real :: v(nx1:nx2,ny1:ny2,nz1:nz2) ! Variable at coordinates.
integer :: error ! Error status.
! initialize the data...
error = a_vtk_file%initialize(format='binary', filename='XML_STRG-binary.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='float64_scalar', 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()
Note that all VTKFortran functions return an error code that can be used for sophisticated error trapping algorithms.