Skip to content

vtk_fortran_pvd_file ​

PVD file class: VTK collection of datasets (time series).

A .pvd file lists datasets (VTK XML files written with vtk_file, pvtk_file or vtm_file) with their time step, and optionally part, group and name: readers such as ParaView load the listed files as a time series.

The file is kept valid after each write_dataset: every new dataset is written over the closing tags, which are written again after it. Therefore a run that stops before finalize (crash, killed job) still leaves a readable collection of all the datasets written so far, and a restarted run can continue an existing collection with action='append'.

A file name ending in .series is a ParaView file series instead (JSON: {"file-series-version" : "1.0", "files" : [{"name" : ..., "time" : ...}, ...]}), written, continued and read by the same calls: it lists files and times only (part, group and name are refused), and is valid after each write_dataset too.

Source: src/lib/vtk_fortran_pvd_file.f90

Contents ​

Variables ​

NameTypeAttributesDescription
closing_tagscharacter(len=*)parameterClosing tags.
series_closingcharacter(len=*)parameterClosing of .series.

Derived Types ​

pvd_file ​

PVD file class.

Components ​

NameTypeAttributesDescription
unitinteger(kind=I4P)Logical unit, 0 when the file is not open.
pos_closeinteger(kind=I8P)Stream position of the closing tags, i.e. where the next dataset is written.
file_endinteger(kind=I8P)Size of the file: its last byte.
xmltype(xml_index)Index of the file read (action='read', FoXy).
is_readinglogicalThe file is open for reading.
is_serieslogicalA ParaView .series file (JSON) instead of a .pvd.
n_entriesinteger(kind=I4P)Entries of a .series file written (a comma before the next one).
series_timesreal(kind=R8P)allocatableTimes of the entries.
series_textinteger(kind=I4P)allocatableStart and length of the file name of each entry.
series_charscharacter(len=:)allocatableThe file names.

Type-Bound Procedures ​

NameAttributesDescription
get_datasetspass(self)Return the datasets of a file read.
initializepass(self)Initialize (create or append to) the file.
write_datasetpass(self)Write one dataset entry.
finalizepass(self)Finalize (close) the file.
write_closing_tagspass(self)Write the closing tags at the current end of datasets.
read_seriespass(self)Read the entries of a .series file.

Subroutines ​

write_closing_tags ​

Write the closing tags at the current end of datasets, blank anything after them and flush the file.

Older content after the closing tags (an appended file edited by hand) is overwritten with blanks on the line of the closing tag, not truncated: the file is a valid collection at any time, and ENDFILE does not truncate a stream file with every compiler (nvfortran 26.9).

fortran
subroutine write_closing_tags(self, error)

Arguments

NameTypeIntentAttributesDescription
selfclass(pvd_file)inoutPVD file.
errorinteger(kind=I4P)outError status.

Call graph

Functions ​

initialize ​

Initialize the file: create a new collection, or reopen an existing one to append datasets.

Example of usage ​

fortran
 type(pvd_file) :: pvd
 ...
 error = pvd%initialize(filename='simulation.pvd')                  ! new collection (an existing file is replaced)
 error = pvd%initialize(filename='simulation.pvd', action='append') ! continue an existing collection (e.g. restart)
 error = pvd%initialize(filename='simulation.pvd', action='read')   ! read the collection, see get_datasets
 ...

@note With action='append' the file must exist and be a VTK collection (<Collection>): the datasets already listed are kept and the new ones are written after them. @note With action='read' the file is indexed, its datasets are returned by get_datasets and finalize frees the index: the error is 1 if the file cannot be read, 2 if it is not a VTK collection. @note A file name ending in .series (case insensitive) is a ParaView file series (JSON), with the same actions.

Returns: integer(kind=I4P)

fortran
function initialize(self, filename, action) result(error)

Arguments

NameTypeIntentAttributesDescription
selfclass(pvd_file)inoutPVD file.
filenamecharacter(len=*)inFile name, with the .pvd (or .series) extension.
actioncharacter(len=*)inoptionalAction: new (default), append or read.

