www.pudn.com > FaultCount.rar > FaultAzmDlg.cpp, change:2003-04-04,size:16717b


// FaultAzmDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "FaultAzm.h" 
#include "FaultAzmDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
#include <math.h> 
#define PI 3.1415926 
///////////////////////////////////////////////////////////////////////////// 
// 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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CFaultAzmDlg dialog 
 
CFaultAzmDlg::CFaultAzmDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CFaultAzmDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CFaultAzmDlg) 
	m_f = 0.0; 
	m_strAngle = _T(""); 
	m_strR = _T(""); 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CFaultAzmDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CFaultAzmDlg) 
	DDX_Control(pDX, IDC_LIST2, m_listCtrlRlt); 
	DDX_Control(pDX, IDC_LIST1, m_listCtrl); 
	DDX_Text(pDX, IDC_EDIT_F, m_f); 
	DDX_Text(pDX, IDC_EDIT_ANGLE, m_strAngle); 
	DDX_Text(pDX, IDC_EDIT_R, m_strR); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CFaultAzmDlg, CDialog) 
	//{{AFX_MSG_MAP(CFaultAzmDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen) 
	ON_BN_CLICKED(IDC_BUTTON_RESULT, OnButtonResult) 
	ON_BN_CLICKED(IDC_BUTTON_ZOOMIN, OnButtonZoomin) 
	ON_BN_CLICKED(IDC_BUTTON_ZOOMOUT, OnButtonZoomout) 
	ON_BN_CLICKED(IDC_BUTTON_ZOOMEQ1, OnButtonZoomeq1) 
	ON_WM_LBUTTONDBLCLK() 
	ON_WM_MOUSEMOVE() 
	ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CFaultAzmDlg message handlers 
 
BOOL CFaultAzmDlg::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 
	m_listCtrl.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); 
	m_listCtrl.InsertColumn (0, "id", LVCFMT_RIGHT, 30); 
	m_listCtrl.InsertColumn (1, "datOrg", LVCFMT_RIGHT,60); 
	m_listCtrl.InsertColumn (2, "datSort", LVCFMT_RIGHT,60); 
	m_listCtrl.InsertColumn (3, "S[i+1]-S[i]", LVCFMT_RIGHT,80); 
	m_listCtrl.InsertColumn (4, "", LVCFMT_LEFT,10);//多插入一列 
 
	m_listCtrlRlt.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); 
	m_listCtrlRlt.InsertColumn (0, "组别", LVCFMT_RIGHT,40); 
	m_listCtrlRlt.InsertColumn (1, "数目", LVCFMT_RIGHT,40); 
	m_listCtrlRlt.InsertColumn (2, "百分比", LVCFMT_RIGHT,60); 
	m_listCtrlRlt.InsertColumn (3, "最小值", LVCFMT_RIGHT, 60); 
	m_listCtrlRlt.InsertColumn (4, "最大值", LVCFMT_RIGHT,60); 
	m_listCtrlRlt.InsertColumn (5, "平均值", LVCFMT_RIGHT,60); 
	m_listCtrlRlt.InsertColumn (6, "标准差", LVCFMT_RIGHT,60); 
	m_listCtrlRlt.InsertColumn (7, "", LVCFMT_LEFT,10);//多插入一列 
 
	m_canDrawLine=false; 
	m_Zoom = 1.0; 
	f_PreDraw(); 
	InvalidateRect(m_Rect);//Invalidate(); 
 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
