The Plotutils Package - Data Formats

Go to the first, previous, next, last section, table of contents.

## Reading binary and other data formats

By default, `graph` reads datasets in ASCII format. But it can also read datasets in any of three binary formats (single precision floating point, double precision floating point, and integer). These three input formats are specified by the ``-I d'`, ``-I f'`, and ``-I i'` options, respectively.

There are two advantages to using binary data: 1) `graph` runs significantly faster because the computational overhead for converting data from ASCII to binary is eliminated, and 2) the input files may be significantly smaller. If you have very large datasets, using binary format may reduce storage and runtime costs.

For example, you may create a single precision binary dataset as output from a C language program:

    #include <stdio.h>
    void write_point (float x, float y)
    {
      fwrite(&x, sizeof (float), 1, stdout);
      fwrite(&y, sizeof (float), 1, stdout);
    }

You may plot data written this way by doing:

    graph -T ps -I f < binary_data_file > plot.ps

@ifnottex The inclusion of multiple datasets within a single binary file is supported. If a binary file contains more than a single dataset, successive datasets should be separated by a single occurrence of the the largest possible number. For single precision datasets this is the quantity `FLT_MAX`, for double precision datasets it is the quantity `DBL_MAX`, and for integer datasets it is the quantity `INT_MAX`. On most machines `FLT_MAX` is approximately 3.4x10^38, `DBL_MAX` is approximately 1.8x10^308, and `INT_MAX` is 2^32-1.

If you are reading datasets from more than one file, it is not required that the files be in the same format. For example,

    graph -T ps -I f binary_data_file -I a ascii_data_file > plot.ps

will read `binary_data_file` in ``f'` (binary single precision) format, and `ascii_data_file` in ``a'` (normal ASCII) format.

There is currently no support for reading and plotting binary data with error bars. If you have data with error bars, you should supply the data to `graph` in ASCII, and use the ``-I e'` option.

`graph` can also read data files in the ASCII `table' format produced by the `gnuplot` plotting program. For this, you should use the ``-I g'` option. Such a data file may consist of more than one dataset.

To sum up: there are six supported data formats, ``a'` (normal ASCII), ``e'` (ASCII with error bars), ``g'` (the ASCII `table' format produced by `gnuplot`), ``f'` (binary single precision), ``d'` (binary double precision), and ``i'` (binary integer). Input files may be in any of these six formats.

Go to the first, previous, next, last section, table of contents.