Skip to content

Topologies ​

Write each kind of VTK XML dataset: the serial topologies, several pieces in one file. Complete programs: the cookbook and the tutorial.

The examples of this page are taken from ref_topologies.f90, compiled and run with the documentation; every file it writes is read back. The general workflow for writing a VTK XML file is:

  1. Initialize — open the file and select the format and mesh topology
  2. Write field data (optional) — attach global metadata (time, cycle, etc.)
  3. Open a piece — declare the extent or node/cell counts for the current piece
  4. Write geometry — coordinates (and connectivity for unstructured grids)
  5. Write data arrays — node-centered or cell-centered variables
  6. Close the piece
  7. Finalize — flush and close the file

Every function returns an integer error status, 0 on success (the subroutines get_xml_volatile and free take an optional error). Two failures stop the program instead, with a message on standard error: a binary array larger than the 2 GiB of a UInt32 header (initialize the file with header_type='UInt64'), and a failure of zlib while compressing. To read a file back, see Reading files.

Image Data (VTI) ​

A regular grid with uniform spacing along each axis needs no geometry at all: it is defined by its extents, the coordinates of its origin and its spacing. The point of indexes (i,j,k) is at origin + [i,j,k] * spacing (the origin is the point of indexes (0,0,0), also when the extents do not start at 0).

f90
use vtk_fortran, only : vtk_file
use penf,        only : I4P, R8P

type(vtk_file) :: a_vtk_file
integer(I4P)   :: i, j, k, error
real(R8P)      :: phi(0:15,0:15,0:7)   ! point data, one value per grid point

do k=0, 7 ; do j=0, 15 ; do i=0, 15
  phi(i,j,k) = sin(0.4_R8P*i) * cos(0.4_R8P*j) + 0.1_R8P*k
enddo ; enddo ; enddo
error = a_vtk_file%initialize(format='raw', filename='ref_image.vti', mesh_topology='ImageData', &
                              nx1=0, nx2=15, ny1=0, ny2=15, nz1=0, nz2=7,                     &
                              origin=[0._R8P, 0._R8P, 0._R8P], spacing=[0.1_R8P, 0.1_R8P, 0.2_R8P])
