DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Odd division result and how to Calculate value per channel sub index

Greetings; I perform engine test using EPA certification procedures from FTP75.

As a part of those we measure in ppm various exhaust compounds then convert them into grams.

Later the grams are weighted per section of FTP75 then summed up divided by a distance into a grams/mile value.

I can get part of this accomplished, converting ppm into grams, creating a time stamp. Its when I try to weight the values of a single channel per factors at in certain sections of a channel. I sense what I do not understand is how to make calculation against a channel sub index so that only certain part of the data are modified. Couple of things... 1) as I goto divide grams exhaust by distance I get an odd return, really high number followed by much lower, you can see in SummingEmissPPM.vbs at row 270, 71, 73 I try this. You can see how I create a 0 start time stamp using TimeSTampST.vbs. the two png files show one way of applying the weighting factors to the cold start, stabilize and hot start section. The word document dives deeper into that calculation:

Phil_at_work_0-1603313876344.png

In the end I struggle to create a single channel of grams per mile (weighted) against b2_nox and b1_nox channels.

 

 

   

0 Kudos
Message 1 of 3
(1,320 Views)

Hi Phil,

 

I'm going to answer the following question, which I hope is the crux of the issue that you're struggling with.  You want to perform certain components of a FormulaCalc() or ChnCalculate() or Calculate() command based on whether the current channel row is within an acceptable row range/window, like this:

 

Call FormulaCalc("Ch('["&x&"]/WeightNOxHC') :=   ("Ch('["&x&"]/NOxHC') * 0.43 for sub-index 0 to 505 + ("Ch('["&x&"]/NOxHC') * 1.0 for sub-index 505 to 1372 + ("Ch('["&x&"]/NOxHC') * 0.53 for sub-index 1373 to 1877

 

The only calculations in DIAdem that accept a row range subset as a native parameter are the statistics calculations.  For everything else, you have to handle the row subsets yourself, often by creating a new channel with only the row subset values.  In the case of a Calculator expression where you want to execute piece-wise formulas that are gated by row range, though, I think you'd be best served to create a temporary channel, let's call it "CurrRow", of same length as the other channels in the Calculator expression.  You can fill those values with the ChnLinGen() command or the ChnLinGenImp() command to create a channel whose values reflect the current row value of the Calculator expression calculation.

Data.Root.ChannelGroups(x).Activate()
Call ChnLinGenImp("CurrRow", 1878, 1, 1)
Calculation = "Ch('["&x&"]/WeightNOxHC') := Ch('["&x&"]/NOxHC') * 0.43 * (Ch('["&x&"]/CurrRow')>=   1) * (Ch('["&x&"]/CurrRow')<= 506)" &_
                                         "+ Ch('["&x&"]/NOxHC') * 1.00 * (Ch('["&x&"]/CurrRow')>= 507) * (Ch('["&x&"]/CurrRow')<=1373)" &_
                                         "+ Ch('["&x&"]/NOxHC') * 0.53 * (Ch('["&x&"]/CurrRow')>=1374) * (Ch('["&x&"]/CurrRow')<=1878)"
Call FormulaCalc(Calculation)

 

See if this gets you any further,

Brad Turpin

Technical Support Engineer

NI

0 Kudos
Message 2 of 3
(1,200 Views)

Hey Phil,

 

I had two further thoughts on this issue.  The first is that your FormulaCalc() expression  would be a lot simpler if you would do the channel lookup outside the command and just reference the result, say using global variables L1 and L2.  My second thought is that there's no reason to have a separate "CurrRow" channel for each "x" Group, unless the size of the channels varies from Group to Group, and even then you could get by with one "CurrRow" channel that was simply as long as the longest channel in all the Groups.  In that case you can take the L2 = CNo("CurrRow") below instead of the one that looks in the "x" Group:

 

Data.Root.ChannelGroups(x).Activate()
Call ChnLinGenImp("CurrRow", 1878, 1, 1)
L1 = CNo("["&x&"]/NOxHC")
L2 = CNo("["&x&"]/CurrRow")
L2 = CNo("CurrRow")
Calculation = "Ch('["&x&"]/WeightNOxHC') := Ch(L1) * 0.43 * (Ch(L2)>=   1) * (Ch(L2)<= 506)" &_
                                         "+ Ch(L1) * 1.00 * (Ch(L2)>= 507) * (Ch(L2)<=1373)" &_
                                         "+ Ch(L1) * 0.53 * (Ch(L2)>=1374) * (Ch(L2)<=1878)"
Call FormulaCalc(Calculation)

 

Note how much simpler the expression logic appears when you don't have the distractions from the component channel referencing embedded in it.  There are other ways to gain this benefit, but this shows the idea clearly.  In practice this makes the FormulaCalc() expression MUCH easier to debug.

 

Brad Turpin

Principal Technical Support Engineer

NI

0 Kudos
Message 3 of 3
(1,187 Views)