02-06-2007 03:32 PM
02-06-2007 04:02 PM
Hello Jeff!
The approach with a loop is obvious but slow. You can speed it up with the faster CHDX command and disolve the channel names to channel numbers with CNO in front of the loop.
The realy fast solution is done with the FormulaCalc command. Please set the DIAdem Variable R1 to the BlowerLow value and R2 to the BlowerOff value and than run this line:
Call FormulaCalc("Ch('EP_HP (Low)') := (Ch('EP_HP') > R1) * Ch('EP_HP') + (Ch('EP_HP') <= R1) * R2")
The clue is that a true condition is evaluated to 1 a false to 0. With the multiplication and the to opposit conditions you get the two different values. DIAdem process this verry fast!
Matthias
Matthias Alleweldt Project Engineer / Projektingenieur | Twigeater? |
02-06-2007 04:31 PM
02-07-2007 08:26 AM
02-07-2007 08:33 AM
Found it. You need to reference absolute...i.e. the / in front of channel names to imply default group. The working equation now looks likes this
Call FormulaCalc("Ch('/EP_HP (High)') := (Ch('/EP_HP') <= R1) * Ch('/EP_HP') + (Ch('/EP_HP') > R1) * R2")
THanks! Speed is awesome.
02-07-2007 09:34 AM
Hi Jeff,
One more point on this. If you can use the FormulaCalc() function to do your assignments, there is no faster way in DIAdem. There are times, however, when you need to change only isolated cells in a channel, or when the branching or logic regarding what to write defies the FormulaCalc() syntax. When you absolutely positively have to use a VBScript loop to make channel cell assignments, you should consider the ChDX() command instead of the ChD() command. The ChD() command accepts channel strings ("[1]/Speed"), so it does a fairly quick look-up to find the channel you mean, but more importantly it recalculates the characteristic values (min, max, monotonicity, novaluekey) of the edited channel AFTER EVERY TIME THAT YOU CHANGE A CELL VALUE. This is what really slows down that loop of yours. The ChDX() command only accepts the channel number as returned by CNo() or CNoXGet(), so it avoids the channel name look-up, and it does NOT recalculate the characteristic properties of the channel. This means you should really call ChnCharacter() afterwards so the max, min, etc. values reflect your updates. It also means that the ChDX() command is easily able to make over 100,000 cell assignments per second. Here's what your code would look like with this method:
j = CNo("/EP_HP")
k = CNo("/EP_HP (Low)")
For i = 1 to ArrayLength
if ChDX(i, j) > BlowerLow then
ChDX(i, k) = BlowerOff
else
ChDX(i, k) = ChDX(i, j)
end if
Next
Call ChnCharacter(k)
In case you need it later,
Brad Turpin
DIAdem Product Support Engineer
National Instruments
02-07-2007 09:53 AM
Thanks, Brad. had Matthias' solution not been so elegant, I'd be following this.
Sincerely, Jeff!