The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 get Output from X-Function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

fs_alex

1 Posts

Posted - 04/15/2010 :  05:29:20 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): v8.1.88.89
Operating System: Windows XP

Dear Origin Team,

is there any way that i can fetch the output of a (user defined) X-Function from OriginC ? For example if i want to feed the output of one X-Function to the input of another X-Function.

Penn

China
644 Posts

Posted - 04/20/2010 :  06:11:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000