void CFaultAzmDlg::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 CFaultAzmDlg::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 
	{ 
		f_DrawCircle(); 
		if( m_canDrawLine ) 
			f_DrawLine(); 
		CDialog::OnPaint(); 
	} 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CFaultAzmDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CFaultAzmDlg::OnButtonOpen()  
{ 
	// TODO: Add your control notification handler code here 
	static char BASED_CODE szFilter[]="裂隙倾向数据(*.txt)|*.txt||"; 
	LPCTSTR lpstrDefExt="txt"; 
	LPCTSTR lpszFileName ="*.txt"; 
	CFileDialog dlg(true,lpstrDefExt,lpszFileName, 
	                OFN_HIDEREADONLY|OFN_FILEMUSTEXIST| 
					OFN_OVERWRITEPROMPT | 
					OFN_EXPLORER , 
	                szFilter,NULL); 
	//文件对话框的窗口标题 
	dlg.m_ofn.lpstrTitle="打开裂隙倾向数据文件"; 
 
	if(dlg.DoModal()!=IDOK) 
		return; 
 
	//读文件 
	FILE *fp; 
	int i; 
	if((fp=fopen(dlg.GetPathName(),"r"))==NULL) 
		return; 
	 
	fscanf(fp,"%d\n",&m_N); 
	if( m_N<=0 ) 
		return; 
	m_pdatOrg = new double[m_N]; 
	m_pidSort = new int[m_N];	m_pdatSort = new double[m_N]; 
	m_pdatdAB = new double[m_N]; 
 
	for( i=0; i<m_N; i++) 
	{ 
		fscanf(fp,"%lf\n",&m_pdatOrg[i]); 
		m_pidSort[i]=i; 
		m_pdatSort[i] = m_pdatOrg[i]; 
	} 
	fclose(fp); 
 
	//排序 
	SortData(m_pdatSort,m_N,m_pidSort); 
	 
	//排序数据后者的减去前者 
	m_pdatdAB[0]=-1;//不用 
	for( i=1; i<m_N; i++ ) 
	{ 
		m_pdatdAB[i] = m_pdatSort[i]-m_pdatSort[i-1]; 
	} 
 
	//显示结果到List 
	if( m_listCtrl.GetItemCount() > 0 ) 
		m_listCtrl.DeleteAllItems(); 
 
	CString str; 
	const int nColumns = 4; 
	int iColumn; 
	int iItem; 
	int count=m_N; 
	for ( i=0; i<count; i++) 
	{ 
		str.Format("%d",i+1); 
		iItem = m_listCtrl.InsertItem(i,str,0); 
		for (iColumn = 1; iColumn < nColumns; iColumn++) 
		{ 
			if( iColumn == 1 ) str.Format("%.3lf",m_pdatOrg[i]); 
			else if( iColumn == 2 ) str.Format("%.3lf",m_pdatSort[i]); 
			else if( iColumn == 3 ) str.Format("%.3lf",m_pdatdAB[i]); 
			if( iColumn == 3 && i==0 ) str=""; 
			m_listCtrl.SetItemText(iItem,iColumn,str); 
		} 
	} 
 
	 
} 
 
void CFaultAzmDlg::OnButtonResult()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(true); 
	FindClsPos(m_pdatdAB,m_N,m_f,m_uiaClsPos); 
	// 
	int nCls = m_uiaClsPos.GetSize()+1;//分组数多1 
	if( nCls <=1 ) 
	{ 
		AfxMessageBox("分组阀值太大!"); 
		return; 
	} 
	m_pAmzStatCell = new CELL[nCls]; 
	int t1,t2; 
	for( int i=0; i<nCls; i++ ) 
	{	 
		if( i==0 )	t1=0; 
		else	t1=m_uiaClsPos[i-1]; 
		if( i==nCls-1 ) t2=m_N-1; 
		else	t2=m_uiaClsPos[i]-1; 
		BasStatVar(&m_pdatSort[t1],t2-t1+1,m_pAmzStatCell[i]); 
	} 
	 
	//输出结果 
	if( m_listCtrlRlt.GetItemCount() > 0 ) 
		m_listCtrlRlt.DeleteAllItems(); 
	CString str; 
	const int nColumns = 7;//--5 
	int iColumn; 
	int iItem; 
	for ( i=0; i<nCls; i++) 
	{ 
		str.Format("第%d组",i+1); 
		iItem = m_listCtrlRlt.InsertItem(i,str,0); 
		for (iColumn = 1; iColumn < nColumns; iColumn++) 
		{ 
			if( iColumn == 1 ) str.Format("%d",m_pAmzStatCell[i].n); 
			else if( iColumn == 2 ) str.Format("%.3lf",m_pAmzStatCell[i].per); 
			else if( iColumn == 3 ) str.Format("%.3lf",m_pAmzStatCell[i].min); 
			else if( iColumn == 4 ) str.Format("%.3lf",m_pAmzStatCell[i].max); 
			else if( iColumn == 5 ) str.Format("%.3lf",m_pAmzStatCell[i].mean); 
			else if( iColumn == 6 ) str.Format("%.3lf",m_pAmzStatCell[i].stdvar); 
			else { } 
			m_listCtrlRlt.SetItemText(iItem,iColumn,str); 
		} 
	} 
 
	//绘图 
	m_canDrawLine=TRUE; 
	InvalidateRect(m_Rect); 
	//f_DrawLine(); 
	UpdateData(false); 
} 
 
 
/* 
选择排序 
pdat按从小到达排序,对应的pid随着pdat的移动而移动 
*/ 
void CFaultAzmDlg::SortData(double *pdat, int N, int *pid) 
{ 
	if( N <=0 ) 
		return; 
	int i,j,k; 
	double temp; 
	int t; 
	for( i=0; i<N-1; i++ ) 
	{ 
		k=i; 
		for( j=i+1; j<N; j++ ) 
		{ 
			if( pdat[j]<pdat[k] ) 
				k=j; 
		} 
		if( k!=i ) 
		{ 
			temp=pdat[k]; 
			pdat[k]=pdat[i]; 
			pdat[i]=temp; 
			// 
			t=pid[k]; 
			pid[k]=pid[i]; 
			pid[i]=t; 
		} 
	} 
} 
 
void CFaultAzmDlg::FindClsPos(double *pdat,int N, double clsF, CUIntArray &ruiaClsPos) 
{ 
	if( N <=0 ) 
		return; 
	if( m_uiaClsPos.GetSize()>=0 ) 
		m_uiaClsPos.RemoveAll(); 
	for( int i=0; i<N; i++ ) 
	{ 
		if( pdat[i]>=clsF ) 
			ruiaClsPos.Add(i); 
	} 
} 
 
void CFaultAzmDlg::BasStatVar(double *pdat, int N, CELL &rAmzStatCell) 
{ 
	if( N <=0 ) 
		return; 
	double	min=pdat[0]; 
	double max=pdat[0]; 
	double t=pdat[0]; 
	for( int i=1; i<N; i++ ) 
	{ 
		if( pdat[i]<min ) min=pdat[i]; 
		if( pdat[i]>max ) max=pdat[i]; 
		t+=pdat[i]; 
	} 
	rAmzStatCell.n = N; 
	rAmzStatCell.per = (double)N/m_N*100; 
	rAmzStatCell.min = min; 
	rAmzStatCell.max = max; 
	rAmzStatCell.mean = t/N; 
 
	//计算标准方差 
	t=0; 
	for( i=0; i<N; i++ ) 
	{ 
		t+=(pdat[i]-rAmzStatCell.mean)*(pdat[i]-rAmzStatCell.mean); 
	} 
	if( N>30 )	rAmzStatCell.stdvar = sqrt(t/N); 
	else if( N<=30 && N-1>0 )	rAmzStatCell.stdvar = sqrt(t/(N-1)); 
	else	rAmzStatCell.stdvar = -1;//无效值 
} 
 
void CFaultAzmDlg::f_PreDraw() 
{ 
	//获取占位控件Picture的Rect 
	GetDlgItem(IDC_STATIC_PICAREA)->GetClientRect(&m_Rect); 
 
	m_Rect.DeflateRect(10,10); 
	int width=m_Rect.Width(); 
	int height=m_Rect.Height(); 
	m_x0=m_Rect.left+width/2; 
	m_y0=m_Rect.top+height/2; 
	m_AxisL=width; if(width>height) m_AxisL=height; 
	m_Scale = m_AxisL*0.5/1; 
	//m_AxisL=(int)(m_AxisL*0.95); 
 
} 
 
void CFaultAzmDlg::f_DrawCircle() 
{ 
	CWnd* pWndDraw=GetDlgItem(IDC_STATIC_PICAREA); 
	CDC* pDC=pWndDraw->GetDC(); 
//	pWndDraw->Invalidate(); 
	pWndDraw->UpdateWindow(); 
	//创建画笔 
	CPen *pNewPen; 
	CPen *pOldPen; 
	pNewPen=new CPen; 
	pNewPen->CreatePen(PS_SOLID,1,RGB(192,192,192));	 
	pOldPen=pDC->SelectObject(pNewPen); 
	int r=(int)(1*m_Scale*m_Zoom); 
	//pDC->LineTo(m_x0-r,m_y0-r); 
	pDC->Ellipse(m_x0-r,m_y0-r,m_x0+r,m_y0+r); 
	r/=2; 
	pDC->Ellipse(m_x0-r,m_y0-r,m_x0+r,m_y0+r); 
	r/=2; 
	pDC->Ellipse(m_x0-r,m_y0-r,m_x0+r,m_y0+r); 
	r/=2; 
	pDC->Ellipse(m_x0-r,m_y0-r,m_x0+r,m_y0+r); 
 
	// X--Y 
	r=m_AxisL/2; 
	pDC->MoveTo(m_x0,m_y0);	pDC->LineTo(m_x0-r,m_y0); 
	pDC->MoveTo(m_x0,m_y0);	pDC->LineTo(m_x0+r,m_y0); 
	pDC->MoveTo(m_x0,m_y0);	pDC->LineTo(m_x0,m_y0-r); 
	pDC->MoveTo(m_x0,m_y0);	pDC->LineTo(m_x0,m_y0+r); 
	//\/ 
	r=(int)(1.414*0.5*0.5*m_AxisL); 
	pDC->MoveTo(m_x0,m_y0);	pDC->LineTo(m_x0-r,m_y0-r); 
	pDC->MoveTo(m_x0,m_y0);	pDC->LineTo(m_x0+r,m_y0+r); 
	pDC->MoveTo(m_x0,m_y0);	pDC->LineTo(m_x0-r,m_y0+r); 
	pDC->MoveTo(m_x0,m_y0);	pDC->LineTo(m_x0+r,m_y0-r); 
 
	pDC->SelectObject(pOldPen); 
	delete pNewPen; 
	ReleaseDC(pDC); 
} 
 
void CFaultAzmDlg::f_DrawLine() 
{ 
	CWnd* pWndDraw=GetDlgItem(IDC_STATIC_PICAREA); 
	CDC* pDC=pWndDraw->GetDC(); 
//	pWndDraw->Invalidate(); 
	pWndDraw->UpdateWindow(); 
 
	int nLine = m_uiaClsPos.GetSize()+1; 
	int i; 
	int dx,dy; 
	double sinA,cosA; 
	double L; 
	//创建画笔 
	CPen *pNewPen; 
	CPen *pOldPen; 
	pNewPen=new CPen; 
	pNewPen->CreatePen(PS_SOLID,1,RGB(0,0,255));	 
	pOldPen=pDC->SelectObject(pNewPen); 
 
	for( i=0; i<nLine; i++) 
	{ 
		L=(double)m_pAmzStatCell[i].n/m_N; 
		L*=m_Zoom; 
		sinA = sin(m_pAmzStatCell[i].mean*PI/180); 
		cosA = cos(m_pAmzStatCell[i].mean*PI/180); 
		dx=(int)( L*sinA*m_Scale ); 
		dy=(int)( L*cosA*m_Scale ); 
		pDC->MoveTo(m_x0,m_y0);	 
		pDC->LineTo(m_x0+dx,m_y0-dy); 
	} 
	delete pNewPen; 
	pOldPen=pDC->SelectObject(pNewPen); 
	ReleaseDC(pDC); 
} 
 
void CFaultAzmDlg::OnButtonZoomin()  
{ 
	// TODO: Add your control notification handler code here 
	Invalidate(TRUE); 
	m_Zoom/=0.8;//0.618; 
	InvalidateRect(m_Rect); 
} 
 
void CFaultAzmDlg::OnButtonZoomout()  
{ 
	// TODO: Add your control notification handler code here 
	Invalidate(TRUE); 
	m_Zoom*=0.8;//0.618; 
	InvalidateRect(m_Rect); 
	 
} 
 
void CFaultAzmDlg::OnButtonZoomeq1()  
{ 
	// TODO: Add your control notification handler code here 
	Invalidate(TRUE); 
	m_Zoom=1; 
	InvalidateRect(m_Rect); 
} 
 
void CFaultAzmDlg::OnMouseMove(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	UpdateData(true); 
	m_strAngle = ""; 
	if( m_canDrawLine ) 
	{ 
		double r,angle; 
		GetRadiusAngle(point,r,angle); 
		if( angle >=0 ) 
		{ 
			m_strR.Format("%.3lf",r/m_Scale/m_Zoom); 
			m_strAngle.Format("%.3lf°",angle); 
		} 
		else 
		{ 
			m_strR.Empty(); 
			m_strAngle.Empty(); 
		} 
	} 
	UpdateData(false); 
	CDialog::OnMouseMove(nFlags, point); 
} 
 
void CFaultAzmDlg::OnLButtonDblClk(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	if( m_canDrawLine ) 
	{ 
		//将列表中所有项为非选 
		for( int i=0; i<m_listCtrl.GetItemCount(); i++ ) 
			m_listCtrlRlt.SetItemState(i,0,LVIS_SELECTED); 
		double r,angle; 
		GetRadiusAngle(point,r,angle); 
		int iCls = GetIndexClass(angle,m_pAmzStatCell,m_uiaClsPos.GetSize()+1); 
		if( iCls<0 ) 
			return; 
		//选中 
		m_listCtrlRlt.SetItemState(iCls,LVIS_SELECTED,LVIS_SELECTED); 
		m_listCtrlRlt.SetFocus(); 
		m_listCtrlRlt.EnsureVisible(iCls, FALSE); 
 
 
	} 
	CDialog::OnLButtonDblClk(nFlags, point); 
} 
 
void CFaultAzmDlg::GetRadiusAngle(CPoint point, double& r, double& angle) 
{ 
	int x,y;//鼠标点(屏幕坐标) 
	int x0,y0;//原点(屏幕坐标) 
	 
	CRect rc; 
	GetDlgItem(IDC_STATIC_PICAREA)->GetWindowRect(&rc); 
	x0 = (rc.left+rc.right)/2; 
	y0 = (rc.top+rc.bottom)/2; 
	 
	ClientToScreen(&point); 
	x=point.x; y=point.y; 
 
 
	r=sqrt(( (y-y0)*(y-y0)+(x-x0)*(x-x0) ));  
	if(r<1 || r>m_AxisL/2 )  
	{ 
		r=-1;	angle=-1; 
		return; 
	} 
 
	// double acos( double a )  
	//angle=[0,PI]结合y值为正为负判断鼠标所在区间的角度 
	angle=(x-x0)/r; //余弦值 
	angle=acos(angle);    //弧度 
	angle=180*angle/PI; //角度 
	if( y<=y0 )	 
	{ 
		if( x>=x0 ) angle=90-angle;//第一象限 
		else angle=360-(angle-90);//第二象限 
	} 
	else 
	{ 
		if(x<=x0 ) angle=90+angle;//第三象限 
		else angle=90+angle; 
	} 
 
} 
 
int CFaultAzmDlg::GetIndexClass(double angle, CELL* pAmzStatCell,int nCls) 
{ 
	int iCls=-1; 
	double dA=3; 
	for( int i=0; i<nCls; i++ ) 
	{ 
		if( angle>=pAmzStatCell[i].mean-3 && angle<=pAmzStatCell[i].mean+3 ) 
		{ 
			iCls=i; 
			break; 
		} 
	} 
	return iCls; 
} 
 
 
 
void CFaultAzmDlg::OnButtonSave()  
{ 
	// TODO: Add your control notification handler code here 
	static char BASED_CODE szFilter[]="统计结果(*.txt)|*.txt||"; 
	LPCTSTR lpstrDefExt="txt"; 
	LPCTSTR lpszFileName ="*.txt"; 
	CFileDialog dlg(false,lpstrDefExt,lpszFileName, 
	                OFN_HIDEREADONLY|OFN_FILEMUSTEXIST| 
					OFN_OVERWRITEPROMPT | 
					OFN_EXPLORER , 
	                szFilter,NULL); 
	//文件对话框的窗口标题 
	dlg.m_ofn.lpstrTitle="保存裂隙倾向统计结果文件"; 
 
	if(dlg.DoModal()!=IDOK) 
		return;	 
	//读文件 
	FILE *fp; 
	int i; 
	if((fp=fopen(dlg.GetPathName(),"w"))==NULL) 
		return; 
	 
	fprintf(fp,"对%d个数据排序与差值\n",m_N); 
	for (i=0; i < m_N; i++) 
	{ 
		if( i==0 ) 
			fprintf(fp,"%.3lf\t\n",m_pdatSort[i]); 
		else 
			fprintf(fp,"%.3lf\t%.3lf\n", 
				m_pdatSort[i],m_pdatdAB[i]); 
	} 
	int nCls = m_uiaClsPos.GetSize()+1; 
	fprintf(fp,"当阀值=%.2lf,分组数=%d\n",m_f,nCls); 
	fprintf(fp,"组别\t数目\t百分比(%%)\t最小值\t最大值\t平均值\t标准差\n"); 
	for( i=0; i<nCls; i++) 
	{ 
		fprintf(fp,"第%d组\t%d\t%.3lf\t%.3lf\t%.3lf\t%.3lf\t%.3lf\n", 
		i, 
		m_pAmzStatCell[i].n,m_pAmzStatCell[i].per, 
		m_pAmzStatCell[i].min,m_pAmzStatCell[i].max, 
		m_pAmzStatCell[i].mean,m_pAmzStatCell[i].stdvar); 
 
	} 
	fclose(fp); 
}