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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Need help with x-function mwtest

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
bwadams Posted - 01/24/2008 : 12:37:30 PM
Origin Version (Select Help-->About Origin): 8.0 pro
Operating System: win xp

I'm trying to call an X-function from within Origin C.

void mwtester()
{
//mann-whitney on new sheet for timepoint in column 3
Worksheet wks = Project.ActiveLayer();
DataRange drIn;
string strXFNameToCall = "mwtest";
XFBase xf(strXFNameToCall);
Worksheet wksTemp;

drIn.Add(wks,0,"X");
drIn.Add(wks,2,"Y");
wksTemp.Create("BL");
//void mwtest(const Range& irng, const string& null, const int& tail, ReportTree& rt)
xf.SetArg(1,drIn);
xf.SetArg(4,wksTemp);
xf.Evaluate();
}

Column 1 (0 index) has the grouping (2 possible values) and column 3 (2 index) has the data in wks.

I would ideally like to create a new tab in wks to send the report from mwtest to (instead of creating a new page labeled "BL"), but I don't understand what the ReportTree type is or how to create a new tab and tell mwtest to send the report to "wks::newtab"

Also, running the above without the xf.SetArg(4,wksTemp) line [which fails if I leave it in] gives me the error message:

mwtest:X-Function failed to execute!
Please select one data column and one factor column

I'm not sure what I'm doing wrong as far as the input ranges go. Any ideas?
4   L A T E S T    R E P L I E S    (Newest First)
Echo_Chu Posted - 01/25/2008 : 12:08:09 AM
Your don't need to specify OriginStorage in your code. Moreover, to get value from a treenode, member variable is required.

Your code can be modified as following and it should work

//pvalues[i-1] = tr.OriginStorage.Stats.Stats.C3;
==>pvalues[i-1] = tr.Stats.Stats.C3.dVal;

OriginStorage isn't a treenode of tr, in fact, it is label of tr. So it should not be specified. But we can see that it is confusing. It will be removed later.

Edited by - Echo_Chu on 01/25/2008 12:08:56 AM
bwadams Posted - 01/24/2008 : 5:00:59 PM
I'm looking to retrie data from the ReportTree generated as a result of the mwtest but I've never worked with these structures before and I'm having trouble finding documentation on how to access the nodes in the tree. I can see the value I want within the tree structure when debugging but can't seem to get the syntax right as far as accessing that property. Any help would be appreciated.

void test_mw(int numtp)
{
int nCGroup=0;
int nCData;
string tempstr;
Worksheet wks = Project.ActiveLayer();
WorksheetPage wp = wks.GetPage();
Tree tr;
vector<double> pvalues(numtp);
// add a result sheet
for (int i=1;i<=numtp;i++)
{
int nSheet = wp.AddLayer();
string strCmd;
nCData = 1+i;
strCmd.Format("i:=%s!(%d,%d) rt:=[<input>]%d!", wks.m_strBookSheet, nCGroup+1, nCData+1, nSheet+1);
string strXFNameToCall = "mwtest";
XFBase xf(strXFNameToCall);
int nRet = -1;
if(xf)
nRet = xf.ExecuteLabTalk(strCmd, NULL);
if(nRet == 0) // no error
{
Worksheet wksResult = wp.Layers(nSheet);
uint uid;
wksResult.GetReportTree(tr, &uid);

//THE FOLLOWING IS THE LINE THAT FAILS
pvalues[i-1] = tr.OriginStorage.Stats.Stats.C3;

tempstr.Format("%s MW",wks.Columns(nCData).GetLongName());
wksResult.SetName(tempstr);
}
}
}
bwadams Posted - 01/24/2008 : 3:31:42 PM
Thanks a lot! Works perfectly.
cpyang Posted - 01/24/2008 : 2:43:15 PM
I am afraid we only have LabTalk calling of XF in current version. OC calling is supported for some but not all variable types, and ReportTree is one such variable type that lack OC level support. The following code shows how you can call with LabTalk syntax in Origin C to control the result sheet:

 


// Group Col = wcol(nCGroup+1)
// Data Co = wcol(nCData+1)
void test_mw(int nCGroup = 0, int nCData = 2)
{
Worksheet wks = Project.ActiveLayer();
WorksheetPage wp = wks.GetPage();
// add a result sheet
int nSheet = wp.AddLayer();
string strCmd;
strCmd.Format("i:=%s!(%d,%d) rt:=[<input>]%d!", wks.m_strBookSheet, nCGroup+1, nCData+1, nSheet+1);
string strXFNameToCall = "mwtest";
XFBase xf(strXFNameToCall);
int nRet = -1;
if(xf)
nRet = xf.ExecuteLabTalk(strCmd, NULL);

if(nRet == 0) // no error
{
Worksheet wksResult = wp.Layers(nSheet);
wksResult.SetName("My MW Result Sheet");
}
}



So the ExecuteLabTalk call will allow XF execution done in exactly the same fashion as if calling from LT but still somewhat better error handling.

CP



The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000