Skip to content

vtk_fortran_vtk_file ​

VTK file class.

Source: src/lib/vtk_fortran_vtk_file.f90

Dependencies

Contents ​

Derived Types ​

vtk_file ​

VTK file class.

Components ​

NameTypeAttributesDescription
xml_writerclass(xml_writer_abstract)allocatableXML writer.
xml_readertype(xml_reader)XML reader (initialize(..., action='read')).
is_readinglogicalThe file is open for reading.

Type-Bound Procedures ​

NameAttributesDescription
get_xml_volatilepass(self)Return the eventual XML volatile string file.
initializepass(self)Initialize file.
finalizepass(self)Finalize file.
freepass(self)Free allocated memory.

Subroutines ​

get_xml_volatile ​

Return the eventual XML volatile string file.

Attributes: pure

fortran
subroutine get_xml_volatile(self, xml_volatile, error)

Arguments

NameTypeIntentAttributesDescription
selfclass(vtk_file)inVTK file.
xml_volatilecharacter(len=:)outallocatableXML volatile file.
errorinteger(kind=I4P)outoptionalError status.

Call graph

free ​

Free allocated memory.

Attributes: elemental

fortran
subroutine free(self, error)

Arguments

NameTypeIntentAttributesDescription
selfclass(vtk_file)inoutVTK file.
errorinteger(kind=I4P)outoptionalError status.

Call graph

Functions ​

initialize ​

Initialize file: open it for writing (default) or for reading.

@note This function must be the first to be called.

Reading ​

With action='read' only filename is used: the file is indexed and its data are then read through the xml_reader component (get_info, read_piece, read_geo, read_connectivity, read_polydata_cells, get_dataarray_names, get_dataarray_info, read_dataarray); finalize frees it. Its format, topology, header type and compressor come from the file. The error codes of reading are listed in the vtk_fortran_vtk_file_xml_reader module.

fortran
 type(vtk_file)         :: vtk
 real(R8P), allocatable :: x(:), y(:), z(:), pressure(:)
 error = vtk%initialize(filename='mesh.vtu', action='read')
 error = vtk%xml_reader%read_geo(x=x, y=y, z=z)
 error = vtk%xml_reader%read_dataarray(location='node', data_name='pressure', x=pressure)
 error = vtk%finalize()

Writing ​

format and mesh_topology are required.

Supported output formats are (the passed specifier value is case insensitive): ​

  • ASCII: data are saved in ASCII format;
  • BINARY: data are saved in base64 encoded format;
  • RAW: data are saved in raw-binary format in the appended tag of the XML file;
  • RAW-ZLIB: shorthand of RAW with compressor='zlib';
  • BINARY-APPENDED: data are saved in base64 encoded format in the appended tag of the XML file.

Compression of binary data ​

The optional compressor compresses the data of the binary formats (BINARY, RAW, BINARY-APPENDED) as VTK does (vtkZLibDataCompressor, blocks of 32 KiB): none (default) or zlib, case insensitive; it is ignored by the ASCII format. zlib needs the library built with VTKFORTRAN_USE_ZLIB: otherwise, as for an unknown compressor, initialize returns a non-zero error. RAW-ZLIB with compressor='none' is an error too.

Bytes count header of binary data ​

Each binary DataArray (formats BINARY, RAW, RAW-ZLIB, BINARY-APPENDED) is prefixed by its bytes count (by the header of its compressed blocks, when compressed). The optional header_type selects its width: UInt32 (default) limits each DataArray to 2 GiB (larger ones stop the execution with an explicit error), UInt64 lifts the limit; it is case insensitive and ignored by the ASCII format.

Supported topologies are: ​

  • RectilinearGrid;
  • StructuredGrid;
  • UnstructuredGrid;
  • ImageData: a regular grid, defined by the extents and the origin, spacing (both required) and direction (optional) arguments; the point of indexes (i,j,k) is at origin + direction . ([i,j,k] * spacing). No geometry is written (write_geo is not used).
  • PolyData: points (write_geo(np, nc, x, y, z)) and up to four cell blocks (vertices, lines, triangle strips, polygons) written with write_polydata_cells; the piece is opened with write_piece(np, nverts, nlines, nstrips, npolys).

Example of usage ​

fortran
 type(vtk_file) :: vtk
 integer(I4P)   :: nx1, nx2, ny1, ny2, nz1, nz2
 ...
 error = vtk%initialize('BINARY','XML_RECT_BINARY.vtr','RectilinearGrid',nx1=nx1,nx2=nx2,ny1=ny1,ny2=ny2,nz1=nz1,nz2=nz2)
 ...
 error = vtk%initialize('BINARY','XML_UNST_ZLIB.vtu','UnstructuredGrid',compressor='zlib')
 ...

@note The file extension is necessary in the file name. The XML standard has different extensions for each different topologies (e.g. vtr for rectilinear topology). See the VTK-standard file for more information.

Returns: integer(kind=I4P)

fortran
function initialize(self, format, filename, mesh_topology, is_volatile, nx1, nx2, ny1, ny2, nz1, nz2, origin, spacing, direction, header_type, compressor, action) result(error)

Arguments

NameTypeIntentAttributesDescription
selfclass(vtk_file)inoutVTK file.
formatcharacter(len=*)inoptionalFile format: ASCII, BINARY, RAW, RAW-ZLIB or BINARY-APPENDED.
filenamecharacter(len=*)inFile name.
mesh_topologycharacter(len=*)inoptionalMesh topology.
is_volatilelogicalinoptionalWrite into memory (get_xml_volatile): ascii and binary only.
nx1integer(kind=I4P)inoptionalInitial node of x axis.
nx2integer(kind=I4P)inoptionalFinal node of x axis.
ny1integer(kind=I4P)inoptionalInitial node of y axis.
ny2integer(kind=I4P)inoptionalFinal node of y axis.
nz1integer(kind=I4P)inoptionalInitial node of z axis.
nz2integer(kind=I4P)inoptionalFinal node of z axis.
originreal(kind=R8P)inoptionalOrigin of ImageData: coordinates of the point of indexes (0,0,0).
spacingreal(kind=R8P)inoptionalSpacing of ImageData along each axis.
directionreal(kind=R8P)inoptionalAxes directions of ImageData, row-major 3x3 matrix (default identity).
header_typecharacter(len=*)inoptionalBytes count header of binary data: UInt32 (default) or UInt64.
compressorcharacter(len=*)inoptionalCompressor of binary data: none (default) or zlib.
actioncharacter(len=*)inoptionalAction: write (default) or read, case insensitive.

Call graph

upper_case ​

Return a string in upper case (ASCII letters only).

Attributes: pure

Returns: character(len=len(string))

fortran
function upper_case(string) result(upper)

Arguments

NameTypeIntentAttributesDescription
stringcharacter(len=*)inInput string.

Call graph

finalize ​

Finalize file: close the writer, or free the reader.

Returns: integer(kind=I4P)

fortran
function finalize(self) result(error)

Arguments

NameTypeIntentAttributesDescription
selfclass(vtk_file)inoutVTK file.

Call graph