09-04-2015 05:22 AM
Hi guys,
I have the following problem. I have several channels "Slip" and "Bondstress". The channels start at different times and the loading rate is not constant. I need to find a Bondstress that corresponds to a specific Slip and then make an average of the slip channels. I wrote the following code. I does what needs to be done, but is very slow as I would need aprox. 1000 vlaues in my LinearGenerated channel. The LinearGenerated channel containes the levels of Slip which I am interested in. Does anyone have an idea how to do it more elegant? I can't use the ChnAverage function as the channels have different time domain. I also tried linear mapping but couldn't make it work as the channels are not monotonically increasing - except of the LinearGenerated channel.
Thanks a lot in advance
dim i, n, iDeflection, iRowNo, oMyChn, oMyChnOld, oOldVerbund, oNewVerbund for i=1 to 4 Set oMyChn = Data.Root.ChannelGroups(i).Channels.Add("New schlupf", DataTypeFloat64) Set oMyChnOld = Data.Root.ChannelGroups(i).Channels("Schlupf") Set oOldVerbund = Data.Root.ChannelGroups(i).Channels("Verbundspannung") Set oNewVerbund = Data.Root.ChannelGroups(i).Channels.Add("New Verbundspannung", DataTypeFloat64) for n=1 to ChnLength(Data.Root.ChannelGroups(6).Channels("LinearGenerated")) iDeflection = Data.Root.ChannelGroups(6).Channels("LinearGenerated").values(n) iRowNo = ChnFind("Ch(""["&i &"]/Schlupf"")>="& str(iDeflection)) oMyChn(n)= oMyChnOld(iRowNo) oNewVerbund(n) = oOldVerbund(iRowNo) next next
09-07-2015 10:33 AM
Hello,
could you please add some comments to your code?
In general what you are doing looks fine and I don't see a chance to make it more efficient. I guess, depending on how many values you are working with, this might just take some time.
Best regards,
Kathrin
09-07-2015 11:13 AM
Hi,
I am not very good at programming so please applogize the programming faults. I added some comments to the code. I think that writing the values in the new channels take a lot of time. In Matlab, I would create a temporary vector of rows I am interested in, and then I would just copy these rows from the "Bondstress" channel in one block operation. But I am not sure how to do this in Diadem and if it would speed up the process. This script runs a few minutes. My channels have aprox. 30 000 values. It is also possible that finding the rows of interest takes a lot of time as well 😞
dim i, n, iDeflection, iRowNo, oMyChn, oMyChnOld, oOldVerbund, oNewVerbund for i=1 to 4 Set oMyChn = Data.Root.ChannelGroups(i).Channels.Add("New schlupf", DataTypeFloat64) Set oMyChnOld = Data.Root.ChannelGroups(i).Channels("Schlupf") 'Schlupf=slip Set oOldVerbund = Data.Root.ChannelGroups(i).Channels("Verbundspannung") 'Verbundspannung=bondstress Set oNewVerbund = Data.Root.ChannelGroups(i).Channels.Add("New Verbundspannung", DataTypeFloat64) for n=1 to ChnLength(Data.Root.ChannelGroups(6).Channels("LinearGenerated")) 'I have a generated channel containing slip values I am interested in - ca 500 values iDeflection = Data.Root.ChannelGroups(6).Channels("LinearGenerated").values(n) iRowNo = ChnFind("Ch(""["&i &"]/Schlupf"")>="& str(iDeflection)) 'For every row it looks into the channel of measured slips (that have corresponding bond stresses) and tries to find a deflection closest to my predefined deflection oMyChn(n)= oMyChnOld(iRowNo) 'gets the accutal value of the slip and adds it to the new channel created at the beginning of the script oNewVerbund(n) = oOldVerbund(iRowNo) 'When I have the row Nr.of the slip I am interested in I look into the channel with corresponding Stresses and I write the stress into the new channel next next 'After running this script, I have for all Samples in my Series 500 vlaues of slip and their corresponding stresses. So I can make an average from the stresses.
09-07-2015 04:00 PM
Hi Dasein,
This edited version of your script should run faster. I was unable to test it, though, so I might have introduced an error...
dim i, n, nMax, SlipGroup, Group, iDeflection, iRowNo, oMyChn, oMyChnOld, oOldVerbund, oNewVerbund Set SlipGroup = Data.Root.ChannelGroups(6) Set SlipChannel = SlipGroup.Channels("LinearGenerated") nMax = ChnLength(SlipChannel) for i = 1 to 4 Set Group = Data.Root.ChannelGroups(i) Set oMyChnOld = Group.Channels("Schlupf") 'Schlupf=slip Set oOldVerbund = Group.Channels("Verbundspannung") 'Verbundspannung=bondstress Set oMyChn = Group.Channels.Add("New schlupf", DataTypeFloat64) Set oNewVerbund = Group.Channels.Add("New Verbundspannung", DataTypeFloat64) for n = 1 to nMax 'I have a generated channel containing slip values I am interested in - ca 500 values iDeflection = SlipChannel(n) iRowNo = PNo(oMyChnOld, iDeflection) 'For every row it looks for the closest match oMyChn(n)= oMyChnOld(iRowNo) 'gets the accutal value of the slip and adds it to the new channel created at the beginning of the script oNewVerbund(n) = oOldVerbund(iRowNo) 'When I have the row Nr.of the slip I am interested in I look into the channel with corresponding Stresses and I write the stress into the new channel next next
Brad Turpin
DIAdem Product Support Engineer
National Instruments
09-08-2015 08:14 AM
Hi Brad,
thanks for your adjustments. Your modification of the code work fine, but it is still rather slow. Would there be any way how to store the rows of interest into an array in memory and then just coppy out those rows in one block operation from the respective channels?
Anyway thanks a lot for your help!