ReWARD Project Refraction/Wide-Angle Reflections Database |
INGV-Italy
Unit of Milano |
MARS-88 / FD
Application Note no. 5: Binary Data Format
----------- Document
Revision: 1.1 -----------
(The information in this document is believed to be correct at the time of printing; however, Lennartz electronic GmbH explicitly denies any liability for damage and/or losses, direct and indirect, resulting from the reliance upon this document. The information in this document is subjected to change without notice). |
1. Application Note: Binary data format
1.1 Introduction
This application note describes some details of the current MARS-88 binary data format. This information may be of interest to programmers who want to use the MARSDUMP program with its -b option.
1.2 Terminology
In the context of this document, the term "word" is used to denote a 16-bit data item, the term "long" is used to denote a 32-bit data item, and the term "byte" is used to denote an 8-bit data item. These terms are independent of a particular computer's or compiler's implementation of numerical formats.
Note that the C data type "long" will normally match our notion of "long". However, the C data type "int" does not necessarily correspond to our "word". On many machines, "int" is a 32-bit item, and you will need to use "short" as a synonym for "word".
Hexadecimal numbers are written with a "0x" lead-in. Thus, "0x10" is hexadecimal 10 (that is 16 decimal).
1.3 Data block
Each MARS-88 data block is 1024 bytes long: 24 bytes are Header information, while the remaining 1000 bytes contain 500 words of data.
1.4 Setup block
Setup blocks are always written as ASCII files by the MARSDUMP program. Thus, their internal binary format is not documented in this Application Note.
1.5 Byte sex
The term "byte sex" denotes the way that 16- and 32-bit data are stored in byte-oriented memory. Some microprocessors /e.g. the Motorola 680X0 series) are big-endian (that is, the high byte of a word is stored first), whereas others (e.g. the Intel 808X and 80X86 series) are little-endian (the low byte of a word is stored first).
The MARS-88 data are stored in little-endian format. Thus, in order to be able to correctly read them on a big-endian machine, the word (16 bits) and long (32 bits) data items must be swapped into the correct byte ordering.
1.6 Data block Header
The Data block Header (24 bytes long) consists of the following items:
byte N. | byte quant. | bytes Total | variable | meaning |
1 | 2 | 2 | magic number | Tis is a word-sized integer containing the ASCII representation of the two letters 'l' and 'e'. This magic number can be used to find out if your computer's byte sex matches MARS-88's byte sex. Internally, the magic number is defined as 'l'+('e'<<8) (in C language notation) |
2 | 1 | 3 | block format | This is a byte-sized integer which currently has the value '1'. This description is only valid for block format 1; any change in the block format will be reflected by a change in this value. |
3 | 1 | 4 | data format | This is a byte-sized number which reflects the format of the data words. The value of this item depends on the setting of the exponent variable. The following description of the data format is only valid for data recorded with exponent set to zero. In this case, the data format will also be zero. |
4 | 4 | 8 | device ID | This is a long number containing the device ID of the MARS-88 instrument that wrote the data. Actually, only the 16 least significant bits are currently used. The most significant word always contains the value "0x0001". |
5 | 4 | 12 | time | This is a long integer containing the number of seconds since January 1, 1970. Note that this is compatible with the time format used in the Unix ctime(3C) functions. Thus, you can apply the C compiler's time conversion functions to this item. |
6 | 2 | 14 | delta | This is a word-sized integer containing the current time lag in milliseconds. |
7 | 2 | 16 | reserved | This is a word-sized integer reserved for internal use. |
8 | 1 | 17 | chno | This is a byte-sized integer indicating the channel number of this block. |
9 | 1 | 18 | samp_rate | This is a byte-sized integer indicating the two's logarithm of the sampling rate. Thus, if this contains the value 3, the sampling rate is 2^3=8 milliseconds. |
10 | 2 | 20 | maxamp | This is a word-sized integer indicating the modulus of the maximum amplitude encountered in this block. It is encoded in the same format as the data in the data block. |
11 | 1 | 21 | scale | This is a byte-sized integer indicating the two's logarythm of the scale of the input amplifier. If this contains the value 5, thus the input scale is 2^5=32 μV/LSB. |
12 | 3 | 24 | 3 reserved | Three reserved bytes conclude the data block Header. |
1.7 Data words
The 500 data words per block are encoded as straight 16-bit integers (assuming data format 0).