⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wellfile.cpp

📁 采用距离反比加权算法
💻 CPP
字号:
// WellFile.cpp: implementation of the CWellFile class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Test.h"
#include "WellFile.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CWellFile::CWellFile()
{
  m_nIndex=-1;
  m_nScale=1;
  m_bSelected=FALSE;
}

CWellFile::~CWellFile()
{

}
BOOL CWellFile::GetHead(CString strFileName)
{

	if(!FileExists(strFileName))
		return FALSE;
	
	CStdioFile file;
    CFileException e;
	
	if(!file.Open(strFileName,CFile::modeRead,&e))
	{
      #ifdef _DEBUG
		afxDump << "File could not be opened " << e.m_cause << "\n";
      #endif
		
	}

	file.ReadString (m_strV);
	file.ReadString(m_strVERS);
	file.ReadString(m_strWRAP);
	file.ReadString(m_strVEND);
	file.ReadString (m_strW);
	file.ReadString(m_strSTRT);
	file.ReadString(m_strSTOP);
	file.ReadString(m_strSTEP);
	file.ReadString (m_strNULL);
	file.ReadString(m_strWELL);
	file.ReadString(m_strCOMP);
	file.ReadString(m_strUWI);
	file.ReadString (m_strFLD);
	file.ReadString(m_strCNTY);
	file.ReadString(m_strSTAT);
	file.ReadString(m_strCTRY);
	file.ReadString (m_strPROV);
	file.ReadString(m_strSRVC);
	file.ReadString(m_strPDAT);
	file.ReadString(m_strLMF);
	file.ReadString(m_strDMF);
	file.ReadString (m_strLOC1);
	file.ReadString(m_strLOC2);
	file.ReadString(m_strLOC3);
	file.ReadString(m_strSEC);
	file.ReadString (m_strTWP);
	file.ReadString(m_strRAN);
	file.ReadString(m_strLOC);
	file.ReadString(m_strDATE);
	
	
	//分离井位的起点、终点、步长、无效值及井名
	
	m_strSTRT=GetLeftSplit(GetRightSplit(m_strSTRT," "),":");
	m_strSTOP=GetLeftSplit(GetRightSplit(m_strSTOP," "),":");
	m_strSTEP=GetLeftSplit(GetRightSplit(m_strSTEP," "),":");
	m_strWELL=GetLeftSplit(GetRightSplit(m_strWELL," "),":");
	m_strNULL=GetLeftSplit(GetRightSplit(m_strNULL," "),":");
	
	m_dbStart=atof(m_strSTRT);
	m_dbStop=atof(m_strSTOP);
	m_dbStep=atof(m_strSTEP);
	m_dbNull=atof(m_strNULL);
	
	//读取物性(类别)
	CString strC,strSplitter,strSplitterD;
	
	file.ReadString(strC);
	
	file.ReadString(strC);
	
	while(strC!="~P")
	{
		strSplitter=GetLeftSplit(strC,".");
		m_strArray.Add(strSplitter);
		
		file.ReadString(strC);
	}
	
	file.ReadString(m_strEKB);
	file.ReadString(m_strEDF);
	file.ReadString(m_strEGL);
	file.ReadString(m_strEPD);
	file.ReadString(m_strAPD);
	file.ReadString(m_strLAT);
	file.ReadString(m_strLONG);
	file.ReadString(m_strA);
	
	//分离出x、y值(经度与纬度)
	m_strLAT=GetLeftSplit(GetRightSplit(m_strLAT," "),":");
	m_strLONG=GetLeftSplit(GetRightSplit(m_strLONG," "),":");
    m_strEKB=GetLeftSplit(GetRightSplit(m_strEKB," "),":");

	m_dbY=atof(m_strLAT);              
	m_dbX=atof(m_strLONG);
    m_dbZ=atof(m_strEKB);
	
	file.Close();
	
	return TRUE;
}
BOOL CWellFile::FileExists(CString strFileName)
{
	CFileFind fFind;
	if (!fFind.FindFile(strFileName))
		return FALSE;
	
	return TRUE;
}
CString CWellFile::GetLeftSplit(CString strLine,CString strSplt)
{
	int nIndex = GetInStrIndex(strLine,strSplt);
	CString strRet;
	if(nIndex>=0)
		strRet = strLine.Left (nIndex);
	else
		strRet = strLine;
	
	return strRet;
}

