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

📄 wshm.cpp

📁 提供交互的方式选取合适的震相
💻 CPP
字号:
// wshm.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "wshm.h"

#include <list>
#include <string>
#include <iterator>
#include <fstream>

using namespace std;

#include "MainFrm.h"
#include "wshmDoc.h"
#include "wshmView.h"

#include "../SacIO/SacIO.h"
#include "../iasp91/iasp.h"
#include "CBrowserDir.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWshmApp

BEGIN_MESSAGE_MAP(CWshmApp, CWinApp)
	//{{AFX_MSG_MAP(CWshmApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_APP_IASP91PATH, OnAppIasp91path)
	ON_COMMAND(ID_FILE_CREATELIST, OnFileCreatelist)
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWshmApp construction

CWshmApp::CWshmApp()
{
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CWshmApp object

CWshmApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CWshmApp initialization

BOOL CWshmApp::InitInstance()
{

	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("wshm"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)
	
	CString strValue;

	strValue = GetProfileString("SKS", "IASP91PATH");
	if( strValue.IsEmpty() )
		SetModPath("E:/ShearWaveSplit/wshm/iasp91");
	else
		SetModPath( LPCTSTR(strValue) );

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CWshmDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CWshmView));
	AddDocTemplate(pDocTemplate);
	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();

	return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
		// No message handlers
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CWshmApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CWshmApp message handlers

bool CWshmApp::SelectForder(const char * title, char* path) {
	BROWSEINFO bw;
	ITEMIDLIST* il;
	memset(&bw, 0, sizeof(BROWSEINFO));
	bw.hwndOwner = NULL;
	bw.lpszTitle = title;
	il = SHBrowseForFolder(&bw);
	if( il == NULL)
	{
		return false;
	}

	SHGetPathFromIDList(il, path);

	return true;

}
void CWshmApp::OnAppIasp91path() 
{
	CFileDialog dlg(true, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_FILEMUSTEXIST, 
		"IASP91模型文件(*.TBL)|*.TBL||");

	dlg.m_ofn.lpstrTitle = "定位IASP91模型文件路径";

	if( dlg.DoModal() == IDOK ) {
		CString pathname = dlg.GetPathName();
		pathname = pathname.Left(pathname.GetLength() - 4);

		SetModPath(pathname.GetBuffer(pathname.GetLength()));
			
		WriteProfileString("SKS", "IASP91PATH", pathname);
	}
}

void CWshmApp::OnFileCreatelist() 
{
	CFileDialog dlgOut(true, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_FILEMUSTEXIST, 
		"文件名列表文件(*.nam)|*.nam||");
	string strStationFileList("e:/itpcas/indepth/stationList.nam");
	char stationRootPath[MAX_PATH];

	dlgOut.m_ofn.lpstrTitle = "将文件名列表保存为";
	if( dlgOut.DoModal() == IDOK ) {
		CString strOut = dlgOut.GetPathName();
		strOut.Replace('\\','/');
		strStationFileList = strOut;

		memset( stationRootPath, 0, MAX_PATH);
		if( SelectForder("定位数据文件路径", stationRootPath) ) {
			CBrowserDir Browser(stationRootPath);
			Browser.WriteDirListFile(strStationFileList.c_str());

			//打开台站数据文件列表,查找所有符合条件的文件
			FILE * infp = fopen(strStationFileList.c_str(), "rt");

			if( NULL == infp )
				return;

			char strtmp[MAX_PATH];
			list<string> allStationFiles;
			while( !feof(infp) ) {
				fscanf(infp, "%s", strtmp);
				if( strlen(strtmp) )
					allStationFiles.push_back(strtmp);
			}
			fclose(infp);
			
			list<string>::iterator iter = allStationFiles.begin();
			CSacFile sacFile;
			struct sac_header * pSacHead;
			ofstream outfp(strStationFileList.c_str(), ios::out);

			if( NULL == outfp.is_open() )
				return ;
			
			while( iter != allStationFiles.end() ) {
				sacFile.ReadHead(iter->c_str());
				pSacHead = sacFile.GetHead();

				if( pSacHead->gcarc < 85 || pSacHead->gcarc > 120 ) {
					// 震中距不在85-120度之间
					++iter;
					continue;
				}

				outfp<<iter->c_str()<<endl;
				
				++iter;
			}
			outfp.close();
		
			CString tmp;
			tmp = "成功输出震中距在85-120度之间文件名列表:";
			tmp += strStationFileList.c_str();
			AfxMessageBox( tmp, MB_ICONINFORMATION | MB_OK );
		}	
	}
}

⌨️ 快捷键说明

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