Field File Format


 

Using the Read_Field module

     The Read_Field module reads an AVS/Express field data structure from a disk file into a network.

     For information on using time-dependant fields see Reading In All Data and Writing Out Time-Dependent Fields.

 

 

Native Field Input

     The read_field module can read files in the native AVS field file format into an AVS/Express network. An AVS field file (suffix .fld) has the following components.

 

·     An ASCII header that describes the field

·     two separator characters that divides the ASCII header from the data section.

Note : This is required only if the ASCII header and the node data section (could be binary or ASCII) are in the same physical file.

 

·     Node data and coordinate information ( binary or ASCII ).

Note : AVS field file format cannot handle cell data.

 

Note : ASCII header and the data and coordinate information. need not be in the same physical file.

 

ASCII Header

     The ASCII header contains a series of text lines, each of which is either a comment or a TOKEN = VALUE pair. For example, the following header defines a field of type “field 2D 4-vector byte”, which is the AVS/Express image format :

 

# AVS field file

#

ndim=2                  #number of computational dimensions

dim1=512            

dim2=480

nspace=2            #number of computational dimensions

veclen=4

data=type (byte, integer (short, long), float, double)

field=uniform

 

Note : The first line of the header must begin as follows

# AVS (5 characters).

 

In this example, comments also occur at the end of the third and sixth lines. Any characters following (and including ) # in the header are ignored. Comments are not required.

 

Separator Characters

     The ASCII header must be followed by two formfeed characters (that is, Ctrl –L, octal 14, decimal 12, hex 0C), in order to separate it from the binary area. This scheme allows you use the more(1) shell command to examine the header. When more stops at the formfeeds, press “q” to quit. This avoids the problem of the binary data garbling the screen.

 

Node Data and Coordinate Information

     The node data and coordinate information can be in binary or ASCII. This section describes about the size of the node data and the coordinate data assuming that the data is represented in binary form.

 

Binary Node Data

     

     The size of the node data section is calculated by the taking the product of

·     All the dimensions for the field : ( dim1 * dim2 * … dim n),

·     The number of data values per field element : (veclen), and

·     The byte size of the primitive data type : (byte_size)

 

Thus, the size (in bytes) of the node data section is :

(dim1 * dim2 * …. *dim n * veclen * byte_size)

 

In the block of node data values

·     All the data pertaining to the first node is stored together, then the data pertaining to the second node and so on. This means data from multiple components are interleaved.

·     The last array index varies most quickly.

For Example

If ndim=2, dim1=3,dim2=2, veclen=4 then the data is stored as a contiguous array dimensioned as Array[dim1][dim2][veclen]. The representation of the contiguous array would be as below ( C-style syntax) Remember veclen actually gives the number of field components.

 

Array[1][1][1],Array[1][1][2]…….Array[1][1][4],

Array[1][2][1] ……………………Array[1][2][4],

Array[2][1][1] ……………………Array[2][1][4],

Array[2][2][1] ……………………Array[2][2][4],

Array[3][1][1] ……………………Array[3][1][4],

Array[3][2][1] ……………………Array[3][2][4].

 

Binary Coordinate information

     The size of the coordinate mapping data section depends on the field type : uniform, rectilinear, or irregular.

·     For uniform fields, coordinate mapping data contains two values for each physical dimension (n-space) of the data, one associated with the minimum extent of the data, and the other associated with the maximum extent.

The minimum and maximum extent values in the coordinate binary area are copies of the min_ext and max_ext values in the field data structure, except when the field has been cropped, downsized, or interpolated. Then the field data structure contains the original field's min_ext and max_ext values, while the coordinate section of the binary area contains the minimum and maximum extent of the subsetted data. Mapper modules can use this additional extent information to properly locate their geometric representation of the subsetted data in world coordinate space. The extents in the coordinate binary area are stored in this order: minimum x, maximum x, minimum y, maximum y, minimum z..., and so on.

 

The size of the coordinate mapping data section for a uniform field is simply:

( 2 * nspace ) * sizeof(float)

 

Note: sizeof(float) refers to the size, in bytes, of a single-precision floating-point number. On all architectures that Express runs, this will be 4.

 

·     For rectilinear fields, there is one coordinate for each array index in each dimension of computational space. Thus, the size of the coordinates area is:

( dim1 + dim2 ... + dimn) * sizeof(float)

All of the X-coordinates are stored together, at the beginning of the coordinates area. Following these are all the Y-coordinates, and so on.

 

·     For irregular fields, each field element is mapped to a point in nspace-dimensional physical space. Thus, the size of the coordinates area is:

( dim1 * dim2 ... * dimn ) * nspace * sizeof(float)

