09-22-2023 09:53 AM
Hi, we need to through a channel and find at what time the peak is above a certain value, i.e 20 kPa.
So I can use the PNo-function but that would only return the first value (time) at approx 20 but I need to find a way to return at least the first and second value (when it passes 20 kPa from 18...19...20 kPa but then also the second value when it comes from 22...21...20 kPa). The time for those occurrences or time span is what I am interested in.
Also, if we have more peaks passing 20 kPa then those would be great to cover as well but that is only a bonus...
I run DIAdem version: 2012
Thanks in advance for advices!
/Mikael
09-27-2023 01:29 AM
Hello Mike_77,
DIAdem 2012 is a very old version that is not released for Windows 10 and Windows 11. This version unfortunately does not yet contain the event functions that can be used for your use case. As of DIAdem 2015, you can use the ChnEventDetectionWindow function to find one or more value ranges that are greater than a certain value. In the returned two-dimensional field you get the indices of the value ranges, which you can then use to determine the time range from the associated time channel.
The script, which can be used from DIAdem 2015, determines the value ranges that are above the value 5000.
' Just to get data for the example
call Data.Root.Clear()
call DataFileLoad("EXAMPLE.TDM")
dim i
dim TimeChannel : set TimeChannel = Data.Root.ChannelGroups(1).Channels(1)
dim LimitStart : LimitStart = 5000
ChnEventResultList = ChnEventDetectionWindow(, "[1]/[3]", LimitStart, Novalue)
For i = 1 to ChnEventCount(ChnEventResultList)
if ChnEventResultList(i, 0) > 0 and ChnEventResultList(i, 1) > 0 then
call LogFileWrite("Range No. " & i & " from index " & ChnEventResultList(i, 0) & " to index " & ChnEventResultList(i, 1))
call LogFileWrite(" Time span: " & TimeChannel.Values(ChnEventResultList(i, 0)) & " - " & TimeChannel.Values(ChnEventResultList(i, 1)))
end if
Next
It is recommended to update at least to version 2015.
Of course, you can also write a script that loops over the values and determines the value ranges. However, this will be slower and result in more extensive code than using the event functions of the later DIAdem versions.