DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

script running to long

I have a script that requires almost ten minutes to run. That is to long for my purposes. The script is finding peaks and valleys of data with the time channel being the x-axis. I'm trying then to graph the results versus another channel that corresponds to the time channel (Cycle Count channel). I tried using the built in peak finding functions to do it but it can't get it right so I decided to write a script to do it. The script is below:

 

Call UIAutoRefreshSet(False) 'Deactivate UI refreshing
Dim i,j,k
Call ChnPeakDetect("[1]/Time","[1]/Sample Pressure","/Position","/Amplitude","Peaks",8125,10)
Call ChnPeakDetect("[1]/Time","[1]/Sample Pressure","/Position1","/Amplitude1","Valleys",8120,10)
Call ChnAlloc("Cycle Count Max Pressure",CL("Position"),1,DataTypeFloat64)
Call ChnAlloc("Cycle Count Min Pressure",CL("Position1"),1,DataTypeFloat64)
i=1
Call FormulaCalc ("Ch('Position'):= Round ('Position')")
While (i<=CL("Position"))
   j=ChD(i,"Position")
  k=ChnFind("Ch(""Time"")="&str(j),1)
  ChD(i,"Cycle Count Max Pressure")=ChD(k,"Cycle Count")
  i=i+1
Wend

 

Anybody have any ideas how to cut down the script run time? Thanks.

0 Kudos
Message 1 of 3
(5,184 Views)

Hi,

 

for me it helped a lot using the OO-access, it will look like that

 

Dim oChnPos : Set oChnPos = Data.Root.ChannelGroups(1).Channels("Position")
Dim oChnCCMP : Set oChnCCMP = Data.Root.ChannelGroups(1).Channels("Cycle Count Max Pressure")
Dim oChnCC : Set oChnCC = Data.Root.ChannelGroups(1).Channels("Cycle Count")
Dim i

For i = 1 To oChnPos.Size
  j = oChnPos(i)
  k = ChnFind("Ch(""Time"")="&str(j),1)
  oChnCCMP(i) = oChnCC(k)
Next

 

Message 2 of 3
(5,161 Views)

Hi steinmeister85,

 

If you'll post a data set to test with, I can try to speed things up for you.  I have a couple of ideas that might help.  I definitely agree that the object approach to channel reading, if done right, is faster than any ChD() type of approach, but it looks like you're doing the heavy lifting outside the loop.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 3 of 3
(5,135 Views)