5. The PlainText file format

Plain text files are text files with tables of data. These are standard CSV (Comma Separated Values) files. The file can start with an arbitrary number of lines that may be skipped. The files can be used to represent the following types of data:

  • A collection of curves, all defined on the same domain.
  • Points in 2D or 3D with variables defined on the points.
  • A single variable defined on a 2D regular grid.

5.1. Defining curves with a PlainText file

The first line can be an optional list of variable names. The remaining lines consist of rows, where each row represents one point in each of the curves.

Here are the first 10 lines of an example of a file representing curves.

angle sine cosine
0 0 1
5 0.0871557 0.996195
10 0.173648 0.984808
15 0.258819 0.965926
20 0.34202 0.939693
25 0.422618 0.906308
30 0.5 0.866025
35 0.573576 0.819152
40 0.642788 0.766044

Here is the Python script that created the file.

import math

f = open("curves.csv", "wt")
f.write("angle sine cosine\n")

npts = 73
for i in range(npts):
    angle_deg = float(i) * (360. / float(npts-1))
    angle_rad = angle_deg * (3.1415926535 / 180.)
    sine = math.sin(angle_rad)
    cosine = math.cos(angle_rad)
    f.write("%g %g %g\n" % (angle_deg, sine, cosine))

f.close()

Here are the Plain Text reader options used to read the data.

../_images/PlainTextOptions1.png

If you specify the column for the X coordinates, then that column will be used for the domain for all the curves. If you don’t specify an X coordinate, then it will use the row index for the domain for all the curves.

5.2. Defining 2D or 3D points with variables

The first line can be an optional list of variable names. The remaining lines consist of rows, where each row represents the values for a single point.

Here are the first 10 lines of an example of a file representing 3D points.

x y z value
0 0 0 0
0.0959668 0.0315185 0.10101 0.14285
0.162681 0.119779 0.20202 0.2857
0.175775 0.246841 0.30303 0.42855
0.119968 0.385819 0.40404 0.571399
-0.00801311 0.504987 0.505051 0.714249
-0.198223 0.572728 0.606061 0.857099
-0.428209 0.56266 0.707071 0.999949
-0.665597 0.45823 0.808081 1.1428

Here is the Python script that created the file.

import math

f = open("points.csv", "wt")
f.write("x y z value\n")

n = 100
for i in range(n):
    t = float(i) / float(n-1)
    angle = t * (math.pi * 2.) * 5.
    r = t * 10.
    x = r * math.cos(angle)
    y = r * math.sin(angle)
    z = t * 10.
    value = math.sqrt(x*x + y*y + z*z)
    f.write("%g %g %g %g\n" % (x,y,z,value))

f.close()

Here are the Plain Text reader options used to read the data.

../_images/PlainTextOptions2.png

If you specify the columns for the X and Y coordinates, the points will be defined in 2D space. If you specify the columns for the X, Y and Z coordinates, the points will be defined in 3D space.

5.3. Defining a single variable on a 2D regular grid

The variable is interpreted as a node centered variable and the X and Y coordinates are the indexes into the rows and columns. The rows represent values along the X direction and the rows get stacked in the Y direction.

The first line can be an optional list of variable names. The first variable name will be used for the name of the variable. Note that you will need to provide the same number of variable names as there are columns, even though only the first one is used. The remaining lines consist of rows, where each row represents the values for a single Y coordinate.

Here is an example of a file representing 3D points.

density c2 c3 c4 c5 c6 c7 c8
5.70088 5.14782 4.74342 4.52769 4.52769 4.74342 5.14782 5.70088
4.94975 4.30116 3.80789 3.53553 3.53553 3.80789 4.30116 4.94975
4.30116 3.53553 2.91548 2.54951 2.54951 2.91548 3.53553 4.30116
3.80789 2.91548 2.12132 1.58114 1.58114 2.12132 2.91548 3.80789
3.53553 2.54951 1.58114 0.707107 0.707107 1.58114 2.54951 3.53553
3.53553 2.54951 1.58114 0.707107 0.707107 1.58114 2.54951 3.53553
3.80789 2.91548 2.12132 1.58114 1.58114 2.12132 2.91548 3.80789
4.30116 3.53553 2.91548 2.54951 2.54951 2.91548 3.53553 4.30116
4.94975 4.30116 3.80789 3.53553 3.53553 3.80789 4.30116 4.94975
5.70088 5.14782 4.74342 4.52769 4.52769 4.74342 5.14782 5.70088

Here is the Python script that created the file.

import math

f = open("regulargrid2d.csv", "wt")
f.write("density c2 c3 c4 c5 c6 c7 c8\n")

nx = 8
ny = 10
for iy in range(ny):
    y = float(iy)
    for ix in range(nx):
        x = float(ix)
        dist = math.sqrt((x - 3.5) * (x - 3.5) + (y - 4.5) * (y - 4.5))
        if (ix < nx - 1):
           f.write("%g " % dist)
        else:
           f.write("%g\n" % dist)

f.close()

Here are the Plain Text reader options used to read the data.

../_images/PlainTextOptions3.png

The columns for the X, Y and Z coordinates are not used.