evio  6.0
 All Data Structures Files Functions Variables Typedefs Macros Groups
eviofmtswap.c File Reference
#include <stdio.h>
#include "evio.h"

Macros

#define MIN(a, b)   ( (a) < (b) ? (a) : (b) )
 
#define SWAP64(x)
 
#define SWAP32(x)
 
#define SWAP16(x)
 

Functions

int eviofmtswap (int32_t *iarr, int nwrd, unsigned short *ifmt, int nfmt, int tolocal, int padding)
 This function converts (swaps) an array of EVIO composite type data between IEEE (big endian) and DECS (little endian) in place. More...
 

Macro Definition Documentation

#define MIN (   a,
 
)    ( (a) < (b) ? (a) : (b) )
#define SWAP16 (   x)
Value:
( (((x) & 0x00ff) << 8) | \
(((x) & 0xff00) >> 8) )

Referenced by eviofmtswap().

#define SWAP32 (   x)
Value:
( (((x) & 0x000000ff) << 24) | \
(((x) & 0x0000ff00) << 8) | \
(((x) & 0x00ff0000) >> 8) | \
(((x) & 0xff000000) >> 24) )

Referenced by eviofmtswap().

#define SWAP64 (   x)
Value:
( (((x) & 0x00000000000000ff) << 56) | \
(((x) & 0x000000000000ff00) << 40) | \
(((x) & 0x0000000000ff0000) << 24) | \
(((x) & 0x00000000ff000000) << 8) | \
(((x) & 0x000000ff00000000) >> 8) | \
(((x) & 0x0000ff0000000000) >> 24) | \
(((x) & 0x00ff000000000000) >> 40) | \
(((x) & 0xff00000000000000) >> 56) )

Referenced by eviofmtswap().

Function Documentation

int eviofmtswap ( int32_t iarr,
int  nwrd,
unsigned short *  ifmt,
int  nfmt,
int  tolocal,
int  padding 
)

This function converts (swaps) an array of EVIO composite type data between IEEE (big endian) and DECS (little endian) in place.

This data does NOT include the composite type's beginning tagsegment and the format string it contains. It also does NOT include the data's bank header words.

Converts the data of array (iarr[i], i=0...nwrd-1) using the format code (ifmt[j], j=0...nfmt-1) .

Algorithm description:

Data processed inside while (ib < nwrd) loop, where 'ib' is iarr[] index; loop breaks when 'ib' reaches the number of elements in iarr[]

Parameters
iarrpointer to data to be swapped
nwrdnumber of data words (32-bit ints) to be swapped
ifmtunsigned short array holding translated format
nfmtlength of unsigned short array, ifmt, in # of shorts
tolocalif 0 data is of same endian as local host, else data is of opposite endian
paddingnumber of bytes to ignore in last data word (starting from data end)
Returns
0 if success
-1 if nwrd or nfmt arg(s) < 0

References SWAP16, SWAP32, and SWAP64.