error = a_vtk_file%xml_writer%write_piece(nx1=0, nx2=15, ny1=0, ny2=15, nz1=0, nz2=7)
error = a_vtk_file%xml_writer%write_dataarray(location='node', action='open')
error = a_vtk_file%xml_writer%write_dataarray(data_name='phi', x=phi, 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()
  • origin and spacing are required for ImageData: without them initialize returns a non-zero error (and no file is written).
  • direction (optional) orients the grid axes, as a row-major 3x3 matrix: the point (i,j,k) is at origin + direction . ([i,j,k] * spacing). Default: identity.
  • write_geo is not used. Point data have one value per grid point, cell data one value per cell, written with the usual write_dataarray calls in any format.
  • ImageData is also written in the VTKHDF format (format='vtkhdf', an HDF5 file), with the same calls and one piece: see VTKHDF. So is every other topology.

Rectilinear Grid (VTR) ​

A rectilinear grid has independent 1-D coordinate arrays along each axis.

f90
use vtk_fortran, only : vtk_file
use penf,        only : I4P, I8P, R8P

type(vtk_file)          :: a_vtk_file
integer(I4P), parameter :: nx1=0, nx2=8, ny1=0, ny2=4, nz1=0, nz2=4
integer(I4P), parameter :: nn=(nx2-nx1+1)*(ny2-ny1+1)*(nz2-nz1+1)
real(R8P)               :: x(nx1:nx2), y(ny1:ny2), z(nz1:nz2)
integer(I4P)            :: v(1:nn)   ! one value per point
integer(I4P)            :: i, error

x = [(0.5_R8P*i, i=nx1, nx2)] ; y = [(0.5_R8P*i, i=ny1, ny2)] ; z = [(0.5_R8P*i, i=nz1, nz2)]
v = [(i, i=1, nn)]
error = a_vtk_file%initialize(format='binary', filename='ref_rectilinear.vtr', &
                              mesh_topology='RectilinearGrid',                  &
                              nx1=nx1, nx2=nx2, ny1=ny1, ny2=ny2, nz1=nz1, nz2=nz2)
! optional global field data
error = a_vtk_file%xml_writer%write_fielddata(action='open')
error = a_vtk_file%xml_writer%write_fielddata(x=0._R8P, data_name='TIME')
error = a_vtk_file%xml_writer%write_fielddata(x=1_I8P,  data_name='CYCLE')
error = a_vtk_file%xml_writer%write_fielddata(action='close')

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(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='node_value', x=v)
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()

In the VTKHDF format (format='vtkhdf', one piece) the coordinates are the datasets XCoordinates, YCoordinates and ZCoordinates: see VTKHDF.

Structured Grid (VTS) ​

A structured grid has full 3-D coordinate arrays — each grid point has its own (x, y, z) position.

f90
use vtk_fortran, only : vtk_file
use penf,        only : I4P, R8P

type(vtk_file)          :: a_vtk_file
integer(I4P), parameter :: nx1=0, nx2=9, ny1=0, ny2=5, nz1=0, nz2=5
integer(I4P), 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(I4P)            :: i, j, k, error

do k=nz1, nz2 ; do j=ny1, ny2 ; do i=nx1, nx2   ! a sheared box
  x(i,j,k) = i + 0.3_R8P*j ; y(i,j,k) = j ; z(i,j,k) = k ; v(i,j,k) = x(i,j,k)**2
enddo ; enddo ; enddo
error = a_vtk_file%initialize(format='binary', filename='ref_structured.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()

Arrays of rank 2 to 4 hold the components in their first dimension (see Writing arrays): without one_component=.true., the rank-3 scalar v(0:9,0:5,0:5) would be written as an array of 10 components and 36 tuples instead of 1 component and 360 tuples, a file that readers reject or misread. Pass one_component=.true. for every scalar field stored in an array of rank 2 to 4.

In the VTKHDF format (format='vtkhdf', one piece) the points are the dataset Points, from any of the write_geo layouts: see VTKHDF and the recipe A grid in a .vtkhdf file.

Unstructured Grid (VTU) ​

An unstructured grid requires explicit node coordinates, a connectivity table, cell offsets, and cell types. Here a unit cube (a hexahedron, points 0 to 7) with a pyramid on top of it (its base is the top face of the cube, its apex the point 8):

f90
use vtk_fortran, only : vtk_file
use penf,        only : I1P, I4P, R4P, R8P

type(vtk_file)          :: a_vtk_file
integer(I4P), parameter :: np = 9    ! number of points: a unit cube and the apex of a pyramid on top of it
integer(I4P), parameter :: nc = 2    ! number of cells: a hexahedron and a pyramid
real(R4P),    parameter :: x(np) = [0, 1, 1, 0, 0, 1, 1, 0, 0]
real(R4P),    parameter :: y(np) = [0, 0, 1, 1, 0, 0, 1, 1, 0]
real(R4P),    parameter :: z(np) = [0, 0, 0, 0, 1, 1, 1, 1, 2]
integer(I4P), parameter :: connect(13)  = [0,1,2,3,4,5,6,7, 4,5,6,7,8]   ! the point ids of each cell, 0-based
integer(I4P), parameter :: offset(nc)   = [8, 13]                        ! the end of each cell in connect
integer(I1P), parameter :: cell_type(nc) = [12_I1P, 14_I1P]               ! VTK_HEXAHEDRON, VTK_PYRAMID
real(R8P)               :: v(np)              ! scalar at the points
real(R8P)               :: vx(np), vy(np), vz(np) ! vector at the points
integer(I4P)            :: error

v = real(z, R8P) ; vx = 0._R8P ; vy = 0._R8P ; vz = 1._R8P
error = a_vtk_file%initialize(format='binary', filename='ref_unstructured.vtu', mesh_topology='UnstructuredGrid')
error = a_vtk_file%xml_writer%write_piece(np=np, nc=nc)
error = a_vtk_file%xml_writer%write_geo(np=np, nc=nc, x=x, y=y, z=z)
error = a_vtk_file%xml_writer%write_connectivity(nc=nc, connectivity=connect, offset=offset, cell_type=cell_type)
error = a_vtk_file%xml_writer%write_dataarray(location='node', action='open')
error = a_vtk_file%xml_writer%write_dataarray(data_name='scalars', x=v)
error = a_vtk_file%xml_writer%write_dataarray(data_name='vector', x=vx, y=vy, z=vz)
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()

How the three arrays describe the two cells:

The connectivity, offsets and cell types of a hexahedron and a pyramid012345678hexahedron (12) and pyramid (14)connectivity0123456745678offset813cell_type1214cell ends813cell i: connectivity(offset(i-1)+1 : offset(i))point ids from 0, in the order of the cell type

Unstructured grids are written in every format, compressed or not, as the other topologies, and in the VTKHDF format (format='vtkhdf', an HDF5 file) too, with the same calls: each piece is a partition of the file, polyhedra included. See VTKHDF and the recipe Write a .vtkhdf file.

Cell types are passed as integer(I1P) and written as a UInt8 DataArray, as the VTK XML format specifies (VTK cell type codes are all below 128, so the bytes are the same).

Cell types ​

The VTK codes of the cells, with their number of points. The points of each cell are listed in the order VTK defines for its type (for the hexahedron: the bottom face counter-clockwise seen from above, then the top face in the same order); see figures 2 and 3 of the VTK file formats for the drawings, with the order of the points of every type.

CodeCellPointsCodeCellPoints
1vertex121quadratic edge3
2poly-vertexany22quadratic triangle6
3line223quadratic quad8
4polylineany24quadratic tetrahedron10
5triangle325quadratic hexahedron20
6triangle stripany26quadratic wedge15
7polygonany27quadratic pyramid13
8pixel428bi-quadratic quad9
9quad429tri-quadratic hexahedron27
10tetrahedron442polyhedronany, see below
11voxel8
12hexahedron8
13wedge6
14pyramid5

Pixels and voxels are the axis-aligned quad and hexahedron, with their points in the order i, then j, then k: not the order of the quad and hexahedron.

The linear cells, each labelled with its code and its points with their position in the connectivity of the cell, as written by ref_cells.f90 (every cell checked by VTK's cell validator):

the 14 linear VTK cells, from the vertex to the pyramid, their points numbered in VTK order

Polyhedron cells ​

General polyhedra (VTK cell type 42) need two more arrays, passed to write_connectivity as the optional face and faceoffset arguments:

  • face: for each polyhedron, the number of its faces followed, for each face, by the number of its points and the point ids, listed counter-clockwise seen from outside the cell (the normal of each face points out: VTK flags a face listed the other way as a wrong orientation);
  • faceoffset: for each cell, the position in face where the description of that cell ends, or -1 if the cell is not a polyhedron.

The connectivity of a polyhedron lists the (unique) ids of its points, as for any other cell. For example, a unit cube written as a polyhedron (points 0–7) followed by a tetrahedron (points 8–11):

f90
integer(I4P), parameter :: connect(12)  = [0,1,2,3,4,5,6,7, 8,9,10,11]
integer(I4P), parameter :: offset(2)    = [8, 12]
integer(I1P), parameter :: cell_type(2) = [42_I1P, 10_I1P]  ! polyhedron, tetrahedron
integer(I4P), parameter :: face(31)     = [6,                &  ! the cube has 6 faces,
                                           4, 0,3,2,1,       &  ! each made of 4 points, listed
                                           4, 4,5,6,7,       &  ! counter-clockwise seen from outside
                                           4, 0,1,5,4,       &
                                           4, 1,2,6,5,       &
                                           4, 2,3,7,6,       &
                                           4, 3,0,4,7]
integer(I4P), parameter :: faceoffset(2) = [31, -1]          ! the tetrahedron is not a polyhedron

error = a_vtk_file%xml_writer%write_connectivity(nc=2, connectivity=connect, offset=offset, cell_type=cell_type, &
                                                  face=face, faceoffset=faceoffset)

See src/tests/vtk_fortran_write_vtu_polyhedron.f90 for the complete program. The same calls write the polyhedra in the VTKHDF format (format='vtkhdf', VTKHDF 2.5), as the faces and the faces of each polyhedron: see VTKHDF.

Polygonal Data (VTP) ​

PolyData describe points and up to four blocks of cells: vertices, lines (polylines), triangle strips and polygons, typical of surfaces, curves and point clouds. Open the piece with the number of points and of cells of each block, write the points with write_geo, then the blocks with write_polydata_cells:

f90
use vtk_fortran, only : vtk_file
use penf,        only : I4P, R8P

type(vtk_file) :: a_vtk_file
integer(I4P)   :: error
real(R8P)      :: x(7), y(7), z(7)   ! a square (points 0-3) and a polyline (points 4-6)

x = [0, 1, 1, 0, 0, 1, 2] ; y = [0, 0, 1, 1, 2, 3, 2] ; z = 0
error = a_vtk_file%initialize(format='raw', filename='ref_polydata.vtp', mesh_topology='PolyData')
error = a_vtk_file%xml_writer%write_piece(np=7, nverts=0, nlines=1, nstrips=0, npolys=2)
error = a_vtk_file%xml_writer%write_geo(np=7, nc=3, x=x, y=y, z=z)
error = a_vtk_file%xml_writer%write_polydata_cells(lines_connectivity=[4,5,6], lines_offset=[3],          &
                                                    polys_connectivity=[0,1,2, 0,2,3], polys_offset=[3,6])
error = a_vtk_file%xml_writer%write_dataarray(location='cell', action='open')
error = a_vtk_file%xml_writer%write_dataarray(data_name='id', x=[1,2,3])   ! the polyline, then the two triangles
error = a_vtk_file%xml_writer%write_dataarray(location='cell', action='close')
error = a_vtk_file%xml_writer%write_piece()
error = a_vtk_file%finalize()
  • Each block is a pair of arrays, as in write_connectivity: the point ids (0-based) of its cells one after the other, and the cumulative offset of the end of each cell. Pass only the blocks you have; a block with only one of its two arrays is an error. The number of cells of each block must match the counts given to write_piece.
  • Cell data follow the VTK order of the blocks: vertices, then lines, then strips, then polygons, whatever the order of the arguments.
  • The nc argument of write_geo is not used for PolyData (it writes the points only).
  • PolyData are written in the VTKHDF format (format='vtkhdf', an HDF5 file) too, with the same calls: each piece is a partition of the file, each block a group. See VTKHDF and the recipe A PolyData in a .vtkhdf file.

Table ​

A Table holds columns of values, with no mesh: time histories, probes, integrals (a VTK vtkTable). It is written (mesh_topology='Table') as a .vtt in the XML formats, which ParaView opens, or as a VTKHDF file (format='vtkhdf'), with the same calls: its columns between write_dataarray(location='row', action='open') and action='close', every column of the same rows:

f90
! the history of x'' + 0.2 x' + x = 0, x(0) = 1, v(0) = 0 (semi-implicit Euler), one sample per time step
t(1) = 0 ; x(1) = 1 ; v(1) = 0
do i=2, n_samples
  t(i) = t(i-1) + dt
  v(i) = v(i-1) - dt * (0.2_R8P * v(i-1) + x(i-1))
  x(i) = x(i-1) + dt * v(i)
enddo
! one Table: a column per quantity, a row per sample
error = a_vtk_file%initialize(format='vtkhdf', filename='history.vtkhdf', mesh_topology='Table')
error = a_vtk_file%xml_writer%write_dataarray(location='row', action='open')
error = a_vtk_file%xml_writer%write_dataarray(data_name='time', x=t)
error = a_vtk_file%xml_writer%write_dataarray(data_name='displacement', x=x)
error = a_vtk_file%xml_writer%write_dataarray(data_name='velocity', x=v)
error = a_vtk_file%xml_writer%write_dataarray(location='row', action='close')
error = a_vtk_file%finalize()
  • A column is any write_dataarray (every kind, components as for a data array) or write_dataarray_unsigned.
  • A .vtt has one Piece with NumberOfCols and NumberOfRows, written at the close of the columns (they are kept in memory until then), and the columns in RowData. A time series of .vtt files is a .pvd.
  • In a VTKHDF time series (write_step(time) before each output) every step writes the same columns, with any number of rows.
  • No pieces and no point or cell data. The layouts, the refusals and the readers: VTKHDF; complete programs: A time history (Table).

OverlappingAMR (VTKHDF) ​

A block-structured AMR (a VTK vtkOverlappingAMR): levels of uniform boxes, each finer level of a smaller spacing, its boxes overlapping those of the levels before. It is written in the VTKHDF format only (format='vtkhdf', mesh_topology='OverlappingAMR', origin its origin): write_level(level, spacing) starts a level, then each box is a piece of it, its point extent in the indices of the level, with its point and cell data:

f90
error = a_vtk_file%initialize(format='vtkhdf', filename='amr.vtkhdf', mesh_topology='OverlappingAMR', &
                              origin=[0._R8P, 0._R8P, 0._R8P])
! level 0: the whole domain, spacing 1
error = a_vtk_file%xml_writer%write_level(level=0, spacing=[1._R8P, 1._R8P, 1._R8P])
error = box(nx1=0, nx2=16, ny1=0, ny2=8, h=1._R8P)
! level 1: spacing 0.5, two boxes around the hot spot (their point indices are those of level 1)
error = a_vtk_file%xml_writer%write_level(level=1, spacing=[0.5_R8P, 0.5_R8P, 0.5_R8P])
error = box(nx1=8, nx2=16, ny1=4, ny2=12, h=0.5_R8P)
error = box(nx1=16, nx2=24, ny1=4, ny2=12, h=0.5_R8P)
error = a_vtk_file%finalize()
  • Levels 0, 1, ... in order; the boxes of level 0 come first (they bound the boxes of the finer levels).
  • A box has at least one cell along every axis: VTK reads every box in 3D, so a 2D AMR is one cell thick.
  • Every box of every level writes the same arrays; no field data (VTK 9.7.2 reads none of an OverlappingAMR). In a time series every step writes its levels and boxes again.
  • The layout, the refusals and the readers: VTKHDF; a complete program: A block-structured AMR.

HyperTreeGrid ​

A tree-based AMR (a VTK vtkHyperTreeGrid): a root grid whose cells are the roots of trees, quadtrees or octrees (branch factor 2) or their kin of branch factor 3. It is a .htg file in the XML formats, or a .vtkhdf one (mesh_topology='HyperTreeGrid', the extent the points of the root grid, branch_factor): one piece with its root coordinates, its trees (write_tree, each the refinement of its cells breadth first) and their cell data:

f90
error = a_vtk_file%initialize(format='vtkhdf', filename='quadtree.vtkhdf', mesh_topology='HyperTreeGrid', &
                              nx1=0, nx2=nx, ny1=0, ny2=ny, nz1=0, nz2=0, branch_factor=2)
error = a_vtk_file%xml_writer%write_piece(nx1=0, nx2=nx, ny1=0, ny2=ny, nz1=0, nz2=0)
error = a_vtk_file%xml_writer%write_geo(x=[(real(i, R8P), i=0, nx)], y=[(real(j, R8P), j=0, ny)], z=[0._R8P])
allocate(depths(0))
do j=0, ny - 1 ; do i=0, nx - 1 ! the tree of root cell (i, j): its id i + nx j
  error = a_vtk_file%xml_writer%write_tree(tree_id=i + nx * j, descriptor=tree(real(i, R8P), real(j, R8P)))
enddo ; enddo
error = a_vtk_file%xml_writer%write_dataarray(location='cell', action='open')
error = a_vtk_file%xml_writer%write_dataarray(data_name='depth', x=depths)
error = a_vtk_file%xml_writer%write_dataarray(location='cell', action='close')
error = a_vtk_file%xml_writer%write_piece()
error = a_vtk_file%finalize()
  • A tree is given breadth first, the children of a cell x fastest, every depth but the deepest (its cells are all leaves); a mask can hide leaves.
  • Cell data only, one value per cell of the trees, after the trees, in their order.
  • In a time series (write_step before each output, VTKHDF) every step writes its piece: coordinates, trees, cell data; an XML .htg is one dataset (a series is a .pvd of them).
  • The .htg is written as VTK 9.7.2 writes it (version 2.0): the HyperTreeGrid element (BranchFactor, Dimensions, the interface names of set_interface, called before the piece), its Grid (the coordinates), its Trees (Descriptors and Mask as Bit arrays, NumberOfVerticesPerDepth, TreeIds, DepthPerTree), its CellData; no field data. VTK 9.7.2 reads it in every XML format.
  • The layout, the refusals and the readers: VTKHDF; a complete program: A tree-based AMR.

Multiple pieces in one file ​

A single file can hold several pieces, e.g. the blocks of a multi-block solver written by one process without a parallel header: open and close each piece with write_piece, and write its geometry, connectivity and data in between, exactly as for a single-piece file. Readers (VTK, ParaView) merge the pieces into one dataset.

f90
error = a_vtk_file%initialize(format='raw', filename='ref_blocks.vtu', mesh_topology='UnstructuredGrid')
do b=1, nblocks
  x = [0, 1, 0, 0] + 2._R8P*b ; p = b   ! the points and the data of block b
  error = a_vtk_file%xml_writer%write_piece(np=np(b), nc=nc(b))
  error = a_vtk_file%xml_writer%write_geo(np=np(b), nc=nc(b), x=x, y=y, z=z)
  error = a_vtk_file%xml_writer%write_connectivity(nc=nc(b), connectivity=[0,1,2,3], offset=[4], cell_type=[10_I1P])
  error = a_vtk_file%xml_writer%write_dataarray(location='node', action='open')
  error = a_vtk_file%xml_writer%write_dataarray(data_name='pressure', x=p)
  error = a_vtk_file%xml_writer%write_dataarray(location='node', action='close')
  error = a_vtk_file%xml_writer%write_piece()
enddo
error = a_vtk_file%finalize()
  • Each piece has its own points: the point ids of its connectivity (and offsets) are local to the piece, starting from 0.
  • Every piece must carry the same data arrays (same names, types and components): VTK takes the arrays of the first piece, so an array missing in the first piece is dropped, and one missing in a later piece is silently filled with zeros there.
  • For structured topologies (RectilinearGrid, StructuredGrid, ImageData), initialize sets the whole extent and each write_piece(nx1=..., nx2=..., ...) sets the extent of the piece inside it; adjacent pieces share their boundary plane.
  • It works with every format; the test src/tests/vtk_fortran_write_multipiece.f90 writes both kinds of grids.

Coordinates (write_geo) ​

Every topology but ImageData stores its points; write_geo takes them in the form of the topology. The coordinates are R8P (written as Float64) or R4P (Float32).

TopologyCallCoordinates
RectilinearGridwrite_geo(x, y, z)rank 1: the coordinates along each axis, nx2-nx1+1, ny2-ny1+1, nz2-nz1+1 values
StructuredGridwrite_geo(n, x, y, z)rank 1 x(n) or rank 3 x(i,j,k): n points, i varying first
StructuredGridwrite_geo(xyz)rank 2 xyz(3,n) or rank 4 xyz(3,i,j,k)
UnstructuredGrid, PolyDatawrite_geo(np, nc, x, y, z)rank 1 x(np); np and nc I4P or I8P
UnstructuredGrid, PolyDatawrite_geo(np, nc, xyz)rank 2 xyz(3,np)
ImageDatanoneorigin, spacing and direction of initialize

The packed forms, from ref_topologies.f90:

f90
real(R8P) :: xyz(3,0:2,0:1,0:1)   ! StructuredGrid: (x,y,z) of each point, the points in the order i, j, k
real(R8P) :: pts(3,4)             ! UnstructuredGrid and PolyData: (x,y,z) of each point
f90
error = a_vtk_file%xml_writer%write_geo(xyz=xyz)
f90
error = a_vtk_file%xml_writer%write_geo(np=4, nc=1, xyz=pts)

A count that does not match the size of the arrays (n, np) makes write_geo return 1, with nothing written.

Errors ​

Every function returns an integer status: 0 on success, otherwise the file is not complete and the status says why.

StatusCause
1an argument is invalid: initialize with an unknown format, header_type, compressor or action, without format or mesh_topology, format='raw-zlib' with compressor='none', compressor='zlib' with a library built without zlib, is_volatile=.true. with an appended format, ImageData without origin and spacing; a parallel header (pvtk_file) of points without mesh_kind; write_geo with counts that do not match the arrays; write_polydata_cells with a block given only one of its two arrays; write_dataarray_unsigned of an I8P value of 2^63 or more in ASCII
other positive valuesan input/output statement failed (opening, writing, closing the file: a missing directory, no permission, a full disk): the iostat of the compiler

Two failures stop the program instead (error stop, with a message on standard error): a binary array larger than the 2 GiB of a UInt32 header (initialize the file with header_type='UInt64', see Large data arrays), and a failure of zlib while compressing. The readers have codes of their own, see Reading files. vtm_file and pvd_file return 1 for an unknown action or a file that cannot be appended to, and the iostat of a failed input/output statement.

Mesh topology strings ​

The mesh_topology argument is case-sensitive:

ValueProduces
ImageData.vti file (requires origin and spacing)
RectilinearGrid.vtr file
StructuredGrid.vts file
UnstructuredGrid.vtu file
PolyData.vtp file
Table.vtt (XML formats) or .vtkhdf (format='vtkhdf')
OverlappingAMR.vtkhdf file only (format='vtkhdf', origin); an XML one is a .vthb (vtm_file)
HyperTreeGrid.htg (XML formats) or .vtkhdf (format='vtkhdf'), branch_factor
PRectilinearGrid.pvtr file (pvtk_file only)
PStructuredGrid.pvts file (pvtk_file only)
PUnstructuredGrid.pvtu file (pvtk_file only)
PImageData.pvti file (pvtk_file only, requires origin and spacing)
PPolyData.pvtp file (pvtk_file only)