📄 segdread.c
字号:
* * Credits: * EOPG: Marc Schaming, Jean-Daniel Tissot * SEP: Stew Levin - fixed low-order bit error in conversion * of negative values on 2's complement machines. * Use ldexp() function instead of much slower value*pow(2,expo) * SEP: Adapted F8015 to F0015 conversion * * * Parameters: * from - input vector * to - output vector * len - number of packets of 4 floats in vectors * *//* * * Format 0015 is a 10 byte per 4 words (2 1/2 bytes per word) * representation. According to the SEG specifications, the * bit layout of the 10 bytes is: * * * Bit 0 1 2 3 4 5 6 7 *----------------------------------------------------------- * Byte 1 C3 C2 C1 C0 C3 C2 C1 C0 Exponents for * Byte 2 C3 C2 C1 C0 C3 C2 C1 C0 channels 1 thru 4 * * Byte 3 S Q-1 Q-2 Q-3 Q-4 Q-5 Q-6 Q-7 Channel 1 * Byte 4 Q-8 Q-9 Q-10 Q-11 Q-12 Q-13 Q-14 0 * Byte 5 S Q-1 Q-2 Q-3 Q-4 Q-5 Q-6 Q-7 Channel 2 * Byte 6 Q-8 Q-9 Q-10 Q-11 Q-12 Q-13 Q-14 0 * Byte 7 S Q-1 Q-2 Q-3 Q-4 Q-5 Q-6 Q-7 Channel 3 * Byte 8 Q-8 Q-9 Q-10 Q-11 Q-12 Q-13 Q-14 0 * Byte 9 S Q-1 Q-2 Q-3 Q-4 Q-5 Q-6 Q-7 Channel 4 * Byte 10 Q-8 Q-9 Q-10 Q-11 Q-12 Q-13 Q-14 0 * * S=sign bit. - (One = negative number) * C=binary exponents. - This is a 4 bit positive binary exponent of 2 * CCCC * written as 2 where CCCC can assume values of 0-15. The four * exponents are in channel number order for the four channels starting * with channel one in bits 0-3 of Byte 1. * Q1-14-fraction. - This is a 14 bit one's complement binary fraction. * The radix point is to the left of the most significant bit (Q-1) * -1 * with the MSB being defined as 2 . The sign and fraction can assume * -14 -14 * values from 1-2 to -1+2 . Note that bit 7 of the second byte * of each sample must be zero in order to guarantee the uniqueness of * the start of scan. Negative zero is invalid and must be converted * to positive zero. * CCCC MP MP * Input signal = S.QQQQ,QQQQ,QQQQ,QQ x 2 x 2 millivolts where 2 * is the value required to descale the data word to the recording * system input level. MP is defined in Byte 8 of each of the corre- * sponding channel set descriptors in the scan type header. * Note that in utilizing this data recording method, the number of data * channels per channel set must be exactly divisible by 4 in order to * preserve the data grouping of this method. */ static void F0015_to_float (Sfio_t *from, float to[], int len){ register int i; register short ex1_4; int expo; short fraction; for (i = 0; i < len; i += 4) { ex1_4 = GET_S(from); expo = ((ex1_4 >> 12) & 0x0F) - 15; fraction = GET_S(from); if (fraction < 0) fraction = -((~fraction)&(~1)); *(to++) = ldexp((double) fraction, expo); expo = ((ex1_4 >> 8) & 0x0F) - 15; fraction = GET_S(from); if (fraction < 0) fraction = -((~fraction)&(~1)); *(to++) = ldexp((double) fraction, expo); expo = ((ex1_4 >> 4) & 0x0F) - 15; fraction = GET_S(from); if (fraction < 0) fraction = -((~fraction)&(~1)); *(to++) = ldexp((double) fraction, expo); expo = (ex1_4 & 0x0F) - 15; fraction = GET_S(from); if (fraction < 0) fraction = -((~fraction)&(~1)); *(to++) = ldexp((double) fraction, expo); }} /* F8015_to_float - convert 20 bit binary demultiplexed data into floating numbers * * Credits: * EOPG: Marc Schaming, Jean-Daniel Tissot * SEP: Stew Levin - fixed low-order bit error in conversion * of negative values on 2's complement machines. * Use ldexp() function instead of much slower value*pow(2,expo) * * Parameters: * from - input vector * to - output vector * len - number of packets of 4 floats in vectors * *//* * * Format 8015 is a 10 byte per 4 words (2 1/2 bytes per word) * representation. According to the SEG specifications, the * bit layout of the 10 bytes is: * * * Bit 0 1 2 3 4 5 6 7 *----------------------------------------------------------- * Byte 1 C3 C2 C1 C0 C3 C2 C1 C0 Exponents for * Byte 2 C3 C2 C1 C0 C3 C2 C1 C0 channels 1 thru 4 * * Byte 3 S Q-1 Q-2 Q-3 Q-4 Q-5 Q-6 Q-7 Channel 1 * Byte 4 Q-8 Q-9 Q-10 Q-11 Q-12 Q-13 Q-14 Q-15 * Byte 5 S Q-1 Q-2 Q-3 Q-4 Q-5 Q-6 Q-7 Channel 2 * Byte 6 Q-8 Q-9 Q-10 Q-11 Q-12 Q-13 Q-14 Q-15 * Byte 7 S Q-1 Q-2 Q-3 Q-4 Q-5 Q-6 Q-7 Channel 3 * Byte 8 Q-8 Q-9 Q-10 Q-11 Q-12 Q-13 Q-14 Q-15 * Byte 9 S Q-1 Q-2 Q-3 Q-4 Q-5 Q-6 Q-7 Channel 4 * Byte 10 Q-8 Q-9 Q-10 Q-11 Q-12 Q-13 Q-14 Q-15 * * S=sign bit. - (One = negative number) * C=binary exponents. - This is a 4 bit positive binary exponent of 2 * CCCC * written as 2 where CCCC can assume values of 0-15. The four * exponents are in channel number order for the four channels starting * with channel one in bits 0-3 of Byte 1. * Q1-15-fraction. - This is a 15 bit one's complement binary fraction. * The radix point is to the left of the most significant bit (Q-1) * -1 * with the MSB being defined as 2 . The sign and fraction can assume * -15 -15 * values from 1-2 to -1+2 . Negative zero is invalid and must be * converted to positive zero. * CCCC MP MP * Input signal = S.QQQQ,QQQQ,QQQQ,QQQ x 2 x 2 millivolts where 2 * is the value required to descale the data word to the recording * system input level. MP is defined in Byte 8 of each of the corre- * sponding channel set descriptors in the scan type header. * Note that in utilizing this data recording method, the number of data * channels per channel set must be exactly divisible by 4 in order to * preserve the data grouping of this method. */static void F8015_to_float (Sfio_t *from, float to[], int len){ register int i; register short ex1_4; int expo; short fraction; for (i = 0; i < len; i += 4) { ex1_4 = GET_S(from); expo = ((ex1_4 >> 12) & 15) - 15; fraction = GET_S(from); if (fraction < 0) fraction = -(~fraction); *(to++) = ldexp((double) fraction, expo); expo = ((ex1_4 >> 8) & 15) - 15; fraction = GET_S(from); if (fraction < 0) fraction = -(~fraction); *(to++) = ldexp((double) fraction, expo); expo = ((ex1_4 >> 4) & 15) - 15; fraction = GET_S(from); if (fraction < 0) fraction = -(~fraction); *(to++) = ldexp((double) fraction, expo); expo = (ex1_4 & 15) - 15; fraction = GET_S(from); if (fraction < 0) fraction = -(~fraction); *(to++) = ldexp((double) fraction, expo); }} /* F8022_to_float - convert 8 bit quaternary demultiplexed data into floating numbers * * Credits: * SEP: Stew Levin * * Parameters: * from - input sfio unit * to - output vector * len - number of packets of 4 floats in vectors * *//* * * Format 8022 is a 1 byte per word representation. * According to the SEG specifications, the bit * layout of the byte is: * * * Bit 0 1 2 3 4 5 6 7 *----------------------------------------------------------- * Byte 1 S C2 C1 C0 Q-1 Q-2 Q-3 Q-4 * * S=sign bit. - (One = negative number) * C=quaternary exponent. - This is a 3 bit positive binary exponent of 4 * CCC * written as 4 where CCC can assume values of 0-7. * Q1-4-fraction. - This is a 4 bit one's complement binary fraction. * The radix point is to the left of the most significant bit (Q-1) * -1 * with the MSB being defined as 2 . The fraction can have values * -4 -4 * from 1-2 to -1+2 . Negative zero is invalid and must be * converted to positive zero. * CCC MP MP * Input signal = S.QQQQ x 4 x 2 millivolts where 2 is the * value required to descale the data word to the recording system * input level. MP is defined in Byte 8 of each of the corre- * sponding channel set descriptors in the scan type header. */static void F8022_to_float (Sfio_t *from, float to[], int len){ register int i; register int ex1_4; int expo; short fraction; for (i = 0; i < len; i ++) { ex1_4 = GET_C(from); expo = ((ex1_4 >> 3) & 14) - 4; fraction = ex1_4 & 15; if (ex1_4 & 128) fraction = -(15^fraction); *(to++) = ldexp((double) fraction, expo); }} /* F8024_to_float - convert 16 bit quaternary demultiplexed data into floating numbers * * Credits: * SEP: Stew Levin * * Parameters: * from - input sfio unit * to - output vector * len - number of packets of 4 floats in vectors * *//* * * Format 8024 is a 2 byte per word representation. * According to the SEG specifications, the bit * layout of the bytes is: * * * Bit 0 1 2 3 4 5 6 7 *----------------------------------------------------------- * Byte 1 S C2 C1 C0 Q-1 Q-2 Q-3 Q-4 * Byte 2 Q-5 Q-6 Q-7 Q-8 Q-9 Q-10 Q-11 Q-12 * * S=sign bit. - (One = negative number) * C=quaternary exponent. - This is a 3 bit positive binary exponent of 4 * CCC * written as 4 where CCC can assume values of 0-7. * Q1-12-fraction. - This is a 12 bit one's complement binary fraction. * The radix point is to the left of the most significant bit (Q-1) * -1 * with the MSB being defined as 2 . The fraction can have values * -12 -12 * from 1-2 to -1+2 . Negative zero is invalid and must be * converted to positive zero. * CCC MP MP * Input signal = S.QQQQ,QQQQ,QQQQ x 4 x 2 millivolts where 2 * is the value required to descale the data word to the recording * system input level. MP is defined in Byte 8 of each of the corre- * sponding channel set descriptors in the scan type header. */static void F8024_to_float (Sfio_t *from, float to[], int len){ register int i; register int ex1_4; int expo; short fraction; for (i = 0; i < len; i ++) { ex1_4 = GET_S(from); expo = ((ex1_4 >> 11) & 14) - 12; fraction = ex1_4 & 4095; if (ex1_4 & 32768) fraction = -(4095^fraction); *(to++) = ldexp((double) fraction, expo); }} /* F8036_to_float - convert 24 bit quaternary demultiplexed data into floating numbers * * Credits: * SEP: Stew Levin * * Parameters: * from - input sfio unit * to - output vector * len - number of packets of 4 floats in vectors * *//* * * Format 8036 is a 3 byte per word representation. * According to the SEG specifications, the bit * layout of the bytes is: * * * Bit 0 1 2 3 4 5 6 7 *----------------------------------------------------------- * Byte 1 Q-1 Q-2 Q-3 Q-4 Q-5 Q-6 Q-7 Q-8 * Byte 2 Q-9 Q-10 Q-11 Q-12 Q-13 Q-14 Q-15 Q-16 * Byte 3 Q-17 Q-18 Q-19 Q-20 Q-21 Q-22 Q-23 Q-24 * * Q1-24-integer. - This is a 24 bit two's complement binary integer. * MP MP * Input signal = Q...Q x 2 millivolts where 2 * is the value required to descale the data word to the recording * system input level. MP is defined in Byte 8 of each of the corre- * sponding channel set descriptors in the scan type header. */static void F8036_to_float (Sfio_t *from, float to[], int len){ register int i; register long int ival; for (i = 0; i < len; i ++) { ival = GET_UC(from); ival <<= 8; ival |= GET_UC(from); ival <<= 8; ival |= GET_UC(from); if(ival > 8388607) ival -= 16777216; *(to++) = (float) ival; }} /* F8038_to_float - convert 32 bit quaternary demultiplexed data into floating numbers * * Credits: * SEP: Stew Levin * * Parameters: * from - input sfio unit * to - output vector * len - number of packets of 4 floats in vectors * *//* * * Format 8038 is a 4 byte per word representation. * According to the SEG specifications, the bit * layout of the bytes is: * * * Bit 0 1 2 3 4 5 6 7 *----------------------------------------------------------- * Byte 1 Q-1 Q-2 Q-3 Q-4 Q-5 Q-6 Q-7 Q-8 * Byte 2 Q-9 Q-10 Q-11 Q-12 Q-13 Q-14 Q-15 Q-16 * Byte 3 Q-17 Q-18 Q-19 Q-20 Q-21 Q-22 Q-23 Q-24 * Byte 4 Q-25 Q-26 Q-27 Q-28 Q-29 Q-30 Q-31 Q-32 * * Q1-32-fraction. - This is a 32 bit two's complement binary integer. * MP MP * Input signal = Q...Q x 2 millivolts where 2 * is the value required to descale the data word to the recording * system input level. MP is defined in Byte 8 of each of the corre- */ /* Note this conversion routine assumes the target architecture is * already 2's complement.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -