69,373
社区成员
发帖
与我相关
我的任务
分享
char converInput[256];
int mycomtrade_build_dat(DATETYPE *date,char *channelName,short int data[][SVAEFILELEN],int id,int samplelen)
{
char datName[100]={0},datContex[100];
FILE *fp;
int i,writelen;
unsigned int iLoop, tmp_u32, bufferLength, dataLength;
unsigned short int tmp_u16,chlNum,chlIndex;
if(date==NULL || channelName==NULL || samplelen<0)
return 1;
sprintf(datName,"%s_%04d%02d%02d_%02d%02d%02d.dat",channelName,\
date->Year,date->Month,date->Date,date->Hour,date->Minute,date->Msecond);
fp=fopen(datName,"w");//这里的文件名均没有问题
if(fp==NULL)
{
zz("%s生成失败\n",datName);
return 1;
}
memset( converInput, 0, sizeof(converInput) );
bufferLength=0;
dataLength = samplelen;
for( iLoop=0; iLoop< dataLength; iLoop++ )
{
//写dat文件
// 序号4,时标微秒4,2字节数据
//4字节序号
tmp_u32 = iLoop;
memcpy(converInput+bufferLength, &tmp_u32, 4 ); bufferLength += 4;
//4字节时标(微秒单位)
tmp_u32 = iLoop * 250 ;
memcpy(converInput+bufferLength, &tmp_u32, 4 ); bufferLength += 4;
///写2字节数据:交换高低字节顺序
tmp_u16 = data[id][iLoop];
memcpy(converInput+bufferLength, &tmp_u16, 2 ); bufferLength += 2;
//每组写一次,还是固定长度写一次
if( bufferLength > 100 )
{
//写一组数据
fwrite( converInput, bufferLength, 1, fp );
bufferLength = 0;
memset( converInput, 0, sizeof(converInput) );
}
}
if( bufferLength > 100 )
{
fwrite( converInput, bufferLength, 1, fp );
bufferLength = 0;
}
fclose(fp);
}