C++中调用SPLUS对象经典例子
2006-03-27 09:53
447 查看
此例子是我再SPLUS的自带的例子上修改而来,对初学者具有较高的阅读价值
// spllm.cxx : a simple console application that illustrates how to
// 1. create a connection to S-PLUS.
// 2. create permanent objects in S database.
// 3. evaluate an S expression.
//
// Steps to build and test this program from a DOS prompt.
// 1. Change current directory to directory containing this file
// cd <directory containing this file>
// 2. Build the program
// msdev spllm.dsp /make
// 3. Run the program
// spllm.exe S_HOME=%SHOME%
// 4. Run the S-PLUS console
// %SHOME%/cmd/sqpe.exe
// 5. Look for S objects: x, y and z. For example,
// > objects()
#include "sconnect.h"
#include "iostream"
#include "string"
using namespace std;
//A global connection object
CSPengineConnect g_engineConnect;
int main(int argc, char* argv[])
{
//Create the connection to S-PLUS
g_engineConnect.Create( argc, argv);
//Create S object with name "x" in the current database.
//Same as x<-1:10 at the command line.
string x;
cout<<"输入数目:";
cin>>x;
x="1:"+x;
CSPnumeric sx;
sx.Create(x.c_str(),"x");
//Squaring sx, which is the same as S expression sy <- x*x in a local frame,
//but here we set it to local C++ variable sy.
CSPnumeric sy = sx * sx;
int i ;
for( i=0;i<sy.length();i++)
cout<<sy[i]<<endl;
// Assign the result as S object with name "y" in the current database.
sy.Assign("y");
//Evaluate z<-lm(y~x)
g_engineConnect.SyncParseEval("z<-lm(y~x)");
CSPlist result = g_engineConnect.get("z");
CSPnumeric rank=result.GetAt("rank");
cout<<"rank:";
for( i=0;i<rank.length();i++)
cout<<rank[i];
cout<<endl;
CSPcharacter call=result.GetAt("call");
cout<<"回归表达式:" <<(char *)call(1) <<"=";
for( i=1;i<call.length();i++)
cout<<(char *)call[i];
cout<<endl;
CSPmatrix coefficients =result.GetAt("coefficients");
cout<<"回归截距:"<<(double)coefficients(1,1)<<endl;
cout<<"回归系数:"<<(double)coefficients(2,1)<<endl;
return 1;
}
// spllm.cxx : a simple console application that illustrates how to
// 1. create a connection to S-PLUS.
// 2. create permanent objects in S database.
// 3. evaluate an S expression.
//
// Steps to build and test this program from a DOS prompt.
// 1. Change current directory to directory containing this file
// cd <directory containing this file>
// 2. Build the program
// msdev spllm.dsp /make
// 3. Run the program
// spllm.exe S_HOME=%SHOME%
// 4. Run the S-PLUS console
// %SHOME%/cmd/sqpe.exe
// 5. Look for S objects: x, y and z. For example,
// > objects()
#include "sconnect.h"
#include "iostream"
#include "string"
using namespace std;
//A global connection object
CSPengineConnect g_engineConnect;
int main(int argc, char* argv[])
{
//Create the connection to S-PLUS
g_engineConnect.Create( argc, argv);
//Create S object with name "x" in the current database.
//Same as x<-1:10 at the command line.
string x;
cout<<"输入数目:";
cin>>x;
x="1:"+x;
CSPnumeric sx;
sx.Create(x.c_str(),"x");
//Squaring sx, which is the same as S expression sy <- x*x in a local frame,
//but here we set it to local C++ variable sy.
CSPnumeric sy = sx * sx;
int i ;
for( i=0;i<sy.length();i++)
cout<<sy[i]<<endl;
// Assign the result as S object with name "y" in the current database.
sy.Assign("y");
//Evaluate z<-lm(y~x)
g_engineConnect.SyncParseEval("z<-lm(y~x)");
CSPlist result = g_engineConnect.get("z");
CSPnumeric rank=result.GetAt("rank");
cout<<"rank:";
for( i=0;i<rank.length();i++)
cout<<rank[i];
cout<<endl;
CSPcharacter call=result.GetAt("call");
cout<<"回归表达式:" <<(char *)call(1) <<"=";
for( i=1;i<call.length();i++)
cout<<(char *)call[i];
cout<<endl;
CSPmatrix coefficients =result.GetAt("coefficients");
cout<<"回归截距:"<<(double)coefficients(1,1)<<endl;
cout<<"回归系数:"<<(double)coefficients(2,1)<<endl;
return 1;
}
相关文章推荐
- c++ 引用调用例子 形参指针 经典代码
- vs2015中c++中multiset容器定义对象时参数列表中显式调用greater无法被识别的解决办法
- 用servlet实现jnative调用c++写的dll的例子
- C++ Pirmer : 第十四章 : 重载运算符与类型转换之函数调用运算符与标准库的定义的函数对象
- C++:可调用对象与function
- PB程序调用C++ COM生成对象发回-2问题
- 关注C++细节——含有本类对象指针的类的构造函数、析构函数、拷贝构造函数、赋值运算符的例子
- c++继承经典例子
- 利用C++的operator new实现同一对象多次调用构造函数
- C++对象实例化及调用
- 深度探索C++对象模型---Member Function的各种调用方式
- C++中一个class类对象占用多少内字节(7个例子,很清楚)
- Android JNI之JAVA与C++对象建立对称关联(JNI优化设计,确保JNI调用的稳定性)
- java中通过ndk调用c/c++ 例子,详细解释
- c++中为什么父类名可以直接调用自己的非静态函数测试例子!(父类名::非静态函数)
- PowerShell中调用.NET对象的静态方法、静态属性和类方法、类属性例子
- C++对象布局及多态之虚成员函数调用
- C++ 函数返回对象时并没有调用拷贝构造函数
- [c++]继承的经典例子
- C++中可调用对象与function