DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Split Data Into Multiple Channels From An Event Search

Solved!
Go to solution

Hello,

 

I'm trying to streamline my scripts and this is the last manual thing that I have to do. I have some data go through an event search and end up with a data channel that is zero's or one's. Then I would multiply that by the data I'm interested in looking at. Is there a way that I can split up that data the final data into as many channels as there is distinct blocks of data?

 

For example in the picture below there are 3 distinct blocks of data. The top graph is the event search and the bottom one is the data after multiplication with the event search. I would like to run a script that breaks it up into three different channels.

 

TW_Test_0-1619652341258.png

 

I'm trying to figure out a DataBlCopy command inside a loop, but I don't know how to do that. I also could maybe use ChnSplitAtValue inside a loop?

 

Thanks,

Tyler

0 Kudos
Message 1 of 9
(2,136 Views)

I got a purely hardcoded script put together. This will be good enough for most of my testing at the moment. I couldn't figure out how to get this into a dynamic for... loop. If anyone has any additional information for getting the for... loop to work that would be appreciated.

 

Dim Mark1, Mark2, Mark3, Mark4, Mark5, Mark6, Mark7, Mark8, Mark9, Mark10, Mark11, Mark12

Mark1 = ChnFind("Ch(""EventKPH"")>0",0)
Mark2 = ChnFind("Ch(""EventKPH"")=0",Mark1)

Mark3 = ChnFind("Ch(""EventKPH"")>0",Mark2)
Mark4 = ChnFind("Ch(""EventKPH"")=0",Mark3)

Mark5 = ChnFind("Ch(""EventKPH"")>0",Mark4)
Mark6 = ChnFind("Ch(""EventKPH"")=0",Mark5)

Mark7 = ChnFind("Ch(""EventKPH"")>0",Mark6)
Mark8 = ChnFind("Ch(""EventKPH"")=0",Mark7)

Mark9 = ChnFind("Ch(""EventKPH"")>0",Mark8)
Mark10 = ChnFind("Ch(""EventKPH"")=0",Mark9)

Mark11 = ChnFind("Ch(""EventKPH"")>0",Mark10)
Mark12 = ChnFind("Ch(""EventKPH"")=0",Mark11)

Call DataBlClpCopy("[1]/Integrated", Mark1, Mark2-Mark1)
Call ChnClpPaste(1, True)
Call DataBlClpCopy("[1]/Integrated", Mark3, Mark4-Mark3)
Call ChnClpPaste(1, True)
Call DataBlClpCopy("[1]/Integrated", Mark5, Mark6-Mark5)
Call ChnClpPaste(1, True)
Call DataBlClpCopy("[1]/Integrated", Mark7, Mark8-Mark7)
Call ChnClpPaste(1, True)
Call DataBlClpCopy("[1]/Integrated", Mark9, Mark10-Mark9)
Call ChnClpPaste(1, True)
Call DataBlClpCopy("[1]/Integrated", Mark11, Mark12-Mark11)
Call ChnClpPaste(1, True)
0 Kudos
Message 2 of 9
(2,085 Views)

Please have also a look at the Event functions in ANALYSIS and possibly at the example "EventDetection.VBS"

 

P1.png

 

Greetings

Walter

0 Kudos
Message 3 of 9
(2,059 Views)

Thanks Walter. Unless there is more functionality in the "Event Search" function that I'm missing, that is how I came up with the segmented runs. Before that there was data in between the distinct blocks of data.

 

I'm working on a for...loop right now that isn't quite working, but I'll try posting it later today to see if someone can get it all the way there.

 

Thanks,

Tyler

0 Kudos
Message 4 of 9
(2,051 Views)

Hey TW_Test,

 

Aside from the looping question, I would recommend that you switch away from the clipboard commands you probably Script Recorded:

Call DataBlClpCopy("[1]/Integrated", Mark1, Mark2-Mark1)
Call ChnClpPaste(1, True)

The DataBlClpCopy() command formats all the data values you're copying as strings and saves them to the Windows clipboard, then the ChnClpPaste() command unformats them from those clipboard strings back into DBL values.  It's a completely unnecessary pair of steps that will slow execution. 

 

You can accomplish the same thing with one traditional DIAdem command:

Call DataBlCopy("[1]/Integrated", Mark1, Mark2-Mark1, NewChannel)

 

You can also use built in methods of the Channel object to do the same thing:

Set Channel = Data.Root.ChannelGroups(1).Channels("Integrated")
Values = Channel.GetValuesBlock(Mark1, Mark2-Mark1)
Call NewChannel.SetValuesBlock(Values)

 

Brad Turpin

Principal Technical Support Engineer

NI

0 Kudos
Message 5 of 9
(2,046 Views)

Thanks Brad. You are correct, I just Script Recorded those clipboard commands. I will try to integrate the Channel objects you mentioned below. I think those will help me out when trying to write future scripts.

 

Thanks,

