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
 foreach loop
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

alex_eagle

Austria
36 Posts

Posted - 10/17/2003 :  06:11:50 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I tried to access the %C system variable when looping through the dataplots in a graph by using foreach and collections.
Somewhere in the help file it says that Labtalk does not support collections. Does that mean that I cannot use a foreach loop through the dataplots and access %C to get the active plot.
The solution which works for me is shown below. It simply uses
the doc -e command in a C function.

void Integ(double low, double high){
LT_set_var("LOW", low);
LT_set_var("HIGH", high);
LT_execute("doc -e D {
integrate %C -b LOW -e HIGH;
integ.area = ;};");
}

Can this be done in "pure" C ?


cpyang

USA
1406 Posts

Posted - 10/17/2003 :  08:08:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The following code will show you how, but I notice a problem. After the correct integration, this line

crvMyCurve.SetLowerBound(save_i1);

is not restoring the plot lower bound to the original, looks like a bug.


CP

 

void integ_all(int i1 = 0, int i2 = -1)
{

GraphLayer gl = Project.ActiveLayer();
if(!gl)
return;

printf("Plot\tName\tArea\n");
int nPlot = 1;
int save_i1, save_i2;
foreach(DataPlot dp in gl.DataPlots)
{
Curve crvMyCurve(dp);
if(i2 > i1)
{
save_i1 = crvMyCurve.GetLowerBound();
save_i2 = crvMyCurve.GetUpperBound();
crvMyCurve.SetLowerBound(i1);
crvMyCurve.SetUpperBound(i2);
}
IntegrationResult irMyResults; // Origin C structure to store integration results
Curve_integrate( &crvMyCurve, &irMyResults); // Perform integration
printf("%d\t%s\t%f\n", nPlot++, crvMyCurve.GetName(), irMyResults.Area );
if(i2 > i1)
{
crvMyCurve.SetLowerBound(save_i1);
crvMyCurve.SetUpperBound(save_i2);
}

}
}



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