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

📄 dlgtyphoon.cpp

📁 中央气象台与日本台风数据之间的格式转换程序
💻 CPP
字号:
// DlgTyphoon.cpp : implementation file
//

#include "stdafx.h"
#include "DataDispose.h"
#include "DataBuffer.h"
#include "DlgTyphoon.h"
#include "EvsDlgPathSelect.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgTyphoon dialog


CDlgTyphoon::CDlgTyphoon(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgTyphoon::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgTyphoon)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgTyphoon::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgTyphoon)
	DDX_Control(pDX, IDC_EDT_SDIR, m_edtSDir);
	DDX_Control(pDX, IDC_EDT_DDIR, m_edtDDir);
	DDX_Control(pDX, IDC_LST_FILES, m_lstFiles);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgTyphoon, CDialog)
	//{{AFX_MSG_MAP(CDlgTyphoon)
	ON_BN_CLICKED(IDC_BTN_BROWSE1, OnBtnBrowse1)
	ON_BN_CLICKED(IDC_BTN_BROWSE2, OnBtnBrowse2)
	ON_BN_CLICKED(ID_BTN_DISPOSE, OnBtnDispose)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgTyphoon message handlers

void CDlgTyphoon::OnBtnBrowse1() 
{
	CEvsDlgPathSelect dlgPathSelect;
	CString csDir; 
	m_edtSDir.GetWindowText(csDir); 
	if ( csDir == _T("") )
		csDir = "d:\\";
	dlgPathSelect.m_csPath = csDir;
	
	if (IDOK == dlgPathSelect.DoModal())
	{
		m_edtSDir.SetWindowText(dlgPathSelect.m_csPath);
		ListSearchFiles (dlgPathSelect.m_csPath, "*.txt");
		UpdateData(FALSE);
		
	}
	
}

void CDlgTyphoon::OnBtnBrowse2() 
{
	CEvsDlgPathSelect dlgPathSelect;
	CString csDir; 
	m_edtDDir.GetWindowText(csDir); 
	if ( csDir == _T("") )
		csDir = "d:\\";
	dlgPathSelect.m_csPath = csDir;
	
	if (IDOK == dlgPathSelect.DoModal())
	{
		m_edtDDir.SetWindowText(dlgPathSelect.m_csPath);
		UpdateData(FALSE);
		
	}	
	
}

