1153 lines
26 KiB
C++
1153 lines
26 KiB
C++
/////////////////////////////////////////////
|
||
// MyDlisLib.h
|
||
#pragma once
|
||
|
||
|
||
#define MAX_CURVE_NUM 256
|
||
|
||
struct Info_Reel // 轴信息 Type 132 133
|
||
{
|
||
char ServiceName[6]; //6 65 Service Name
|
||
char NoUse1[6]; //6 65
|
||
char Date[8]; //6 65
|
||
char NoUse2[2]; //6 65
|
||
char DataOrigin[4]; //6 65
|
||
char Nouse3[2]; //6 65
|
||
char ReelName[8]; //6 65
|
||
char NoUse4[2]; //6 65
|
||
char ReelContinueNo[2]; //2 65
|
||
char NoUse5[2]; //2 65
|
||
char PreReelName[8]; //8 65
|
||
char NoUse6[2]; //2 65
|
||
char Comments[74]; //74 65
|
||
};
|
||
|
||
struct Info_Tape // 磁带信息 Type 130 131
|
||
{
|
||
char ServiceName[6]; //6 65 Service Name
|
||
char NoUse1[6]; //6 65
|
||
char Date[8]; //6 65
|
||
char NoUse2[2]; //6 65
|
||
char DataOrigin[4]; //6 65
|
||
char Nouse3[2]; //6 65
|
||
char TapeName[8]; //6 65
|
||
char NoUse4[2]; //6 65
|
||
char TapeContinueNo[2]; //2 65
|
||
char NoUse5[2]; //6 65
|
||
char PreTapeName[8]; //8 65
|
||
char NoUse6[2]; //2 65
|
||
char Comments[74]; //74 65
|
||
};
|
||
|
||
struct Info_File //文件头尾信息
|
||
{
|
||
char FileName[10]; // 10 65 文件名
|
||
char NoUse1[2]; // 2 65 空白
|
||
char ServiceID[6]; // 6 65 次级服务名
|
||
char VerID[8]; // 8 65 版本号
|
||
char ProductDate[8]; // 8 65 软件生成日期
|
||
char NoUse2; // 1 65 空白
|
||
char MaxPhiLen[5]; // 5 65 最大物理记录长度
|
||
char NoUse3[2]; // 2 65 空白
|
||
char FileType[2]; // 2 65 文件类型
|
||
char NoUse4[2]; // 4 65 空白
|
||
char FileNameB[10]; // 10 65 前邻文件名
|
||
};
|
||
|
||
struct Info_Block
|
||
{
|
||
BYTE Type ; // 1 66 元件类型码
|
||
BYTE DataCode; // 1 66 元件表示码
|
||
BYTE Length; // 1 66 元件长度
|
||
BYTE Kind; // 1 66 元件种类
|
||
char MNEM[4]; // 4 65 元件名称
|
||
char UNIT[4]; // 4 65 元件单位
|
||
};
|
||
|
||
struct DataItem
|
||
{
|
||
BYTE Type; // 1 66 项块类型
|
||
BYTE Length; // 1 66 项块长度
|
||
BYTE DataCode; // 1 66 表示码值
|
||
};
|
||
|
||
struct CurveS0 //40 BYTE 数据说明块 0
|
||
{
|
||
char Name[4]; // 4 65 曲线名称
|
||
char ServeID[6]; // 6 65 服务ID
|
||
char ServeSort[8]; // 8 65 服务序号
|
||
char Unit[4]; // 4 65 单位
|
||
struct APICodeS // API代码
|
||
{
|
||
BYTE LogType; // 1 66 API测井类型
|
||
BYTE CurveType; // 1 66 API曲线类型
|
||
BYTE CurveGrade; // 1 66 API曲线级别
|
||
BYTE DefineData; // 1 66 API定义数
|
||
}APICode;
|
||
BYTE FileNo[2]; // 2 79 文件号
|
||
BYTE Length[2]; // 2 79 长度 帧中存放的字节数
|
||
short noUse1; // 2 79 备用
|
||
BYTE ProcID; // 1 66 处理级
|
||
BYTE DotsNum; // 1 66 样点数
|
||
BYTE DataType; // 1 66 表示码 数据存放类型
|
||
BYTE Nouse2; // 1 66 备用
|
||
int Nouse3; // 4 73 备用
|
||
};
|
||
|
||
struct CurveS1 //40 BYTE 数据说明块 1
|
||
{
|
||
char Name[4]; // 4 65 曲线名称
|
||
char ServeID[6]; // 6 65 服务ID
|
||
char ServeSort[8]; // 8 65 服务序号
|
||
char Unit[4]; // 4 65 单位
|
||
struct APICodeS // API代码
|
||
{
|
||
BYTE LogType; // 1 66 API测井类型
|
||
BYTE CurveType; // 1 66 API曲线类型
|
||
BYTE CurveGrade; // 1 66 API曲线级别
|
||
BYTE DefineData; // 1 66 API定义数
|
||
}APICode;
|
||
BYTE FileNo[2]; // 2 79
|
||
BYTE Length[2]; // 2 79
|
||
BYTE noUse1[3]; // 3 66 备用
|
||
BYTE DotsNum; // 1 66 样点数
|
||
BYTE DataType; // 1 66 表示码 数据存放类型
|
||
BYTE ProcID[5]; // 5 77 处理级
|
||
};
|
||
struct Data_Explain_Block
|
||
{
|
||
BYTE End_Flag; // 1 66 项块结束标志
|
||
BYTE Data_Type; // 1 66 数据记录类型
|
||
BYTE Data_Mode; // 1 66 数据说明类型
|
||
int Frame_Length; // 1 73 数据帧长度
|
||
BYTE Log_Dir; // 1 66 上下测标志
|
||
BYTE Record_Unit; // 1 66 测井深度单位
|
||
float Refer_Point; // 4 68 数据参考点
|
||
char Refer_Unit[4]; // 4 65 数据参考点单位
|
||
float Frame_Step; // 2 79 帧之间的深度差
|
||
int Max_Frame_Count; // 1 66 最大记录帧数
|
||
float Invalid_Data; // 4 68 无效数据
|
||
BYTE Depth_Mode; // 1 66 深度记录方式
|
||
char Depth_Unit[4]; // 1 65 深度记录单位
|
||
BYTE Depth_Code; // 1 66 深度表示码
|
||
BYTE Curve_Mode; // 1 66 数据说明块的子类型
|
||
};
|
||
|
||
struct UseCurveS
|
||
{
|
||
char Name[40];
|
||
char Unit[40];
|
||
byte DotCount;
|
||
float BytesNum;
|
||
byte DataType;
|
||
|
||
};
|
||
|
||
class MyLisLib
|
||
{
|
||
private:
|
||
|
||
struct CurveS0 theCurveS0[MAX_CURVE_NUM];
|
||
struct CurveS1 theCurveS1[MAX_CURVE_NUM];
|
||
|
||
bool openFlag;
|
||
int fileOptions;
|
||
int Max_Phi_Len;
|
||
BYTE tmpb[8200];
|
||
struct Data_Explain_Block m_explain_block;
|
||
|
||
float curIndex;
|
||
double realFrame_Step;
|
||
int m_depth_mode;
|
||
|
||
int b_ptr ; //填充块指针
|
||
BYTE tmp[40*1000*4];
|
||
|
||
int ii;
|
||
|
||
int DataPtr[MAX_CURVE_NUM]; //曲线数据在一条记录里的指针位置
|
||
|
||
|
||
public:
|
||
//attrib
|
||
|
||
struct UseCurveS Curve[MAX_CURVE_NUM];
|
||
QFile *DataFile;
|
||
int Year,Month,Day;
|
||
|
||
int LogDir ; //-1 Up, 0 Time ,1 Down;
|
||
float Frame_Step;
|
||
|
||
int ProcessBlock;
|
||
int CurveNum;
|
||
|
||
int projRecordCount;
|
||
|
||
|
||
MyLisLib()
|
||
{
|
||
|
||
Max_Phi_Len=1024;
|
||
memset(tmpb,0,8200);
|
||
Year=2000;
|
||
Month=1;
|
||
Day=1;
|
||
openFlag=false;
|
||
fileOptions=0;
|
||
projRecordCount=1;
|
||
|
||
LogDir=-1;
|
||
Frame_Step=0.1f;
|
||
m_depth_mode=1;//1;//深度记录方式:0-每帧数据都有一个深度,1-一个物理块只包含一个深度值
|
||
//=1时回转的数据再解编不正确,估计应该是转换模块的问题
|
||
ProcessBlock=0;
|
||
CurveNum=0;
|
||
for(int i=0;i<MAX_CURVE_NUM;i++)
|
||
{
|
||
memset(&theCurveS0[i],0,sizeof(CurveS0));
|
||
memset(&theCurveS1[i],0,sizeof(CurveS1));
|
||
DataPtr[i]=0;
|
||
}
|
||
|
||
};
|
||
|
||
~MyLisLib()
|
||
{
|
||
delete DataFile;
|
||
};
|
||
|
||
int OpenDataFile(QString dataFileName, int nOpenFlags)
|
||
{
|
||
// srcFileFlag //nOpenFlags =0,Read,=1 Write,=2,readwrite;
|
||
|
||
if (openFlag)
|
||
{
|
||
DataFile->close();
|
||
openFlag = false;
|
||
}
|
||
//////////////////////////////////////////////////////////////////////////
|
||
///注释掉:是因为当再次打开别的文件时会提醒文件已经关闭的异常提示
|
||
//////////////////////////////////////////////////////////////////////////
|
||
{
|
||
DataFile=new QFile(dataFileName);
|
||
fileOptions = nOpenFlags;
|
||
if (fileOptions == 0)
|
||
{
|
||
DataFile->open(QIODevice::ReadOnly);
|
||
}
|
||
else if (fileOptions == 1)
|
||
{
|
||
DataFile->open(QIODevice::WriteOnly);
|
||
}
|
||
|
||
else if (fileOptions == 2)
|
||
{
|
||
DataFile->open(QIODevice::ReadWrite);
|
||
}
|
||
|
||
openFlag = true;
|
||
}
|
||
return 1;
|
||
|
||
};
|
||
|
||
int CloseDataFile()
|
||
{
|
||
if (openFlag)
|
||
{
|
||
DataFile->close();
|
||
openFlag = false;
|
||
}
|
||
return 0;
|
||
};
|
||
|
||
int FillLisFileHead()
|
||
{
|
||
unsigned short phiLen;
|
||
struct Info_File *fileH;
|
||
///////////////////////////////////////// 文件头物理记录
|
||
tmpb[0]=0;
|
||
tmpb[1]=62; // =4+2+sizoef(Info_File){56}
|
||
tmpb[2]=0x80;
|
||
tmpb[3]=0;
|
||
////////////////////////////////////////// // 填充文件头
|
||
tmpb[4]=128;
|
||
tmpb[5]=0;
|
||
|
||
fileH=(struct Info_File *)(&tmpb[6]);
|
||
|
||
memset(fileH,0x20,sizeof(struct Info_File));
|
||
|
||
strcpy(fileH->FileName,"LISOUT.001");
|
||
strcpy(fileH->ServiceID,"MYYLIS");
|
||
strcpy(fileH->VerID,"2.00");
|
||
strcpy(fileH->ProductDate,"10/10/10");
|
||
strcpy(fileH->FileType,"LO");
|
||
char tmp[10];
|
||
memset(tmp,0,10);
|
||
sprintf(tmp,"%d",Max_Phi_Len);
|
||
|
||
strncpy(fileH->MaxPhiLen,tmp,5);
|
||
//////////////////////////////////////////////
|
||
phiLen =tmpb[1]+tmpb[0]*0x100;
|
||
DataFile->seek(0);
|
||
DataFile->write((char*)&tmpb[0],phiLen);
|
||
return phiLen;
|
||
|
||
};
|
||
|
||
int FillLisFileTail()
|
||
{
|
||
unsigned short phiLen;
|
||
struct Info_File * fileT;
|
||
///////////////////////////////////////// 文件头物理记录
|
||
tmpb[0]=0;
|
||
tmpb[1]=62; // =4+2+sizoef(Info_File){56}
|
||
tmpb[2]=0x80;
|
||
tmpb[3]=0;
|
||
////////////////////////////////////////// // 填充文件头
|
||
tmpb[4]=129;
|
||
tmpb[5]=0;
|
||
|
||
fileT = (struct Info_File *)(&tmpb[6]);
|
||
|
||
memset(fileT,0x20,sizeof(struct Info_File));
|
||
|
||
strcpy(fileT->FileName,"LISOUT.001");
|
||
strcpy(fileT->ServiceID,"MYYLIS");
|
||
strcpy(fileT->VerID,"2.00");
|
||
|
||
sprintf(fileT->ProductDate,"%2d/%2d/%2d",Month,Day,Year%100);
|
||
|
||
strcpy(fileT->FileType,"LO");
|
||
|
||
char tmp[10];
|
||
memset(tmp,0,10);
|
||
sprintf(tmp,"%d",Max_Phi_Len);
|
||
|
||
strncpy(fileT->MaxPhiLen,tmp,5);
|
||
//////////////////////////////////////////////
|
||
phiLen =tmpb[1]+tmpb[0]*0x100;
|
||
|
||
DataFile->write((char*)&tmpb[0],phiLen);
|
||
|
||
|
||
return phiLen;
|
||
};
|
||
|
||
int FillLisDataItemT(BYTE Type, BYTE Length, BYTE DataCode, BYTE tmpt[],unsigned short phiLen)
|
||
{
|
||
int item_Len;
|
||
struct DataItem item;
|
||
|
||
item.Type = Type;
|
||
item.Length = Length;
|
||
item.DataCode= DataCode;
|
||
|
||
memcpy(tmpb+phiLen,&item,sizeof(DataItem));
|
||
|
||
if( item.Length>0)
|
||
{
|
||
memcpy(tmpb+phiLen+sizeof(DataItem),tmpt,item.Length);
|
||
}
|
||
|
||
item_Len = sizeof(struct DataItem) +item.Length ;
|
||
|
||
return item_Len;
|
||
};
|
||
|
||
long FillLisDataBolck()
|
||
{
|
||
int i,tmpi;
|
||
unsigned short phiLen;
|
||
BYTE t1[100];
|
||
|
||
|
||
ProcessBlock=0;
|
||
for(i=0;i<CurveNum;i++)
|
||
{
|
||
ProcessBlock+=Curve[i].BytesNum;
|
||
}
|
||
|
||
/////////////////////////////// 填写数据说明块的物理记录
|
||
tmpb[0] = 0;
|
||
tmpb[1] = 0;
|
||
tmpb[2] = 0x80;
|
||
tmpb[3] = 0;
|
||
|
||
tmpb[4] =64; //type
|
||
tmpb[5] =0;
|
||
|
||
phiLen=6;
|
||
|
||
memset(&m_explain_block,0,sizeof(struct Data_Explain_Block));
|
||
|
||
m_explain_block.Data_Mode = 0;
|
||
m_explain_block.Data_Type = 0;
|
||
|
||
if(LogDir<0)m_explain_block.Log_Dir=1;
|
||
else m_explain_block.Log_Dir=255;
|
||
|
||
if(LogDir==0)m_explain_block.Record_Unit = 0;
|
||
else m_explain_block.Record_Unit = 255;
|
||
|
||
m_explain_block.Frame_Step=Frame_Step;
|
||
|
||
m_explain_block.Invalid_Data= -9999.99f;
|
||
m_explain_block.Depth_Mode = m_depth_mode;
|
||
m_explain_block.Depth_Code = 68;
|
||
m_explain_block.Curve_Mode = 1;
|
||
|
||
m_explain_block.Frame_Length= ProcessBlock+(1-m_explain_block.Depth_Mode)*sizeof(float) ;
|
||
|
||
//逻辑类型
|
||
t1[0]=m_explain_block.Data_Mode;
|
||
phiLen += FillLisDataItemT(1,1,66,t1,phiLen);
|
||
|
||
//数据说明块的类型
|
||
t1[0]=m_explain_block.Data_Type;
|
||
phiLen += FillLisDataItemT(2,1,66,t1,phiLen);
|
||
|
||
//帧长度
|
||
tmpi=m_explain_block.Frame_Length;
|
||
ConvertFloatToLisData((float)tmpi,t1,79);
|
||
phiLen += FillLisDataItemT(3,2,79,t1,phiLen);
|
||
|
||
// 测井方向
|
||
// 1=上测 ;255=下测; 0为二者都不是;缺省为1
|
||
|
||
t1[0]=m_explain_block.Log_Dir;
|
||
phiLen += FillLisDataItemT(4,1,66,t1,phiLen);
|
||
|
||
// 深度单位
|
||
// 1= 英尺 ; 255=米 ;0= 时间; 缺省为1 *
|
||
t1[0]=m_explain_block.Record_Unit;
|
||
phiLen += FillLisDataItemT(5,1,66,t1,phiLen);
|
||
|
||
|
||
//数据参考点
|
||
memset(t1,0,4);
|
||
phiLen += FillLisDataItemT(6,4,73,t1,phiLen);
|
||
|
||
|
||
if(LogDir !=0 ) //depth
|
||
{
|
||
//数据参考点数值单位
|
||
memcpy(t1,"M ",4);
|
||
phiLen += FillLisDataItemT(7,4,65,t1,phiLen);
|
||
|
||
//帧间隔
|
||
ConvertFloatToLisData(float(m_explain_block.Frame_Step),t1,68);
|
||
phiLen += FillLisDataItemT(8,4,68,t1,phiLen);
|
||
|
||
//帧间隔单位
|
||
memcpy(t1,"M ",4);
|
||
|
||
phiLen += FillLisDataItemT(9,4,65,t1,phiLen);
|
||
|
||
}
|
||
else //time
|
||
{
|
||
//数据参考点数值单位
|
||
|
||
memcpy(t1,"S ",4);
|
||
phiLen += FillLisDataItemT(7,4,65,t1,phiLen);
|
||
|
||
//帧间隔
|
||
ConvertFloatToLisData(float(m_explain_block.Frame_Step),t1,68);
|
||
phiLen += FillLisDataItemT(8,4,68,t1,phiLen);
|
||
|
||
//帧间隔单位
|
||
memcpy(t1,"S ",4);
|
||
|
||
phiLen += FillLisDataItemT(9,4,65,t1,phiLen);
|
||
|
||
}
|
||
// 最大记录帧数
|
||
t1[0]=(Max_Phi_Len-6 -m_explain_block.Depth_Mode *sizeof(float))/ProcessBlock;
|
||
if(t1[0]>255)
|
||
t1[0]=255;
|
||
if(t1[0]==0)
|
||
t1[0]=1;
|
||
phiLen += FillLisDataItemT(11,1,66,t1,phiLen);
|
||
|
||
//无效数据 缺省为-9999.95
|
||
ConvertFloatToLisData(m_explain_block.Invalid_Data,t1,68);
|
||
phiLen += FillLisDataItemT(12,4,68,t1,phiLen);
|
||
|
||
if(m_explain_block.Depth_Mode==1)
|
||
{
|
||
//深度记录方式
|
||
t1[0]=m_explain_block.Depth_Mode;
|
||
phiLen += FillLisDataItemT(13,1,66,t1,phiLen);
|
||
|
||
//深度单位
|
||
|
||
if(LogDir !=0)
|
||
memcpy(t1,"M ",4);
|
||
else
|
||
memcpy(t1,"S ",4);
|
||
|
||
phiLen += FillLisDataItemT(14,4,65,t1,phiLen);
|
||
|
||
//深度代码
|
||
t1[0]=m_explain_block.Depth_Code;
|
||
phiLen += FillLisDataItemT(15,1,66,t1,phiLen);
|
||
|
||
}
|
||
|
||
//数据说明块子类型
|
||
t1[0]=m_explain_block.Curve_Mode;
|
||
phiLen += FillLisDataItemT(16,1,66,t1,phiLen);
|
||
|
||
//项块结束标志
|
||
t1[0]=0;
|
||
m_explain_block.End_Flag= (phiLen+sizeof(struct DataItem))%2;
|
||
phiLen += FillLisDataItemT(0,m_explain_block.End_Flag,66,t1,phiLen);
|
||
|
||
///////////////////////////////////////////////////////////////////////
|
||
// 数据说明块
|
||
struct CurveS1 curve1;
|
||
struct CurveS0 curve0;
|
||
|
||
memset(&curve1,0x20,sizeof(struct CurveS1));
|
||
memset(&curve0,0x20,sizeof(struct CurveS0));
|
||
|
||
BYTE ProcID=2;
|
||
|
||
if(LogDir<0) // Up logging
|
||
ProcID += 128;
|
||
|
||
else if( LogDir>0 ) // down logging
|
||
ProcID += 64;
|
||
|
||
else // time logging
|
||
ProcID += 16; // data channel not on depth
|
||
|
||
//////////////////////////////// DEPT//////////////////////
|
||
if(m_explain_block.Depth_Mode==0)
|
||
{
|
||
if(m_explain_block.Curve_Mode==1)
|
||
{
|
||
memset(&curve1,0x20,sizeof(struct CurveS1));
|
||
strncpy(curve1.Name,"DEPT",4);
|
||
strncpy(curve1.ServeID ,"MYYLIS",6);
|
||
strncpy(curve1.Unit,"M ",4);
|
||
memset(&curve1.APICode,0,4);
|
||
curve1.DotsNum = 1;
|
||
ConvertFloatToLisData(float( 1 *sizeof(float)),curve1.Length,79);
|
||
curve1.DataType = 68; //PC机的IEEE格式 表示码为?
|
||
ConvertFloatToLisData((float)1.0,curve1.FileNo,79);
|
||
memset(&curve1.ProcID,0,5);
|
||
curve1.ProcID[0]=ProcID;
|
||
memcpy(tmpb+phiLen,&curve1,sizeof(struct CurveS1));
|
||
phiLen+=sizeof(struct CurveS1);
|
||
}
|
||
else
|
||
{
|
||
memset(&curve0,0x20,sizeof(struct CurveS0));
|
||
strncpy(curve0.Name,"DEPT",4);
|
||
strncpy(curve0.ServeID ,"MYYLIS",6);
|
||
strncpy(curve0.Unit,"M ",4);
|
||
memset(&curve0.APICode,0,4);
|
||
curve0.DotsNum = 1;
|
||
ConvertFloatToLisData(float( 1 *sizeof(float)),curve0.Length,79);
|
||
curve0.DataType = 68; //PC机的IEEE格式 表示码为?
|
||
ConvertFloatToLisData((float)1.0,curve0.FileNo,79);
|
||
memset(&curve0.ProcID,0,1);
|
||
curve0.ProcID=ProcID;
|
||
memcpy(tmpb+phiLen,&curve0,sizeof(struct CurveS0));
|
||
phiLen+=sizeof(struct CurveS0);
|
||
}
|
||
}
|
||
///////////////////////////////////////////
|
||
for(i=0;i<CurveNum;i++)
|
||
{
|
||
memset(&curve1,0x20,sizeof(struct CurveS1));
|
||
if(m_explain_block.Curve_Mode==1)
|
||
{
|
||
strncpy(curve1.Name,Curve[i].Name,4);
|
||
strncpy(curve1.ServeID ,"MYYLIS",6);
|
||
strncpy(curve1.Unit,Curve[i].Unit,4);
|
||
memset(&curve1.APICode,0,4);
|
||
|
||
curve1.DotsNum = Curve[i].DotCount;
|
||
|
||
ConvertFloatToLisData(Curve[i].BytesNum,curve1.Length,79);
|
||
curve1.DataType = Curve[i].DataType; //PC机的IEEE格式 表示码为?
|
||
|
||
memset(&curve1.ProcID,0,5);
|
||
curve1.ProcID[0]=ProcID;
|
||
memcpy(tmpb+phiLen,&curve1,sizeof(struct CurveS1));
|
||
phiLen+=sizeof(struct CurveS1);
|
||
}
|
||
else
|
||
{
|
||
strncpy(curve0.Name,Curve[i].Name,4);
|
||
strncpy(curve0.ServeID ,"MYYLIS",6);
|
||
strncpy(curve0.Unit,Curve[i].Unit,4);
|
||
memset(&curve0.APICode,0,4);
|
||
|
||
curve0.DotsNum = Curve[i].DotCount;
|
||
|
||
ConvertFloatToLisData(Curve[i].BytesNum,curve0.Length,79);
|
||
curve0.DataType = Curve[i].DataType; //PC机的IEEE格式 表示码为?
|
||
|
||
memset(&curve0.ProcID,0,1);
|
||
curve0.ProcID=ProcID;
|
||
memcpy(tmpb+phiLen,&curve0,sizeof(struct CurveS0));
|
||
phiLen+=sizeof(struct CurveS0);
|
||
|
||
}
|
||
}
|
||
|
||
///////////////////////////// 填写数据说明块记录的物理记录
|
||
|
||
if(phiLen > Max_Phi_Len)
|
||
{
|
||
tmpb[0] = Max_Phi_Len/0x100;
|
||
tmpb[1] = Max_Phi_Len%0x100;
|
||
tmpb[2] = 0x80;
|
||
tmpb[3] = 0x01;
|
||
DataFile->write((char*)&tmpb[0],Max_Phi_Len);
|
||
int lastLen;
|
||
|
||
lastLen= phiLen - Max_Phi_Len + 4 ;
|
||
|
||
tmpb[Max_Phi_Len-4] = lastLen /0x100;
|
||
|
||
tmpb[Max_Phi_Len-3] = lastLen %0x100;
|
||
|
||
tmpb[Max_Phi_Len-2] = 0x80;
|
||
|
||
tmpb[Max_Phi_Len-1] = 0x02;
|
||
|
||
DataFile->write((char*)&tmpb[0] + Max_Phi_Len -4,lastLen);
|
||
}
|
||
else
|
||
{
|
||
tmpb[0] = phiLen/0x100;
|
||
tmpb[1] = phiLen%0x100;
|
||
tmpb[2] = 0x80;
|
||
tmpb[3] = 0;
|
||
|
||
DataFile->write((char*)&tmpb[0],phiLen);
|
||
|
||
|
||
}
|
||
|
||
return phiLen;
|
||
};
|
||
|
||
BYTE t1[100];
|
||
void Data_Write(BYTE *ProjBuf)
|
||
{
|
||
if(m_explain_block.Depth_Mode==0)//每帧数据都有一个深度
|
||
{
|
||
ConvertFloatToLisData((float)(curIndex+ii*realFrame_Step) ,t1,m_explain_block.Depth_Code);
|
||
memcpy(&tmp[b_ptr],t1,4);
|
||
b_ptr+=4;
|
||
}
|
||
|
||
for(int i=0;i<CurveNum;i++)
|
||
{
|
||
if(Curve[i].DataType==79)
|
||
{
|
||
int len=Curve[i].BytesNum/2;
|
||
for(int j=0;j<len;j++)
|
||
{
|
||
ConvertFloatToLisData(*(short*)(ProjBuf+DataPtr[i]+j*2),&tmp[b_ptr],Curve[i].DataType);
|
||
b_ptr+=2;
|
||
}
|
||
}
|
||
else if(Curve[i].DataType==73)
|
||
{
|
||
int len=Curve[i].BytesNum/4;
|
||
for(int j=0;j<len;j++)
|
||
{
|
||
ConvertFloatToLisData(*(int*)(ProjBuf+DataPtr[i]+j*4),&tmp[b_ptr],Curve[i].DataType);
|
||
b_ptr+=4;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
int len=Curve[i].BytesNum/4;
|
||
for(int j=0;j<len;j++)
|
||
{
|
||
ConvertFloatToLisData(*(float*)(ProjBuf+DataPtr[i]+j*4),&tmp[b_ptr],68);
|
||
b_ptr+=4;
|
||
}
|
||
}
|
||
}
|
||
|
||
ii++;
|
||
int curRecordCount=projRecordCount;
|
||
|
||
if(ii%projRecordCount==0)//一个逻辑数据块
|
||
{
|
||
b_ptr=(ProcessBlock+(1-m_explain_block.Depth_Mode)*sizeof(float))*curRecordCount;
|
||
|
||
int PhiN=0,LogHead;
|
||
do//全部数据分块存储,块号PhiN
|
||
{
|
||
//物理记录头4bytes,逻辑记录类型2bytes,深度初始值
|
||
tmpb[2]=0x80;
|
||
tmpb[3]=0x00;
|
||
unsigned short phiLen;
|
||
phiLen = 4;
|
||
if(PhiN==0)
|
||
{
|
||
tmpb[4] = 0; //逻辑记录头 数据记录
|
||
tmpb[5] = 0;
|
||
phiLen += 2;
|
||
if(m_explain_block.Depth_Mode==1)//一个物理块只包含一个深度值
|
||
{
|
||
ConvertFloatToLisData((float)(curIndex+(ii-projRecordCount+1)*realFrame_Step) ,t1,m_explain_block.Depth_Code);
|
||
memcpy(tmpb+phiLen,t1,4);
|
||
phiLen += 4;
|
||
}
|
||
}
|
||
else
|
||
{//只有物理信息,没有逻辑信息
|
||
}
|
||
LogHead=phiLen;
|
||
if(Max_Phi_Len-LogHead<b_ptr)
|
||
{
|
||
memcpy(tmpb+phiLen,tmp+(ProcessBlock+(1-m_explain_block.Depth_Mode)*sizeof(float))*curRecordCount-b_ptr,Max_Phi_Len-LogHead);
|
||
phiLen+= (Max_Phi_Len-LogHead);
|
||
b_ptr -= (Max_Phi_Len-LogHead);
|
||
|
||
if(PhiN==0)
|
||
tmpb[3] = 1;
|
||
else if(b_ptr>0)
|
||
tmpb[3] = 3;
|
||
else
|
||
tmpb[3] = 2;
|
||
}
|
||
else
|
||
{
|
||
memcpy(tmpb+phiLen,tmp+(ProcessBlock+(1-m_explain_block.Depth_Mode)*sizeof(float))*curRecordCount-b_ptr,b_ptr);
|
||
phiLen+= b_ptr;
|
||
b_ptr=0;
|
||
if(PhiN==0)
|
||
tmpb[3]=0;
|
||
else
|
||
tmpb[3] = 2;
|
||
}
|
||
tmpb[0] =(BYTE)(phiLen / 0x100);
|
||
tmpb[1] =(BYTE)(phiLen % 0x100);
|
||
DataFile->write((char*)&tmpb[0], phiLen);
|
||
PhiN++;
|
||
}while(b_ptr>0);
|
||
}
|
||
};
|
||
|
||
void End_Flush()
|
||
{
|
||
int curRecordCount=projRecordCount;
|
||
|
||
if(ii%projRecordCount>0 )
|
||
{
|
||
curRecordCount=ii%projRecordCount; //剩余块
|
||
|
||
b_ptr=(ProcessBlock+(1-m_explain_block.Depth_Mode)*sizeof(float))*curRecordCount;
|
||
|
||
int PhiN=0,LogHead;
|
||
do
|
||
{
|
||
//物理记录头4bytes,逻辑记录类型2bytes,深度初始值
|
||
tmpb[2]=0x80;
|
||
tmpb[3]=0x00;
|
||
unsigned short phiLen;
|
||
phiLen = 4;
|
||
if(PhiN==0)
|
||
{
|
||
tmpb[4] = 0; //逻辑记录头 数据记录
|
||
tmpb[5] = 0;
|
||
phiLen += 2;
|
||
if(m_explain_block.Depth_Mode==1)//一个物理块只包含一个深度值
|
||
{
|
||
ConvertFloatToLisData((float)(curIndex+(ii-curRecordCount+1)*realFrame_Step) ,t1,m_explain_block.Depth_Code);
|
||
memcpy(tmpb+phiLen,t1,4);
|
||
phiLen += 4;
|
||
}
|
||
}
|
||
else
|
||
{//只有物理信息,没有逻辑信息
|
||
}
|
||
LogHead=phiLen;
|
||
if(Max_Phi_Len-LogHead<b_ptr)
|
||
{
|
||
memcpy(tmpb+phiLen,tmp+(ProcessBlock+(1-m_explain_block.Depth_Mode)*sizeof(float))*curRecordCount-b_ptr,Max_Phi_Len-LogHead);
|
||
phiLen+= (Max_Phi_Len-LogHead);
|
||
b_ptr -= (Max_Phi_Len-LogHead);
|
||
|
||
if(PhiN==0)
|
||
tmpb[3] = 1;
|
||
else if(b_ptr>0)
|
||
tmpb[3] = 3;
|
||
else
|
||
tmpb[3] = 2;
|
||
}
|
||
else
|
||
{
|
||
memcpy(tmpb+phiLen,tmp+(ProcessBlock+(1-m_explain_block.Depth_Mode)*sizeof(float))*curRecordCount-b_ptr,b_ptr);
|
||
phiLen+= b_ptr;
|
||
b_ptr=0;
|
||
if(PhiN==0)
|
||
tmpb[3]=0;
|
||
else
|
||
tmpb[3] = 2;
|
||
}
|
||
tmpb[0] =(BYTE)(phiLen / 0x100);
|
||
tmpb[1] =(BYTE)(phiLen % 0x100);
|
||
DataFile->write((char*)&tmpb[0], phiLen);
|
||
PhiN++;
|
||
}while(b_ptr>0);
|
||
}
|
||
|
||
};
|
||
|
||
|
||
void Begin_Write(float StartIndex)
|
||
{
|
||
curIndex=StartIndex;
|
||
ii=0;
|
||
|
||
realFrame_Step = m_explain_block.Frame_Step;
|
||
|
||
if(LogDir<0) //up logging
|
||
realFrame_Step *= (-1);
|
||
|
||
if(m_explain_block.Depth_Mode) //一个数据物理块只有一个深度
|
||
projRecordCount= (Max_Phi_Len-6-sizeof(float) )/ProcessBlock;
|
||
else //每帧数据都有一个深度
|
||
projRecordCount= (Max_Phi_Len-6)/ (ProcessBlock+sizeof(float));
|
||
|
||
if(projRecordCount>255) projRecordCount=255;
|
||
if(projRecordCount==0) projRecordCount=1;
|
||
|
||
int recl=0;
|
||
for(int i=0;i<CurveNum;i++)
|
||
{
|
||
DataPtr[i]=recl;
|
||
recl+=Curve[i].BytesNum;
|
||
}
|
||
|
||
b_ptr=0;
|
||
memset(t1,0,100);
|
||
|
||
};
|
||
|
||
|
||
void ConvertFloatToLisData(float srcData, BYTE tmpb[], BYTE dataCode)
|
||
{
|
||
int i,j,sign,dd,IntData;
|
||
double TailData;
|
||
|
||
if(srcData<0) sign=-1;
|
||
else sign=1;
|
||
|
||
switch(dataCode)
|
||
{
|
||
case 65: // 'C' ASCII
|
||
case 66: // 'B' 8位无符号整数
|
||
tmpb[0]= (BYTE)(srcData);
|
||
break;
|
||
case 56: // 8位补码整数
|
||
dd= (int)fabs(srcData);
|
||
if(srcData<0)
|
||
{
|
||
dd = ((~dd) &0x0ff +1)&0xff;
|
||
dd=dd|0x80;
|
||
}
|
||
tmpb[0]=dd;
|
||
break;
|
||
case 79:// 16位补码整数
|
||
dd= (int)(fabs(srcData)+0.5);
|
||
if(srcData<0)
|
||
{
|
||
dd=( (~dd)+1)&0xffff;
|
||
dd=dd|0x8000;
|
||
}
|
||
tmpb[0]=dd>>8;
|
||
tmpb[1]=dd&0x0ff;
|
||
break;
|
||
case 73:// 32位补码整数
|
||
dd= (int)(srcData);
|
||
if(srcData<0)
|
||
{
|
||
dd=( (~dd)+1)&0xffffffff;
|
||
dd=dd|0x80000000;
|
||
}
|
||
tmpb[0]=dd>>24;
|
||
tmpb[1]=dd>>16;
|
||
tmpb[2]=dd>>8;
|
||
tmpb[3]=dd&0x0ff;
|
||
break;
|
||
case 70: // 32位定点数
|
||
//整数部分
|
||
dd=(int)(fabs(srcData)*10);
|
||
dd=dd/10;
|
||
IntData=dd;
|
||
if(srcData<0)
|
||
{
|
||
dd=( (~dd)+1)&0xffff;
|
||
dd=dd|0x8000;
|
||
}
|
||
tmpb[0]=dd>>8;
|
||
tmpb[1]=dd&0x0ff;
|
||
//小数部分
|
||
TailData = fabs(srcData) -IntData;
|
||
for(i=0;i<2;i++)
|
||
{ tmpb[2+i]=0;
|
||
for(j=0;j<8;j++)
|
||
{
|
||
TailData *=2.0;
|
||
if(TailData>=1)
|
||
tmpb[2+i]+=(int)pow(2.,8-j);
|
||
}
|
||
}
|
||
break;
|
||
case 49: // 16位 低分辨率 浮点数
|
||
|
||
break;
|
||
case 50: // 'F' 32位低分辨率浮点数
|
||
|
||
break;
|
||
case 68: // 'D' 32位高分辨率浮点数
|
||
{
|
||
int ExData,TailData;
|
||
float *tmpf;
|
||
BYTE tmpt[4];
|
||
|
||
tmpf=(float *)tmpt;
|
||
*tmpf=srcData;
|
||
//填充阶码
|
||
ExData = (tmpt[3]&0x7f )<<1;
|
||
ExData = ExData+(tmpt[2]>>7);
|
||
ExData = ExData-127;
|
||
ExData = ExData+1;
|
||
if(srcData>0)
|
||
{
|
||
ExData=128 + ExData;
|
||
tmpb[0] = ExData>>1 ;
|
||
tmpb[1] =(ExData &0x01) *0x80;
|
||
}
|
||
else
|
||
{
|
||
ExData=127 - ExData;
|
||
tmpb[0] =( ExData>>1) +0x80;
|
||
tmpb[1] =(ExData &0x01) *0x80;
|
||
}
|
||
//填充尾数
|
||
TailData = (tmpt[2]&0x7f) *0x10000 + tmpt[1]*0x100+ tmpt[0];
|
||
TailData =TailData &0x7fffff;
|
||
|
||
double aa;
|
||
|
||
aa=0;
|
||
for(i=0;i<23;i++)
|
||
{
|
||
if(TailData &0x01)
|
||
aa+=pow(2.,i-23);
|
||
|
||
TailData=TailData>>1;
|
||
}
|
||
aa=aa+1;
|
||
|
||
aa=aa/2.0;
|
||
|
||
int ww;
|
||
|
||
ww=0;
|
||
for(i=0;i<23;i++)
|
||
{
|
||
aa =aa*2;
|
||
if(aa>=1.0)
|
||
{
|
||
ww+=(int)pow(2.,22-i);
|
||
aa=aa-1.0;
|
||
}
|
||
}
|
||
|
||
if(srcData<0)
|
||
{
|
||
ww= (~ww)+1;
|
||
}
|
||
ww =ww&0x7fffff;
|
||
int aq;
|
||
aq=ww>>16;
|
||
aq=aq&0x7f;
|
||
tmpb[1]+=aq;
|
||
|
||
aq=ww>>8;
|
||
aq=aq&0xff;
|
||
tmpb[2]=aq;
|
||
|
||
aq=ww&0xff;
|
||
tmpb[3]=aq;
|
||
}
|
||
break;
|
||
}
|
||
|
||
};
|
||
float ConvertLisDataToFloat(BYTE dataCode, BYTE srcData[])
|
||
{
|
||
int i,sign,dd;
|
||
double rData,ExData,TailData;
|
||
|
||
rData=0;
|
||
|
||
if(srcData[0]&0x80) sign=-1;
|
||
else sign=1;
|
||
|
||
switch(dataCode)
|
||
{
|
||
case 56: // //8 位有符号整数
|
||
rData=srcData[0];
|
||
if(sign<0)
|
||
rData = rData -pow(2.,8);
|
||
break;
|
||
case 65: //'C'
|
||
case 66: // 'B' //8 位无符号整数
|
||
rData=srcData[0];
|
||
break;
|
||
case 73: // 'I' //32位整数
|
||
{
|
||
dd = ((srcData[0] &0x7f)*0x100 +srcData[1]) *0x10000
|
||
+srcData[2]*0x100 +srcData[3];
|
||
if(sign<0)
|
||
{
|
||
dd=~(dd-1);
|
||
}
|
||
rData =sign *dd;
|
||
}
|
||
break;
|
||
case 79: // 'N' //16位整数
|
||
{
|
||
dd = (srcData[0] &0x7f)*0x100 +srcData[1];
|
||
if(sign<0)
|
||
{
|
||
dd=~(dd-1);
|
||
}
|
||
rData =sign *dd;
|
||
}
|
||
break;
|
||
case 49: // 16位浮点数
|
||
{ //填充阶码
|
||
ExData= srcData[1] &0x0f;
|
||
//填充尾数
|
||
dd=(srcData[0] &0x7f )*0x10 +(srcData[1]>>4);
|
||
if(sign<0)
|
||
{
|
||
dd=~(dd-1);
|
||
}
|
||
TailData=0;
|
||
for(i=0;i<11;i++)
|
||
{
|
||
if(dd &0x01)
|
||
{
|
||
TailData+=pow(2.,i-11);
|
||
}
|
||
dd=dd>>1;
|
||
}
|
||
TailData =sign *TailData;
|
||
|
||
rData = TailData *pow(2,ExData);
|
||
}
|
||
break;
|
||
case 50: // 'F' 32位低分辨率浮点数
|
||
{ //填充阶码
|
||
dd= srcData[0]*0x100 + srcData[1];
|
||
if(sign<0)
|
||
{
|
||
dd=~(dd-1);
|
||
}
|
||
dd=dd&0x7f;
|
||
|
||
ExData=0;
|
||
for(i=0;i<15;i++)
|
||
{
|
||
if(dd&0x01)
|
||
ExData+=pow(2.,i+1);
|
||
dd=dd>>1;
|
||
}
|
||
ExData= sign *ExData;
|
||
//填充尾数
|
||
if(srcData[2]&0x80) sign=-1;
|
||
else sign=1;
|
||
|
||
dd= srcData[2]*0x100 + srcData[3];
|
||
if(sign<0)
|
||
{
|
||
dd=~(dd-1);
|
||
}
|
||
dd=dd&0x7f;
|
||
TailData=0;
|
||
for(i=0;i<15;i++)
|
||
{
|
||
if(dd &0x01)
|
||
TailData+=pow(2.,i-15);
|
||
dd=dd>>1;
|
||
}
|
||
TailData = sign *TailData;
|
||
|
||
rData=TailData *pow(2.,ExData);
|
||
}
|
||
break;
|
||
case 68: // 'D' //32浮点数
|
||
{ //填充浮点数的阶码
|
||
dd=(srcData[0]&0x7f)*2 +(srcData[1]>>7);
|
||
ExData=dd &0x0ff;
|
||
// 填充浮点数的尾数
|
||
dd= ((srcData[1]&0x7f)*0x100 + srcData[2])*0x100+ srcData[3];
|
||
if(sign<0)
|
||
{
|
||
dd=~(dd-1);
|
||
}
|
||
TailData=0;
|
||
for(i=0;i<23;i++)
|
||
{
|
||
if(dd&0x01)
|
||
TailData+=pow(2.,i-23);
|
||
dd=dd>>1;
|
||
}
|
||
TailData = sign *TailData;
|
||
|
||
if(sign>0)
|
||
rData= TailData *pow(2.,ExData-128);
|
||
else
|
||
rData= TailData *pow(2.,127-ExData);
|
||
}
|
||
break;
|
||
case 70: // 32位定点数
|
||
{ //填充阶码
|
||
dd= (srcData[0] &0x7f)*0x100+ srcData[1];
|
||
if(sign<0)
|
||
{
|
||
dd=~(dd-1);
|
||
}
|
||
dd=dd&0x7fff;
|
||
ExData=dd*sign;
|
||
//填充尾数
|
||
dd=srcData[2]*0x100+srcData[3];
|
||
TailData=0;
|
||
for(i=0;i<16;i++)
|
||
{
|
||
if(dd&0x01)
|
||
TailData+=pow(2.,i-16);
|
||
dd=dd>>1;
|
||
}
|
||
TailData =sign *TailData;
|
||
|
||
rData=ExData+TailData;
|
||
}
|
||
break;
|
||
}//switch
|
||
return (float)rData;
|
||
};
|
||
};
|
||
|
||
|