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

📄 teomdlg.cpp

📁 针对国内环境检测领域
💻 CPP
字号:
// teomDlg.cpp : implementation file
//

#include "stdafx.h"
#include "teom.h"
#include "teomDlg.h"
#include "FECFileDialog.h"
#include "io.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// 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)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CTeomDlg dialog

CTeomDlg::CTeomDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTeomDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTeomDlg)
	m_printfscreen = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTeomDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTeomDlg)
	DDX_Text(pDX, IDC_STATIC1, m_printfscreen);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTeomDlg, CDialog)
	//{{AFX_MSG_MAP(CTeomDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTeomDlg message handlers

BOOL CTeomDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTeomDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTeomDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTeomDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CTeomDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
		int datafileline=0;///////////分别代表临时文件的行数(也就是temptfilename.txt的行数)、TEOM文件的行数
	CString file_tmpcontent;////临时文件的内容
	CString file_TEOMfilepath;///////////TEOM文件的路径,用于写入到临时文件中	    
	CString read_filedata;///读取TEOM文件
	TCHAR douhao=44,fenhao=58,kongge=32;////tab键的ASII码	
	CStdioFile file_createtemptname;////创建临时文件
	CStdioFile file_opentmp;///////再次打开临时文件的路径
	CStdioFile file_savename;//////创建输出文件(out.txt)
    CStdioFile file_read;	//////读取TEOM文件
	CString date;///////////从文件名中提取时间信息
    CString date_tmp1,time_tmp1,time_tmp2,data_tmp1,data_tmp2;
	CString hour_tmp1,min_tmp1,min_tmp2,sec;
	CFECFileDialog fd(TRUE,
		NULL,
		NULL, 
		OFN_ALLOWMULTISELECT | OFN_NODEREFERENCELINKS | OFN_EXPLORER);	
		file_createtemptname.Open("e:\\temptfilename.txt",CFile::modeCreate|CFile::modeWrite,NULL);
		if (fd.DoModal() == IDOK)
		{	 
		   POSITION pos = fd.GetStartPosition();///d得到起始文件的路径
		    while (pos)
			{
			     file_TEOMfilepath=fd.GetNextPathName(pos);//顺延,得到下一个文件的路径
			     file_TEOMfilepath+="\n";
			     file_createtemptname.WriteString(file_TEOMfilepath);///写到临时文件中		
			}
		file_createtemptname.Close();///关闭临时文件
		} 
		else
		{		
			return;		
		}
		///再次打开临时文件	
	     file_opentmp.Open("e:\\temptfilename.txt",CFile::modeRead|CFile::typeText,NULL);///再次打开临时文件		
	     if(!file_opentmp)
		 {          
		      AfxMessageBox("Failed to open file,Exit!!");
		 }
		 ///创建并打开输出文件out.txt
		 /////////////////////在这修改保存的文件名
		 file_savename.Open("e:\\20060228TEOM.txt",CFile::modeCreate|CFile::modeWrite,NULL);
		 while(file_opentmp.ReadString(file_tmpcontent))///读出临时文件中的内容
		 {
             file_tmpcontent=file_tmpcontent.Left(file_tmpcontent.GetLength()-4);///去掉文件名的后缀	
			 file_tmpcontent+=".txt";///加上后缀,得到TEOM文件路径					  					  					  
			 file_read.Open(file_tmpcontent,CFile::modeRead|CFile::typeText,NULL);///依据上面所得到的路径,打开TEOM文件						  
			 while(file_read.ReadString(read_filedata))/////读取TEOM文件内容
			 {
				 date_tmp1=read_filedata.Left(read_filedata.Find(douhao));
				 /////////////////////在这里修改文件名
				 if(date_tmp1.Compare(" 6- 2-28")==0)////////" 6- 2-19"必须加空格在6头里
				 {
					// 
					 time_tmp1=read_filedata.Right(read_filedata.GetLength()-read_filedata.Find(douhao)-1);
                     time_tmp2=time_tmp1.Left(time_tmp1.Find(douhao));///得到时间
					 hour_tmp1=time_tmp2.Left(time_tmp2.Find(fenhao));///得到小时
					 if(atoi(hour_tmp1)<10)
					 {
						 hour_tmp1=hour_tmp1.Right(1);
						 hour_tmp1="0"+hour_tmp1;
					 }
					 else
					 {
						 hour_tmp1=hour_tmp1.Right(2);
					 }
					 min_tmp1=time_tmp2.Right(time_tmp2.GetLength()-time_tmp2.Find(fenhao)-1);
					 min_tmp2=min_tmp1.Left(min_tmp1.Find(fenhao));
					 if(atoi(min_tmp2)<10)
					 {
						 min_tmp2=min_tmp2.Right(1);
						 min_tmp2="0"+min_tmp2;
					 }
					 else
					 {
						 min_tmp2=min_tmp2.Right(2);
					 }
					 sec=min_tmp1.Right(2);
					 data_tmp1=time_tmp1.Right(time_tmp1.GetLength()-time_tmp1.Find(douhao)-1);
                     data_tmp1=data_tmp1.Right(data_tmp1.GetLength()-data_tmp1.Find(kongge)-1);
					 data_tmp1=data_tmp1.Right(data_tmp1.GetLength()-data_tmp1.Find(kongge)-1);
					 data_tmp1=data_tmp1.Right(data_tmp1.GetLength()-data_tmp1.Find(kongge)-1);
					 data_tmp1=data_tmp1.Left(data_tmp1.Find(douhao))+"\n";						 
					 file_savename.WriteString(hour_tmp1+min_tmp2+sec+"\t");
					 file_savename.WriteString(data_tmp1);	
					 //AfxMessageBox(data_tmp1);				
				 }
							 
			 }						  
			file_read.Close();////关闭TEOM文件的行数						 	 
		 }		 
		file_opentmp.Close();///关闭临时文件
		file_savename.Close();////关闭保存文件		
	file_opentmp.Remove("e:\\temptfilename.txt");///删除临时文件

}

void CTeomDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
 CStdioFile tf,savefile;
 CString date,data,date_tmp,data_tmp,filecontent;
 CString savepath;
 int fileline=0;
 TCHAR tab=9;
	static char BASED_CODE szFilter[] = "TEOM数据文件Files (*.dat;*.txt)|*.dat;*.txt|Lidar 二进制数据文件(*.sig)|*.sig||";
	CFileDialog fd(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter);
	fd.m_ofn.lpstrTitle="查找TEOM数据文件...";
	if(fd.DoModal()==IDCANCEL)
	{
		return;
	}
		
	tf.Open(fd.GetPathName(),CFile::modeRead|CFile::typeText);////打开批处理文件
	savepath=fd.GetPathName();
	m_printfscreen=savepath;
	UpdateData(false);
	savepath=savepath.Left(savepath.GetLength()-4)+".lvd";
	savefile.Open(savepath,CFile::modeCreate|CFile::modeWrite);
	
	if(!tf)
	{
		AfxEndThread(0);
		AfxMessageBox("Failed to open file,Exit!!");
	}
	while(tf.ReadString(filecontent))
	{
		date=filecontent.Left(filecontent.Find(tab));//读出日期
		data=filecontent.Right(filecontent.GetLength()-filecontent.Find(tab)-1);//读出数据
		if(fileline==1)
		{
			date_tmp=date;//把有效数据的第一行分别赋值
			data_tmp=data;
		}
		//////设计的初衷就是:把第一有效值确定以后,作为判断值,然后把第二个值同它比较,如果相同,第二个值不写入文件
		/////////,然后把这个值再赋给判断值,依次比较下去
		if(fileline>0)///第一行文件头,不写入保存文件中
		{
			if(date==date_tmp)
			{
			}
			else
			{
               savefile.WriteString(date+"\t");
			   savefile.WriteString(data+"\n");
			}

		}
        date_tmp=date;
		data_tmp=data;
		fileline+=1;
	}
  tf.Close();
  savefile.Close();
 fileline=0;
}

void CTeomDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	float data[300];
	char dataa[10];
    CString filename,date;
	CString filecontent;
	CString savefilepath;
	int fileline=0;
	TCHAR tab=9;

	CFileDialog aDlg(true,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT);	         
    aDlg.m_ofn.lpstrInitialDir=NULL;//显示的初始目录
	aDlg.m_ofn.lpstrTitle="请选择数据文件";
	aDlg.m_ofn.lpstrFilter="Data text\0*.lvd;*.sdt;*.dat\0\0";	      
	if(aDlg.DoModal()==IDCANCEL)///////////没有这一句的话,没选择文件是要出错误的
	{
		return;
	}
    filename=aDlg.GetPathName();//此文件名是带路径的
	m_printfscreen=filename;
	UpdateData(false);
	savefilepath=filename.Left(filename.GetLength()-4)+".dat";    
    CStdioFile fp;
     FILE *savefile;
  savefile=fopen(savefilepath,"w");        
   fp.Open( filename, CFile::modeRead|CFile::typeText);
   if(!fp)
   {
           AfxMessageBox("Failed to open file,Exit!!");
   }      
	   while(fp.ReadString(filecontent))
	   {     
		   

		     data[fileline]=atof(filecontent.Right(filecontent.GetLength()-filecontent.Find(tab)-1));
		  
		   fileline+=1;	 
	   } 
	   for(int i=0;i<=fileline;i++)
	   {
		   if(data[i]<0)
		   {
			   data[i]=0.5*(data[i-1]+data[i+1]);
		   }
	   }
	   fileline=0;
	   fp.SeekToBegin();
	   while(fp.ReadString(filecontent))
	   {
		   
		   date=filecontent.Left(filecontent.Find(tab));
		   fprintf(savefile,"%s\t%f\n",date,data[fileline]);
		   fileline+=1;
	   }
	       	  
   
   fileline=0;
   fp.Close();
   fclose(savefile);
  
  Invalidate(TRUE);
}

⌨️ 快捷键说明

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