DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

CHD Command is SLOW...How can I speed up processing

I have the following loop in a Diadem Script...Any thoughts on how to make it run FASTER...A channel with "only" 13792 elements is taking over 20 seconds to process...and I have to repeat this three times..
 
For Counter = 1 to ArrayLength
   if CHD(Counter, "/EP_HP") > BlowerLow then
      CHD(Counter, "/EP_HP (Low)") = BlowerOff
   else
      CHD(Counter, "/EP_HP (Low)") = CHD(Counter, "/EP_HP")
   end if
Next
 
 
Any insight would be appreciated.
0 Kudos
Message 1 of 7
(4,116 Views)

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?  
0 Kudos
Message 2 of 7
(4,104 Views)
Thanks, Matthias.  It certainly faster.  The numbers aren't coming out correctly, but I'm looking into that.  I repeat this three times, and two appear OK, the third doesn't.
 
Thanks for this...much, much better.
0 Kudos
Message 3 of 7
(4,098 Views)
Matthias...I'm noticing that the FormulaCalc command increments the array index once for each call to the channel, hence my resulting channel has 1/2 the number of values as the input.
 
Any thoughts?
0 Kudos
Message 4 of 7
(4,078 Views)

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.

0 Kudos
Message 5 of 7
(4,077 Views)

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

0 Kudos
Message 6 of 7
(4,073 Views)

Thanks, Brad.  had Matthias' solution not been so elegant, I'd be following this.

 

Sincerely, Jeff!

0 Kudos
Message 7 of 7
(4,069 Views)