tecio.TecplotDatWriter#

class tecio.TecplotDatWriter(path, title='untitled', variables=None, file_type=FileType.FULL, *, precision=DataType.FLOAT)#

Bases: TecplotWriter

Write Tecplot ASCII (.dat/.tec) files.

The public interface matches TecplotSzlWriter and TecplotPltWriter.

Parameters:
  • path – Destination file path.

  • title – Dataset title. Defaults to "untitled".

  • variables – Variable name list. None defers file creation until the first zone-writing call (lazy open).

  • file_type – FileType enum. Defaults to FULL.

  • precision – Uniform floating point precision for the whole file. DataType.FLOAT (default; "single") or DataType.DOUBLE ("double"). Also accepts those strings directly ("single"/"double", or "float" for the enum’s own name). Applies only to floating-point variables: a float64 array is downcast to SINGLE under the default, but integer variables (LONGINT/SHORTINT/BYTE) always keep their own inferred type in the zone’s DT= declaration regardless of precision. Also sets the significant digit count used for every variable uniformly (9 for FLOAT, 17 for DOUBLE).

precision#

Uniform floating-point precision for the file. Governs the ASCII significant-digit count and which of FLOAT/DOUBLE is declared for float-inferred variables; integer-inferred variables keep their own type regardless (see precision above).

_fp#

The open text file handle, or None before the file has been opened (or after close()).

_opened#

True once the file has been opened (eagerly or lazily) and its header written, False before that and after close().

_float_fmt#

format()-compatible scientific-notation format string derived from precision (9 significant digits for FLOAT, 17 for DOUBLE), used to print every floating-point value in the file.

Attributes

meta

Read-only record of everything written to this file so far.

Methods

add_auxdataset_dict(auxdict)

Buffer dataset-level auxiliary data from a dictionary.

add_auxvar_dict(auxdict)

Buffer variable-level auxiliary data from a dictionary.

close()

Flush and close the output file (safe to call more than once).

flush_aux()

Write buffered dataset- and variable-level aux data to the file.

write_fe_zone(data, zone_type[, node_map, ...])

Write a complete finite-element zone.

write_femixed_zone(data[, cell_shapes, ...])

Not supported: DAT files cannot hold FEMIXED zones.

write_ordered_zone(data, *[, title, ...])

Write a complete IJK-ordered zone.

write_poly_zone(data, zone_type, *[, ...])

Write a complete FEPOLYGON or FEPOLYHEDRON (face-based) zone.

close()[source]#

Flush and close the output file (safe to call more than once).

Flushes any buffered aux data first (in case it was added after the first zone, and so never reached the automatic pre-first-zone flush, e.g. add_auxdataset_dict called after a zone is already written); DAT’s DATASETAUXDATA/VARAUXDATA keywords are valid anywhere in the file, including after the last zone, so this is always a legal position to write them.

write_fe_zone(data, zone_type, node_map=None, *, title=None, variables=None, value_locations=None, passive_vars=None, var_sharing=None, con_sharing=None, face_neighbors=None, face_neighbor_mode=None, face_neighbors_complete=None, solution_time=0.0, strand_id=0, aux=None, datapacking=DataPacking.BLOCK)[source]#

Write a complete finite-element zone.

Node and cell counts are inferred from node_map, or if node_map is omitted from the zone referenced by con_sharing.

Warning

FEPOLYGON and FEPOLYHEDRON are face-based and raise ValueError, write them with write_poly_zone().

