I'll start by saying I'm garbage at coding.
I've been collecting gobs of strain, sound, accelerometer, temperature, etc. data.
I typically run the same functions on data given it's units.
I'd love to be able to create a script that runs a certain function (rainflow counting), on every channel that has certain units (ue) and store the resulting channel(s) with the channel name + within the group that the data came from.
Sometimes the function outputs new channels with the same units as the original. I know enough to know I don't want this script to recure on it's results.
Below is a screen capture of an example.
Any help is appreciated and, is literally lifesaving...(at least the saving of many hours of my life.
Below is a basic script template. You didn't provide enough information for a complete solution. Please run the 'Rainflow Classification' dialog, configure it the way you want, and then use the keys 'Ctrl-Shift-C' to copy the dialog settings to the clipboard. Paste those settings into a reply to this message post. You may be able to update the script I provided with those settings.
Dim sPathData, oChnX, oChnY, sUnit, oGrp, oChn, oElementList, oChnCopy
'Load DIAdem example file
sPathData = ProgramDrv & "Examples\Data\"
Call DataFileLoad(sPathData & "Example_data.tdm", "TDM", "Load|ChnXYRelation")
'Create some channels with the unit µε
sUnit = "µε" 'edit to what microstrain unit you are looking for.
'Add the unit µε two a few channels
Set oChn = Data.GetChannel("Example/RPM") :oChn.UnitSymbol = sUnit
Set oChn = Data.GetChannel("Noise data/Noise_4") :oChn.UnitSymbol = sUnit
Set oChn = Data.GetChannel("Room temperatures/Temperature_2") :oChn.UnitSymbol = sUnit
'Build an ElementList with the channel references to those channels that contain the unit symbol = sUnit
'(this is necessary, because each execution of the Rainflow Classification will create new channels,
'preventing the option of just iterating across the channel groups and channels).
Set oElementList = Data.CreateElementList()
For Each oGrp In Data.Root.ChannelGroups
For Each oChn In oGrp.Channels
If StrComp(oChn.UnitSymbol, sUnit, vbTextCompare) = 0 Then
Call LogFileWrite("Found channel '" & oChn.GetReference(eReferenceIndexName) & "' with unit '" & sUnit & "'")
Call LogFileWrite(Str(oElementList.Count) & " channels found with the unit symbol '" & sUnit & "'")
'Perform a Rainflow Classification on the channels in oElementList
For Each oChn In oElementList
'Create a channel group to hold the results
Set oGrp = Data.Root.ChannelGroups.Add(oChn.Name & "_Rainflow")
Call LogFileWrite("Performing Rainflow Classification on channel '" & oChn.GetReference(eReferenceIndexName) & "' and storing results into '" & oGrp.Name & "'")
'Put a copy of the oChn into the new channel group
Set oChnCopy = oGrp.Channels.AddChannel(oChn)
'The command below puts the new channels created by ChnRainCalc() in the same channel group ad oChn
'Here is where you would do the Rainflow Classification
RainResiduumCalc = False
Hysteresis = 0
RainInclFirstLastVal = False
'------- Classification Parameters ------
ClassMeth2 = "Automatic"
ClassNo = 10
ClassBegin = oChnCopy.Minimum
ClassRangeWidth = oChnCopy.Maximum - oChn.Minimum
ClassWidth = ClassRangeWidth/10
ClassEnd = oChnCopy.Maximum
'----------- Result Parameters ----------
RainFrequencyTyp = "Cumulative"
RainChnContain = "Class mean"
RainMatTrans(1) = False
RainMatTrans(2) = False
RainOneParaCalc(1) = True
RainOneParaCalc(2) = True
RainOneParaCalc(3) = True
RainOneParaCalc(4) = True
RainSpecOnePara(1) = True
RainSpecOnePara(2) = True
RainSpecOnePara(3) = True
RainSpecOnePara(4) = True
'------------ Command -------------------
Call ChnRainCalc(oChnCopy, "Automatic", False, 0, "Cumulative")
Thank you markwkiehl!
After just a little bit of tweaking, your code ran great. 240 rainflows with the click of a button.
I'm very excited to try modifying it for use on the many other data types I record and mine.
There is still much for me to learn, but this was very instructional.