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
 foreach loop

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
alex_eagle Posted - 10/17/2003 : 06:11:50 AM
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 ?


1   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 10/17/2003 : 08:08:48 AM
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);
}

}
}




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