.traj Trajectory File Format

This is the format of trajectory files, as written by tools like pb2traj.

Each <xxx> is a four-byte, 32-bit value (integer int32 or IEEE floating-point float32) unless otherwise specified. The <fmtchar> byte at the beginning determines whether that's in big-endian or little-endian format. Codes for fmtchar are

In the binary formats, most quantities are 32-bit; all of those are aligned to 4-byte boundaries. The format is also designed to be the streaming message format for a networked trajectory-calculating server; some of the fields aren't useful in a disk file format, and their values can be ignored.

The .traj file begins with:

That's a total of 64 bytes of fixed-length header.

Following this come two sets of headers describing attributes. In these, each <type> is a four-byte int32 which may be either

and each <name> is a sequence:

Given this, here's the first header:

Per-trajectory attribute header

This gives the names and datatypes of the attributes that appear once for each trajectory.
<ntrajattrs> (int32)
number of per-trajectory attributes.
<trajattrtype0> (int32)
type ('i' or 'f') of first per-traj attribute
<trajattrname0> (string preceded by int32 length)
name of first per-traj attr
<trajattrtype1> (int32)
type ('i' or 'f') of second per-traj attribute
<trajattrname1> (string preceded by int32 length)
name of second per-traj attr
...
Among these per-trajectory attributes will be
"id"
(type int32) particle id number; next will be
"group"
(type int32) particle group number; then comes
"ttime0"
(type float32) trajectory-time at start of this trajectory
Following the per-trajectory header comes the...

Per-sample attribute header

This gives the names and datatypes of the attributes that appear for each sample point along each trajectory.

There be none of these, or there might be several, e.g. "u", "v", "w", "temp", "salt" for wind velocities, temperature, and salinity, sampled at each point.

<nsampleattrs> (int32)
number of per-sample attributes
<sampattrtype0> (int32)
datatype ('i' or 'f') of first per-sample attribute
<sampattrname0> (string preceded by int32 length)
name of first per-sample attr
...

Trajectory Body

Now the number of trajectories: and finally, for each trajectory,
<nsamples> (int32)
number of samples in this trajectory
<per-trajectory-attributes>
series of <ntrajattrs> trajectory attribute values, a total of ntrajattrs*4 bytes long, of the types given in the "per-trajectory attributes" header.
<sequence of nsamples records>
each record (3+nsampleattrs)*4 bytes long:
X Y Z sampleattr0 sampleattr1 sampleattr2 ...
The X Y Z coordinates are all of type float32; other attributes have the datatypes specified in the per-sample attribute header.

In case it matters, along each trajectory, the simulation time "datatime" is related to the sample number (counting from 0) as:

datatime = startdatatime + (ttime0 + samplenumber * sampledt) * datarate

See also the .pb file format description.