10-10-2016 09:04 AM
Hi. I'm relatively new to DIAdem and have limited scripting skills. I can't figure out how to do this either by a DIAdem function or by a script...
I have multiple time channels, each offset by a fraction from the other time channels. Each time channel has a corresponding Y-value channel. I want to merge the x-y pairs into a single x (time) channel, sorted, and a single y channel. So for example, the original data is:
Channel 1: t0, t1, t2, t3,...
Channel 2: y0, y1, y2, y3,...
Channel 3: t0+0.1, t1+0.1, t2+0.1, t3+0.1,...
Channel 4: z0, z1, z2, z3,...
Channel 5: t0+0.2, t1+0.2, t2+0.2, t3+0.2,...
Channel 6: p0, p1, p2, p3,...
etc.
I want these merged into:
Channel 1: t0, t0+0.1, t0+0.2,...,t1, t1+0.1, t1+0.2,...,t2, t2+0.1, t2+0.2,..., t3, t3+0.1, t3+0.2,...
Channel 2: y0, z0, p0,..., y1, z1, p1,..., y2, z2, p2,..., y3, z3, p3,...
Can anyone guide me as to how I can most easily to this?
Thanks!
10-10-2016 05:32 PM - edited 10-10-2016 05:32 PM
The code below gives you the desired result for the time channel. It can be modified to do the same for the y channels. Without knowing exactly how many channels of each, and how your Data Portal is setup, it's hard to create a script that will automatically adjust for the number of channels. It would be easiest if you had the time channels in one group. the y channels in another and a third group for the merged channels. If you're okay with that let me know and I can adjust.
Dim ChnMax ChnMax = 9 '-- Enter the length of the merged channel here Call ChnOffset("[1]/Channel 1","[1]/Channel 3",0.1,"free offset") Call ChnOffset("[1]/Channel 1","[1]/Channel 5",0.2,"free offset") Call Data.Root.ChannelGroups(1).Channels.Add("Channel 1 Merge",DataTypeFloat64,1) Call Data.Root.ChannelGroups(1).Channels("Channel 1 Merge").Properties.Add("Length",ChnMax) Dim iLoop, i i = 1 For iLoop = 1 to ChnMax / 3 CHV(i, "[1]/Channel 1 Merge") = CHV(iLoop, "[1]/Channel 1") CHV(i+1, "[1]/Channel 1 Merge") = CHV(iLoop, "[1]/Channel 3") CHV(i+2, "[1]/Channel 1 Merge") = CHV(iLoop, "[1]/Channel 5") i = i + 3 Next
10-10-2016 06:16 PM
The script below will work with any number of channels if all your time channels are in group 1, and all your y channels are in group 2 (in the correct order). It will create a third group with the merged channels. If you aren't in need of creating the time channels, delete lines 1-3. I can upload a sample TDM if you want to see how it works.
'-- Create Offset Time Channels Call ChnOffset("[1]/Channel 1","[1]/Channel 3",0.1,"free offset") Call ChnOffset("[1]/Channel 1","[1]/Channel 5",0.2,"free offset") '-- Create Merged Channels Dim ChnMax ChnMax = ChnLength("[1]/[1]") * GroupChnCount(1) Call Data.Root.ChannelGroups.Add("Merged", 3) Call Data.Root.ChannelGroups(3).Channels.Add("Channel 1",DataTypeFloat64,1) Call Data.Root.ChannelGroups(3).Channels("Channel 1").Properties.Add("Length",ChnMax) Call Data.Root.ChannelGroups(3).Channels.Add("Channel 2",DataTypeFloat64,2) Call Data.Root.ChannelGroups(3).Channels("Channel 2").Properties.Add("Length",ChnMax) '-- Build Merged Channels Dim i, iLoop, iLoopC i = 1 For iLoopC = 1 to GroupChnCount(1) For iLoop = 1 to ChnLength("[1]/[1]") CHV(i, "[3]/Channel 1") = CHV(iLoop, "[1]/["&iLoopC&"]") CHV(i, "[3]/Channel 2") = CHV(iLoop, "[2]/["&iLoopC&"]") i = i + 3 Next i = iLoopC + 1 Next
10-11-2016 10:29 AM
Thanks, everyone. A coworker of mine came up with a simple solution using ChnConcat and ChnMultipleSort !