// SeismicFile.cpp: implementation of the CSeismicFile class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DlgShowProgress.h"
#include <math.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// 地震数据文件
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SERIAL(CSeismicFile,CObject,1)
CSeismicFile::CSeismicFile()
{
m_nSamples = 0;
m_fltSampleInterval = 0.0f;
m_nFileType = ShotFileTypeUnknown;
m_uFileHeadLen = 0;
m_uTraceHeadLen = 0;
m_uTraceDataLen = 0;
m_nDataFormat = SampleDataFormatUnknown;
m_nDataBits = 0;
m_hFile = INVALID_HANDLE_VALUE;
m_pTraceBuffer = NULL;
m_strPath="";
}
CSeismicFile::~CSeismicFile()
{
Close();
}
void CSeismicFile::Serialize(CArchive &ar)
{
CObject::Serialize(ar);
if (ar.IsStoring())
{
ar<<m_strFileName<<m_nSamples<<m_fltSampleInterval;
ar<<m_nFileType<<m_uFileHeadLen<<m_uTraceHeadLen<<m_uTraceDataLen;
ar<<m_nDataFormat<<m_nDataBits<<m_bRevByte<<m_fltStartTime;
}
else
{
ar>>m_strFileName>>m_nSamples>>m_fltSampleInterval;
ar>>m_nFileType>>m_uFileHeadLen>>m_uTraceHeadLen>>m_uTraceDataLen;
ar>>m_nDataFormat>>m_nDataBits>>m_bRevByte>>m_fltStartTime;
}
}
CSeismicFile* CSeismicFile::CreateSeismicFile(int nFileType)
{
CSeismicFile *pFile = NULL;
switch(nFileType)
{
case ShotFileTypeGrisys:
pFile = new CFileGrisys;
break;
case ShotFileTypeSegY:
pFile = new CFileSegY;
break;
case ShotFileTypeSegD:
pFile = new CFileSegD;
break;
///xulj add
case ShotFileTypeSegY_NoFileHead:
pFile = new CFileSegY_NoFileHead;
break;
default:
break;
}
return pFile;
}
BOOL CSeismicFile::LoadSeismicFile(CSeismicAgent *pSeismicAgent,CString &strFileName,CStringArray &strPrompts)
{
CSeismicFile *pFile = NULL;
//xulj for (int i= ShotFileTypeSegD;i<=ShotFileTypeSegY;i++)
for (int i= ShotFileTypeSegD;i<=ShotFileTypeSegY_NoFileHead;i++)
{
pFile = CreateSeismicFile(i);
if (pFile->ReadSeismicFile(pSeismicAgent,strFileName,strPrompts))
return TRUE;
else
delete pFile;
}
CString strPromptInfo;
strPromptInfo.Format("不能识别文件(%s)的记录格式,忽略该文件\n\n",strFileName);
strPrompts.Add(strPromptInfo);
return FALSE;
}
BOOL CSeismicFile::CloneSeismicShot(CSeismicShot *pSeismicShot,CString &strFileName)
{
ASSERT(pSeismicShot->m_pSeismicFile == this);
BOOL bOpenFlag = Open();
if (!bOpenFlag)
{
TRACE("不能打开原始数据文件\n");
return FALSE;
}
HANDLE hFile = ::CreateFile(strFileName,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_RANDOM_ACCESS,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
TRACE("不能创建克隆文件\n");
return FALSE;
}
UINT uTraceLen = m_uTraceHeadLen + m_uTraceDataLen;
DWORD dwBufSize = (uTraceLen > m_uFileHeadLen)?uTraceLen:m_uFileHeadLen;
BYTE *pBuffer = new BYTE[dwBufSize];
if (pBuffer == NULL)
{
TRACE("分配内存失败\n");
CloseHandle(hFile);
return FALSE;
}
DWORD dwRead,dwWritten;
BOOL bWrite,bRead;
// 读写文件头
if (m_uFileHeadLen > 0)
{
dwRead = ReadFileHeader(pBuffer);
if (dwRead == (DWORD)-1)
{
TRACE("读取文件头失败\n");
CloseHandle(hFile);
delete[] pBuffer;
return FALSE;
}
bWrite = ::WriteFile(hFile,pBuffer,m_uFileHeadLen,&dwWritten,NULL);
if (!bWrite || dwWritten != m_uFileHeadLen)
{
TRACE("写文件头失败\n");
CloseHandle(hFile);
delete[] pBuffer;
return FALSE;
}
}
// 读写整道
int nTotalTraceNum = pSeismicShot->GetTotalTraceNum();
__int64 liReadStartPos = pSeismicShot->GetStartPosInSeismic();
if (!SetFilePointerEx(m_hFile,liReadStartPos))
{
CloseHandle(hFile);
delete[] pBuffer;
return FALSE;
}
for (int i=0;i<nTotalTraceNum;i++)
{
bRead = ::ReadFile(m_hFile,pBuffer,uTraceLen,&dwRead,NULL);
if (!bRead || dwRead != uTraceLen)
{
CloseHandle(hFile);
delete[] pBuffer;
return FALSE;
}
bWrite = ::WriteFile(hFile,pBuffer,uTraceLen,&dwWritten,NULL);
if (!bWrite || dwWritten != uTraceLen)
{
CloseHandle(hFile);
delete[] pBuffer;
return FALSE;
}
}
delete[] pBuffer;
::CloseHandle(hFile);
return TRUE;
}
BOOL CSeismicFile::CreateSeismicShotFrame(CSeismicShot *pSeismicShot,CString &strFileName)
{
// 为了简化格式转换,固定采用IEEEFLOAT格式生成新数据
if (m_nDataFormat == SampleDataFormatIEEEFLOAT32)
return CloneSeismicShot(pSeismicShot,strFileName);
// 如果是其它格式,需要转换格式代码
else
{
BOOL bOpenFlag = Open();
if (!bOpenFlag)
{
TRACE("不能打开文件\n");
return FALSE;
}
HANDLE hFile = ::CreateFile(strFileName,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_RANDOM_ACCESS,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
TRACE("不能创建文件\n");
return FALSE;
}
DWORD dwBufSize = (m_uTraceHeadLen > m_uFileHeadLen)?m_uTraceHeadLen:m_uFileHeadLen;
BYTE *pBuffer = new BYTE[dwBufSize];
if (pBuffer == NULL)
{
CloseHandle(hFile);
return FALSE;
}
DWORD dwRead,dwWritten;
BOOL bWrite;
// 读写文件头
if (m_uFileHeadLen > 0)
{
dwRead = ReadFileHeader(pBuffer);
if (dwRead == (DWORD)-1)
{
CloseHandle(hFile);
delete[] pBuffer;
return FALSE;
}
// 修改文件头中数据格式
ModifyDataFormatFromFileHead(pBuffer);
bWrite = ::WriteFile(hFile,pBuffer,m_uFileHeadLen,&dwWritten,NULL);
if (!bWrite || dwWritten != m_uFileHeadLen)
{
CloseHandle(hFile);
delete[] pBuffer;
return FALSE;
}
}
// 读写道头
int nTotalTraceNum = pSeismicShot->GetTotalTraceNum();
__int64 liReadStartPos = pSeismicShot->GetStartPosInSeismic();
__int64 liWriteStartPos = m_uFileHeadLen;
for (int i=0;i<nTotalTraceNum;i++)
{
dwRead = ReadTraceHeader(liReadStartPos,i,pBuffer);
if (dwRead == (DWORD)-1)
{
CloseHandle(hFile);
delete[] pBuffer;
return FALSE;
}
// 修改道头中数据格式
ModifyDataFormatFromTraceHead(pBuffer);
if (!SetFilePointerEx(hFile,liWriteStartPos))
{
CloseHandle(hFile);
delete[] pBuffer;
return FALSE;
}
bWrite = ::WriteFile(hFile,pBuffer,m_uTraceHeadLen,&dwWritten,NULL);
if (!bWrite || dwWritten != m_uTraceHeadLen)
{
CloseHandle(hFile);
delete[] pBuffer;
return FALSE;
}
liWriteStartPos += m_nSamples*sizeof(float)+m_uTraceHeadLen;
}
delete[] pBuffer;
::CloseHandle(hFile);
return TRUE;
}
return TRUE;
}
CString& CSeismicFile::GetFileName()
{
CFileFind find;
if (!find.FindFile(m_strFileName))
{
int nLen=m_strFileName.ReverseFind('\\');
if (nLen!=-1)
m_strFileName=m_strFileName.Right(m_strFileName.GetLength()-m_strFileName.ReverseFind('\\'));
m_strFileName=m_strPath+m_strFileName;
}
return m_strFileName;
}
BOOL CSeismicFile::Open(BOOL bWritable)
{
if (IsOpen())
return TRUE;
m_hFile = ::CreateFile(m_strFileName,
bWritable?GENERIC_READ|GENERIC_WRITE:GENERIC_READ,
bWritable?FILE_SHARE_READ|FILE_SHARE_WRITE:FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_RANDOM_ACCESS,
NULL);
if (m_hFile != INVALID_HANDLE_VALUE)
{
UINT uTraceLen = m_uTraceHeadLen+m_uTraceDataLen;
if (uTraceLen > 0)
AllocTraceBuffer();
return TRUE;
}
else
{
int nLen=m_strFileName.ReverseFind('\\');
if (nLen!=-1)
m_strFileName=m_strFileName.Right(m_strFileName.GetLength()-m_strFileName.ReverseFind('\\'));
m_strFileName=m_strPath+m_strFileName;
m_hFile = ::CreateFile(m_strFileName,
bWritable?GEN
weixin_38744207
- 粉丝: 344
- 资源: 2万+
最新资源
- 精选项目-外卖搭伴拼团php后端.zip
- 精选项目-音乐播放器带后端.zip
- 精选项目-游轮中心带后端.zip
- 精选项目-云商城(带php后端).zip
- 单目相机+投影仪标定算法,C++语言,可同时进行相机标定与投影仪标定,标定结果以yml文件格式进行输出 非matlab工具箱 重投影误差均在0.1个像素内
- 线上辅导班系统(代码+数据库+LW)
- 永磁同步电机转速滑模控制Matlab simulink仿真模型,参数已设置好,可直接运行 属于PMSM转速电流双闭环矢量控制系统 电流内环采用PI控制器,转速外环采用滑模控制 波形完美,包含原理
- 锐捷办公云桌面-资料包
- 计算机视觉深度修复领域的创新模型DepthLab及其应用
- 基于Opencv和Python的车道线检测系统(带UI界面) 在自动驾驶中,让汽车保持在车道线内是非常重要的,所以这次我们来说说车道线的检测 我们主要用到的是openCV, numpy, matpl
- openssh-9.8p1 RPM安装包
- openssl 1.1.1s RPM安装包
- 基于长短期记忆网络算法LSTM的时间序列预测 单输入单输出预测 代码含详细注释,不负责 数据存入Excel,替方便,指标计算有决定系数R2,平均绝对误差MAE,平均相对误差MBE
- stm32 远程升级 OTA升级 使用WIFI连接升级 芯片 stm32f103系列 升级方式:wifi模块?自建服务器 升级文件为BIN文件,需要使用配套的exe文件将原来的bin文件内的数据,每隔
- 融合A*改进RRT算法的路径规划代码仿真 全局路径规划 - RRT算法原理 RRT算法,即快速随机树算法(Rapid Random Tree),是LaValle在1998年首次提出的一种高效的路径规划
- foc 基于stm32 弦波无刷电机控制资料 源码 带video教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0