DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

calculation problems

Solved!
Go to solution

Hi,

i wanted to write a script for multiple calculations where i should be able to change the inputs and outputs at the beginning of my script.

The problem is, if i use the easiest way of tha calculation script i can't define variables or i don't know how.

this was my try

 

Call Calculate("Ch(""[2]/pa_Titel"")= Exp(456 - (123 / (Ch(""[2]/T_LL_Ansaug"") + 789)))",NULL,NULL,pa_Einheit)

 

 

the problem is i want to assign another name to pa_Titel and T_LL_Ansaug at the beginning of my script.

like this

 

Dim tL
Dim pa_Titel
Dim pa_Einheit 
pa_Einheit = "mbar"
pa_Titel = "[2]/Wasserdampfsättigungsdruck"
tL = "[2]/T_LL_Ansaug" 
Call Calculate("Ch("pa_Titel")= Exp(789 - (456 / (Ch("tL") + 123)))",NULL,NULL,pa_Einheit)

 but that didn't work.

 

then i tried this

 

Dim tL
Dim pa_Titel
Dim pa_Einheit 
pa_Einheit = "mbar"
pa_Titel = "[2]/Wasserdampfsättigungsdruck"
tL = "[2]/T_LL_Ansaug"   

Dim  CurrSymbols(2), CurrValues(2)
CurrSymbols(1) = "pa_Titel"
CurrSymbols(2) = "tL"
Set CurrValues(1) = Data.GetChannel(pa_Titel)
Set CurrValues(2) = Data.GetChannel(tL)
Call Calculate("pa_Titel = Exp(789 - (456 / (tl + 123)))",CurrSymbols,CurrValues,pa_Einheit)

 the problem here is that the channel pa_Titel doens't exist and that the output should be called Wasserdampfsättigungsdruck and not pa_Titel.

 

i could do it with the calculation manager but i have many calculations and it's easier to do this in a script.

can you tell me how to do this.

 

 

0 Kudos
Message 1 of 12
(4,784 Views)

i just saw that the output of the last version IS called Wasserdampfsättigungsdruck. but it only works if the channel exists.

i think i only have to change this part

 

Set CurrValues(1) = Data.GetChannel(pa_Titel)

 

i could create a Channel with the right name before i use the calculation but is there not a better way to do this?

the Problem is if i create a channel with 

Call Data.Root.ChannelGroups(2).Channels.Add(pa_Titel,DataTypeFloat64)

 i get a channel which is called [2]\Wasserdampfsättigungsdruck in the group 2. is there another way to do my calculation?

 

0 Kudos
Message 2 of 12
(4,778 Views)

Hello Norman,

 

It seems that the string syntax in your calculation function is not correct. If you're using variable for the channel names you need to set the correct quotation mark syntax and concatenate the string fragments. But I would like to point to the Calculation Manager in DIAdem-ANALYSIS which is a more powerful and easier of use tool for calculations like yours. If you once set-up your formulas in the Calculation Manager you can change the input channel names very easy. In the following example the first input channel of a formula (which is defined in a formula group) is changed.

 

 

dim oMyCalc
call CalculationSet.Load("My Calculation Set")
set oMyCalc = CalculationSet.CalculationGroups("My Calculation Group").Calculations("My Calculation")
oMyCalc.Inputs(1).Reference.Channel = "My New Channel"
oMyCalc.Run

 I hope this can help you

 

Greetings

Walter

 

0 Kudos
Message 3 of 12
(4,775 Views)

Hi Walter,

thanks for the hint with the calculation manager but it's easier with a script. i don't need automatically change the calculations. in a while a need to change the inputs from the calculations and there are about 100 calculations. it's faster to do this in the scripting part.

 

i tried your tip with concatenating the strings but i didn't get it to work. i think i made a mistake with the quotation mark.

this is my calculation. and the error is ')' expected.

 

Call Calculate("Ch(""[2]/"& pa_Titel &")= Exp(123 - (456 / (Ch("""& tL & """) + 789)))",NULL,NULL,pa_Einheit)

 

can you help me to find my mistake?

 

 

Regards, Normann

0 Kudos
Message 4 of 12
(4,762 Views)

the solution was

 

Call Calculate("Ch(""[2]/"& pa_Titel &""")= Exp(123 - (456 / (Ch(""[2]/T_LL_Ansaug"") + 789)))",NULL,NULL,pa_Einheit)

 

 

thanks for your help Walter.

 

Regars Normann

0 Kudos
Message 5 of 12
(4,755 Views)
Solution
Accepted by topic author Normann

Hi Normann,

 

The following should work.

 

 

Call Calculate("ch(""" & pa_Titel & """) = Exp(789 - (456 / ( ch(""" & tl & """) + 123)))",Null, Null, pa_Einheit)

 

 

The calculation manager is of course designed to be used in scripts - but it is more easy to create the formula and to reuse it in scripts or interactively as often as it is needed.

 

Greetings

Walter

Message 6 of 12
(4,754 Views)

Ich bin gerade fertig geworden mit meinem Skript und wollte es laufen lassen aber leider funktioniert es nicht. Das Problem scheinen Double Werte zu sein die ich eine Calculation reinpacken will. geht das nicht oder muss ich es anders machen?

 

Dim zahl1, zahl2, zahl3
zahl1 = 4.5
zahl2 = 3.7
zahl3 = zahl1+zahl2


Call Calculate("Ch(""[2]/test"")="& zahl3 &"",NULL,NULL,"")

 wenn ich 4.5 und 3.5 addiere geht es aber wenn das Ergebnis ein Double Wert ist dann kommt immer der fehler "anweisungsende erwartet" muss ich Zahl3 irgendwie als Double definieren wie in VBA oder kann ich nur strings und integer in eine Calculation packen?

 

 

0 Kudos
Message 7 of 12
(4,649 Views)

ich habe gerade die Str-Funktion gefunden, damit funktioniert das umwandeln in einen String. Ist das die einzige Möglichkeit mit der ich berechnete Größen in einer Calculation verwenden kann?

0 Kudos
Message 8 of 12
(4,643 Views)

Hi Normann,

 

If you want to use a variable in the Calculate expression, then you need to make that variable a global variable with GlobalDim instead of just Dim.

 

Dim zahl1, zahl2
GlbalDim "zahl3"

zahl1 = 4.5
zahl2 = 3.7
zahl3 = zahl1+zahl2

Call Calculate("Ch(""[2]/test"")="& zahl3 &"",NULL,NULL,"")

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 9 of 12
(4,636 Views)

Hi Brad,

if i use your code i get the same error. i corrected the GlobalDim command.

can i compute with global and normal variables?

like

Dim zahl1, zahl2
GlobalDim "zahl3"
GlobalDim "zahl4"

zahl1 = 4.5
zahl2 = 3.7
zahl3 = zahl1+zahl2
zahl4 = zahl3*zahl1

Call Calculate("Ch(""[2]/test"")="& zahl3 &"",NULL,NULL,"")

 it would be nice if that works. if not i have to convert every calculation which is not done with in a Call Calculate with the Str Command.

 

Regards,

Normann

 

0 Kudos
Message 10 of 12
(4,632 Views)