As with rectilinear fields, all of the X-coordinates are stored together, at the beginning of the coordinates area. Following these are all the Y-coordinates, and so on.

 

 

Example 1

The following ASCII header describes a volume (3D uniform field) with a single byte of data for each field element. This format might be used to represent CAT scan data, where all of the 2D slices are equally spaced:

 

# AVS field file
ndim=3 # number of dimensions in the field
dim1=64 # dimension of axis 1
dim2=64 # dimension of axis 2
dim3=64 # dimension of axis 3
nspace=3 # number of physical coordinates per point
veclen=1 # number of components at each point
data=byte # data type (byte, integer, float, double)
field=uniform # field type (uniform, rectilinear, irregular)

 

In the binary area, the node data area occupies this amount of space:

(64 * 64 * 64) * 1 * 1 = 262,144 bytes

 

The coordinates area occupies (2 * 4) * 3 bytes. The total binary area occupies 262,168 bytes.

 

Example 2

The following ASCII header describes a volume (3D uniform field) whose data for each field element is a 3D vector of single-precision values. This format might be used to represent a volume of data from a sampling device where the samples are not equally spaced.

 

# AVS field file
ndim=3 # number of dimensions in the field
dim1=27 # dimension of axis 1
dim2=25 # dimension of axis 2
dim3=32 # dimension of axis 3
nspace=3 # number of physical coordinates per point
veclen=3 # number of components at each point
data=float # data type (byte, integer, float, double)
field=uniform # field type (uniform, rectilinear, irregular)

 

In the binary area, the node data area occupies this amount of space:

(27 * 25 * 32) * 4 * 3 = 259,200 bytes

The coordinates area occupies (2 * 4) * 3 bytes. The total binary area occupies 259,224 bytes.

 

Example 3

The following ASCII header describes an irregular volume (3D irregular field) with one single-precision value for each field element. The binary area includes an (X,Y,Z) coordinate triple for each field element, indicating the corresponding point in physical space. This format might be used to represent velocity data from a simulation of fluid flow around a curved object (for example, an airplane wing). Note that the data type is specified as xdr_float. This means that the data file is written in Sun Microsystems' external data representation (XDR) format. This allows for transporation of field files between machines of dissimilation data storage architectures ("big-endian" vs "little-endian"). When using Read_Field, if Auto is selected on the control panel, Read_Field will look at the data specification. If it is simply float, (or integer, or double), it will assume the file is written in the system's native format. If it is xdr_integer, xdr_float, or xdr_double it will translate the XDR format into its native format. If Portable is selected rather than Auto, it will always assume the file is written in XDR format.

 

# AVS field file
ndim=3 # number of dimensions in the field
dim1=40 # dimension of axis 1
dim2=32 # dimension of axis 2
dim3=32 # dimension of axis 3
nspace=3 # number of physical coordinates per point
veclen=1 # number of components at each point
data=xdr_float # data type (byte, integer, float, double)
field=irregular # field type (uniform, rectilinear, irregular)

 

In the binary area, the node data area occupies this amount of space:

(40 * 32 * 32) * 4 * 1 = 163,840 bytes

 

The coordinates area occupies this amount of space:

(40 * 32 * 32) * 4 * 3 = 491,520 bytes

 

ASCII Node & Coordinate Data Description File

As the example below shows, the ASCII description file contains a series of text lines that define the AVS/Express field to construct. Each line is either:

·     a comment

·     a required line in the form token=value

·     an optional line in the form token=value

·     a variable or coord parsing specification

 

 

The following ASCII description files imports 3D curvilinear data with a vector of values at each point into an AVS/Express field of type "field 3D 3-vector irregular float". This type of data often occurs in computational fluid dynamics applications. The data and coordinate information are in separate files, both of which were written as straight binary data. Both files happen to have a serial organization. In the data file, all of the component values of node 1 appear, then all of the component values of node 2 appear, and then all of component values of node 3 appear. In the X, Y, Z coordinate file, all the X coordinate values appear, then all the Y's, then all the Z's.

 

Each line's meaning is explained in detail below.