CString CWellFile::GetRightSplit(CString strLine,CString strSplt)
{
	int nLen = strLine.GetLength();
	int nIndex = GetInStrIndex(strLine,strSplt);
	CString strRet;
	if(nIndex>=0)
		strRet = strLine.Right (nLen - nIndex - 1);
	
	return strRet;
}
int CWellFile::GetInStrIndex(CString& str,CString strSet)
{
	char* pMs =(char *)(LPCTSTR)str;
	int nLen = str.GetLength();
	for (int i=0;i<nLen;i++)
	{
		int nIndex = strSet.Find (*pMs);
		if (nIndex>=0)
			return i;
		
		pMs++;
	}
	return -1;
}
BOOL CWellFile::GetBody()
{
	if(!FileExists(m_strFilePath))
		return FALSE;

	if(m_nIndex==-1)
		return FALSE;
	
	
	CStdioFile file;
    CFileException e;
	
	if(!file.Open(m_strFilePath,CFile::modeRead,&e))
	{
#ifdef _DEBUG
		afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
		
	}
     
	CString strContent="";

	while(strContent!="~A")
	{
		file.ReadString(strContent);	
	}
	
	CString       strUnit;
	CStringArray  strUnitArray;
    m_dbTempArray.RemoveAll();
    CString       strValue;
	double        dbValue;
    file.ReadString(strUnit);
	
	while(strUnit!="")
	{
		
		int nCount=GetSplitArray(strUnit," ",strUnitArray);
		
		for(int i=0;i<nCount;i++)
		{
			strValue=GetLeftSplit(strUnitArray[i]," ");
			
			dbValue=atof(strValue);
			m_dbTempArray.Add(dbValue);
			
		}
		
		file.ReadString(strUnit);
		
	}
    file.Close();

///////////////////////提取有效值///////////////////////////////////
	int nPro=m_strArray.GetSize()*m_nScale;
    int nTempCount=m_dbTempArray.GetSize();

	if(nTempCount<1)
		return FALSE;
    int nIndex=0;
	while (nIndex<nTempCount) 
	{
		point pt;
		pt.z=m_dbTempArray.GetAt(nIndex);
		pt.v=m_dbTempArray.GetAt(nIndex+m_nIndex);
		if(fabs(pt.v-m_dbNull)>0.1)
		   m_pointArray.Add(pt);
		nIndex+=nPro;
	}
	
	return TRUE;
}
BOOL CWellFile::PropCurrentExist(CString strProp)
{

	int nCount=m_strArray.GetSize();

	for(int i=0;i<nCount;i++)
	{
      CString str=m_strArray.GetAt(i);

	  if(str==strProp)
	  {
		  m_nIndex=i;
		  return TRUE;
	  }
	  
	}
	return FALSE;
}
int CWellFile::GetSplitArray(CString strLine,CString strSplt,CStringArray& arraySplt)
{
	int nLen = strLine.GetLength();
	
	char* pchar = new char[nLen+1];
	strcpy(pchar,strLine);
	
	char* psplt = (char *)(LPCTSTR)strSplt;
	char* punit = NULL;
	
	punit = strtok(pchar,psplt);
	
	CString strUnit;
	arraySplt.RemoveAll();
	
	while(punit != NULL)
	{
		strUnit = punit;
		arraySplt.Add (strUnit);
		
		punit = strtok(NULL,psplt);
	}
	
	delete pchar;
	
	return arraySplt.GetSize();
}
void CWellFile::Clear()
{
  m_dbTempArray.RemoveAll();
  m_pointArray.RemoveAll();
  m_nIndex=-1;
  m_bSelected=FALSE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -