Appearance
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:
- Initialize — open the file and select the format and mesh topology
- Write field data (optional) — attach global metadata (time, cycle, etc.)
- Open a piece — declare the extent or node/cell counts for the current piece
- Write geometry — coordinates (and connectivity for unstructured grids)
- Write data arrays — node-centered or cell-centered variables
- Close the piece
- 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()originandspacingare required forImageData: without theminitializereturns 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 atorigin + direction . ([i,j,k] * spacing). Default: identity.write_geois not used. Point data have one value per grid point, cell data one value per cell, written with the usualwrite_dataarraycalls 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:
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.
| Code | Cell | Points | Code | Cell | Points | |
|---|---|---|---|---|---|---|
| 1 | vertex | 1 | 21 | quadratic edge | 3 | |
| 2 | poly-vertex | any | 22 | quadratic triangle | 6 | |
| 3 | line | 2 | 23 | quadratic quad | 8 | |
| 4 | polyline | any | 24 | quadratic tetrahedron | 10 | |
| 5 | triangle | 3 | 25 | quadratic hexahedron | 20 | |
| 6 | triangle strip | any | 26 | quadratic wedge | 15 | |
| 7 | polygon | any | 27 | quadratic pyramid | 13 | |
| 8 | pixel | 4 | 28 | bi-quadratic quad | 9 | |
| 9 | quad | 4 | 29 | tri-quadratic hexahedron | 27 | |
| 10 | tetrahedron | 4 | 42 | polyhedron | any, see below | |
| 11 | voxel | 8 | ||||
| 12 | hexahedron | 8 | ||||
| 13 | wedge | 6 | ||||
| 14 | pyramid | 5 |
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):

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 infacewhere the description of that cell ends, or-1if 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 towrite_piece. - Cell data follow the VTK order of the blocks: vertices, then lines, then strips, then polygons, whatever the order of the arguments.
- The
ncargument ofwrite_geois 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) orwrite_dataarray_unsigned. - A
.vtthas onePiecewithNumberOfColsandNumberOfRows, written at the close of the columns (they are kept in memory until then), and the columns inRowData. A time series of.vttfiles 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_stepbefore each output, VTKHDF) every step writes its piece: coordinates, trees, cell data; an XML.htgis one dataset (a series is a.pvdof them). - The
.htgis written as VTK 9.7.2 writes it (version 2.0): theHyperTreeGridelement (BranchFactor,Dimensions, the interface names ofset_interface, called before the piece), itsGrid(the coordinates), itsTrees(DescriptorsandMaskasBitarrays,NumberOfVerticesPerDepth,TreeIds,DepthPerTree), itsCellData; 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),initializesets the whole extent and eachwrite_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.f90writes 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).
| Topology | Call | Coordinates |
|---|---|---|
RectilinearGrid | write_geo(x, y, z) | rank 1: the coordinates along each axis, nx2-nx1+1, ny2-ny1+1, nz2-nz1+1 values |
StructuredGrid | write_geo(n, x, y, z) | rank 1 x(n) or rank 3 x(i,j,k): n points, i varying first |
StructuredGrid | write_geo(xyz) | rank 2 xyz(3,n) or rank 4 xyz(3,i,j,k) |
UnstructuredGrid, PolyData | write_geo(np, nc, x, y, z) | rank 1 x(np); np and nc I4P or I8P |
UnstructuredGrid, PolyData | write_geo(np, nc, xyz) | rank 2 xyz(3,np) |
ImageData | none | origin, 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 pointf90
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.
| Status | Cause |
|---|---|
| 1 | an 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 values | an 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:
| Value | Produces |
|---|---|
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) |