RSF Comprehensive Description: Difference between revisions

From Madagascar
Jump to navigation Jump to search
Nick (talk | contribs)
m RSF Data Format Specification moved to RSF Formal Specification: Old name was redundant, imprecise
Nick (talk | contribs)
No edit summary
Line 1: Line 1:
==Introduction==
The Regularly Sampled Format (RSF) is the way in which most Madagascar programs organize their output and expect their input to be.
The RSF originated as a representation of a discrete set of values of a single-valued function defined on a ''n''-dimensional [http://en.wikipedia.org/wiki/Space_%28mathematics%29 space]. A real-world example of this would be the values of pressure in a space-time volume through which an acoustic wavefield propagates. Each dimension of the space is either discrete and regular, or continuous, but sampled discretely and regularly. In this context, regularity is defined as the property of a set of reals or integers of being consecutive integer multiples of a finite quantity of the same kind of themselves. In simple words -- "matrices with physical dimensions".
The physicality of dimensions, while useful for jargon, for mental images and for the definition of parameters below, is not compulsory. Ultimately RSF is just a sane way of storing '''n'''-d arrays on disk. Just like programming languages use intrinsic methods and user-defined procedures to work with arrays held in memory, Madagascar uses both its main distribution and user-written programs to work with data stored in RSF. RSF files are just meta-arrays.
==Encoded information==
==Encoding protocol==
RSF "files" actually consist of a header file and a data file.  
RSF "files" actually consist of a header file and a data file.  


This file attempts to document the actual interface implemented in [http://rsf.svn.sourceforge.net/viewvc/rsf/trunk/api/c/file.c?view=markup file.c]; it is not a formal specification, and in the event of a disagreement the code should be taken as the official reference.
This file attempts to document the actual interface implemented in [http://rsf.svn.sourceforge.net/viewvc/rsf/trunk/api/c/file.c?view=markup file.c]; it is not a formal specification, and in the event of a disagreement the code should be taken as the official reference.


==Header Files==
===Header Files===


Associated with each such data file is a header file. The header file is 7 bit ASCII (UTF-7).
Associated with each such data file is a header file. The header file is 7 bit ASCII (UTF-7).
Line 20: Line 33:
n1 must be specified. The size of the array is the product of all n# values with the size of the fundamental type
n1 must be specified. The size of the array is the product of all n# values with the size of the fundamental type


===Optional elements===
====Optional elements====


In addition to the above, many filters enforce the following conventions:
In addition to the above, many filters enforce the following conventions:
Line 28: Line 41:
"o#" is the physical origin in some absolute coordinate system of the respective dimension
"o#" is the physical origin in some absolute coordinate system of the respective dimension


==Data Files==
===Data Files===


Data files are rectangular arrays of data. The following data formats are supported
Data files are rectangular arrays of data. The following data formats are supported
Line 49: Line 62:
* complex (real, imaginary float pairs)
* complex (real, imaginary float pairs)


==RSF files in streams==
===RSF files in streams===
====Input====
====Input====
When a Madagascar program writes a RSF file to disk (i.e.: <tt>sfprog >file.rsf</tt>), it will create a header file and a binary file as described above.
When a Madagascar program writes a RSF file to disk (i.e.: <tt>sfprog >file.rsf</tt>), it will create a header file and a binary file as described above.

Revision as of 13:20, 22 December 2009

Introduction

The Regularly Sampled Format (RSF) is the way in which most Madagascar programs organize their output and expect their input to be.

The RSF originated as a representation of a discrete set of values of a single-valued function defined on a n-dimensional space. A real-world example of this would be the values of pressure in a space-time volume through which an acoustic wavefield propagates. Each dimension of the space is either discrete and regular, or continuous, but sampled discretely and regularly. In this context, regularity is defined as the property of a set of reals or integers of being consecutive integer multiples of a finite quantity of the same kind of themselves. In simple words -- "matrices with physical dimensions".

The physicality of dimensions, while useful for jargon, for mental images and for the definition of parameters below, is not compulsory. Ultimately RSF is just a sane way of storing n-d arrays on disk. Just like programming languages use intrinsic methods and user-defined procedures to work with arrays held in memory, Madagascar uses both its main distribution and user-written programs to work with data stored in RSF. RSF files are just meta-arrays.

Encoded information

Encoding protocol

RSF "files" actually consist of a header file and a data file.

This file attempts to document the actual interface implemented in file.c; it is not a formal specification, and in the event of a disagreement the code should be taken as the official reference.

Header Files

Associated with each such data file is a header file. The header file is 7 bit ASCII (UTF-7).

Lines with no "=" are considered comments and are ignored. Lines with more than one "=" are illegal.

Lines with a single "=", with no adjacent spaces, assign a value to an alphanumeric named variable

Textstrings must be delimited by pairs of quotes. Numerical values are subject to C's parsing rules.

"in=" parameter contains the fully qualified path to the relevant data and is required

"n#" (n1, n2, n3) etc. is the number of points in a dimension. n1 is the fastest direction (maps directly onto memory).

n1 must be specified. The size of the array is the product of all n# values with the size of the fundamental type

Optional elements

In addition to the above, many filters enforce the following conventions:

"d#" is the physical spacing in the respective dimension

"o#" is the physical origin in some absolute coordinate system of the respective dimension

Data Files

Data files are rectangular arrays of data. The following data formats are supported

  • ASCII (C-compatible input)
  • XDR (device independent binary standard)
  • native binary (default)

ASCII format is most useful for debugging, while XDR format is useful for portability across formats.

Performance is optimized for native format.

The following data formats are supported:

  • unsigned byte
  • byte
  • int (native int)
  • short (2 bytes)
  • float (native float)
  • complex (real, imaginary float pairs)

RSF files in streams

Input

When a Madagascar program writes a RSF file to disk (i.e.: sfprog >file.rsf), it will create a header file and a binary file as described above.

If the output is to a stream, or if the parameter --out=stdout is passed to the program, then the program will write to the stdout stream the ASCII header, followed by the sequence of three special characters: EOL EOL EOT (\014\014\004), followed by the binary.

Output

When a Madagascar program reads from the stdin stream, it expects either a EOF character indicating the end of the ASCII header (after which it transfers the stdin to reading from the binary cube), or a EOL EOL EOT sequence indicating that the data follows immediately on stdin.