LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dead loop in formula node

Hi,
 
I have encountered the following problem in a formula node. Everything seems simple and right. But there is no output and the loop goes on forever. The sizes of both input arrays are the same. Need your advice. Thanks.
 
Rut
 
 
0 Kudos
Message 1 of 7
(3,511 Views)
Are you sure you want the test condition of the FOR loop to be "n1-1"? this in a neverchanging condition and will always be false. try e.g. "n1-i" or whatever is appropriate.
0 Kudos
Message 2 of 7
(3,497 Views)
Hi, altenbach,
 
I still don't see why the n1-1 is neverchanging condition. I think my question was clear enough. The restated question is: I have this loop in a system and every 100ms when data (about 100points for each array) come in, the formula node is called to do some calculation and output to 2 arrays of the same amount of data points. I tested the formula with 4 points of data in each array and it never ended. I couldn't see anything that could go wrong with inside statements. Need somebody's advice. Also, wondering how to debug formula and script nodes, and how to debug general Labview programs. The inside statements are as follows:
 
float d=2;
float B=6.29;
float V1=300;
float dv1[100];
float dv2[100];
int i;
float D1[100];
float D2[100];
for (i=0;n1-1;i++){
dv1[i]=-(log(VL1[i]/V1))/(d*B);
dv2[i]=-(log(VL2[i]/V1))/(d*B);
D1[i]=1.426*dv1[i]-0.773*dv2[i];
D2[i]=-0.78*dv1[i]+0.108*dv2[i];
}
 
where dv1 and dv2 are input arrays with same dimension, and n1 is the size of them. D1 and D2 are output arrays.
 
Thank you very much,
 
Rut
0 Kudos
Message 3 of 7
(3,467 Views)

Look, I am far out on a limb here, because I am not a C programmer. Whatever you're doing would make more sense from a FORTRAN point of view. 🙂

The LabVIEW formula node uses BNF notation (check the help), which is in many ways C like. So the syntax for a FOR loop is:

for ( InitExpression ; CondExpression ; LoopExpression ) Statement

This means the loop iterates until "CondExpression" is true.

Do a google search on "C For loop" and you might find for example pages like:

http://www.hitmill.com/programming/cpp/forLoop.htm
http://www.geocities.com/learnprogramming123/Clesson8Beginner.htm

Your condExpression is "n1-1", which, during the execution of the node is a constant. For example if you array size is 50, n1-1=49, FOREVER! The condition is never true so the loop will never stop.

I hope somebody more knowledgable will chip in at one point. 🙂

0 Kudos
Message 4 of 7
(3,460 Views)

Your condition for stopping is incorrect. You are not comparing it to anything. For example, you should have something like i<n1-1.

You can also quite easily implement this with native LabVIEW functions.



Message Edited by Dennis Knutson on 11-16-2007 10:30 AM
0 Kudos
Message 5 of 7
(3,459 Views)
sorry. should read "was not clear enough".
0 Kudos
Message 6 of 7
(3,457 Views)

altenbach and Denis,

Thanks for both of you and you guys are right. My incorrect test condition had something to do with Matlab (not pure though). I thought Labview supports Matlab scripts this way. It should be in the script node that I haven't tried yet. It's working now. I appreciate your time and kindness.

Rut

0 Kudos
Message 7 of 7
(3,445 Views)