Call graph

write_dataset ​

Write one dataset entry: the file name of the dataset and its time step (and optionally part, group and name).

The collection is valid (closing tags included) as soon as this function returns.

Example of usage ​

fortran
 error = pvd%write_dataset(filename='simulation_0010.vtu', timestep=0.1_R8P)
 error = pvd%write_dataset(filename='simulation_0010_rank1.vtu', timestep=0.1_R8P, part=1)

@note filename is written as given: a relative path is relative to the directory of the .pvd file. filename, group and name are escaped as XML attribute values (&, <, >, ", '). In a .series file the entry is { "name" : filename, "time" : timestep } (a JSON string: " and \ escaped, control characters as \u00XX, read back); part, group and name are refused (error 1).

Returns: integer(kind=I4P)

fortran
function write_dataset(self, filename, timestep, part, group, name) result(error)

Arguments

NameTypeIntentAttributesDescription
selfclass(pvd_file)inoutPVD file.
filenamecharacter(len=*)inFile name of the dataset.
timestepreal(kind=R8P)inTime step (time value) of the dataset.
partinteger(kind=I4P)inoptionalPart (piece) of the dataset at this time step, default 0.
groupcharacter(len=*)inoptionalGroup of the dataset.
namecharacter(len=*)inoptionalName of the dataset.

Call graph

finalize ​

Finalize the file: close it. The file is already a valid collection, the datasets written so far included.

Returns: integer(kind=I4P)

fortran
function finalize(self) result(error)

Arguments

NameTypeIntentAttributesDescription
selfclass(pvd_file)inoutPVD file.

Call graph

get_datasets ​

Return the datasets of a file read (initialize(..., action='read')), in the order of the file.

Missing attributes are returned as 0 (timestep, part) or empty (group, name, file). The strings are blank padded to the longest one; relative files are relative to the directory of the .pvd file. A .series file gives the name of each entry as file and its time as timestep (its position in the list, from 0, without time, as ParaView takes it); part 0, group and name empty.

fortran
 type(pvd_file)                :: pvd
 real(R8P),        allocatable :: timestep(:)
 character(len=:), allocatable :: file(:)
 error = pvd%initialize(filename='simulation.pvd', action='read')
 error = pvd%get_datasets(timestep=timestep, file=file)
 error = pvd%finalize()

Returns: integer(kind=I4P)

fortran
function get_datasets(self, timestep, part, group, name, file) result(error)

Arguments

NameTypeIntentAttributesDescription
selfclass(pvd_file)inPVD file.
timestepreal(kind=R8P)outallocatable, optionalTime step of the datasets.
partinteger(kind=I4P)outallocatable, optionalPart of the datasets.
groupcharacter(len=:)outallocatable, optionalGroup of the datasets.
namecharacter(len=:)outallocatable, optionalName of the datasets.
filecharacter(len=:)outallocatable, optionalFile of the datasets.

Call graph

read_series ​

Read the entries of a .series file (JSON): the name and time of each object of the array files. Error 1 if the file cannot be read, 2 if it is not a file series (no file-series-version, no files array, an entry without name, a time that is not a number).

Returns: integer(kind=I4P)

fortran
function read_series(self, filename) result(error)

Arguments

NameTypeIntentAttributesDescription
selfclass(pvd_file)inoutPVD file.
filenamecharacter(len=*)inFile name.

Call graph

json_escape ​

Return a string as the content of a JSON string: " and \ escaped, control characters as \u00XX.

Attributes: pure

Returns: character(len=:)

fortran
function json_escape(string) result(escaped)

Arguments

NameTypeIntentAttributesDescription
stringcharacter(len=*)inInput string.

Call graph

upper ​

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

Attributes: pure

Returns: character(len=len(string))

fortran
function upper(string) result(upper_string)

Arguments

NameTypeIntentAttributesDescription
stringcharacter(len=*)inInput string.

Call graph