# Output File Overview

The HNBody package can generate several types of output files. Unless explicitly disabled (see OutputHeader), these files begin with a header containing information identifying the type of file and certain parameters used in the integration. The format of the header is:

    MAGIC TYPE [TYPE-dependent fields]
    [zero or more lines of TYPE-dependent fields]
    #
    # User-readable comment lines, as appropriate...
    #
    [main DATA lines...]

## Format of header line 1

- MAGIC (= 462639) is a number that affirms the file is an HNBody output file.

- TYPE is a number specifying the type of output file; posibilities are:
  - 0-99 implies the file is a SaveFile; the format and meaning of any and all data following the TYPE field, and on all lines following line 1, is unspecified and subject to change. SaveFiles encode low-level information and are not intended to be examined or modified by users.
  - 100-199 implies the file is an EnergyFile; TYPE is the last field on line 1.
  - 200-299 implies the file is an OutputFile; TYPE is followed by the IdTag of the corresponding body, then by G, c, and M for the system (in the user-chosen units).
  - 300-399 implies the file is a StateFile; TYPE is followed by the Time corresponding to the file data, then by G, c, and M for the system (in the user-chosen units).

The second (tens) digit of TYPE determines the physical format of the main data lines: 100, 20x and 30x imply data lines are ordinary text; 110, 21x and 31x imply data lines are single precision binary numbers; 120, 22x and 32x imply data lines are double precision binary numbers; 23x imply data lines are single precision binary numbers, with difference encoding of slowly varying quantities to extend range. Binary data is always output in MSB (big-endian) order to facilitate file sharing. Binary data ``lines'' are not separated by newlines, nor are their fields padded in any way.

The final (ones) digit of TYPE determines the coordinate system of the output DATA: 2x0 and 3x0 imply Barycentric coordinates, 2x1 and 3x1 imply Bodycentric coordinates, and 2x2 and 3x2 imply Jacobi coordinates.

## Format of header line 2

For all TYPEs (100-399), header line 2 contains the initial time (option Tinitial) followed by the effective stepsize (option StepSize or StepSizeZWPs, whichever is larger); this allows the Time field for the main DATA lines to be omitted without loss of information in simple cases, saving space at the expense of convenience. (If storage space is not a concern, it is more robust to output the Time explicitly with the DATA ---and even necessary, for time-regularized integrations.) Column 3 gives the DATA sampling interval in units of the StepSize. Columns 4 and 5 of this line list the number of DATA columns, and the digits of precision (text files) or the bytes per number (binary files), respectively.

## Format of header line 3

- For TYPE 100-199, line 3 = E0 Lx0 Ly0 Lz0, the total system energy E and angular momentum {Lx, Ly, Lz} at Time = Tinitial.

- For TYPEs 200-299 and 300-399, line 3 identifies the type of data the corresponding DATA column represents, via a numerical code; the meaning of the codes is:

        0-Time (= Epoch)  1-x1 2-x2 3-x3   4-v1 5-v2 6-v3
        7-SemiMajorAxis   8-Eccentricity   9-Inclination
       10-LongAscendNode 11-ArgPeriapse   12-LongPeriapse
       13-TimePeriapse   14-PeriDistance  15-MeanAnomaly
       16-TrueAnomaly    17-MeanLongitude 18-TrueLongitude
       19-MeanLatitude   20-TrueLatitude  21-Mass
       22-EncRadius      23-CaptRadius    24-IdTag
       25-JacIndex

One or more comment lines may follow the initial header in files with text DATA. For binary files, the main DATA begins immediately following the newline of the last header line; no comments are permitted since the binary data itself may happen to begin with a '#' character.

Following the header and comments (if present), are the main file DATA lines. The meaning of the DATA lines is as follows:

- For TYPE = 100-199: DATA = Time (E-E0)/E0 (Lx-Lx0)/L0 (Ly-Ly0)/L0 (Lz-Lz0)/L0

- For TYPE = 200-299: DATA is the body-specific data at a particular Time. The meaning of each column is determined by the codes on header line 3. Files are not output for particle types omitted from OutputTypes. For TYPE 23x (SmartFloat OutputFiles), a line of offset values for each DATA column, output as ordinary text, precedes the binary data; these must be added to each DATA column to recover the absolute quantities. Technically the offset is not considered part of the header since its presence is required in order to reconstruct the data and not affected by the value of OutputHeader.

- For TYPE = 300-399: DATA is the data for a single body at the Time on header line 1 The meaning of each column is determined by the codes on header line 3. Each line corresponds to a different body; bodies are listed in ascending IdTag order, possibly omitting any or all particle types, as directed by StateTypes.