397 lines
12 KiB
C++
397 lines
12 KiB
C++
/////////////////////////////////////////////
|
|
// MyLpsLib.h
|
|
#pragma once
|
|
#include "GeometryUtils.h"
|
|
#include <QSettings>
|
|
#include <QTextCodec>
|
|
#define WLD_FILE_FLAG "WellMessage"
|
|
#define I1D_FILE_FLAG "CurveIndex1d"
|
|
#define D1D_FILE_FLAG "CurveData1d"
|
|
#define I2D_FILE_FLAG "CurveIndex2d"
|
|
#define D2D_FILE_FLAG "CurveData2d"
|
|
#define I3D_FILE_FLAG "CurveIndex3d"
|
|
#define D3D_FILE_FLAG "CurveData3d"
|
|
typedef struct
|
|
{
|
|
char flag[16];
|
|
int length;
|
|
char reserved[12];
|
|
}WldFileHead;
|
|
typedef struct {
|
|
char name[32]; // 井名 32
|
|
char region[32]; // 地区名 32
|
|
int chin_code[16]; // 井名的汉字代码数组 64
|
|
char type[16]; // 井的类别标识 16
|
|
float x_coor, y_coor; // 井位的大地坐标 8
|
|
char oil_company[40]; // 油公司名称 40
|
|
float height; // 井的补心高度 4
|
|
float bit_program[5][2]; // 钻头程序 40
|
|
float case_program[5][2]; // 套管程序 40
|
|
char reserved[64]; // 保留未用 64
|
|
} WSM; // 340
|
|
|
|
typedef struct {
|
|
int log_times; // 测井次数 4
|
|
char log_company[40]; // 测井公司名称 40
|
|
char log_team[32]; // 测井队名称 32
|
|
char log_series[16]; // 测井系列标识 16
|
|
char log_project[16]; // 测井项目标识 16
|
|
char log_profile[16]; // 地层剖面类别标识 16
|
|
char log_date[12]; // 测井日期 12
|
|
float stdep,endep; // 测量井段的起始深度和结束深度 8
|
|
float bottom_temp; // 井底温度 4
|
|
char mud_type[12]; // 泥浆类别标识 12
|
|
float mud_viscosity; // 泥浆粘度 4
|
|
float mud_density; // 泥浆密度 4
|
|
float mud_resistivity; // 泥浆电阻率 4
|
|
char reserved[64]; // 保留未用 64
|
|
} WDM; //236
|
|
|
|
typedef struct {
|
|
char name[8]; /* 曲线名称 */
|
|
char alias[8]; /* 曲线别名 */
|
|
char flag[16]; /* 曲线附加标志 */
|
|
float sdepth; /* 曲线的起始深度 */
|
|
float edepth; /* 曲线的结束深度 */
|
|
float dstep; /* 曲线采样的深度间距 */
|
|
char dunit[8]; /* 深度值量纲 */
|
|
char vunit[8]; /* 曲线值量纲 */
|
|
char data_type[8]; /* 曲线值存储类型*/
|
|
int address; /* 曲线值的存储首地址 */
|
|
} CurveIndex1d;
|
|
|
|
typedef struct {
|
|
char name[8]; /* 曲线名称 */
|
|
char alias[8]; /* 曲线别名 */
|
|
char flag[16]; /* 曲线附加标志 */
|
|
float sdepth; /* 线的起始深度 */
|
|
float edepth; /* 曲线的结束深度 */
|
|
float dstep; /* 曲线采样的深度间距 */
|
|
char dunit[8]; /* 深度值量纲 */
|
|
float stime; /* 起始采样时间 */
|
|
float etime; /* 结束采样时间 */
|
|
float tstep; /* 采样时间间隔 */
|
|
char tunit[8]; /* 时间量纲 */
|
|
char vunit[8]; /* 曲线值量纲 */
|
|
char data_type[8]; /* 曲线值存储类型 */
|
|
int address; /* 曲线值的存储首地址 */
|
|
} CurveIndex2d;
|
|
|
|
typedef struct {
|
|
char name[8]; /* 曲线名称 */
|
|
char alias[8]; /* 曲线别名 */
|
|
char flag[16]; /* 曲线附加标志 */
|
|
float sdepth; /* 曲线的起始深度 */
|
|
float edepth; /* 曲线的结束深度 */
|
|
float dstep; /* 曲线采样的深度间距 */
|
|
char dunit[8]; /* 深度值量纲 */
|
|
float sangle; /* 起始采样角度 */
|
|
float eangle; /* 结束采样角度 */
|
|
float astep; /* 采样角度间隔 */
|
|
char aunit; /* 角度量纲 */
|
|
float stime; /* 起始采样时间 */
|
|
float etime; /* 结束采样时间 */
|
|
float tstep; /* 采样时间间隔 */
|
|
char tunit[8]; /* 时间量纲 */
|
|
char vunit[8]; /* 曲线值量纲 */
|
|
char data_type[8]; /* 曲线值存储类型 */
|
|
int address; /* 曲线值的存储首地址 */
|
|
}CurveIndex3d;
|
|
extern short ReverseShort(short num);
|
|
extern long ReverseLong(long num);
|
|
extern int ReverseInt(int num);
|
|
extern float ReverseFloat(float num);
|
|
extern double ReverseDouble(double num);
|
|
|
|
class MyLpsLib
|
|
{
|
|
public:
|
|
WSM wsm;
|
|
WDM wdm;
|
|
Slf_FILE_MESSAGE FILE_MESSAGE;
|
|
// WELL_DYNAMIC_INFO WellDynamicInfo;
|
|
// WELL_STATIC_INFO WellStaticInfo;
|
|
float minrlev,stdep,endep;
|
|
CurveIndex1d *c1d;
|
|
CurveIndex2d *c2d;
|
|
CurveIndex3d *c3d;
|
|
int num1d,num2d,ResultId,CoreId;
|
|
QString PathName,WellName;
|
|
QFile *dataFile;
|
|
MyLpsLib()
|
|
{
|
|
num1d=0,num2d=0;
|
|
ResultId=-1,CoreId=-1;
|
|
};
|
|
~MyLpsLib()
|
|
{
|
|
if(num1d)delete []c1d;
|
|
if(num2d)delete []c2d;
|
|
};
|
|
int OpenDataFile(QString ExtName)
|
|
{
|
|
QString filename;
|
|
filename=PathName+WellName+ExtName;
|
|
dataFile=new QFile(filename);
|
|
dataFile->open(QIODevice::WriteOnly);
|
|
return 1;
|
|
};
|
|
int Rewind()
|
|
{
|
|
dataFile->seek(0);
|
|
int pos=dataFile->pos();
|
|
return 0;
|
|
};
|
|
int CloseDataFile()
|
|
{
|
|
dataFile->close();
|
|
return 0;
|
|
};
|
|
int WriteDataFile(char *buf,int len)
|
|
{
|
|
return dataFile->write(buf, len);
|
|
};
|
|
void TurnData(int iType,int nCount,void *pVal)
|
|
{
|
|
int i;
|
|
if ( iType == REPR_INT ) // 1 int
|
|
{
|
|
int *p;
|
|
p = (int *)pVal;
|
|
for (i=0; i<nCount; i++)
|
|
p[i] = ReverseInt(p[i]);
|
|
}
|
|
if ( iType == REPR_SHORT ) // 2 short
|
|
{
|
|
short int *p;
|
|
p = (short int *)pVal;
|
|
for (i=0; i<nCount; i++)
|
|
p[i] = ReverseShort(p[i]);
|
|
}
|
|
if ( iType == REPR_LONG ) // 3 long
|
|
{
|
|
long *p;
|
|
p = (long *)pVal;
|
|
for (i=0; i<nCount; i++)
|
|
p[i] = ReverseLong(p[i]);
|
|
}
|
|
if ( iType == REPR_FLOAT ) // 4 float
|
|
{
|
|
float *p;
|
|
p = (float *)pVal;
|
|
for (i=0; i<nCount; i++)
|
|
p[i] = ReverseFloat(p[i]);
|
|
}
|
|
if ( iType == REPR_DOUBLE ) // 5
|
|
{
|
|
double *p;
|
|
p = (double *)pVal;
|
|
for (i=0; i<nCount; i++)
|
|
p[i] = ReverseDouble(p[i]);
|
|
}
|
|
if ( iType == REPR_USHORT ) // 9 unsigned short
|
|
{
|
|
unsigned short int *p;
|
|
p = (unsigned short int *)pVal;
|
|
for (i=0; i<nCount; i++)
|
|
p[i] = ReverseShort(p[i]);
|
|
}
|
|
if ( iType == REPR_UINT ) // 10 unsigned int
|
|
{
|
|
unsigned int *p;
|
|
p = (unsigned int *)pVal;
|
|
for (i=0; i<nCount; i++)
|
|
p[i] = ReverseInt(p[i]);
|
|
}
|
|
if ( iType == REPR_ULONG ) // 11 unsigned long
|
|
{
|
|
}
|
|
if ( iType == REPR_STRING ) // 6 string
|
|
{
|
|
}
|
|
};
|
|
// 取数据类型 : 将数据类型编码,转换为数据类型字符串
|
|
const char * GetDataType(int iType)
|
|
{
|
|
// 编码从1开始
|
|
const char *strDataType[]={"null","int","short","long","float","double"
|
|
,"string","char","UCHAR","WORD"
|
|
,"UINT","ULONG"};
|
|
if ( iType >=0 && iType < 11 )
|
|
return strDataType[iType];
|
|
else
|
|
return "unknown";
|
|
};
|
|
// 取数据类型 : 将数据类型编码,转换为数据类型字符串
|
|
//---- 注意:-------------------------------------------
|
|
// 该类型定义所有程序一定要统一,标准制定后既不能改变
|
|
//------------------------------------------------------
|
|
int GetDataTypeCode(char *strType,int *nCodeLen)
|
|
{
|
|
const char *strDataType[]={"null","int","short","long","float","double"
|
|
,"string","char","UCHAR","WORD"
|
|
,"UINT","ULONG"};
|
|
int nDataTypeLen[]={0,4,2,4,4,8,1,1,1,2,4,4};
|
|
QString cs1,cs2;
|
|
cs2 = QString(QLatin1String(strType)).toUpper();
|
|
int iCode = 4;
|
|
*nDataTypeLen = 4;
|
|
for (int i=0; i<11; i++)
|
|
{
|
|
cs1 = QString(QLatin1String(strDataType[i])).toUpper();
|
|
if ( cs1==cs2)
|
|
{
|
|
iCode = i;
|
|
*nCodeLen = nDataTypeLen[i];
|
|
break;
|
|
}
|
|
}
|
|
return iCode;
|
|
};
|
|
|
|
bool WriteWLD()
|
|
{
|
|
QString filename;
|
|
filename=PathName+WellName+".wld";
|
|
FILE *fp=fopen(filename.toStdString().c_str(),"w+b");
|
|
if(!fp)
|
|
{
|
|
QMessageBox::information(NULL,"提示","产生文件"+filename+"产生文件失败");
|
|
return 0;
|
|
}
|
|
//将动静态信息转换成wsm、wdm
|
|
//给静态信息赋值
|
|
strncpy(wsm.region,FILE_MESSAGE.AreaName,32);
|
|
strncpy(wsm.oil_company,FILE_MESSAGE.OilCompanyName,32);
|
|
strncpy(wsm.name,FILE_MESSAGE.WellName,32);
|
|
QString temp = ::GetConfPath()+"data.ini";
|
|
QSettings settings(temp,QSettings::IniFormat,0);
|
|
settings.setIniCodec(QTextCodec::codecForName("UTF-8"));
|
|
QStringList serials=settings.value("wellType",0).toStringList();
|
|
int i=serials.indexOf(FILE_MESSAGE.WellType);
|
|
if(i>=serials.size()) i=serials.size()-1;
|
|
if(i<0) i=0;
|
|
if(i<serials.size()-1) strcpy(FILE_MESSAGE.WellType,serials[i].toStdString().c_str());
|
|
strcpy(wsm.type,FILE_MESSAGE.WellType);
|
|
wsm.x_coor=FILE_MESSAGE.Xcoor;
|
|
wsm.y_coor=FILE_MESSAGE.Ycoor;
|
|
wsm.height=ConvertDataByFloat(FILE_MESSAGE.Kelly).toFloat();
|
|
for (int i=0; i<5; i++)
|
|
{
|
|
sscanf(FILE_MESSAGE.Prog,"%f %f",&wsm.bit_program[i][0],&wsm.bit_program[i][1]);
|
|
// sscanf(FILE_MESSAGE.[i],"%f %f",&wsm.case_program[i][0],&wsm.case_program[i][1]);
|
|
}
|
|
//给动态信息赋值:WellDynamicInfo
|
|
strncpy(wdm.log_company,FILE_MESSAGE.LogCompanyName,40);
|
|
QString str=ctime((time_t *)&FILE_MESSAGE.LoggingDate);
|
|
|
|
strncpy(wdm.log_date,str.toStdString().c_str(),12);
|
|
strncpy(wdm.log_series,FILE_MESSAGE.LoggingSerial,16);
|
|
strncpy(wdm.log_team,FILE_MESSAGE.LoggingTeam,16);
|
|
strncpy(wdm.log_project,FILE_MESSAGE.YqType,16);
|
|
strncpy(wdm.mud_type,FILE_MESSAGE.Mud_Property,12);
|
|
//float WaterLoss;
|
|
wdm.mud_viscosity=FILE_MESSAGE.Mud_Viscosity[0];
|
|
wdm.mud_density=FILE_MESSAGE.Mud_Density[0];
|
|
wdm.mud_resistivity=FILE_MESSAGE.Mud_Resistivity[0] ;
|
|
wdm.bottom_temp=FILE_MESSAGE.Mud_Temp;
|
|
//pctosun
|
|
// 井位的大地坐标
|
|
wsm.x_coor = ReverseFloat(wsm.x_coor);
|
|
wsm.y_coor = ReverseFloat(wsm.x_coor);
|
|
// 井的补心高度
|
|
wsm.height = ReverseFloat(wsm.height);
|
|
for ( int i=0;i<5; i++)
|
|
{
|
|
// 钻头程序
|
|
wsm.bit_program[i][0] = ReverseFloat(wsm.bit_program[i][0]);
|
|
wsm.bit_program[i][1] = ReverseFloat(wsm.bit_program[i][1]);
|
|
// 套管程序
|
|
wsm.case_program[i][0] = ReverseFloat(wsm.case_program[i][0]);
|
|
wsm.case_program[i][1] = ReverseFloat(wsm.case_program[i][1]);
|
|
}
|
|
wdm.log_times = ReverseInt(wdm.log_times); // 测井次数
|
|
wdm.stdep = ReverseFloat(wdm.stdep);
|
|
wdm.endep =ReverseFloat(wdm.endep ); // 测量井段的起始深度和结束深度
|
|
wdm.bottom_temp = ReverseFloat(wdm.bottom_temp); // 井底温度
|
|
wdm.mud_viscosity = ReverseFloat(wdm.mud_viscosity); // 泥浆粘度
|
|
wdm.mud_density = ReverseFloat(wdm.mud_density); // 泥浆密度
|
|
wdm.mud_resistivity = ReverseFloat(wdm.mud_resistivity); // 泥浆电阻率
|
|
|
|
/* write head */
|
|
int len=32+sizeof(WSM)+sizeof(WDM);
|
|
WldFileHead wld;
|
|
fseek(fp,0L,0);
|
|
strcpy(wld.flag,WLD_FILE_FLAG);
|
|
wld.length=ReverseInt(1);
|
|
fwrite((char *)&wld, 32,1,fp );
|
|
fseek(fp,32L,0);
|
|
fwrite(&wsm, sizeof(wsm) ,1 , fp );
|
|
fwrite(&wsm, sizeof(wdm) ,1 , fp );
|
|
fclose(fp);
|
|
return 1;
|
|
};
|
|
bool WriteI1D()
|
|
{
|
|
QString filename;
|
|
filename=PathName+WellName+".i1d";
|
|
FILE *fp=fopen(filename.toStdString().c_str(),"w+b");
|
|
if(!fp)
|
|
{
|
|
QMessageBox::information(NULL,"提示","产生文件"+filename+"产生文件失败");
|
|
return 0;
|
|
}
|
|
/* write head */
|
|
//int len=32;
|
|
WldFileHead i1d;
|
|
fseek(fp,0L,0);
|
|
strcpy(i1d.flag,I1D_FILE_FLAG);
|
|
i1d.length=ReverseInt(num1d);
|
|
fwrite(&i1d, sizeof(WldFileHead) ,1 , fp );
|
|
fseek(fp,32L,0);
|
|
for(int i=0;i<num1d;i++)
|
|
{
|
|
c1d[i].address = ReverseInt(c1d[i].address);
|
|
c1d[i].sdepth = ReverseFloat(c1d[i].sdepth);
|
|
c1d[i].edepth = ReverseFloat(c1d[i].edepth);
|
|
c1d[i].dstep = ReverseFloat(c1d[i].dstep);
|
|
fwrite(&c1d[i],sizeof(CurveIndex1d),1,fp);
|
|
}
|
|
fclose(fp);
|
|
return 1;
|
|
};
|
|
bool WriteI2D()
|
|
{
|
|
QString filename;
|
|
filename=PathName+WellName+".i2d";
|
|
FILE *fp=fopen(filename.toStdString().c_str(),"w+b");
|
|
if(!fp)
|
|
{
|
|
QMessageBox::information(NULL,"提示","产生文件"+filename+"产生文件失败");
|
|
return 0;
|
|
}
|
|
/* write head */
|
|
WldFileHead i2d;
|
|
fseek(fp,0L,0);
|
|
strcpy(i2d.flag,I2D_FILE_FLAG);
|
|
i2d.length=ReverseInt(num2d);
|
|
fwrite(&i2d, sizeof(WldFileHead) ,1 , fp );
|
|
fseek(fp,32L,0);
|
|
for(int i=0;i<num2d;i++)
|
|
{
|
|
c2d[i].address = ReverseInt(c2d[i].address);
|
|
c2d[i].sdepth = ReverseFloat(c2d[i].sdepth);
|
|
c2d[i].edepth = ReverseFloat(c2d[i].edepth);
|
|
c2d[i].dstep = ReverseFloat(c2d[i].dstep);
|
|
c2d[i].stime = ReverseFloat(c2d[i].stime);
|
|
c2d[i].etime = ReverseFloat(c2d[i].etime);
|
|
c2d[i].tstep = ReverseFloat(c2d[i].tstep);
|
|
fwrite(&c2d[i],sizeof(CurveIndex2d),1,fp);
|
|
}
|
|
fclose(fp);
|
|
return 1;
|
|
};
|
|
|
|
};
|
|
|