Parameters:
  • data (Sequence[npt.ArrayLike]) – Sequence of 1-D arrays, one per active (non-passive, non-shared) dataset variable, in dataset order. NODAL arrays must have length num_nodes; CELL_CENTERED arrays must have length num_cells. num_nodes and num_cells are inferred from node_map (or from the con_sharing source zone when node_map is omitted).

  • zone_type (ZoneType) – FE zone type from the ZoneType enum. Must be one of the types in _FE_SIMPLE.

  • node_map (npt.ArrayLike) – Integer array of shape (num_cells, nodes_per_cell) containing 0-based node indices. Required unless con_sharing is set, in which case the connectivity are inherited from the source zone instead.

  • title (str) – Zone title string. Defaults to "FE_Zone_{index}", this zone’s 0-based index.

  • variables (list[str]) – Variable name list. Required only when the file has not been opened yet (lazy-open path). Ignored on subsequent zones once the file is already initialised. Default to [V1, V2, V3, ...] if not provided in open or zone call.

  • value_locations (Sequence[ValueLocation]) – Per-active-variable ValueLocation. Defaults to all NODAL.

  • passive_vars (list | tuple | set | None) – Variables to mark passive: a list, tuple, or set of variable names, or of 0-based indices, e.g. {"x"} or [3]. Defaults to all active (passive_vars=None).

  • var_sharing (Mapping[int | str, int]) – Variables to share from another zone: a {variable: source zone} mapping, name or 0-based index to 0-based zone index. Defaults to no sharing (None or an empty mapping). Cross-checked against node_map / con_sharing for a consistent node/cell count.

  • con_sharing (int) – Optional zone index that the connectivity is shared from. None indicates no sharing (this zone owns its connectivity). The first zone in a dataset must own its connectivity. Connectivity cannot be shared when face neighbor mode is set to global. Connectivity cannot be shared between cell-based and face-based finite element zones.

  • face_neighbors (npt.ArrayLike) – Optional face-neighbor connectivity, always a flat array (whatever shape you pass is flattened before writing). The number of values per connection depends on face_neighbor_mode, a fixed 3 or 4 for the one-to-one modes, a variable, self-describing count per record for the “many” modes. The connection count is always derived from this array, never a separate parameter.

  • face_neighbor_mode (FaceNeighborMode) – Default to None meaning no face-neighbor data. If face_neighbors is supplied without defining a face neighbor mode, it is treated as LOCAL_ONE_TO_ONE. Cannot be defined without also supplying a face_neighbors array.

  • face_neighbors_complete (bool) – Whether face_neighbors is the entire adjacency picture (True), Tecplot shouldn’t auto-detect anything further, or a supplement to auto-detected conformal adjacency (False). None (the default) omits the FEFACENEIGHBORSCOMPLETE keyword entirely, deferring to the Tecplot default. ASCII-only: neither the classic nor new C API can express this, so it has no equivalent on TecplotSzlWriter or TecplotPltWriter.

  • solution_time (float) – Solution time for transient data. Default to 0.0 if not defined.

  • strand_id (int) – Strand ID for transient data. Use 0 for static zones. Default to 0 (static) if not defined.

  • aux (dict[str, str | float | int]) – Zone-level auxiliary data as {name: value} string pairs.

  • datapacking (DataPacking | str) – In POINT format, the values for all variables are given for the first point, then the second point, and so on. In BLOCK format, all of the values for the first variable are given in a block, then all of the values for the second variable, then all of the values for the third, and so forth. BLOCK format must be used for cell-centered data and polyhedral zones (FEPOLYGON/FEPOLYHEDRAL), as well as for all binary data. POINT and BLOCK keyword strings also accepted. Defaults to BLOCK.

Raises:
  • TypeError – If passive_vars/var_sharing isn’t a list/tuple/set/mapping as appropriate, or mixes variable names and indices.

  • ValueError – For FEPOLYGON or FEPOLYHEDRON (use write_poly_zone()); on variable count or array length mismatch; if node_map is omitted without con_sharing; if var_sharing/con_sharing reference a zone with no recorded node/cell count, or one whose count disagrees with this zone’s; or a variable named in both passive_vars and var_sharing.

  • ValueError – If I/O operation attempted on closed or None file handle.

  • RuntimeError – If attempting to write variable aux before variables are defined.

  • KeyError – A passive_vars/var_sharing name doesn’t match any dataset variable.

  • IndexError – A passive_vars/var_sharing index is out of range.

write_femixed_zone(data, cell_shapes=None, node_maps=None, *, title=None, variables=None, value_locations=None, passive_vars=None, var_sharing=None, con_sharing=None, solution_time=0.0, strand_id=0, aux=None, datapacking=DataPacking.BLOCK)[source]#

Not supported: DAT files cannot hold FEMIXED zones.

The signature matches TecplotSzlWriter.write_femixed_zone() so every writer exposes the same interface.

Raises:

NotImplementedError – Always. Write a .szplt file instead, see TecplotSzlWriter.write_femixed_zone().

write_ordered_zone(data, *, title=None, variables=None, value_locations=None, passive_vars=None, var_sharing=None, solution_time=0.0, strand_id=0, aux=None, datapacking=DataPacking.BLOCK)[source]#

Write a complete IJK-ordered zone.

Zone dimensions are inferred from the shape of the first NODAL array.

Parameters:
  • data (Sequence[npt.ArrayLike]) – One NumPy array per active (non-passive, non-shared) dataset variable, in dataset order. Array shape is used to infer imax, jmax, and kmax; Fortran (column-major) order is assumed. Pass None to write a zone header only.

  • title (str) – Zone title. Defaults to "IJK_Zone_{index}", this zone’s 0-based index.

  • variables (list[str]) – Variable name list. Required on the first call when the file has not been opened yet (lazy-open path); ignored once the file is already initialised. Default to [V1, V2, V3, ...] if not provided in open or zone call.

  • value_locations (Sequence[ValueLocation]) – Per-active-variable ValueLocation. Defaults to all NODAL.

  • passive_vars (list | tuple | set | None) – Variables to mark passive: a list, tuple, or set of variable names, or of 0-based indices, e.g. {"x"} or [3]. Defaults to all active (passive_vars=None).

  • var_sharing (Mapping[int | str, int]) – Variables to share from another zone: a {variable: source zone} mapping, name or 0-based index to 0-based zone index, e.g. {"x": 0, "y": 0}. Defaults to no sharing.

  • solution_time (float) – Solution time for transient data. Default to 0.0 if not defined.

  • strand_id (int) – Strand ID for transient data. Use 0 for static zones. Default to 0 (static) if not defined.

  • aux (dict[str, str | float | int]) – Zone-level auxiliary data as {name: value} string pairs.

  • datapacking (DataPacking | str) – In POINT format, the values for all variables are given for the first point, then the second point, and so on. In BLOCK format, all of the values for the first variable are given in a block, then all of the values for the second variable, then all of the values for the third, and so forth. BLOCK format must be used for cell-centered data and polyhedral zones (FEPOLYGON/FEPOLYHEDRAL), as well as for all binary data. POINT and BLOCK keyword strings also accepted. Defaults to BLOCK.

Raises:
  • TypeError – If passive_vars/var_sharing isn’t a list/tuple/set/mapping as appropriate, or mixes variable names and indices.

  • ValueError – If I/O operation attempted on closed or None file handle, or a variable is named in both passive_vars and var_sharing.

  • RuntimeError – If attempting to write variable aux before variables are defined.

  • KeyError – A passive_vars/var_sharing name doesn’t match any dataset variable.

  • IndexError – A passive_vars/var_sharing index is out of range.

write_poly_zone(data, zone_type, *, face_nodes=None, face_node_counts=None, face_left_elements=None, face_right_elements=None, boundary_connection_counts=None, boundary_connection_elements=None, boundary_connection_zones=None, title=None, variables=None, value_locations=None, passive_vars=None, var_sharing=None, con_sharing=None, solution_time=0.0, strand_id=0, aux=None, datapacking=DataPacking.BLOCK)[source]#

Write a complete FEPOLYGON or FEPOLYHEDRON (face-based) zone.

Node and element counts are inferred from the face map, or from the con_sharing source zone when it is omitted. Every index is 0-based in Python and shifted to the 1-based ASCII convention here (0 for no element, -k for the k-th boundary face).

The face map follows the variable blocks as integer sections introduced by the same # comment lines Tecplot writes: # node count per face (polyhedra only), # face nodes, # left elements, # right elements, and with boundary connections # boundary connection counts, # boundary connection elements, and # boundary connection zones. Nothing is written for a zone that shares connectivity.

Parameters:
  • data (Sequence[npt.ArrayLike]) – Sequence of 1-D arrays, one per active (non-passive, non-shared) dataset variable, in dataset order. NODAL arrays need num_nodes values, CELL_CENTERED arrays num_elements, both inferred from the face map.

  • zone_type (ZoneType) – FEPOLYGON or FEPOLYHEDRON.

  • face_nodes (npt.ArrayLike) – Flat 0-based node indices of all faces, in face order. Two per face for a polygon zone. Required unless con_sharing is set.

  • face_node_counts (npt.ArrayLike) – Number of nodes of each face. Required for FEPOLYHEDRON. Optional for FEPOLYGON, where every face has 2 nodes.

  • face_left_elements (npt.ArrayLike) – Element on the left of each face: a 0-based element index, -1 for no element, or -(b + 2) for boundary face b (0-based).

  • face_right_elements (npt.ArrayLike) – Element on the right of each face, same convention as face_left_elements.

  • boundary_connection_counts (npt.ArrayLike) – Number of connections of each boundary face. Boundary faces describe neighbors in other zones, or faces with more than one neighbor.

  • boundary_connection_elements (npt.ArrayLike) – Flat 0-based neighbor element of every boundary connection.

  • boundary_connection_zones (npt.ArrayLike) – Flat 0-based zone of every neighbor element. May only reference a zone already written or this zone.

  • title (str) – Zone title string. Defaults to "Poly_Zone_{index}", with this zone’s 0-based index.

  • variables (list[str]) – Variable name list, only used when the file has not been opened yet (lazy-open path). Defaults to [V1, V2, V3, ...].

  • value_locations (Sequence[ValueLocation]) – Per-active-variable ValueLocation. Defaults to all NODAL.

  • passive_vars (list | tuple | set | None) – Variables to mark passive: a list, tuple, or set of variable names, or of 0-based indices. Defaults to all active.

  • var_sharing (Mapping[int | str, int]) – Variables to share from another zone: a {variable: source zone} mapping, name or 0-based index to 0-based zone index.

  • con_sharing (int) – Zone index to share the face map from, which must be a zone of the same type without boundary faces (TecIO does not allow sharing those). None means this zone owns its connectivity.

  • solution_time (float) – Solution time for transient data. Defaults to 0.0.

  • strand_id (int) – Strand ID for transient data, 0 for static zones.

  • aux (dict[str, str | float | int]) – Zone-level auxiliary data as {name: value} pairs.

  • datapacking (DataPacking | str) – Must be BLOCK. Tecplot refuses POINT for poly zones, whether or not they have cell-centered variables.

Raises:
  • TypeError – If passive_vars/var_sharing isn’t a list/tuple/set/mapping as appropriate, or mixes variable names and indices.

  • ValueError – If datapacking is POINT. For a zone_type other than FEPOLYGON or FEPOLYHEDRON (use write_fe_zone()); on a missing, inconsistent, or out of range face map, boundary connection, or variable array.

  • KeyError – A passive_vars/var_sharing name doesn’t match any dataset variable.

  • IndexError – A passive_vars/var_sharing index is out of range.