Tyler

0 Kudos
Message 6 of 9
(2,037 Views)

This is ideally how I would want to write this loop, but either I don't have the right syntax or I can't define a variable with a collection of string and a different variable.

 

Mark0 = 0

For n = 0 to 6 Step 2
a = n + 1
b = n + 2
"Mark" & a = ChnFind("Ch(""[1]/EventKPH"")>0", "Mark" & n)
"Mark" & b = ChnFind("Ch(""[1]/EventKPH"")=0", "Mark" & a)
Next

 

To get around that I tried to make a new channel for each time ChnFind finds the next row. This should work, but I can't figure out how to call the first value from the channel. So it starts at zero each time and just finds the same point each time it goes through the loop. Both ChnFind and PNo find the row that corresponds with a value. I can't figure out how to call the value in row 1 of Channel "Mark0" for example, which is zero. The MsgBox is just for me to try to figure out why it is not working.

 

Dim n, a, b
Dim Mark0, MarkFirst, MarkFirstNum, MarkStart, MarkStartNum, MarkEnd, MarkEndNum
Dim sInput

Call Data.Root.ChannelGroups(1).Channels.Add("Mark0",DataTypeFloat64)
Call Data.Root.ChannelGroups(1).Channels("Mark0").SetValues(0,1,1)

For n = 0 to 6 Step 2
a = n + 1
b = n + 2

MarkFirst = "Mark" & n
'MarkFirstNum = ChnFind("Ch(""[1]/" & MarkFirst & """)>-1",0)
'MarkFirstNum = PNo(Data.Root.ChannelGroups(1).Channels(MarkFirst),1)
MarkStartNum = ChnFind("Ch(""[1]/EventKPH"")>0",MarkFirstNum)
MarkStart = "Mark" & a
Call Data.Root.ChannelGroups(1).Channels.Add(MarkStart,DataTypeFloat64)
Call Data.Root.ChannelGroups(1).Channels(MarkStart).SetValues(MarkStartNum,1,1)

MarkEndNum = ChnFind("Ch(""[1]/EventKPH"")=0",MarkStartNum)
MarkEnd = "Mark" & b
Call Data.Root.ChannelGroups(1).Channels.Add(MarkEnd,DataTypeFloat64)
Call Data.Root.ChannelGroups(1).Channels(MarkEnd).SetValues(MarkEndNum,1,1)

sInput = "MarkFirst = " & Markfirst & vbCRLF & " MarkFirstNum = " & MarkFirstNum & vbCRLF & " MarkStart = " & MarkStart & vbCRLF & " MarkStartNum = " & MarkStartNum & vbCRLF & " MarkEnd = " & MarkEnd & vbCRLF & " MarkEndNum = " & MarkEndNum
Call MsgBox(sInput)

Next

 

0 Kudos
Message 7 of 9
(2,022 Views)

I knew it would be an easy thing I was overlooking. I'll play around with it some more now and try to get the rest of it working.

 

MarkFirstNum = Data.Root.ChannelGroups(1).Channels(MarkFirst).Values(1)

 

0 Kudos
Message 8 of 9
(2,020 Views)
Solution
Accepted by topic author TW_Test

Here is the loop that I got working. Thought I would put this up here in case it helps anyone.

 

Call Data.Root.ChannelGroups(1).Channels.Add("Mark0",DataTypeFloat64)
Call Data.Root.ChannelGroups(1).Channels("Mark0").SetValues(0,1,1)

For n = 0 to 6 Step 2
a = n + 1
b = n + 2
MarkFirst = "Mark" & n
MarkFirstNum = Data.Root.ChannelGroups(1).Channels(MarkFirst).Values(1)
MarkStartNum = ChnFind("Ch(""[1]/EventKPH"")>0",MarkFirstNum)
MarkStart = "Mark" & a
Call Data.Root.ChannelGroups(1).Channels.Add(MarkStart,DataTypeFloat64)
Call Data.Root.ChannelGroups(1).Channels(MarkStart).SetValues(MarkStartNum,1,1)
MarkEndNum = ChnFind("Ch(""[1]/EventKPH"")=0",MarkStartNum)
MarkEnd = "Mark" & b
Call Data.Root.ChannelGroups(1).Channels.Add(MarkEnd,DataTypeFloat64)
Call Data.Root.ChannelGroups(1).Channels(MarkEnd).SetValues(MarkEndNum,1,1)

Set Channel = Data.Root.ChannelGroups(1).Channels("Integrated")
Values = Channel.GetValuesBlock(MarkStartNum, MarkEndNum - MarkStartNum)
Call Data.Root.ChannelGroups(1).Channels.Add("Integrated" & n,DataTypeFloat64)
Set NewChannel = Data.Root.ChannelGroups(1).Channels("Integrated" & n)
Call NewChannel.SetValuesBlock(Values)
Next 

 

0 Kudos
Message 9 of 9
(1,946 Views)