64,691
社区成员
发帖
与我相关
我的任务
分享
// sqroot.h : main header file for the SQROOT DLL
//
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CSqrootApp
// See sqroot.cpp for the implementation of this class
//
class CSqrootApp : public CWinApp
{
public:
CSqrootApp();
double data[200*200];
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSqrootApp)
//}}AFX_VIRTUAL
//{{AFX_MSG(CSqrootApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
// sqroot.cpp
#include "stdafx.h"
#include "sqroot.h"
#include <stdio.h>//
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <math.h>
BEGIN_MESSAGE_MAP(CSqrootApp, CWinApp)
//{{AFX_MSG_MAP(CSqrootApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CSqrootApp::CSqrootApp()
{
// The constructor
// Remove next line for a "quiet" version of MyUser.DLL
FILE *f = fopen("c:\\1.txt", "r");//读取的数据,如果是CSV格式,下面的代码该如何写?
FILE *p = fopen("c:\\data.txt","wt");
int i, j;
for (i = 0; i < 100; i++)
for (j = 0; j < 58; j++)
fscanf(f, "%lf", &data[i*200+j]);
//for (i = 0; i < 1; i++)
//for (j = 0; j < 100; j++)
//for (j=0;j<100;j++)
// printf("%lf \n",data[j*200+0]);
for (j = 0; j < 10; j++)
fprintf(p,"%lf \n",data[j*200+1]);
fclose(p);
fclose(f);
//加载就能读取1.txt的数据,以上已经尝试实现,但是我的数据是CSV格式的,又该如何写?
AfxMessageBox("Plugin Loaded ");
}
CSqrootApp theApp;
extern "C" __declspec( dllexport) void MYUSER( int* pnNumberOfArgs, double* x, double* dResult)
{
double result=0;
int x0=x[0];
switch(x0)
{
case 1000:
//
{
//
double a,b;
a=x[1]/0.2;//x[1]任意正实数,横坐标,用公式算出x[1]在变量DATA【】【】中的位置,例如每0.2间隔一个数
b=(x[2]-0.3)/0.1;//x[2]任意正实数,纵坐标,用公式算出x[2]在变量DATA【】【】中的位置,例如每0.1间隔一个数
result=data[a*200+b];//此处返回CSqrootApp::CSqrootApp()中的变量data[][],要求给出DATA[][]的坐标,能返回他的值,
//但是有可能给出的x[1],x[2],计算出的a,b值不是整数,要求返回附近数据的平均值
//比如只有数据data[2][3],data[2][4],data[3][3],data[3][4],但是需要计算x[1]=0.5,x[2]=0.33时的DATA[][],如何写代码?
}
break;
default:
break;
}
*dResult =result;//返回结果
}
// sqroot.h : main header file for the SQROOT DLL
//
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CSqrootApp
// See sqroot.cpp for the implementation of this class
//
class CSqrootApp : public CWinApp
{
public:
CSqrootApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSqrootApp)
//}}AFX_VIRTUAL
//{{AFX_MSG(CSqrootApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
// sqroot.cpp
#include "stdafx.h"
#include "sqroot.h"
#include <stdio.h>//
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <math.h>
extern double Data[100][100];
BEGIN_MESSAGE_MAP(CSqrootApp, CWinApp)
//{{AFX_MSG_MAP(CSqrootApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CSqrootApp::CSqrootApp()
{
// The constructor
// Remove next line for a "quiet" version of MyUser.DLL
static double Data[200][200];
FILE *f = fopen("c:\\1.txt", "r");//读取的数据,如果是CSV格式,下面的代码该如何写?
FILE *p = fopen("c:\\data.txt","wt");
int i, j;
for (i = 0; i < 100; i++)
for (j = 0; j < 58; j++)
fscanf(f, "%lf", &Data[i][j]);
//for (i = 0; i < 1; i++)
//for (j = 0; j < 100; j++)
//for (j=0;j<100;j++)
// printf("%lf \n",Data[j][0]);
for (j = 0; j < 10; j++)
fprintf(p,"%lf \n",Data[j][1]);
fclose(p);
//加载就能读取1.txt的数据,以上已经尝试实现,但是我的数据是CSV格式的,又该如何写?
AfxMessageBox("Plugin Loaded ");
}
CSqrootApp theApp;
extern "C" __declspec( dllexport) void MYUSER( int* pnNumberOfArgs,
double* x, double* dResult)
{
double data[200][200];
double result=0;
int x0=x[0];
switch(x0)
{
case 1000:
//
{
//
double a,b;
a=x[1]/0.2;//x[1]任意正实数,横坐标,用公式算出x[1]在变量DATA【】【】中的位置,例如每0.2间隔一个数
b=(x[2]-0.3)/0.1;//x[2]任意正实数,纵坐标,用公式算出x[2]在变量DATA【】【】中的位置,例如每0.1间隔一个数
result=data[a][b];//此处返回CSqrootApp::CSqrootApp()中的变量data[][],要求给出DATA[][]的坐标,能返回他的值,
//但是有可能给出的x[1],x[2],计算出的a,b值不是整数,要求返回附近数据的平均值
//比如只有数据data[2][3],data[2][4],data[3][3],data[3][4],但是需要计算x[1]=0.5,x[2]=0.33时的DATA[][],如何写代码?
}
break;
default:
break;
}
*dResult =result;//返回结果
}