Ressources naturelles Canada
Symbol of the Government of Canada

Definition of the Canadian Archive (CA) Waveform Format


A CNSN Archive (CA) waveform file is formatted as follows.

28 bytes of Pre Header including:
	A 4 byte file type identifier consisting of the 4 ASCII characters CA01.
	A 20 byte ASCII start time of the earliest data in the file.  In the
		format YYYYMMDD.HHMMSS, padded with NULLS (ASCII 0).
	The number of channels in file.  4 byte integer.
	
A file header consisting of several 16 byte entries, one for each channel
in the file.  The 16 byte entry contains:
	A 2 byte ARO id (ID Hi & ID Lo)
	A 10 byte, NULL padded, ASCII channel name (station and component).
		The channel name is 5 char station name followed by a '.' (dot)
		followed by a 3 char component name followed by a NULL.
	A byte offset from the start of the file to where the channel header
		for this station starts.  4 byte integer.

A channel header and channel data section for each channel in the file.
The channel header consists of:
	The number of packets in this channel's data section. 4 byte integer.
	The epochal start time (# seconds since the beginning of Jan 1, 1970)
		of the first packet offset for this channel (note, the first
		packet can be missing or present).  4 byte integer.
	Nominal time correction in tenths of milliseconds.  4 byte integer.
	A list of offsets to each packet in this channel's data section.
		There is one 4 byte integer offset for each packet.
		Each offset represents the number of bytes from the start of
		the channel header.  A missing packet must have an offset of 0.

The channel data section consists of concatenated CNSN packets,
including the header and CRC but not the start and end sync bytes.

Notes and conventions:

All integers are IEEE (2's compliment) integers with forward byte
ordering, aka sparc/motorola "little endian" byte ordering, aka Most
Significant Byte first, MSB, and most significant bit first, msb.

CA files must be "rectangular".  That is, each channel must start at
the same time and contain the same number of seconds of data.  Missing
data packets must be indicated with packet offsets of zero.

A graphical description of the CA file format follows.


      +----   +---------------------------+
      |       |          CA01             |           File Type Id (C*4)
      |       +---------------------------+
Pre Header    |    YYYYMMDD.HHMMSS        |           Start Time (C*20, ASCII)
      |       +---------------------------+
      |       |  Number of Channels       |           I*4
      +-----  +---------------------------+
      |       | AroId/ChanName/Offset Ch1 |--+        C*2 / C*10 / I*4
      |       +---------------------------+  |
      |       | AroId/ChanName/Offset Ch2 |--|---+    C*2 / C*10 / I*4
File Header   +---------------------------+  |   |
      |       ...                       ...  |   |    1 entry per channel
      |       +---------------------------+  |   |
      |       | AroId/ChanName/Offset Chn |--|---|-+  C*2 / C*10 / I*4
      +----   +---------------------------+  |   | |
      |       |   Number of Packets       |<-+   | |  I*4
      |       +---------------------------+      | |
      |       |   Data Start Time         |      | |  I*4 (epochal seconds)
      |       +---------------------------+      | |
      |       |   Time Corr (0.1 ms)      |      | |  I*4 (tenths of ms)
      |       +---------------------------+      | |
      |       |  Offset to 1st Packet     |--+   | |  I*4 (bytes from chan hdr)
              +---------------------------+  |   | |
Chan 1 Header |  Offset to 2nd Packet     |--|-+ | |  I*4 (bytes from chan hdr)
              +---------------------------+  | | | |
      |       ...                       ...  | | | |  1 entry per packet
      |       +---------------------------+  | | | |
      |       |  Offset to last Packet    |  | | | |  I*4 (bytes from chan hdr)
      +----   +---------------------------+  | | | |
      |       |         Packet            |<-+ | | |  1st Packet (inc hdr & CRC)
      |       +---------------------------+    | | |
              |         Packet            |<---+ | |  2nd Packet (inc hdr & CRC)
Chan 1 Data   +---------------------------+      | |
              ...                       ...      | |  1 entry per packet
      |       +---------------------------+      | |
      |       |         Packet            |      | |  Last Packet
      +----   +---------------------------+      | |
                                                 | |
              +---------------------------+ <----+ |     
              |                           |        |      
              |     Chan 2 Header         |        |
              |                           |        |
              +- - - - - - - - - - - - - -+        |
              |                           |        |
              |     Chan 2 Data           |        |
              |                           |        |
              +---------------------------+        |
              ...                       ...        |
              +---------------------------+ <------+      
              |                           |      
              |     Chan n Header         |
              |                           |
              +- - - - - - - - - - - - - -+
              |                           |
              |     Chan n Data           |
              |                           |
              +---------------------------+