📄 pcmjiema.txt
字号:
// 测试Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "测试.h"
#include "测试Dlg.h"
#include "pcm.h"
#include "Introduction.h"
#include "math.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()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
m_time = 0.0;
m_OutPath = _T("");
m_func = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_COMBO1, m_choosefunc);
DDX_Text(pDX, IDC_EDIT1, m_time);
DDX_Text(pDX, IDC_EDIT2, m_OutPath);
DDX_CBString(pDX, IDC_COMBO1, m_func);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_COMMAND(ID_MENUITEM32771, OnMenuitem32771)
ON_COMMAND(ID_MENUITEM32774, OnMenuitem32774)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
char code1[9];
char code2[8];
int s[8];
void encode(double input)
{
void dlm(int n);
void dnm(int x,int m,int n);
int ipre(int x,int y[8]);
void jiema();
long int c,temp;
int x;
code1[8]=NULL;
temp=input*128*16;
if(temp>0)
code1[0]='1';
else {code1[0]='0';temp=fabs(temp);}
if(temp>=0 && temp<16) {dlm(0);dnm(temp,0,1);}
if(temp>=16 && temp<32) {dlm(1);dnm(temp,16,1);}
if(temp>=32 && temp<64) {dlm(2);dnm(temp,32,2);}
if(temp>=64 && temp<128) {dlm(3);dnm(temp,64,4);}
if(temp>=128 && temp<256) {dlm(4);dnm(temp,128,8);}
if(temp>=256 && temp<512) {dlm(5);dnm(temp,256,16);}
if(temp>=512 && temp<1024) {dlm(6);dnm(temp,512,32);}
if(temp>=1024 && temp<2048) {dlm(7);dnm(temp,1024,64);}
}
void dlm(int n) //段落码
{
switch(n)
{
case 0:code1[1]='0';code1[2]='0';code1[3]='0';break;
case 1:code1[1]='0';code1[2]='0';code1[3]='1';break;
case 2:code1[1]='0';code1[2]='1';code1[3]='0';break;
case 3:code1[1]='0';code1[2]='1';code1[3]='1';break;
case 4:code1[1]='1';code1[2]='0';code1[3]='0';break;
case 5:code1[1]='1';code1[2]='0';code1[3]='1';break;
case 6:code1[1]='1';code1[2]='1';code1[3]='0';break;
case 7:code1[1]='1';code1[2]='1';code1[3]='1';break;
}
}
void dnm(int x,int m,int n) //段内码
{
int l=(x-m)/n;
switch(l)
{
case 0:code1[4]='0';code1[5]='0';code1[6]='0';code1[7]='0';break;
case 1:code1[4]='0';code1[5]='0';code1[6]='0';code1[7]='1';break;
case 2:code1[4]='0';code1[5]='0';code1[6]='1';code1[7]='0';break;
case 3:code1[4]='0';code1[5]='0';code1[6]='1';code1[7]='1';break;
case 4:code1[4]='0';code1[5]='1';code1[6]='0';code1[7]='0';break;
case 5:code1[4]='0';code1[5]='1';code1[6]='0';code1[7]='1';break;
case 6:code1[4]='0';code1[5]='1';code1[6]='1';code1[7]='0';break;
case 7:code1[4]='0';code1[5]='1';code1[6]='1';code1[7]='1';break;
case 8:code1[4]='1';code1[5]='0';code1[6]='0';code1[7]='0';break;
case 9:code1[4]='1';code1[5]='0';code1[6]='0';code1[7]='1';break;
case 10:code1[4]='1';code1[5]='0';code1[6]='1';code1[7]='0';break;
case 11:code1[4]='1';code1[5]='0';code1[6]='1';code1[7]='1';break;
case 12:code1[4]='1';code1[5]='1';code1[6]='0';code1[7]='0';break;
case 13:code1[4]='1';code1[5]='1';code1[6]='0';code1[7]='1';break;
case 14:code1[4]='1';code1[5]='1';code1[6]='1';code1[7]='0';break;
case 15:code1[4]='1';code1[5]='1';code1[6]='1';code1[7]='1';break;
case 16:code1[4]='1';code1[5]='1';code1[6]='1';code1[7]='1';break;
default:break;
}
}
int jdlm(int x,int y[8]) //解段落码
{
int a;
switch(x)
{
case 0:a=0;y[0]=1;break;
case 1:a=16;y[1]=1;break;
case 2:a=32;y[2]=2;break;
case 3:a=64;y[3]=4;break;
case 4:a=128;y[4]=8;break;
case 5:a=256;y[5]=16;break;
case 6:a=512;y[6]=32;break;
case 7:a=1024;y[7]=64;break;
default:break;
}
//printf("起点:%d\n间隔:%d\n",a,y[x]);
return (a);
}
float jiema() //解码: 从文件读取编码并解码
{
int i,c,m,tmp[8];
float t,n;
char b;
for(i=0;i<8;i++)
{
if(code2[i]=='1')
tmp[i]=1;
else
tmp[i]=0;
}
c=tmp[1]*4+tmp[2]*2+tmp[3];
m=jdlm(c,s); //调用解段落码子函数
n=tmp[7]+tmp[6]*2+tmp[5]*4+tmp[4]*8+0.5;
t=m+n*s[c];
if(code2[7]==0)
t=-t;
return t;
}
BOOL CMyDlg::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
m_func="sin(t)";
m_OutPath="c:\\";// TODO: Add extra initialization here
m_time=1.0;
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDlg::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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
double fun1(double x)
{
return cos(x);
}
double fun2(double x)
{
if(x==0.0)
return 1.0;
else
return sin(x)/x;
}
double fun3(double x)
{
return sin(x);
}
double (*fun)(double);
void CMyDlg::OnButton1()
{
UpdateData(true);
int nSel=m_choosefunc.GetCurSel();
switch(nSel)
{
case 0: fun=fun1;break;
case 1: fun=fun2;break;
case 2: fun=fun3;break;
default:break;
}
CString str_code;//code
CStdioFile myfile;
CFileException mExcept;
int i=1;
LARGE_INTEGER t1, t2, tc,f;
QueryPerformanceCounter(&t1);
QueryPerformanceFrequency(&f);
tc.QuadPart=m_time*f.QuadPart; //time
myfile.Open("c:\\hj.xls",CFile::modeWrite|CFile::modeCreate,&mExcept);
while(t2.QuadPart-t1.QuadPart<tc.QuadPart)
{
QueryPerformanceCounter(&t2);
if(1000000*(t2.QuadPart-t1.QuadPart)/f.QuadPart>=125*i)
{
encode(fun(1000000*(t2.QuadPart-t1.QuadPart)/f.QuadPart));
myfile.WriteString("编码:");
myfile.WriteString(code1);
myfile.WriteString("\n");
i++;
}
QueryPerformanceCounter(&t2);
}
myfile.Close();
MessageBox("OK!");
}
void CMyDlg::OnButton2() //jiema
{
CString str_t;
CStdioFile filein,fileout;
char temp[9];
filein.Open("c:\\hj.xls",CFile::modeRead);
fileout.Open("c:\\out.xls",CFile::modeWrite|CFile::modeCreate);
filein.Seek(5,CFile::begin);
while(filein.GetLength()>filein.GetPosition()) //文件指针小于文件长度时循环
{
for(int i=0;i<8;i++)
filein.Read(&code2[i],1);
str_t.Format("%f",jiema()); //double型转换为字符串便于输出
fileout.WriteString("编码 ");
fileout.WriteString(code2);
fileout.WriteString(" "); //写入空格
fileout.WriteString("量化值 ");
fileout.WriteString(str_t);
fileout.WriteString("\n"); //写入回车
filein.Seek(7,CFile::current); //注意指针的修改
}
filein.Close();
fileout.Close();
MessageBox("OK!");
}
void CMyDlg::OnMenuitem32771()
{
}
void CMyDlg::OnMenuitem32774()
{
Introduction myIntr;
myIntr.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -