资源简介
此代码适用于sgy学习的人,里面记录如何读取数据,并将其写成.txt
代码片段和文件信息
#include “stdio.h“
#include “stdlib.h“
#include
#include “math.h“
#include
#include
#define ulong unsigned long
union Data{float a; char dat[4];};
union SI{unsigned short a; char s[2];};
union SP{unsigned short i; char s[2];};
/*float Ibm2decimal(char dat[]) //IBM浮点数转换
{
ulong DataUint32;
char *p=NULL;
char ch=dat[0]; //高低位转换开始
dat[0]=dat[3];
dat[3]=ch;
ch=dat[1];
dat[1]=dat[2];
dat[2]=ch; //高低位转换结束
p=(char*)(&DataUint32);
p[0]=dat[0];
p[1]=dat[1];
p[2]=dat[2];
p[3]=dat[3];
// gain sign from first bit
double sign = (double )( DataUint32 >>31) ;
// gain exponent from first byte last 7 bits
double exp0 = (double) ( ( DataUint32 &0x7f000000 ) >>24) ;
// remove bias from exponent
double exp =(double )(exp0 - 64 ) ;
// gain mantissa from last 3 bytes
double frac = ( double )( DataUint32 &0x00ffffff ) ;
double fmant = frac/ (pow(2 24) ) ;
float result = ( 1-2*sign)*( pow( 16 exp) ) *fmant;
// printf(“IEEE is:%f\n“ result);
return result;
}
*/
main()
{
int Tn;
int i;
int j;
int k;
char ch;
// float dat;
union SI si;//采样点数
union SP sp;//定义采样
评论
共有 条评论