Hi,
The following example illustrates how to fetch use the output of one X-Function from Origin C, and then feed the output to the input of another X-Function.
#include <XFbase.h>
void output_as_input()
{
Worksheet wks = Project.ActiveLayer();
if(!wks)
return;
Column col = wks.Columns(0); // first column in worksheet
// X-Function: spline
string strXF1 = "spline";
XFBase xf1(strXF1);
vector vData(col);
xf1.SetArg("ix", vData); // set input: ix
vector vOutput;
vOutput.SetSize(vData.GetSize());
xf1.SetArg("ox", vOutput); // set output: ox
DataRange dr;
dr.Add("X", wks, 0, 1, -1, 1); // second column in worksheet
dr.Add("Y", wks, 0, 2, -1, 2); // third column in worksheet
xf1.SetArg("iy", dr); // set argument iy
// execute X-Function spline
xf1.Evaluate();
// X-Function: stats
string strXF2 = "stats";
XFBase xf2(strXF2);
// set input: ix, with the output of X-Function spline
xf2.SetArg("ix", vOutput);
// output of X-Function stats
double dMean;
double dMin;
double dMax;
double dSum;
xf2.SetArg("mean", dMean);
xf2.SetArg("min", dMin);
xf2.SetArg("max", dMax);
xf2.SetArg("sum", dSum);
// execute X-Function stats
xf2.Evaluate();
// print result of X-Function stats
printf("Statistics Results:\nMean=%f\nMin=%f\nMax=%f\nSum=%f\n", dMean, dMin, dMax, dSum);
}
Please note that, those X-Function, whose input and output data type is related to the worksheet, for example, Range, DataRange, etc., can not be used in such case. In the code above, the data type of output in X-Function spline is vector, and the data type of input in stats owns the same one with spline.
Penn
OriginLab Technical Services