#include "dcltng.h" unsigned short lt_shrt ( int endianness, unsigned char *bullx, int *ibxptr ) /************************************************************************ * lt_shrt * * * * This routine reads two bytes as an unsigned short 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_SHRT USHRT* Unsigned short 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 shrt_bit_shifts[2][2] = { { 8, 0 }, /* successive bit shifts when reading as big-endian */ { 0, 8 } /* successive bit shifts when reading as little-endian */ }; unsigned short result = 0; unsigned char in; unsigned short ii; for ( ii = 0; ii < 2; ii++ ) { in = (unsigned char) bullx[++(*ibxptr)]; result += in << shrt_bit_shifts[endianness][ii]; } return result; }