# AVS field file the string "# AVS" must be the first five
# characters in the file.
#
# When a '#' character appears in a line,
# the rest of the line is a comment
#
ndim=3                  # REQUIRED - the number of dimensions
dim1=40            # REQUIRED - dimension of axis 1
dim2=32            # REQUIRED - dimension of axis 2
dim3=32       # REQUIRED - dimension of axis 3
nspace=3            # REQUIRED - coordinates per point
veclen=3            # REQUIRED - components at each point
data=float            # REQUIRED - data type
field=irregular            # REQUIRED - field type
min_ext=-1.0 -1.0 -1.0 # OPTIONAL - coordinate space extent
max_ext=1.0 1.0 1.0 # OPTIONAL - coordinate space extent
label=x-velocity      # OPTIONAL - label for variable 1
label=y-velocity            # OPTIONAL - label for variable 2
label=z-velocity            # OPTIONAL - label for variable 3
unit=miles-per-second      # OPTIONAL - unit label for variable 1
unit=miles-per-second      # OPTIONAL - unit label for variable 2
unit=miles-per-second      # OPTIONAL - unit label for variable 3
min_val=-2.1 -0.3 -3.7      # OPTIONAL - minimum data values
max_val=5.79 3.54 1.50      # OPTIONAL - maximum data values
#
# For each coordinate X, Y, and Z: data reading instructions
#
coord 1 file=/jetdata/wing.bin filetype=binary skip=12
coord 2 file=/jetdata/wing.bin filetype=binary skip=163852
coord 3 file=/jetdata/wing.bin filetype=binary skip=327692
#
# For each value in the vector: data reading instructions
#
variable 1 file=/jetdata/wdata.bin filetype=binary skip=28
variable 2 file=/jetdata/wdata.bin filetype=binary skip=163868
variable 3 file=/jetdata/wdata.bin filetype=binary skip=327708

 

Any characters following (and including) # in a header line are ignored.

NOTE: The first five characters in the ASCII description file must be "# AVS" or Read_Field will not recognize the file as valid.

 

The example above shows the entire required TOKEN=VALUE token names: an ASCII description file that is missing one or more of these lines causes Read_Field to generate an error. Required TOKEN=VALUE pairs are stored in the AVS/Express field that Read_Field produces as output.

 

Optional TOKEN=VALUE pairs are stored in the output AVS/Express field as well, if they are provided. min_ext and max_ext are stored in the output AVS/Express field even if they are not specified, as Read_Field calculates them if they are not provided.

The variable and coord lines are not stored in the output AVS/Express field. They are only instructions to Read_Field.

With the exception of filenames, ASCII description file specifications are not case-sensitive. You can surround the = character with any amount of white space (including none at all). For example, "dim2 = 32", "DIM 2 =32", and "Dim2=32" are all equivalent.

 

Below is a complete description of all of the tokens recognized by the Read_Field parser:

 

ndim = value (required)

The number of computational dimensions in the field. For an image, ndim = 2. For a volume, ndim = 3.

dim1 = value (required)
dim2 = value (required, depending on total number of dimensions)
dim3 = value (required, depending on total number of dimensions)
...

The dimension size of each axis (the array bound for each dimension of the computational array). The number of dimx entries must match the value of ndim. For instance, if you specify a 3D computational space field (ndim=3), you must specify the length of the X dimension (dim1), the length of the Y dimension (dim2), and the length of the Z dimension (dim3). Note that counting is 1-based, not 0-based. If you have scatter data (ndim=1) in 3D coordinate space (nspace=3), there will be only dim1=value.

 

nspace = value (required)

The dimensionality of the physical space that corresponds to the computational space (number of physical coordinates per field element).

In many cases, the values of nspace and ndim are the same - the physical and computational spaces have the same dimensionality. But you might embed a 2D computational field in 3D physical space to define a manifold; or you might embed a 1D computational field in 3D physical space to define an arbitrary set of points (a "scatter").

 

veclen = value (required)

The number of data values for each field element. All the data values must be of the same primitive type (for example, integer), so that the collection of values is conceptually a veclen-dimensional vector. If veclen=1, the single data value is, effectively, a scalar. Thus, the term scalar field is often used to describe such a field.

NOTE : veclen in the field file specifies the number of components at each point and does not correspond to the number of vectors for each component. This veclen is different from the variable veclen of Express which can be seen in the network editor.

 

data = byte (one of the four options is required)
data = integer
data = float
data = double

The primitive data type of all the data values. xdr_integer, sdr_float, and xdr_double may also be specified. If Auto is selected on input, read_field will examine the data= field. If the specification is unqualified, it assumes the

 

 

Binary Compatibility on Different Hardware Platforms

 

Memory addressing on 32-bit systems is usually divided into two major hardware classes:

 

"Big-endian"

32-bit words are divided into 4 8-bit bytes, where the high-order byte is byte 0. Systems with this organization include Sun, Hewlett-Packard, and IBM workstations.

"Little-endian"

32-bit words are divided into 4 8-bit bytes, where the low-order byte is byte 0. Systems with this organization include Digital Equipment Corporation workstations.

 

Binary byte data are compatible between the two kinds of systems. Binary integer, floating point, and double-precision floating point data are not compatible between the two kinds of systems. For example, an integer AVS field file written on a Sun workstation would not normally be readable on a DEC workstation.

 

To make AVS field data interchangeable among platforms, the write field module has a Native/Portable(XDR) switch. Selecting Portable(XDR) will write the binary area of the field in Sun’s external data representation (XDR). The field header will show "data=xdr_integer|xdr_float|xdr_double". If Native is selected, the field header will contain a comment at the end of the "data=" line stating what platform the field file was created on. read field uses its Auto/Portable(XDR) switches to either examine the ASCII header for the "data=xdr_" flag, or to force reading the data file as XDR format no matter what the ASCII header says. (Note: XDR format is sim-ply 32-bit "big-endian" integers and IEEE standard format floating point.)

 

EXAMPLE 1

 

The following ASCII header describes a volume (3D uniform field) with a single byte of data for each field element. This format might be used to represent CAT scan data.

 

# AVS field file

ndim=3 # number of dimensions in the field

dim1=64 # dimension of axis 1

dim2=64 # dimension of axis 2

dim3=64 # dimension of axis 3

nspace=3 # number of physical coordinates per point

veclen=1 # number of components at each point

data=byte # data type (byte, integer, float, double)

field=uniform # field type (uniform, rectilinear, irregular)

 

In the binary area, the data area occupies this amount of space:

(64 * 64 * 64) * 1 * 1 = 262,144 bytes

The coordinates area occupies (2 * 4) * 3 bytes. The total binary area occupies 262,168 bytes.

 

EXAMPLE 2

 

The following ASCII header describes a volume (3D uniform field) whose data for each field element is a 3D vector of single-precision values. This format might be used to represent the wind velocity at each point in space. This field file is written in XDR format.

 

# AVS field file

ndim=3 # number of dimensions in the field

dim1=27 # dimension of axis 1

dim2=25 # dimension of axis 2

dim3=32 # dimension of axis 3

nspace=3 # number of physical coordinates per point

veclen=3 # number of components at each point

data=xdr_float # portable data format

field=uniform # field type (uniform, rectilinear, irregular)

 

In the binary area, the data area occupies this amount of space:

(27 * 25 * 32) * 4 * 3 = 259,200 bytes

The coordinates area occupies (2 * 4) * 3 bytes. The total binary area occupies 259,224 bytes.

 

EXAMPLE 3

 

The following ASCII header describes an irregular volume (3D irregular field) with one single-precision value for each field element. The binary area includes an (X,Y,Z) coordinate triple for each field element, indicating the corresponding point in physical space. This format might be used to represent fluid flow data.

 

# AVS field file

ndim=3 # number of dimensions in the field

dim1=40 # dimension of axis 1

dim2=32 # dimension of axis 2

dim3=32 # dimension of axis 3

nspace=3 # number of physical coordinates per point

veclen=1 # number of components at each point

data=float # data type (byte, integer, float, double)

field=irregular # field type (uniform, rectilinear, irregular)

 

In the binary area, the data area occupies this amount of space:

(40 * 32 * 32) * 4 * 1 = 163,840 bytes

The coordinates area occupies this amount of space:

(40 * 32 * 32) * 4 * 3 = 491,520 bytes

 

DATA-PARSING INPUT MODE

 

In its second input mode, read field can convert a certain class of data stored in ASCII, Fortran unformatted, or pure binary data files into AVS field format. To import data into AVS, you must create an ASCII description file that defines the structure of the AVS field to make. The first part of this description file is identical in format and meaning to the ASCII header file described above.

 

The second part of this file contains commands that specify which files contain the data or coordinate information, its data type (ASCII, binary, or Fortran unformatted) and simple parsing instructions. read field can read a file that is parseable by this general scheme:

 

skip n lines or bytes

move over an offset of m columns on this line (ASCII only)

read the value

do until # of values needed

{

take p stride(s) to the next value

read the value

}

 

The ASCII description file, data, and coordinate information for rectilinear and irregular data can all be read from different files. If the resulting AVS field contains a vec-tor of data values at each point, each vector element can also be read from a separate file.

 

The ASCII description file must have a .fld file suffix or the read field file browser will not display the file.

 

read field data parsing capablility is meant to be used only once, in order to convert data to AVS field format. The parsing activity makes read field run more slowly than when it reads a file that is already in AVS field format. Once you have read your data using read field’s data-parsing mode, you should use the write field module to store it permanently on disk in AVS field file format.

 

Suggestion:

While experimenting with read field’s ASCII description file, connect its output port to the print field module’s input port and use print field. This allows you to examine the results online, to see whether the data is being interpreted correctly.

 

read field chronicles its progress in a status display below the file browser widget as it works through the input files to assemble the AVS field.

 

ASCII Description File

 

As the example below shows, the ASCII description file contains a series of text lines that define the AVS field to construct. Each line is either: