1. Home
  2. Data & files

Plotting · export

Exporting Data to Tecplot: Writing ASCII Zone Files

Eigenfield editorial team ·

Tecplot Focus is a commercial visualization package for engineering and scientific data, widely used for fields on grids. Getting results into it from a script means writing a text file in a layout it understands: a title, a list of variable names, and one or more zones holding the numbers. This page describes that layout in general terms, shows how to write a gridded field with a short script, and lists checks to run before loading. The keywords below should be confirmed against the documentation of the Tecplot version in use, since file-format details are the vendor’s to define. The page is part of the export material under Data and files.

Structure of an ASCII data file

An ASCII Tecplot file has a small header followed by data. The header names the data set and its variables. Each zone then starts with a line describing its type and size and continues with rows of numbers, one row per point, with one value for each variable in the order listed.

Why bother with a text file at all, when binary formats exist? Text is easy to inspect, easy to diff, and easy to write from any language without a library. The price is size and speed: a million points at three variables take tens of megabytes as text and load more slowly than the equivalent binary. For a few thousand points, which covers most hand-made plots, the difference is invisible and the transparency is worth far more. Switch to a binary route only when load time becomes a real nuisance, and keep the text writer around as the reference against which the binary output is verified.

TITLE = "wave field"
VARIABLES = "X", "Y", "Z"
ZONE T="grid", I=3, J=2, DATAPACKING=POINT
0.0 0.0 0.00
0.5 0.0 0.25
1.0 0.0 1.00
0.0 1.0 0.00
0.5 1.0 0.25
1.0 1.0 1.00

Here I=3 and J=2 declare an ordered zone with 3 points in one index direction and 2 in the other, so 6 data rows follow. The count must match exactly; a zone that promises 6 points and delivers 5 is the most frequent reason for a load error.

Ordered zones and point order

For an ordered zone the file lists points with the first index running fastest. In the example, I advances 0.0, 0.5, 1.0 within each row of constant y, and J advances only after a full I-sweep. That corresponds to a matrix Z whose rows follow y and whose columns follow x, flattened row by row. A script that flattens the matrix in the other order silently writes a transposed field, and the plot looks like the function mirrored across a diagonal.

import numpy as np
x = np.linspace(0, 1, 3)
y = np.linspace(0, 1, 2)
X, Y = np.meshgrid(x, y)         # X, Y have shape (J, I) = (2, 3)
Z = X**2
with open("field.dat", "w") as f:
    f.write('TITLE = "wave field"\nVARIABLES = "X", "Y", "Z"\n')
    f.write(f'ZONE T="grid", I={len(x)}, J={len(y)}, DATAPACKING=POINT\n')
    for xv, yv, zv in zip(X.ravel(), Y.ravel(), Z.ravel()):
        f.write(f"{xv:.8g} {yv:.8g} {zv:.8g}\n")

The ravel call walks the array row by row, which gives the first index fastest for arrays shaped (J, I). The values in the example, x² at x = 0, 0.5 and 1, are 0, 0.25 and 1, matching the sample rows.

Variables, units and naming

Variable names appear on axes and in menus, so choose them for the reader. Short names without spaces are the safest, and units can go into the name, as in T_K or velocity_ms, because the file format has no separate unit field. Keep the same names across every file of a project; contouring a field called p in one file and pressure in the next means retyping settings each time. The order of the variables matters as well. Put the coordinates first, in the order X, Y, Z, followed by the solution variables, since many tools assume the leading columns are positions and offer them as axes by default.

Precision deserves a decision of its own. Eight significant digits are plenty for display, but if the same file is the archive of a calculation that may be re-run or compared later, write 17 and accept the larger file. A value written with 17 significant digits reads back as the identical double, which makes later comparisons exact.

Several zones

Different data sets, time steps or regions each get their own zone. All zones must use the same variable list; a variable that exists in only one region must be filled with a placeholder value or exported as its own file. Give each zone a distinct title through the T option, because the title is what appears in menus and legends.

Unstructured meshes use a finite-element zone instead, which lists nodal values first and then a connectivity table of node indices for each element. Node numbering in the table is one-based. A common bug is to write the zero-based indices that scripting languages use, which shifts every element by one node.

Checks before loading

  • Count the rows of each zone against the declared size.
  • Check that the variable count matches the number of columns.
  • Search the file for nan or inf, which most readers reject.
  • Write the numbers with enough digits, 8 significant figures for plotting, and a period as the decimal mark.
  • Load a small version of the file first. A 3 × 2 grid takes a second to inspect by eye, and any ordering error is obvious.

Contour lines can be exported as their own zones, which the page on contour zones for Tecplot describes. The same worksheet-style layout works for other graphing programs, as in graphing results in SigmaPlot. Verifying that a written file reads back to the original values uses the methods of comparing two files, and the broader choice of plot is discussed under data visualization.

Back to top