#include "dcltng.h" unsigned int lt_word ( int endianness, unsigned char *bullx, int *ibxptr ) /************************************************************************ * lt_word * * * * This routine reads four bytes as an unsigned int from the given * * bulletin. The byte ordering can be big-endian or little-endian and * * is specified during input. * * * * Input parameters: * * ENDIANNESS INT Byte-ordering scheme within bulletin: * * 0 = big-endian * * 1 = little-endian * * BULLX CHAR* Lightning bulletin * * IBXPTR INT* Pointer within BULLX * * * * Output parameters: * * IBXPTR INT* Updated pointer within BULLX * * LT_WORD UINT* Unsigned int value * ** * * Log: * * S. Guan/NCEP 10/08 Initial version * * S. Guan/NCEP 01/09 Reconstruct * * J. Ator/NCEP 10/13 Read from bullx instead of stdin * * J. Ator/NCEP 04/15 Added endianness argument * ***********************************************************************/ { static unsigned short word_bit_shifts[2][4] = { { 24, 16, 8, 0 }, /* successive bit shifts when reading as big-endian */ { 0, 8, 16, 24 } /* successive bit shifts when reading as little-endian */ }; unsigned int result = 0; unsigned char in; unsigned short ii; for ( ii = 0; ii < 4; ii++ ) { in = (unsigned char) bullx[++(*ibxptr)]; result += in << word_bit_shifts[endianness][ii]; } return result; }