DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Write a value to the end of a channel

Solved!
Go to solution

I have an RPM channel with about 100 rpm ranges in it and several other load data channels.  

I am calling the StatBlockCalc command, same as the "descriptive statistics" in the analysis tab on the load channels.

Setting StatBlockCalc to give me the Min/Max/Mean of a block of values from the load channels. 

Each block represents one rpm ranges.

I need to save/write each of these values to their perspective channels: channel Min, channel Max, channel Mean.

I'll call this function repeatedly until I get each Min/Max/Mean value from the various rpm ranges.

After running StatBlockCalc command the variables StatMin, StatMax & StatArithMean are available.

 

What command do I need to use to write the 3 variables to their perspective channels and have them appended to the end of the channel?

Or is there a better way to do this?

 

Thank you for your help, 

Dave

0 Kudos
Message 1 of 5
(2,498 Views)

StatBlockCalc() is obsolete . Use ChnStatisticsBlockCalc() or ChnStatisticsChannelCalc()

It is not clear to me what you mean by "rpm ranges". Can you use my example below to explain that?

You say that you want to add the min, max, and mean values to the end of the channels (and I demonstrate how to do that in the example below), but I'm thinking it would be better to reference those property values. I have attempted to demonstrate that as well.

 

 

'-------------------------------------------------------------------------------
'-- VBS script file
'-- Author: Mark W Kiehl
' www.SavvyDiademSolutions.com
'-------------------------------------------------------------------------------
Option Explicit
Call LogFileDel()

'Load DIAdem example data..
Call Data.Root.Clear(): Portal.NoOfGroupsToExpand = 1
If FileExist(sFilePathDIAdemExample("Example.tdm")) Then
Call DataFileLoadSel(sFilePathDIAdemExample("Example.tdm"),"TDM","[1]/*")
ElseIf FileExist(sFilePathDIAdemExample("Example.tdms")) Then
Call DataFileLoadSel(sFilePathDIAdemExample("Example.tdms"),"TDMS","[1]/*")
ElseIf FileExist(sFilePathDIAdemExample("Example_data.tdm")) Then
Call DataFileLoadSel(sFilePathDIAdemExample("Example_data.tdm"),"TDM","[1]/*")
Else
Call LogFileWrite("DIAdem example files cannot be found")
End If

' ChnStatisticsChannelCalc - calculate characteristic statistical values by channel.
' ChnStatisticsChannelCalc(ChnList1, StatsSelection, [StatsStartIndex], [StatsEndIndex], [StatsUsePopulationFormula], [StatsResultChn], [StatsResultChnNames], [StatsResultChnNameFormat])
' Call SUDDlgShow("Main", ResourceDrv & "AnaChnStatisticsChannel_BlockCalc")
'
' Note: If you specify start/end rows for the calculation, then the result must be written
' to channels rather than file properties. Use the parameter: StatsResultChn = 1
'
' Note that command StatBlockCalc() is obsolete.
Dim oChn
Set oChn = Data.Root.ChannelGroups(1).Channels("RPM")
StatsSelection = eStatsMinimum + eStatsMaximum + eStatsArithmeticMean + eStatsSquareMean + eStatsGeometricMean
StatsUsePopulationFormula= 0
StatsResultChn = 0
StatsResultChnNames= 0
StatsResultChnNameFormat= "NameName"
Call ChnStatisticsChannelCalc(oChn, StatsSelection, , , False, False, False, "NameName")
'See "Result~.." under custom properties for channel "RPM" for min, max, and mean
Call LogFileWrite("Min = " & Str(oChn.Properties("Result~Statistics~ExtremeValues~Minimum").Value,"AutoAdj"))
Call LogFileWrite("Max = " & Str(oChn.Properties("Result~Statistics~ExtremeValues~Minimum").Value,"AutoAdj"))
Call LogFileWrite("Mean = " & Str(oChn.Properties("Result~Statistics~MeanValues~ArithmeticMean").Value,"AutoAdj"))

'Add the mean value to the channel "RPM" as a new last value
Call LogFileWrite("Channel '" & oChn.GetReference(eRefTypeIndexName) & "' size before = " & oChn.Size & "; last value = " & Str(oChn.Values(oChn.Size),"AutoAdj"))
oChn.Values(oChn.Size+1) = oChn.Properties("Result~Statistics~MeanValues~ArithmeticMean").Value
Call LogFileWrite("Channel '" & oChn.GetReference(eRefTypeIndexName) & "' size after = " & oChn.Size & "; last value = " & Str(oChn.Values(oChn.Size),"AutoAdj"))

 

'-------------------------------------------------------------------------------

Function sFilePathDIAdemExample(ByVal sFilename)
'Returns the full absolute file/path for the location of the DIAdem
'example (TDM/TDMS) file sFilename. Looks in the usual places.
'Returns "" if the file cannot be found.
sFilePathDIAdemExample = ""
Dim arrFilePaths, sFilePath, sFolder: ReDim arrFolders(1)
arrFolders(0) = ProgramDrv: arrFolders(1) = CommonDocumentsPath
Call MsgLineDisp("Searching DIAdem examples for file '" & sFilename & "'..")
For Each sFolder In arrFolders
arrFilePaths = DirListGet(sFolder,sFilename,"Date/Time","FullFilenamesRecursive")
If IsArray(arrFilePaths) Then
For Each sFilePath In arrFilePaths
If InStr(1,sFilePath,"Libr",vbTextCompare) = 0 Then
sFilePathDIAdemExample = sFilePath
Exit For
End If
Next
End If
If Len(sFilePathDIAdemExample) > 0 Then Exit For
Next
If IsArray(arrFilePaths) Then Call Erase(arrFilePaths)
If IsArray(arrFolders) Then Call Erase(arrFolders)
Call MsgLineDisp(vbTab)
End Function 'sFilePathDIAdemExample()

0 Kudos
Message 2 of 5
(2,465 Views)

Thanks markwkiehl, you went above and beyond.

Unfortunatly I'm using Diadem 2015 SP2 and ChnStatisticsBlockCalc isn't available in this version, at least according to DIAdem help.

I get your code for finding the Min/Max/Mean but I'm not sure the LogFile commands achieve writing the min, max & mean values to individual channels in the data portal.

Did I misunderstand?

Thanks

 

0 Kudos
Message 3 of 5
(2,406 Views)
Solution
Accepted by Swimmer
Dim Chnl, Mean
Set Chnl = Data.Root.ChannelGroups(X).Channels(Y)
Mean = Chnl.Properties("Result~Statistics~MeanValues~ArithmeticMean").Value
Chnl.Values(Chnl.Size + 1) = Mean

Here I set the last value of that channel to the mean of that channel.  Just replace the X Y with group and channel number/name and add any other values you want to the end.

Message 4 of 5
(2,394 Views)

You are correct, the LogFileWrite() command doesn't write the values anywhere but the LogFile.  This was just extra information.  I should have added a comment before the command below, letting you know this is the command that updates the last channel value.  Variable oChn references the channel.  The .Values() allows you to assign a value to a row.  Below I reference a new row for the channel with oChn.Size+1.  Everything to the right of the equal sign gets the channel property value that I added previously.  

 

oChn.Values(oChn.Size+1) = oChn.Properties("Result~Statistics~MeanValues~ArithmeticMean").Value

0 Kudos
Message 5 of 5
(2,348 Views)