void CDlgTyphoon::OnBtnDispose() 
{
	char szSourceFileName[_MAX_PATH] = "";
    char szDistFileName[_MAX_PATH] = "";
	CString csSDir,csDDir,csFileTitle;
	
	m_edtSDir.GetWindowText(csSDir);
	m_edtDDir.GetWindowText(csDDir);
	if ( csDDir == _T("") )
		csDDir = csSDir;
	for ( int i = 0 ; i < m_lstFiles.GetCount() ; i++ )
	{	
		memset(szSourceFileName , 0 , _MAX_PATH);
        memset(szDistFileName , 0 , _MAX_PATH);
	    m_lstFiles.GetText(i , csFileTitle);
		strcpy(szSourceFileName , csSDir.GetBuffer(csSDir.GetLength()));
		strcat(szSourceFileName ,"\\");
		strcat(szSourceFileName , csFileTitle.GetBuffer(csFileTitle.GetLength()));
		strcat(szSourceFileName , ".txt");
		strcpy(szDistFileName , csDDir.GetBuffer(csDDir.GetLength()));
		strcat(szDistFileName ,"\\");
		strcat(szDistFileName , csFileTitle.GetBuffer(csFileTitle.GetLength()));
		strcat(szDistFileName , ".typ");
		DisposeData(szSourceFileName, szDistFileName);
	}
	
}
void CDlgTyphoon::DisposeData(CString csSourceFileName , CString csDistFileName)
{
	int nPos,nFlag;
	CStdioFile fd,fdDist;
	CString csValue,csValue1,csTemp,csHeader;
	
	//CDataBuffer buff;
	nFlag = 0;
	fdDist.Open(csDistFileName , CFile::modeCreate  | CFile::modeReadWrite);
	if (fdDist.m_hFile == NULL )
		return;
	fd.Open(csSourceFileName , CFile::modeRead);
	if ( fd.m_hFile != NULL )
    {
		/*while( fd.ReadString(csValue) )
			buff.AddString(csValue); 
		buff.OutputData(csDistFileName);*/
		while( fd.ReadString(csValue) )
        {
			nPos = csValue.Find("6666",0 );
			if ( nPos != -1 )
            {
				if ( nFlag != 0 )
					fdDist.WriteString("#1899-12-30#,0,0,0,0,0,0,0,0,0\n");
				else
					nFlag = 1;
				csTemp = csValue.Right(8);
                csTemp = csTemp.Left(4); 
				csHeader = csTemp.Left(2);
				csValue = csValue.Left(csValue.GetLength()- 8);
				csValue.TrimRight(" ");
				csValue = csValue.Right(20); 
				csValue.TrimLeft(" ");
				
								 
				fdDist.WriteString("\"");
				fdDist.WriteString("West Pacific");
				fdDist.WriteString("\",");
				fdDist.WriteString("\"");
				fdDist.WriteString(csValue);
				fdDist.WriteString("\",");
				fdDist.WriteString(csTemp);
				fdDist.WriteString(",\"");
				fdDist.WriteString("中央气象台");
				fdDist.WriteString("\",");
				fdDist.WriteString("\"");
				fdDist.WriteString("Finish");
				fdDist.WriteString("\"\n");	
                 
			}
			else
            {
				//分析数据
				csValue.TrimRight(); 
				csValue1 = "";
				csValue1 = "#" + csHeader + csValue.Left(2) +"-" +  csValue.Mid(2,2) + "-" ;
                csValue1 = csValue1 + csValue.Mid(4,2) + " " + csValue.Mid(6,2) +":00:00#,";
                csTemp = csValue.Mid(15,3);
				csTemp.TrimRight(); 
				float fLat = atoi(csTemp.GetBuffer(csTemp.GetLength())) / 10.0;
				csTemp.Format("%.1f",fLat);
				csValue1 = csValue1 + csTemp + ",";
                
				csTemp = csValue.Mid(19,4);
				csTemp.TrimRight(); 
				float fLon = atoi(csTemp.GetBuffer(csTemp.GetLength())) / 10.0;
				csTemp.Format("%.1f",fLon);
				csValue1 = csValue1 + csTemp + ",";

				csTemp = csValue.Mid(24,4);
				csTemp.TrimRight(); 
				csValue1 = csValue1 + csTemp + ",";
				
				if ( csValue.GetLength() <= 42 )
					csValue1 = csValue1 + "000,000,0,0,0";
				else
				{
					csTemp = csValue.Mid(43,3);
					csTemp.TrimRight(); 
					for ( int i = 0 ; i < 3- csTemp.GetLength() ; i++ )
						csTemp = "0" + csTemp;
					csValue1 = csValue1 + csTemp + ",";

					csTemp = csValue.Mid(54,3);
					csTemp.TrimRight(); 
					csValue1 = csValue1 + csTemp + ",";
					csValue1 = csValue1 + "0,0,0";
                 
				}
                fdDist.WriteString(csValue1); 
				fdDist.WriteString("\n");

			}


		}
		fdDist.WriteString("#1899-12-30#,0,0,0,0,0,0,0,0,0\n");
		fdDist.Close();
		fd.Close();
	}	


}

BOOL CDlgTyphoon::ListSearchFiles (const char* pszDataPath,const char* pszShortFileName)
									  
{
	//Clear the list
	m_lstFiles.ResetContent();

	BOOL bOK = FALSE;

	struct _finddata_t	c_file;
	long  hFile = -1;
	
	//Copy Path
	char szSearchFileName[_MAX_PATH] = "";
	strcpy(szSearchFileName, pszDataPath);
	
	strcat(szSearchFileName, "\\");
	strcat(szSearchFileName, pszShortFileName);
	
	hFile = _findfirst( szSearchFileName , &c_file );
	
	if (-1 == hFile) 
		return -1;
	else
	{
		
		//Searched filename
		char szFileName[_MAX_PATH];		
		memset(szFileName, 0, _MAX_PATH);	
		
		CString csFileName;
		csFileName = c_file.name;
		int nPos = csFileName.Find("." , 0); 
		if ( nPos == -1 )
			return -1;
		csFileName = csFileName.Left(nPos); 
			//Platform file object
		//CUmPbsFile cpbsFile;		

		//Get the filename
		//cpbsFile.GetTitle(c_file.name, szFileName);
		
		// Add this filename into the listbox	
		m_lstFiles.AddString(csFileName);
		
		/* Find the rest of the data files */
		while( _findnext( hFile, &c_file ) == 0 )
		{
			//Get the filename
			//memset(szFileName, 0, _MAX_PATH);	
			//cpbsFile.GetTitle(c_file.name, szFileName);
				CString csFileName;
		csFileName = c_file.name;
		int nPos = csFileName.Find("." , 0); 
		if ( nPos == -1 )
			return -1;
		csFileName = csFileName.Left(nPos); 
			// Add this filename into the listbox
			m_lstFiles.AddString(csFileName);
		}
		_findclose( hFile );
	}
	return 1;
}

⌨️ 快捷键说明

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