# Forum FlexPro – Discuss your topic!

## if condition

Home > Community > FPScript > if condition

Ansicht von 9 Beiträgen – 1 bis 9 (von insgesamt 9)
• Autor
Beiträge
• #12506
Dirk Kampffmeyer
Teilnehmer

I have serious problems to implement `if` conditions. For instance I have to calculate dewpoints which is not any obstacle, but afterwards I attempt to sum these dewpoints up to partial pressures and it doesn`t work. To illustrate my problem I give the program code:

dim tau,pv,i,s,ppm

For Each Row i In CH1 Do

tau=ch1.Y/2*130-110 // dewpoint

if tau<0 then
pv=611.15*exp(22.542*tau/(tau+273.48)); // partial pressure
else
pv=611.21*exp(17.502*tau/(240.97+(tau*65-110)));
end
ppm=pv/101325*10^6

end

#8169
Dirk Kampffmeyer
Teilnehmer

I have serious problems to implement `if` conditions. For instance I have to calculate dewpoints which is not any obstacle, but afterwards I attempt to sum these dewpoints up to partial pressures and it doesn`t work. To illustrate my problem I give the program code:

dim tau,pv,i,s,ppm

For Each Row i In CH1 Do

tau=ch1.Y/2*130-110 // dewpoint

if tau<0 then
pv=611.15*exp(22.542*tau/(tau+273.48)); // partial pressure
else
pv=611.21*exp(17.502*tau/(240.97+(tau*65-110)));
end
ppm=pv/101325*10^6

end

#8806
Bernhard Kantz
Teilnehmer

You have forgotten to return the result:

``````
For
...
End
ppm //or return ppm
``````

But in this case the result is only the ppm of the last value. If you want to calculate the ppm of each value try this

``````
Dim tau = ch1.Y/2*130-110 // dewpoint
Dim idxAbove = ValuesAboveLevel(tau, 0, EVENT_INDEX)
tau = 611.15*exp(22.542*tau/(tau+273.48)) // partial pressure
tau[idxAbove] = 611.21*exp(17.502*tau[idxAbove]/(240.97+(tau[idxAbove]*65-110)))
tau/101325*10^6
``````

FPScript is a vectorial script language. Therefore you need no loop to manipulate the whole signal.

support@weisang.com

#8807
Dirk Kampffmeyer
Teilnehmer

Thank you for your support. The formula is working rather well, but if the signal is rising up to 1.7 the results become too high.
Signal:
21 1,68925
22 1,71725
23 1,7133125
24 1,735625
25 1,732875
26 1,736
27 1,7446875
28 1,7549375
29 1,758875
30 1,7646875
31 1,7715625
32 1,7709375
33 1,769125
34 1,77425
35 1,770125
36 1,76425
37 1,7693125
38 1,77175
39 1,7569375
40 1,762
41 1,7371875
42 1,7355
43 1,7155625
44 1,692125
Results:
21 5933,50484
22 2696401011
23 2514035768
24 3697558728
25 3530971112
26 3720759050
27 4291879038
28 5053249400
29 5372463216
30 5872151797
31 6508674208
32 6448717840
33 6277230852
34 6771345639
35 6371406764
36 5833334034
37 6294807061
38 6526743852
39 5213478477
40 5636824868
41 3795002615
42 3689851293
43 2616946068
44 6025,680376

I really do not know what the formula sums up.
Code:
Dim tau = ch1.Y/2*130-110 // dewpoint
Dim idxAbove = ValuesAboveLevel(tau, 0, EVENT_INDEX)
tau = 611.15*exp(22.542*tau/(tau+273.48)) // partial pressure
tau[idxAbove] = 611.21*exp(17.502*tau[idxAbove]/(240.97+(tau[idxAbove])))
tau/101325*10^6

#8808
Bernhard Kantz
Teilnehmer

Use

``````
tau[idxAbove] = 611.21*exp(17.502*tau[idxAbove]/(240.97+(tau[idxAbove]*65-110)))
``````

``````
tau[idxAbove] = 611.21*exp(17.502*tau[idxAbove]/(240.97+(tau[idxAbove])))
``````

support@weisang.com

#8809
Dirk Kampffmeyer
Teilnehmer

The problem, however, is that I modified my formula. That is why I need the new one:
tau[idxAbove] = 611.21*exp(17.502*tau[idxAbove]/(240.97+(tau[idxAbove])))
I sumed it up by my calculator and there was not such high figure as result.

#8810
Bernhard Kantz
Teilnehmer

The code “tau = …” changes all tau values. Therefore the next line uses the wrong values to calculate the values above 0.

Use the IndexNot function to calculate the indices of tau values below 0.

``````
Dim tau = ch1.Y/2*130-110
Dim idxAbove = ValuesAboveLevel(tau, 0, EVENT_INDEX)
Dim idxBelow = IndexNot(idxAbove, NumberOfRows(ch1))
tau[idxBelow] = 611.15*exp(22.542*tau[idxBelow]/(tau+273.48))
tau[idxAbove] = 611.21*exp(17.502*tau[idxAbove]/(240.97+(tau[idxAbove])))
tau/101325*10^6
``````

support@weisang.com

#8811
Dirk Kampffmeyer
Teilnehmer

Hello,
first of all I would like to thank you. Now I have a last request: I would like to search the maximum of the signal and let the program sum it up from this maximum.
dim tau = ch1.y/2*130-110
Dim idxAbove = ValuesAboveLevel(tau, 0, EVENT_INDEX)
Dim idxBelow = IndexNot(idxAbove, NumberOfRows(ch1))
tau[idxBelow] = 611.15*exp(22.542*tau[idxBelow]/(tau[idxBelow]+273.48))
tau[idxAbove] = 611.21*exp(17.502*tau[idxAbove]/(240.97+tau[idxAbove]))
tau/101325*10^6

#8812
Bernhard Kantz
Teilnehmer

You can use the Maximum-function to calculate the maximum of the signal. You find all FPScript functions in the function wizard.