Appearance
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
| Name | Type | Attributes | Description |
|---|---|---|---|
xml_writer | class(vtk_writer_abstract) | allocatable | Writer (XML; its name is kept for compatibility). |
xml_reader | type(xml_reader) | XML reader (initialize(..., action='read')). | |
is_reading | logical | The file is open for reading. |
Type-Bound Procedures
| Name | Attributes | Description |
|---|---|---|
get_xml_volatile | pass(self) | Return the eventual XML volatile string file. |
initialize | pass(self) | Initialize file. |
finalize | pass(self) | Finalize file. |
free | pass(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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(vtk_file) | in | VTK file. | |
xml_volatile | character(len=:) | out | allocatable | XML volatile file. |
error | integer(kind=I4P) | out | optional | Error status. |
Call graph
free
Free allocated memory.
Attributes: elemental
fortran
subroutine free(self, error)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(vtk_file) | inout | VTK file. | |
error | integer(kind=I4P) | out | optional | Error 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 (and dataset: a dataset of a VTKHDF MultiBlockDataSet or PartitionedDataSetCollection, its path under /VTKHDF as vtm_file%get_entries gives it as the file of the dataset; refused without action='read'): 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()Continuing a time series
With format='vtkhdf' and action='append' a VTKHDF time series written before (xml_writer%write_step) is reopened to append steps, e.g. after a restart: filename is the only other argument used, the rest comes from the file. What an interrupted run left after its last complete piece is dropped. The next write_step needs a later time.
fortran
error = vtk%initialize(format='vtkhdf', filename='run.vtkhdf', action='append')
error = vtk%xml_writer%write_step(time=t)
...Writing
format and mesh_topology are required. mesh_topology='Table' (columns of values, no mesh) is a .vtt file in the XML formats (one Piece: NumberOfCols, NumberOfRows and the columns in RowData, written between write_dataarray(location='row', action='open') and ...'close')) or a VTKHDF Table. 'OverlappingAMR' (the boxes of the levels of a block-structured AMR, origin its origin) is written in the VTKHDF format only (an XML OverlappingAMR is a .vthb of .vti boxes, vtm_file). 'HyperTreeGrid' (the trees of a tree-based AMR on a root grid, nx1...nz2 its points, branch_factor 2 or 3) is a .htg in the XML formats (one piece: write_piece with the whole root grid, write_geo(x, y, z), write_tree for each tree, its cell data, write_piece()), or a VTKHDF HyperTreeGrid.
Writing one file from MPI ranks
With format='vtkhdf' and comm (a Fortran MPI communicator: MPI_Comm%MPI_VAL of mpi_f08, or the integer handle of the mpi module) the ranks of comm write one file together (the library built with VTKFORTRAN_USE_MPI and a parallel HDF5): an UnstructuredGrid or a PolyData, each rank one piece, a partition of the file; or an ImageData, RectilinearGrid or StructuredGrid of the whole extent given here, each rank one region of it (write_piece with its sub-extent, its arrays and geometry of that region; the regions checked: inside the whole extent, not overlapping, covering it; an empty one, an upper bound before its lower one, writes nothing). Every rank makes the same calls, with the same arrays in the same order: the HDF5 calls are collective (ranks writing different arrays in a call are refused on every rank). A time series too: every rank calls write_step with the same time, then writes its piece (its region of a grid) of the step; action='append' with comm continues one (a parallel restart). Polyhedra (on any ranks) and compressor='zlib' (an HDF5 1.10.2 or later with the deflate filter: parallel filtered writes, collective) too. Refused with comm: compressor='zlib' for a grid, the other formats, action='read'.
fortran
error = vtk%initialize(format='vtkhdf', filename='mesh.vtkhdf', mesh_topology='UnstructuredGrid', &
comm=MPI_COMM_WORLD%MPI_VAL)
error = vtk%xml_writer%write_piece(np=np, nc=nc) ! the piece of this rank
...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;
- VTKHDF: an HDF5 file in the VTKHDF layout (needs the library built with
VTKFORTRAN_USE_HDF5): ImageData, RectilinearGrid, StructuredGrid (one piece), UnstructuredGrid and PolyData (each piece a partition), Table, OverlappingAMR, HyperTreeGrid; see thevtk_fortran_vtk_file_vtkhdf_writermodule.
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. With VTKHDF, zlib deflates the HDF5 datasets: it needs the deflate filter of the HDF5 library, not VTKFORTRAN_USE_ZLIB.
Chunks of the VTKHDF datasets
The VTKHDF datasets that grow (the partitions of an UnstructuredGrid or a PolyData, the steps of a time series) or are deflated (compressor='zlib') are stored by chunks. A chunk holds whole rows (the last dimension of the values, e.g. the points, or the time slices of a grid): as many as fit in chunk_bytes (default 1 MiB), at least one, at most the rows written when the dataset is created (those of all the ranks with comm; one row for a dataset created empty). Larger chunks mean fewer HDF5 metadata operations (large parallel runs, a chunk aligned to the stripe size of a parallel file system), smaller ones less unused space in short series. chunk_bytes is refused when not positive, and with the XML formats or action='read'; with action='append' it applies to the datasets created from then on, those of the file keep their chunks. With comm every rank gives the same chunk_bytes (or none): different ones are refused on every rank.
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 and VTKHDF formats.
Supported topologies are:
- RectilinearGrid;
- StructuredGrid;
- UnstructuredGrid;
- ImageData: a regular grid, defined by the extents and the
origin,spacing(both required) anddirection(optional) arguments; the point of indexes (i,j,k) is atorigin + direction . ([i,j,k] * spacing). No geometry is written (write_geois not used). - PolyData: points (
write_geo(np, nc, x, y, z)) and up to four cell blocks (vertices, lines, triangle strips, polygons) written withwrite_polydata_cells; the piece is opened withwrite_piece(np, nverts, nlines, nstrips, npolys). - Table: columns of values, no mesh (
.vttin the XML formats); see Writing above.
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, comm, branch_factor, chunk_bytes, dataset) result(error)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(vtk_file) | inout | VTK file. | |
format | character(len=*) | in | optional | File format: ASCII, BINARY, RAW, RAW-ZLIB, BINARY-APPENDED, VTKHDF. |
filename | character(len=*) | in | File name. | |
mesh_topology | character(len=*) | in | optional | Mesh topology. |
is_volatile | logical | in | optional | Write into memory (get_xml_volatile): ascii and binary only. |
nx1 | integer(kind=I4P) | in | optional | Initial node of x axis. |
nx2 | integer(kind=I4P) | in | optional | Final node of x axis. |
ny1 | integer(kind=I4P) | in | optional | Initial node of y axis. |
ny2 | integer(kind=I4P) | in | optional | Final node of y axis. |
nz1 | integer(kind=I4P) | in | optional | Initial node of z axis. |
nz2 | integer(kind=I4P) | in | optional | Final node of z axis. |
origin | real(kind=R8P) | in | optional | Origin of ImageData: coordinates of the point of indexes (0,0,0). |
spacing | real(kind=R8P) | in | optional | Spacing of ImageData along each axis. |
direction | real(kind=R8P) | in | optional | Axes directions of ImageData, row-major 3x3 matrix (default identity). |
header_type | character(len=*) | in | optional | Bytes count header of binary data: UInt32 (default) or UInt64. |
compressor | character(len=*) | in | optional | Compressor of binary data: none (default) or zlib. |
action | character(len=*) | in | optional | Action: write (default), read or append (VTKHDF). |
comm | integer(kind=I4P) | in | optional | MPI communicator (Fortran handle): one VTKHDF file from its ranks. |
branch_factor | integer(kind=I4P) | in | optional | Branch factor of a HyperTreeGrid: 2 (default) or 3. |
chunk_bytes | integer(kind=I4P) | in | optional | Bytes of a chunk of the VTKHDF datasets at most (default 1 MiB). |
dataset | character(len=*) | in | optional | With action read: a dataset of a VTKHDF composite file. |
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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
string | character(len=*) | in | Input string. |
Call graph
finalize
Finalize file: close the writer, or free the reader.
Returns: integer(kind=I4P)
fortran
function finalize(self) result(error)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(vtk_file) | inout | VTK file. |
Call graph