Libraries and Packages: The VOS Interface

2.9 Bit & Byte Operations -- osb


Byte and Character Conversions

Table 2.70: Byte and Character Conversions.

chars are signed integers, whereas bytes as unsigned integers. The bswapT() routines are used to swap bytes in short and long integer arrays, as is sometimes required when transporting data between machines. The mii package is available for conversions between a machine independent integer format and the SPP data types (documented elsewhere). See
"Binary File I/O" on page 98 for an example of extracting individual bytes from a word.

Character Comparisons

The following are macro functions defined in the system include file ctype.h. The statement

include <ctype.h> 
must be in the code in order to use them.

Table 2.71: Character Comparison Functions.

These are macro definitions, not procedures (they produce in-line code and need not be declared). TO_UPPER() and TO_LOWER() must only be applied to letters of the proper case (use the procedures chrupr(), chrlwr() otherwise).

Pack and Unpack Characters

These procedures convert between SPP character strings (short int arrays) and packed byte blocks, i.e., a sequence of characters stored one per byte, delimited by EOS (ASCII NUL). The conversion may be performed in-place. That is, the input and output arrays may be the same.

Table 2.72: Pack and Unpack Functions.

Fortran Strings

There are two procedures that convert between SPP and Fortran character strings: f77pak() converts an SPP string to a Fortran string and f77upk() converts a Fortran string to an SPP string. An example is shown in Example 2.28.

Table 2.73: SPP/Fortran String Conversion.

Note the escaped Fortran statement, preceded by %. See also "Fortran statements" on page 7.

Machine Independent I/O -- mii

The mii integer format provides for three machine independent integer data types and two IEEE floating point formats.

Table 2.74: Machine-Independent Integer Data Types.

These types are defined in the system include file mii.h which must be included if using mii. The mii data types are the same as are used in the FITS transportable image format. In the case of the short and long integers, the most significant bytes of an integer are given first.

The routines in this package are provided for converting to and from the mii format and the SPP format. The latter format, of course, is potentially quite machine dependent. The implementation given here assumes that the SPP data types include 16-bit and 32-bit twos-complement integers; the ordering of the bytes within these integer formats is described by the machine constants BYTE_SWAP2 and BYTE_SWAP4. Byte swapping for the IEEE floating formats is defined by the machine constants IEEE_SWAP4 and IEEE_SWAP8.

Table 2.75: Machine-Independent/SPP Conversion Functions.

Note the distinction in the above table between the size of an mii array, specified as the number of array elements and the size of the SPP buffer, specified as the number of SPP chars. The following example illustrates reading an mii binary file consisting of byte (eight bit unsigned) values:

Byte and Character Conversions
Table 2.70: - Byte and Character Conversions.
Character Comparisons
Table 2.71: - Character Comparison Functions.
Pack and Unpack Characters
Table 2.72: - Pack and Unpack Functions.
Fortran Strings
Table 2.73: - SPP/Fortran String Conversion.
Machine Independent I/O -- mii
Table 2.74: - Machine-Independent Integer Data Types.
Table 2.75: - Machine-Independent/SPP Conversion Functions.

Generated with CERN WebMaker