castep_outputs.bin_parsers.fortran_bin_parser#

General parser for the Fortran Unformatted file format.

Classes

FortranBinaryReader(file)

Yield the elements of a Fortran unformatted file.

class castep_outputs.bin_parsers.fortran_bin_parser.FortranBinaryReader(file)[source]#

Bases: object

Yield the elements of a Fortran unformatted file.

Parameters:

file (BinaryIO) – Open file to get binary data from.

Yields:

bytes – Binary data record from Fortran file.

Notes

Each “record” is:

(pre_nbytes: 4; data: nbytes; post_nbytes: 4)

Where pre_nbytes == post_nbytes (this is used in Fortran for rewinding).

So when we rewind, we rewind the current size + post_nbytes (current) + pre_nbytes (current) + post_nbytes (previous) [cursor now before post_nbytes (previous)] which is then read putting the cursor after post_nbytes (previous).

When we do the final rewind, we put the cursor before pre_nbytes ready to read the record.

get(typ: type[T]) T[source]#
get(typ: tuple[type[T], ellipsis]) tuple[T, ...]

Get next value as typ.

Parameters:

typ – Type to retrieve.

Returns:

Value as type.

get_dtype_cycle(dtypes: tuple[type[T], ...]) Iterator[tuple[T, ...]][source]#
get_dtype_cycle(dtypes: tuple[tuple[type[T], ellipsis], ...]) Iterator[tuple[tuple[T, ...], ...]]
get_dtype_cycle(dtypes: tuple[type[T] | tuple[type[T], ellipsis], ...]) Iterator[tuple[T | tuple[T, ...], ...]]
get_dtype_cycle(dtypes: Mapping[K, type[T]]) Iterator[dict[K, T]]
get_dtype_cycle(dtypes: Mapping[K, tuple[type[T], ellipsis]]) Iterator[dict[K, tuple[T, ...]]]
get_dtype_cycle(dtypes: Mapping[K, type[T] | tuple[type[T], ellipsis]]) Iterator[dict[K, T | tuple[T, ...]]]
get_dtype_cycle(_, *, n: int | None = None)

Get iterator over values reading dtypes each cycle.

Parameters:
  • dtypes – Dtypes to load simultaneously.

  • n – Number of iterations to load or infinite if None.

Yields:

Loaded data.

get_dtype_dict(dtypes: Mapping[K, type[T]]) dict[K, T][source]#
get_dtype_dict(dtypes: Mapping[K, tuple[type[T], ellipsis]]) dict[K, tuple[T, ...]]
get_dtype_dict(dtypes: Mapping[K, type[T] | tuple[type[T], ellipsis]]) dict[K, T | tuple[T, ...]]

Get from a dictionary of dtypes to read.

Parameters:

dtypes – Dictionary mapping key names to dtype to read.

Returns:

Loaded data.

get_dtype_iter(dtypes: Iterable[type[T]]) Iterator[T][source]#
get_dtype_iter(dtypes: Iterable[tuple[type[T], ellipsis]]) Iterator[tuple[T, ...]]
get_dtype_iter(dtypes: Iterable[type[T] | tuple[type[T], ellipsis]]) Iterator[T | tuple[T, ...]]

Get next values as types in dtypes.

Parameters:

dtypes – Types of data to read.

Yields:

Loaded data.

rewind(n=1, /)[source]#

Rewind n elements.

Parameters:

n (int) – How many elements to rewind.

Return type:

None

skip(n, /)[source]#

Ignore the next n elements.

Parameters:

n (int) – Number of elements to skip.

Return type:

None