bitio.c File Reference

functions for input and output to/from a bitstream More...

#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <memory.h>
#include "desc.h"
#include "bufr.h"
#include "bitio.h"

Go to the source code of this file.

Functions

int bitio_i_open (void *buf, size_t size)
 This function opens a bitstream for input.
int bitio_i_input (int handle, unsigned long *val, int nbits)
 This function reads a value from a bitstream.
void bitio_i_close (int handle)
 Closes an bitstream that was opened for input.
int bitio_o_open ()
 Opens a bitstream for output.
long bitio_o_append (int handle, unsigned long val, int nbits)
 This function appends a value to a bitstream.
void bitio_o_outp (int handle, unsigned long val, int nbits, long bitpos)
 This function outputs a value to a specified position of a bitstream.
size_t bitio_o_get_size (int handle)
 Returns the size of an output-bitstream (number of bytes).
void * bitio_o_close (int handle, size_t *nbytes)
 This function closes an output-bitstream.


Detailed Description

The functions in this file can be used for input and output to/from a bitstream as needed for BUFR-messages. Data is stored on/read from a bitstream as follows: For example if you wan to store a 12 bit-value VAL on a bit-stream, consisting of a character-array C, the bits are assigned (bit 0 is the least segnificant bit).

VAL bit 00 -> C[0] bit 00
VAL bit 01 -> C[0] bit 01
VAL bit 02 -> C[0] bit 02
VAL bit 03 -> C[0] bit 03
VAL bit 04 -> C[0] bit 04
VAL bit 05 -> C[0] bit 05
VAL bit 06 -> C[0] bit 06
VAL bit 07 -> C[1] bit 07
VAL bit 08 -> C[1] bit 00
VAL bit 09 -> C[1] bit 01
VAL bit 10 -> C[1] bit 02
VAL bit 11 -> C[1] bit 03

if you append another 2-bit value VAL1 to the stream:

VAL bit 00 -> C[1] bit 04
VAL bit 01 -> C[1] bit 05

Functions for output of data to a bit-stream are named bitio_o_*, those for inputing from a bitstream bitio_i_*.

Output to a bit-stream must be as follows:

h = bitio_o_open (); open a bitstrem, handle H is returned to identify for subsequent calls.
bitio_o_append (h, val, nbits); Append VAL to the bitstream.
bitio_o_close (h, nbytes); close bitstream.

Input from a bit-stream must be as follows:

h = bitio_i_open (); open a bitstream for input
bitio_i_input (); read a value from the bitstream
bitio_i_close (); close the bitstream

More details can be found at the description of the functions. Note that the buffer holding the bitstream is organized as an array of characters. So the functions are independent from the computer-architecture (byte-swapping).

Definition in file bitio.c.


Generated on Tue Dec 18 16:52:45 2007 for OPERA BUFR software by  doxygen 1.5.4